From 33358c76eccfc8eb0a878b464f2606eb5c4c329f Mon Sep 17 00:00:00 2001 From: SupraJames Date: Fri, 14 Nov 2025 17:45:11 +0000 Subject: [PATCH] Consolidate RSC funcs --- clone_oracle_database.py | 3 +- introspect_schema.py | 3 +- list_db_snapshots.py | 3 +- list_oracle_databases.py | 3 +- rsc_auth.py => rsc.py | 108 ++++++++++++++++++++++++++++++++++++++- rsc_graphql.py | 108 --------------------------------------- 6 files changed, 111 insertions(+), 117 deletions(-) rename rsc_auth.py => rsc.py (51%) delete mode 100644 rsc_graphql.py diff --git a/clone_oracle_database.py b/clone_oracle_database.py index 3ef4108..f527735 100644 --- a/clone_oracle_database.py +++ b/clone_oracle_database.py @@ -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""" diff --git a/introspect_schema.py b/introspect_schema.py index 2d4ebf1..441708a 100644 --- a/introspect_schema.py +++ b/introspect_schema.py @@ -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""" diff --git a/list_db_snapshots.py b/list_db_snapshots.py index 38b50a1..09e87a0 100644 --- a/list_db_snapshots.py +++ b/list_db_snapshots.py @@ -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): diff --git a/list_oracle_databases.py b/list_oracle_databases.py index 0e486a3..e643ec4 100644 --- a/list_oracle_databases.py +++ b/list_oracle_databases.py @@ -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(): diff --git a/rsc_auth.py b/rsc.py similarity index 51% rename from rsc_auth.py rename to rsc.py index 88f005b..09505fd 100644 --- a/rsc_auth.py +++ b/rsc.py @@ -78,4 +78,110 @@ class RSCAuth: return { 'Authorization': f'Bearer {self.get_token()}', 'Content-Type': 'application/json' - } \ No newline at end of file + } + +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}) \ No newline at end of file diff --git a/rsc_graphql.py b/rsc_graphql.py deleted file mode 100644 index 9012d95..0000000 --- a/rsc_graphql.py +++ /dev/null @@ -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}) \ No newline at end of file