Skip to content

Commit ca2bc00

Browse files
authored
Merge pull request #355 from pconstr/update-delete-registry-auth
add wrappers for UpdateRegistryAuth and UpdateRegistryAuth.
2 parents 345d9d0 + affd202 commit ca2bc00

4 files changed

Lines changed: 129 additions & 0 deletions

File tree

runpod/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
create_endpoint,
1010
create_pod,
1111
create_template,
12+
delete_container_registry_auth,
1213
get_endpoints,
1314
get_gpu,
1415
get_gpus,
@@ -18,6 +19,7 @@
1819
resume_pod,
1920
stop_pod,
2021
terminate_pod,
22+
update_container_registry_auth,
2123
update_endpoint_template,
2224
update_user_settings,
2325
)

runpod/api/ctl_commands.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,38 @@ def create_container_registry_auth(name: str, username: str, password: str):
371371
)
372372
)
373373
return raw_response["data"]["saveRegistryAuth"]
374+
375+
376+
def update_container_registry_auth(registry_auth_id: str, username: str, password: str):
377+
"""
378+
Update a container registry authentication.
379+
380+
Args:
381+
registry_auth_id (str): The id of the container registry authentication
382+
username (str): The username for authentication.
383+
password (str): The password for authentication.
384+
385+
Returns:
386+
dict: The response data containing the updated container registry authentication.
387+
"""
388+
raw_response = run_graphql_query(
389+
container_register_auth_mutations.update_container_registry_auth(
390+
registry_auth_id, username, password
391+
)
392+
)
393+
return raw_response["data"]["updateRegistryAuth"]
394+
395+
396+
def delete_container_registry_auth(registry_auth_id: str):
397+
"""
398+
Delete a container registry authentication.
399+
400+
Args:
401+
registry_auth_id (str): The id of the container registry authentication
402+
"""
403+
raw_response = run_graphql_query(
404+
container_register_auth_mutations.delete_container_registry_auth(
405+
registry_auth_id
406+
)
407+
)
408+
return raw_response["data"]["deleteRegistryAuth"]

runpod/api/mutations/container_register_auth.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,49 @@ def generate_container_registry_auth(name: str, username: str, password: str):
2727
}}
2828
}}
2929
"""
30+
31+
32+
def update_container_registry_auth(registry_auth_id: str, username: str, password: str):
33+
"""
34+
Generate a GraphQL mutation string to update registry authentication details.
35+
36+
Args:
37+
registry_auth_id (str): The id of the container registry authentication
38+
username (str): The username for authentication.
39+
password (str): The password for authentication.
40+
41+
Returns:
42+
str: The GraphQL mutation string.
43+
"""
44+
# Prepare the input dictionary
45+
input_dict = {"id": registry_auth_id, "username": username, "password": password}
46+
47+
# Convert the input dictionary to a string, properly formatted for GraphQL
48+
input_str = ", ".join(f'{key}: "{value}"' for key, value in input_dict.items())
49+
50+
return f"""
51+
mutation UpdateRegistryAuth {{
52+
updateRegistryAuth(input: {{{input_str}}}) {{
53+
id
54+
name
55+
}}
56+
}}
57+
"""
58+
59+
60+
def delete_container_registry_auth(registry_auth_id: str):
61+
"""
62+
Generate a GraphQL mutation string to delete registry authentication details.
63+
64+
Args:
65+
registry_auth_id (str): The id of the container registry authentication
66+
67+
Returns:
68+
str: The GraphQL mutation string.
69+
"""
70+
71+
return f"""
72+
mutation DeleteRegistryAuth {{
73+
deleteRegistryAuth(registryAuthId: "{registry_auth_id}")
74+
}}
75+
"""

tests/test_api/test_mutation_container_registry_auth.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import unittest
44

55
from runpod.api.mutations.container_register_auth import (
6+
delete_container_registry_auth,
67
generate_container_registry_auth,
8+
update_container_registry_auth
79
)
810

911

@@ -33,3 +35,47 @@ def test_generate_container_registry_auth(self):
3335
)
3436
self.assertIn("id", actual_mutation)
3537
self.assertIn("name", actual_mutation)
38+
39+
def test_update_container_registry_auth(self):
40+
"""
41+
Test that the update_container_registry_auth function produces the correct
42+
GraphQL mutation string with the provided registry_auth_id, username and password.
43+
"""
44+
# Define test inputs
45+
registry_auth_id = "testAuthId"
46+
username = "testUser"
47+
password = "testPass"
48+
49+
# Generate the actual mutation string
50+
actual_mutation = update_container_registry_auth(
51+
registry_auth_id, username, password
52+
).strip()
53+
54+
# Verify key components of the mutation string
55+
self.assertIn("mutation UpdateRegistryAuth", actual_mutation)
56+
self.assertIn(
57+
'updateRegistryAuth(input: {id: "testAuthId", username: "testUser", password: "testPass"})', # pylint: disable=line-too-long
58+
actual_mutation,
59+
)
60+
self.assertIn("id", actual_mutation)
61+
self.assertIn("name", actual_mutation)
62+
63+
def test_delete_container_registry_auth(self):
64+
"""
65+
Test that the delete_container_registry_auth function produces the correct
66+
GraphQL mutation string with the provided registry_auth_id
67+
"""
68+
# Define test inputs
69+
registry_auth_id = "testAuthId"
70+
71+
# Generate the actual mutation string
72+
actual_mutation = delete_container_registry_auth(
73+
registry_auth_id
74+
).strip()
75+
76+
# Verify key components of the mutation string
77+
self.assertIn("mutation DeleteRegistryAuth", actual_mutation)
78+
self.assertIn(
79+
'deleteRegistryAuth(registryAuthId: "testAuthId")', # pylint: disable=line-too-long
80+
actual_mutation,
81+
)

0 commit comments

Comments
 (0)