Consolidate RSC funcs
This commit is contained in:
@@ -6,8 +6,7 @@ import os
|
||||
import argparse
|
||||
import time
|
||||
from datetime import datetime
|
||||
from rsc_auth import RSCAuth
|
||||
from rsc_graphql import RSCGraphQL
|
||||
from rsc import RSCAuth, RSCGraphQL
|
||||
|
||||
def parse_options_file(options_file):
|
||||
"""Parse the options file containing Oracle parameters"""
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
import json
|
||||
import sys
|
||||
from rsc_auth import RSCAuth
|
||||
from rsc_graphql import RSCGraphQL
|
||||
from rsc import RSCAuth, RSCGraphQL
|
||||
|
||||
def explore_oracle_types():
|
||||
"""Explore Oracle-related types in the GraphQL schema"""
|
||||
|
||||
@@ -4,8 +4,7 @@ import json
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime
|
||||
from rsc_auth import RSCAuth
|
||||
from rsc_graphql import RSCGraphQL
|
||||
from rsc import RSCAuth, RSCGraphQL
|
||||
from tabulate import tabulate
|
||||
|
||||
def find_database_by_name_or_id(identifier):
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
from rsc_auth import RSCAuth
|
||||
from rsc_graphql import RSCGraphQL
|
||||
from rsc import RSCAuth, RSCGraphQL
|
||||
from tabulate import tabulate
|
||||
|
||||
def list_oracle_databases():
|
||||
|
||||
@@ -78,4 +78,110 @@ class RSCAuth:
|
||||
return {
|
||||
'Authorization': f'Bearer {self.get_token()}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
|
||||
class RSCGraphQL:
|
||||
def __init__(self, auth):
|
||||
self.auth = auth
|
||||
self.endpoint = f"https://{self.auth.host}/api/graphql"
|
||||
|
||||
def query(self, query, variables=None):
|
||||
payload = {'query': query}
|
||||
if variables:
|
||||
payload['variables'] = variables
|
||||
|
||||
headers = self.auth.get_headers()
|
||||
response = requests.post(self.endpoint, json=payload, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
|
||||
# Check for GraphQL errors
|
||||
if 'errors' in data:
|
||||
raise Exception(f"GraphQL errors: {data['errors']}")
|
||||
|
||||
return data
|
||||
|
||||
def introspect_schema(self):
|
||||
"""Introspect the GraphQL schema to get type information"""
|
||||
introspection_query = """
|
||||
query IntrospectionQuery {
|
||||
__schema {
|
||||
types {
|
||||
name
|
||||
kind
|
||||
description
|
||||
fields(includeDeprecated: true) {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
args {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
return self.query(introspection_query)
|
||||
|
||||
def get_type_info(self, type_name):
|
||||
"""Get detailed information about a specific GraphQL type"""
|
||||
query = """
|
||||
query GetTypeInfo($typeName: String!) {
|
||||
__type(name: $typeName) {
|
||||
name
|
||||
kind
|
||||
description
|
||||
fields(includeDeprecated: true) {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
args {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
return self.query(query, {"typeName": type_name})
|
||||
108
rsc_graphql.py
108
rsc_graphql.py
@@ -1,108 +0,0 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
class RSCGraphQL:
|
||||
def __init__(self, auth):
|
||||
self.auth = auth
|
||||
self.endpoint = f"https://{self.auth.host}/api/graphql"
|
||||
|
||||
def query(self, query, variables=None):
|
||||
payload = {'query': query}
|
||||
if variables:
|
||||
payload['variables'] = variables
|
||||
|
||||
headers = self.auth.get_headers()
|
||||
response = requests.post(self.endpoint, json=payload, headers=headers)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
|
||||
# Check for GraphQL errors
|
||||
if 'errors' in data:
|
||||
raise Exception(f"GraphQL errors: {data['errors']}")
|
||||
|
||||
return data
|
||||
|
||||
def introspect_schema(self):
|
||||
"""Introspect the GraphQL schema to get type information"""
|
||||
introspection_query = """
|
||||
query IntrospectionQuery {
|
||||
__schema {
|
||||
types {
|
||||
name
|
||||
kind
|
||||
description
|
||||
fields(includeDeprecated: true) {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
args {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
return self.query(introspection_query)
|
||||
|
||||
def get_type_info(self, type_name):
|
||||
"""Get detailed information about a specific GraphQL type"""
|
||||
query = """
|
||||
query GetTypeInfo($typeName: String!) {
|
||||
__type(name: $typeName) {
|
||||
name
|
||||
kind
|
||||
description
|
||||
fields(includeDeprecated: true) {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
args {
|
||||
name
|
||||
description
|
||||
type {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
ofType {
|
||||
name
|
||||
kind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
return self.query(query, {"typeName": type_name})
|
||||
Reference in New Issue
Block a user