rsc-client 1.0.20260413__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "[0-9]*"
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ environment: pypi
12
+ permissions:
13
+ id-token: write
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.11"
19
+ - run: pip install hatch
20
+ - run: hatch build
21
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,76 @@
1
+ name: Update Schema
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - "schemas/*.graphql"
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ generate:
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.11"
23
+
24
+ - name: Install dependencies
25
+ run: pip install sgqlc graphql-core hatch twine
26
+
27
+ - name: Find latest schema file
28
+ id: schema
29
+ run: |
30
+ SCHEMA_FILE=$(ls schemas/*.graphql | sort | tail -1)
31
+ BASENAME=$(basename "$SCHEMA_FILE" .graphql)
32
+ CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
33
+ MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
34
+ MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
35
+ VERSION="${MAJOR}.${MINOR}.${BASENAME}"
36
+ echo "file=$SCHEMA_FILE" >> "$GITHUB_OUTPUT"
37
+ echo "date=$BASENAME" >> "$GITHUB_OUTPUT"
38
+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
39
+
40
+ - name: Convert SDL to introspection JSON
41
+ run: |
42
+ python3 - <<'EOF'
43
+ import json
44
+ from graphql import build_schema, introspection_from_schema
45
+ with open("${{ steps.schema.outputs.file }}") as f:
46
+ sdl = f.read()
47
+ schema = build_schema(sdl)
48
+ result = introspection_from_schema(schema)
49
+ with open("/tmp/rsc_schema.json", "w") as f:
50
+ json.dump({"data": result}, f)
51
+ EOF
52
+
53
+ - name: Generate schema bindings
54
+ run: python3 -m sgqlc.codegen schema /tmp/rsc_schema.json src/rsc/schema.py
55
+
56
+ - name: Generate operation index
57
+ run: PYTHONPATH=src python3 -m rsc.mcp_indexer
58
+
59
+ - name: Update version in pyproject.toml
60
+ run: |
61
+ VERSION="${{ steps.schema.outputs.version }}"
62
+ sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
63
+
64
+ - name: Commit and tag
65
+ run: |
66
+ git config user.name "github-actions[bot]"
67
+ git config user.email "github-actions[bot]@users.noreply.github.com"
68
+ git add src/rsc/schema.py src/rsc/mcp_index.json src/rsc/mcp_types.json pyproject.toml
69
+ git restore --staged .github/
70
+ git commit -m "chore: generate schema for ${{ steps.schema.outputs.date }}"
71
+ git tag "${{ steps.schema.outputs.version }}"
72
+ git pull --rebase origin main
73
+ git push origin main --tags
74
+
75
+ - name: Build
76
+ run: hatch build
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .DS_Store
7
+ .venv/
8
+ *.egg
9
+ .claude/
@@ -0,0 +1,95 @@
1
+ # RSC Python GraphQL Client
2
+
3
+ Python client for the Rubrik Security Cloud (RSC) GraphQL API. Provides authenticated GraphQL execution, OAuth2 token management, a generated typed schema, and a discovery index for all available operations.
4
+
5
+ ## Project structure
6
+
7
+ ```
8
+ src/rsc/
9
+ __init__.py # Exports RSCClient + index functions
10
+ client.py # RSCClient — execute queries/mutations
11
+ config.py # Credential loading (env vars, files)
12
+ auth.py # OAuth2 token management + caching
13
+ schema.py # Auto-generated sgqlc type bindings (DO NOT EDIT)
14
+ index.py # Discovery functions (search_operations, describe_operation, ...)
15
+ mcp_index.json # Pre-generated operations index (DO NOT EDIT — regenerated by CI)
16
+ mcp_types.json # Pre-generated types index (DO NOT EDIT — regenerated by CI)
17
+ mcp_indexer.py # Script that builds the two JSON files above from the SDL
18
+
19
+ schemas/ # GraphQL SDL source files (YYYYMMDD.graphql)
20
+ ```
21
+
22
+ ## Important constraints
23
+
24
+ - **`src/rsc/schema.py`** — auto-generated by `sgqlc.codegen`. Never edit by hand.
25
+ - **`src/rsc/mcp_index.json` and `mcp_types.json`** — auto-generated by `mcp_indexer.py`. Never edit by hand.
26
+ - **`schemas/*.graphql`** — the SDL is the source of truth for all schema changes.
27
+ - No new runtime dependencies should be added without good reason. Current deps: `sgqlc`, `requests`. `graphql-core` is a transitive dep of `sgqlc` and is used at build time only.
28
+
29
+ ## Key APIs
30
+
31
+ ### RSCClient
32
+
33
+ ```python
34
+ from rsc import RSCClient
35
+
36
+ client = RSCClient() # loads creds from env / ~/.rsc/config.json
37
+ client = RSCClient(service_account_file="path/to/sa.json")
38
+ client.execute("query { accountId }") # raw GraphQL string
39
+ client.execute("query { accountId }", variables={...}) # with variables
40
+ client.execute(sgqlc_operation) # typed sgqlc Operation
41
+ ```
42
+
43
+ ### Discovery index
44
+
45
+ ```python
46
+ from rsc import search_operations, describe_operation, describe_type, list_queries, list_mutations, list_types
47
+
48
+ search_operations("snapshot", "query") # [{name, type, description, return_type}]
49
+ describe_operation("slaDomains", "query") # {name, type, description, return_type, args}
50
+ describe_type("CreateGlobalSlaInput") # {name, kind, fields: {fieldName: {type, description}}}
51
+ describe_type("SlaAssignTypeEnum") # {name, kind, values: [...]}
52
+ list_queries() # [camelCase names]
53
+ list_mutations()
54
+ list_types()
55
+ ```
56
+
57
+ Operation names are camelCase (as in GraphQL), e.g. `slaDomains`, `vSphereVmNewConnection`. The sgqlc Python API uses snake_case equivalents.
58
+
59
+ ## Updating the schema
60
+
61
+ Replace the existing SDL file and push — CI handles everything:
62
+
63
+ ```bash
64
+ rm schemas/*.graphql
65
+ cp ~/Downloads/rsc-schema.graphql schemas/$(date +%Y%m%d).graphql
66
+ git add schemas/
67
+ git commit -m "schema: replace with YYYYMMDD"
68
+ git push origin main
69
+ ```
70
+
71
+ CI will: generate `schema.py`, regenerate `mcp_index.json`/`mcp_types.json`, bump version to `X.Y.YYYYMMDD`, commit, tag, and publish to PyPI.
72
+
73
+ ## Regenerating the index locally
74
+
75
+ After adding a new schema or modifying `mcp_indexer.py`:
76
+
77
+ ```bash
78
+ PYTHONPATH=src python3 -m rsc.mcp_indexer
79
+ ```
80
+
81
+ Commit the resulting `mcp_index.json` and `mcp_types.json`.
82
+
83
+ ## Versioning
84
+
85
+ Format: `X.Y.YYYYMMDD` (e.g. `1.0.20260316`)
86
+ - **YYYYMMDD** — bumped automatically by CI for each new schema
87
+ - **X.Y** — bumped manually for breaking (major) or additive (minor) library API changes
88
+
89
+ ## Credential loading precedence
90
+
91
+ 1. `RSC_SERVICE_ACCOUNT_FILE` env var (path to service account JSON)
92
+ 2. `RSC_URL` + `RSC_CLIENT_ID` + `RSC_CLIENT_SECRET` env vars
93
+ 3. `~/.rsc/config.json` (direct credentials or `service_account_file` pointer)
94
+
95
+ Tokens are cached in `~/.rsc/token_cache_<url-hash>.json` with `0600` permissions and reused until 60 seconds before expiry.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rubrik, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.4
2
+ Name: rsc-client
3
+ Version: 1.0.20260413
4
+ Summary: Low-level Python bindings for the Rubrik Security Cloud GraphQL API
5
+ Project-URL: Homepage, https://github.com/rubrikinc/rubrik-security-cloud-python-graphql-client
6
+ Project-URL: Repository, https://github.com/rubrikinc/rubrik-security-cloud-python-graphql-client
7
+ Project-URL: Bug Tracker, https://github.com/rubrikinc/rubrik-security-cloud-python-graphql-client/issues
8
+ Author: Rubrik, Inc.
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 Rubrik, Inc.
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: api,backup,client,graphql,rsc,rubrik,security
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.9
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
41
+ Requires-Python: >=3.9
42
+ Requires-Dist: requests>=2.28
43
+ Requires-Dist: sgqlc>=9.0
44
+ Description-Content-Type: text/markdown
45
+
46
+ # rubrik-security-cloud-python-graphql-client
47
+
48
+ Python client for the Rubrik Security Cloud (RSC) GraphQL API. Provides authenticated GraphQL execution via [sgqlc](https://github.com/profusion/sgqlc), with OAuth2 token management and a generated typed schema so you never have to write raw GraphQL strings.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install rsc-client
54
+ ```
55
+
56
+ To install directly from this repo:
57
+
58
+ ```bash
59
+ pip install git+https://github.com/rubrikinc/rubrik-security-cloud-python-graphql-client.git
60
+ ```
61
+
62
+ ## Authentication
63
+
64
+ ### Service account file (recommended)
65
+
66
+ Download a service account JSON file from the RSC UI (**Access Control → Service Accounts**) and pass it to the client:
67
+
68
+ ```python
69
+ from rsc import RSCClient
70
+
71
+ client = RSCClient(service_account_file="~/Downloads/my-service-account.json")
72
+ ```
73
+
74
+ Or set an environment variable and call `RSCClient()` with no arguments:
75
+
76
+ ```bash
77
+ export RSC_SERVICE_ACCOUNT_FILE=~/Downloads/my-service-account.json
78
+ ```
79
+
80
+ ### `~/.rsc/config.json`
81
+
82
+ ```json
83
+ {
84
+ "url": "https://myaccount.my.rubrik.com",
85
+ "client_id": "client|...",
86
+ "client_secret": "..."
87
+ }
88
+ ```
89
+
90
+ You can also point this file at a service account file:
91
+
92
+ ```json
93
+ {
94
+ "service_account_file": "/path/to/service-account.json"
95
+ }
96
+ ```
97
+
98
+ ### Environment variables
99
+
100
+ | Variable | Description |
101
+ |---|---|
102
+ | `RSC_SERVICE_ACCOUNT_FILE` | Path to a service account JSON file |
103
+ | `RSC_URL` | RSC base URL |
104
+ | `RSC_CLIENT_ID` | OAuth2 client ID |
105
+ | `RSC_CLIENT_SECRET` | OAuth2 client secret |
106
+
107
+ **Precedence:** `RSC_SERVICE_ACCOUNT_FILE` → `RSC_URL`/`RSC_CLIENT_ID`/`RSC_CLIENT_SECRET` → `~/.rsc/config.json`
108
+
109
+ ---
110
+
111
+ ## Usage
112
+
113
+ `RSCClient.execute()` accepts either a raw GraphQL string or an sgqlc `Operation`. The sgqlc approach is recommended — it gives you typed, auto-completed Python objects and catches field name errors before the request is sent.
114
+
115
+ ### Query example — list SLA domains
116
+
117
+ <table>
118
+ <tr><th>Raw GraphQL string</th><th>sgqlc Operation</th></tr>
119
+ <tr>
120
+ <td>
121
+
122
+ ```python
123
+ result = client.execute("""
124
+ query {
125
+ slaDomains {
126
+ nodes {
127
+ id
128
+ name
129
+ }
130
+ }
131
+ }
132
+ """)
133
+
134
+ for node in result['data']['slaDomains']['nodes']:
135
+ print(node['id'], node['name'])
136
+ ```
137
+
138
+ </td>
139
+ <td>
140
+
141
+ ```python
142
+ from sgqlc.operation import Operation
143
+ from rsc.schema import Query
144
+
145
+ op = Operation(Query)
146
+ nodes = op.sla_domains().nodes()
147
+ nodes.__fields__('id', 'name')
148
+
149
+ result = client.execute(op)
150
+
151
+ # Deserialize into typed objects
152
+ data = (op + result).sla_domains
153
+ for node in data.nodes:
154
+ print(node.id, node.name)
155
+ ```
156
+
157
+ </td>
158
+ </tr>
159
+ </table>
160
+
161
+ ### Mutation example — assign an SLA domain
162
+
163
+ <table>
164
+ <tr><th>Raw GraphQL string</th><th>sgqlc Operation</th></tr>
165
+ <tr>
166
+ <td>
167
+
168
+ ```python
169
+ result = client.execute("""
170
+ mutation {
171
+ assignSla(input: {
172
+ objectIds: ["<object-id>"],
173
+ slaDomainAssignType: PROTECT,
174
+ slaOptionalId: "<sla-id>"
175
+ }) {
176
+ success
177
+ }
178
+ }
179
+ """)
180
+
181
+ print(result['data']['assignSla']['success'])
182
+ ```
183
+
184
+ </td>
185
+ <td>
186
+
187
+ ```python
188
+ from sgqlc.operation import Operation
189
+ from rsc.schema import Mutation, AssignSlaInput, SlaAssignTypeEnum
190
+
191
+ op = Operation(Mutation)
192
+ result_field = op.assign_sla(input=AssignSlaInput(
193
+ object_ids=["<object-id>"],
194
+ sla_domain_assign_type=SlaAssignTypeEnum.PROTECT,
195
+ sla_optional_id="<sla-id>",
196
+ ))
197
+ result_field.__fields__('success')
198
+
199
+ result = client.execute(op)
200
+
201
+ data = (op + result).assign_sla
202
+ print(data.success)
203
+ ```
204
+
205
+ </td>
206
+ </tr>
207
+ </table>
208
+
209
+ ---
210
+
211
+ ## Discovery index
212
+
213
+ The package ships two pre-generated JSON indexes built from the GraphQL SDL: `mcp_index.json` (all queries and mutations with their argument signatures) and `mcp_types.json` (all named types with their fields, enum values, or union members). These are parsed once at import time and cached in memory.
214
+
215
+ ### Why it exists
216
+
217
+ A common mistake when building an MCP server for a GraphQL API is to create one MCP tool per operation — a pattern that produces thousands of redundant tools and defeats the purpose of both technologies. GraphQL was designed so that a single endpoint can express any query or mutation; MCP tools should reflect that by exposing a small, generic surface: one tool to search operations, one to describe an operation, one to execute it. The LLM then does what it's good at — using those tools to discover and compose the right call at runtime.
218
+
219
+ The discovery index makes this practical. The RSC schema is large, and an LLM needs a fast way to answer "what operations exist and how do I call them?" without parsing the raw SDL on every request. The indexes are pre-built by CI whenever the schema changes and committed into the package, so discovery works instantly with no credentials, no network access, and no heavy runtime dependencies.
220
+
221
+ ### Functions
222
+
223
+ ```python
224
+ from rsc import (
225
+ search_operations, # full-text search across names + descriptions
226
+ describe_operation, # full argument signature for one operation
227
+ describe_type, # fields/values for any named type
228
+ list_queries, # all query names
229
+ list_mutations, # all mutation names
230
+ list_types, # all type names
231
+ )
232
+ ```
233
+
234
+ #### `search_operations(search, operation_type="all")`
235
+
236
+ Case-insensitive substring search across operation names and descriptions. Useful for finding the right operation when you know roughly what you're looking for.
237
+
238
+ ```python
239
+ search_operations("snapshot", "query")
240
+ # [{"name": "...", "type": "query", "description": "...", "return_type": "..."}, ...]
241
+
242
+ search_operations("assign", "mutation")
243
+ ```
244
+
245
+ #### `describe_operation(name, operation_type)`
246
+
247
+ Returns the full argument signature for a single query or mutation. Operation names are camelCase as they appear in GraphQL (e.g. `vSphereVmNewConnection`).
248
+
249
+ ```python
250
+ op = describe_operation("slaDomains", "query")
251
+ # {
252
+ # "name": "slaDomains",
253
+ # "type": "query",
254
+ # "description": "...",
255
+ # "return_type": "SlaDomainConnection",
256
+ # "args": {
257
+ # "filter": {"type": "[Filter!]", "description": "..."},
258
+ # ...
259
+ # }
260
+ # }
261
+ ```
262
+
263
+ #### `describe_type(name)`
264
+
265
+ Returns the fields (with types and descriptions) for object/input/interface types, the possible values for enums, or the member types for unions.
266
+
267
+ ```python
268
+ describe_type("CreateGlobalSlaInput")
269
+ # {"name": "CreateGlobalSlaInput", "kind": "input", "fields": {"name": {"type": "String!", ...}, ...}}
270
+
271
+ describe_type("SlaAssignTypeEnum")
272
+ # {"name": "SlaAssignTypeEnum", "kind": "enum", "values": ["PROTECT", "UNPROTECT", ...]}
273
+ ```
274
+
275
+ ### Keeping the index in sync
276
+
277
+ The indexes are regenerated automatically by the CI workflow whenever a new schema file is added. To regenerate locally after adding a schema or modifying `mcp_indexer.py`:
278
+
279
+ ```bash
280
+ PYTHONPATH=src python3 -m rsc.mcp_indexer
281
+ ```
282
+
283
+ Then commit the updated `mcp_index.json` and `mcp_types.json`.
284
+
285
+ ---
286
+
287
+ ## Token caching
288
+
289
+ Tokens are cached in `~/.rsc/token_cache_<hash>.json` (`0600` permissions) and reused until 60 seconds before expiry. Short-lived callers like cron jobs or Telegraf scripts won't re-authenticate on every run. Cache files are keyed by a hash of the RSC URL so multiple accounts on the same machine stay isolated.