trainml 0.5.11__py3-none-any.whl → 0.5.13__py3-none-any.whl

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.
@@ -4,7 +4,7 @@ from pytest import fixture
4
4
  @fixture(scope="module")
5
5
  async def project(trainml):
6
6
  project = await trainml.projects.create(
7
- name="New Project", copy_keys=False, copy_secrets=False
7
+ name="New Project", copy_credentials=False, copy_secrets=False
8
8
  )
9
9
  yield project
10
10
  await project.remove()
@@ -0,0 +1,45 @@
1
+ import re
2
+ import sys
3
+ import asyncio
4
+ from pytest import mark, fixture
5
+
6
+ pytestmark = [mark.sdk, mark.integration, mark.projects]
7
+
8
+
9
+ @mark.create
10
+ @mark.asyncio
11
+ class ProjectCredentialsTests:
12
+ @fixture(scope="class")
13
+ async def project_credential(self, project):
14
+ project_credential = await project.credentials.put(
15
+ type="aws", key_id="ASFHALKF", secret="IUHKLHKAHF"
16
+ )
17
+ yield project_credential
18
+ await project.credentials.remove(type="aws")
19
+
20
+ async def test_list_project_credentials(self, project, project_credential):
21
+ credentials = await project.credentials.list()
22
+ assert len(credentials) > 0
23
+
24
+ async def test_project_credential_properties(self, project, project_credential):
25
+ assert isinstance(project_credential.project_uuid, str)
26
+ assert isinstance(project_credential.type, str)
27
+ assert isinstance(project_credential.key_id, str)
28
+ assert project_credential.type == "aws"
29
+ assert project.id == project_credential.project_uuid
30
+
31
+ async def test_project_credential_str(self, project_credential):
32
+ string = str(project_credential)
33
+ regex = r"^{.*\"type\": \"" + project_credential.type + r"\".*}$"
34
+ assert isinstance(string, str)
35
+ assert re.match(regex, string)
36
+
37
+ async def test_project_credential_repr(self, project_credential):
38
+ string = repr(project_credential)
39
+ regex = (
40
+ r"^ProjectCredential\( trainml , \*\*{.*'type': '"
41
+ + project_credential.type
42
+ + r"'.*}\)$"
43
+ )
44
+ assert isinstance(string, str)
45
+ assert re.match(regex, string)
@@ -17,7 +17,7 @@ class ProjectSecretsTests:
17
17
  yield project_secret
18
18
  await project.secrets.remove(name="secret_value")
19
19
 
20
- async def test_list_project_keys(self, project, project_secret):
20
+ async def test_list_project_secrets(self, project, project_secret):
21
21
  secrets = await project.secrets.list()
22
22
  assert len(secrets) > 0
23
23
 
@@ -175,7 +175,7 @@ class JobAPIResourceValidationTests:
175
175
  disk_size=10,
176
176
  )
177
177
  assert (
178
- "Invalid Request - None (CPU Only) may be not be combined with other GPU Types"
178
+ "Invalid Request - CPU Only may be not be combined with other GPU Types"
179
179
  in error.value.message
180
180
  )
181
181
 
@@ -0,0 +1,26 @@
1
+ import re
2
+ import json
3
+ import click
4
+ from unittest.mock import AsyncMock, patch, create_autospec
5
+ from pytest import mark, fixture, raises
6
+
7
+ pytestmark = [mark.cli, mark.unit, mark.projects]
8
+
9
+ from trainml.cli.project import credential as specimen
10
+ from trainml.projects import (
11
+ Project,
12
+ )
13
+
14
+
15
+ def test_list_credentials(runner, mock_project_credentials):
16
+ with patch("trainml.cli.TrainML", new=AsyncMock) as mock_trainml:
17
+ project = create_autospec(Project)
18
+ mock_trainml.projects = AsyncMock()
19
+ mock_trainml.projects.get = AsyncMock(return_value=project)
20
+ mock_trainml.projects.get_current = AsyncMock(return_value=project)
21
+ project.credentials = AsyncMock()
22
+ project.credentials.list = AsyncMock(return_value=mock_project_credentials)
23
+ result = runner.invoke(specimen, ["list"])
24
+ print(result)
25
+ assert result.exit_code == 0
26
+ project.credentials.list.assert_called_once()
tests/unit/conftest.py CHANGED
@@ -20,7 +20,7 @@ from trainml.projects import (
20
20
  from trainml.projects.datastores import ProjectDatastores, ProjectDatastore
21
21
  from trainml.projects.services import ProjectServices, ProjectService
22
22
  from trainml.projects.data_connectors import ProjectDataConnectors, ProjectDataConnector
23
- from trainml.projects.keys import ProjectKeys, ProjectKey
23
+ from trainml.projects.credentials import ProjectCredentials, ProjectCredential
24
24
  from trainml.projects.secrets import ProjectSecrets, ProjectSecret
25
25
 
26
26
  from trainml.cloudbender import Cloudbender
@@ -532,7 +532,7 @@ def mock_jobs():
532
532
  {"value": "env1val", "key": "env1"},
533
533
  {"value": "env2val", "key": "env2"},
534
534
  ],
535
- "worker_key_types": ["aws", "gcp"],
535
+ "credentials": ["aws", "gcp"],
536
536
  "status": "new",
537
537
  },
538
538
  "vpn": {
@@ -609,7 +609,7 @@ def mock_jobs():
609
609
  "type": "DEEPLEARNING_PY37",
610
610
  "image_size": 39656398629,
611
611
  "env": [],
612
- "worker_key_types": [],
612
+ "credentials": [],
613
613
  "status": "ready",
614
614
  },
615
615
  "vpn": {
@@ -1043,10 +1043,10 @@ def mock_device_configs():
1043
1043
  @fixture(
1044
1044
  scope="session",
1045
1045
  )
1046
- def mock_project_keys():
1046
+ def mock_project_credentials():
1047
1047
  trainml = Mock()
1048
1048
  yield [
1049
- ProjectKey(
1049
+ ProjectCredential(
1050
1050
  trainml,
1051
1051
  **{
1052
1052
  "project_uuid": "proj-id-1",
@@ -1055,7 +1055,7 @@ def mock_project_keys():
1055
1055
  "updatedAt": "2023-06-02T21:22:40.084Z",
1056
1056
  },
1057
1057
  ),
1058
- ProjectKey(
1058
+ ProjectCredential(
1059
1059
  trainml,
1060
1060
  **{
1061
1061
  "project_uuid": "proj-id-1",
@@ -1117,7 +1117,7 @@ def mock_trainml(
1117
1117
  mock_project_datastores,
1118
1118
  mock_project_services,
1119
1119
  mock_project_data_connectors,
1120
- mock_project_keys,
1120
+ mock_project_credentials,
1121
1121
  mock_project_secrets,
1122
1122
  ):
1123
1123
  trainml = create_autospec(TrainML)
@@ -1150,8 +1150,8 @@ def mock_trainml(
1150
1150
  trainml.projects.data_connectors.list = AsyncMock(
1151
1151
  return_value=mock_project_data_connectors
1152
1152
  )
1153
- trainml.projects.keys = create_autospec(ProjectKeys)
1154
- trainml.projects.keys.list = AsyncMock(return_value=mock_project_keys)
1153
+ trainml.projects.credentials = create_autospec(ProjectCredentials)
1154
+ trainml.projects.credentials.list = AsyncMock(return_value=mock_project_credentials)
1155
1155
  trainml.projects.secrets = create_autospec(ProjectSecrets)
1156
1156
  trainml.projects.secrets.list = AsyncMock(return_value=mock_project_secrets)
1157
1157
 
@@ -0,0 +1,100 @@
1
+ import re
2
+ import json
3
+ import logging
4
+ from unittest.mock import AsyncMock, patch
5
+ from pytest import mark, fixture, raises
6
+ from aiohttp import WSMessage, WSMsgType
7
+
8
+ import trainml.projects.credentials as specimen
9
+ from trainml.exceptions import (
10
+ ApiError,
11
+ SpecificationError,
12
+ TrainMLException,
13
+ )
14
+
15
+ pytestmark = [mark.sdk, mark.unit, mark.projects]
16
+
17
+
18
+ @fixture
19
+ def project_credentials(mock_trainml):
20
+ yield specimen.ProjectCredentials(mock_trainml, project_id="1")
21
+
22
+
23
+ @fixture
24
+ def project_credential(mock_trainml):
25
+ yield specimen.ProjectCredential(
26
+ mock_trainml, project_uuid="proj-id-1", type="aws", key_id="AIYHGFSDLK"
27
+ )
28
+
29
+
30
+ class ProjectCredentialsTests:
31
+ @mark.asyncio
32
+ async def test_project_credentials_list(self, project_credentials, mock_trainml):
33
+ api_response = [
34
+ {"project_uuid": "proj-id-1", "type": "aws", "key_id": "AIYHGFSDLK"},
35
+ {"project_uuid": "proj-id-1", "type": "gcp", "key_id": "credentials.json"},
36
+ ]
37
+ mock_trainml._query = AsyncMock(return_value=api_response)
38
+ resp = await project_credentials.list()
39
+ mock_trainml._query.assert_called_once_with(
40
+ "/project/1/credentials", "GET", dict()
41
+ )
42
+ assert len(resp) == 2
43
+
44
+ @mark.asyncio
45
+ async def test_remove_project_credential(
46
+ self,
47
+ project_credentials,
48
+ mock_trainml,
49
+ ):
50
+ api_response = dict()
51
+ mock_trainml._query = AsyncMock(return_value=api_response)
52
+ await project_credentials.remove("aws")
53
+ mock_trainml._query.assert_called_once_with(
54
+ "/project/1/credential/aws", "DELETE", dict()
55
+ )
56
+
57
+ @mark.asyncio
58
+ async def test_put_project_credential(self, project_credentials, mock_trainml):
59
+ requested_config = dict(type="aws", key_id="AIUDHADA", secret="ASKHJSLKF")
60
+ expected_payload = dict(key_id="AIUDHADA", secret="ASKHJSLKF")
61
+ api_response = {
62
+ "project_uuid": "project-id-1",
63
+ "type": "aws",
64
+ "key_id": "AIUDHADA",
65
+ }
66
+
67
+ mock_trainml._query = AsyncMock(return_value=api_response)
68
+ response = await project_credentials.put(**requested_config)
69
+ mock_trainml._query.assert_called_once_with(
70
+ "/project/1/credential/aws", "PUT", None, expected_payload
71
+ )
72
+ assert response.type == "aws"
73
+
74
+
75
+ class ProjectCredentialTests:
76
+ def test_project_credential_properties(self, project_credential):
77
+ assert isinstance(project_credential.type, str)
78
+ assert isinstance(project_credential.key_id, str)
79
+ assert isinstance(project_credential.project_uuid, str)
80
+
81
+ def test_project_credential_str(self, project_credential):
82
+ string = str(project_credential)
83
+ regex = r"^{.*\"type\": \"" + project_credential.type + r"\".*}$"
84
+ assert isinstance(string, str)
85
+ assert re.match(regex, string)
86
+
87
+ def test_project_credential_repr(self, project_credential):
88
+ string = repr(project_credential)
89
+ regex = (
90
+ r"^ProjectCredential\( trainml , \*\*{.*'type': '"
91
+ + project_credential.type
92
+ + r"'.*}\)$"
93
+ )
94
+ assert isinstance(string, str)
95
+ assert re.match(regex, string)
96
+
97
+ def test_project_credential_bool(self, project_credential, mock_trainml):
98
+ empty_project_credential = specimen.ProjectCredential(mock_trainml)
99
+ assert bool(project_credential)
100
+ assert not bool(empty_project_credential)
@@ -75,7 +75,7 @@ class ProjectsTests:
75
75
  requested_config = dict(
76
76
  name="new project",
77
77
  )
78
- expected_payload = dict(name="new project", copy_keys=False, copy_secrets=False)
78
+ expected_payload = dict(name="new project", copy_credentials=False)
79
79
  api_response = {
80
80
  "id": "project-id-1",
81
81
  "name": "new project",
trainml/__init__.py CHANGED
@@ -13,5 +13,5 @@ logging.basicConfig(
13
13
  logger = logging.getLogger(__name__)
14
14
 
15
15
 
16
- __version__ = "0.5.11"
16
+ __version__ = "0.5.13"
17
17
  __all__ = "TrainML"
trainml/cli/job/create.py CHANGED
@@ -172,12 +172,12 @@ def create(config):
172
172
  help="Conda packages to install as a comma separated list 'p1,\"p2=v2\",p3'",
173
173
  )
174
174
  @click.option(
175
- "--key",
175
+ "--credential",
176
176
  type=click.Choice(
177
177
  ["aws", "gcp", "kaggle", "azure", "wasabi"],
178
178
  case_sensitive=False,
179
179
  ),
180
- help="Third Party Keys to add to the job environment",
180
+ help="Third Party Credentials to add to the job environment",
181
181
  multiple=True,
182
182
  )
183
183
  @click.option(
@@ -221,7 +221,7 @@ def notebook(
221
221
  environment,
222
222
  custom_image,
223
223
  env,
224
- key,
224
+ credential,
225
225
  apt_packages,
226
226
  pip_packages,
227
227
  conda_packages,
@@ -254,7 +254,7 @@ def notebook(
254
254
  data=dict(datasets=datasets),
255
255
  model=dict(checkpoints=checkpoints),
256
256
  environment=dict(
257
- worker_key_types=[k for k in key],
257
+ credentials=[k for k in credential],
258
258
  ),
259
259
  )
260
260
 
@@ -500,12 +500,12 @@ def notebook(
500
500
  multiple=True,
501
501
  )
502
502
  @click.option(
503
- "--key",
503
+ "--credential",
504
504
  type=click.Choice(
505
505
  ["aws", "gcp", "kaggle", "azure", "wasabi"],
506
506
  case_sensitive=False,
507
507
  ),
508
- help="Third Party Keys to add to the job environment",
508
+ help="Third Party Credentials to add to the job environment",
509
509
  multiple=True,
510
510
  )
511
511
  @click.option(
@@ -563,7 +563,7 @@ def training(
563
563
  environment,
564
564
  custom_image,
565
565
  env,
566
- key,
566
+ credential,
567
567
  apt_packages,
568
568
  pip_packages,
569
569
  conda_packages,
@@ -596,7 +596,7 @@ def training(
596
596
  data=dict(datasets=datasets),
597
597
  model=dict(checkpoints=checkpoints),
598
598
  environment=dict(
599
- worker_key_types=[k for k in key],
599
+ credentials=[k for k in credential],
600
600
  ),
601
601
  )
602
602
 
@@ -844,12 +844,12 @@ def training(
844
844
  multiple=True,
845
845
  )
846
846
  @click.option(
847
- "--key",
847
+ "--credential",
848
848
  type=click.Choice(
849
849
  ["aws", "gcp", "kaggle", "azure", "wasabi"],
850
850
  case_sensitive=False,
851
851
  ),
852
- help="Third Party Keys to add to the job environment",
852
+ help="Third Party Credentials to add to the job environment",
853
853
  multiple=True,
854
854
  )
855
855
  @click.option(
@@ -907,7 +907,7 @@ def inference(
907
907
  environment,
908
908
  custom_image,
909
909
  env,
910
- key,
910
+ credential,
911
911
  apt_packages,
912
912
  pip_packages,
913
913
  conda_packages,
@@ -933,7 +933,7 @@ def inference(
933
933
  data=dict(datasets=[]),
934
934
  model=dict(checkpoints=checkpoints),
935
935
  environment=dict(
936
- worker_key_types=[k for k in key],
936
+ credentials=[k for k in credential],
937
937
  ),
938
938
  )
939
939
 
@@ -1163,12 +1163,12 @@ def from_json(config, attach, connect, file):
1163
1163
  multiple=True,
1164
1164
  )
1165
1165
  @click.option(
1166
- "--key",
1166
+ "--credential",
1167
1167
  type=click.Choice(
1168
1168
  ["aws", "gcp", "kaggle", "azure", "wasabi"],
1169
1169
  case_sensitive=False,
1170
1170
  ),
1171
- help="Third Party Keys to add to the job environment",
1171
+ help="Third Party Credentials to add to the job environment",
1172
1172
  multiple=True,
1173
1173
  )
1174
1174
  @click.option(
@@ -1230,7 +1230,7 @@ def endpoint(
1230
1230
  environment,
1231
1231
  custom_image,
1232
1232
  env,
1233
- key,
1233
+ credential,
1234
1234
  apt_packages,
1235
1235
  pip_packages,
1236
1236
  conda_packages,
@@ -1257,7 +1257,7 @@ def endpoint(
1257
1257
  max_price=max_price,
1258
1258
  model=dict(checkpoints=checkpoints),
1259
1259
  environment=dict(
1260
- worker_key_types=[k for k in key],
1260
+ credentials=[k for k in credential],
1261
1261
  ),
1262
1262
  )
1263
1263
 
@@ -78,7 +78,7 @@ def remove(config, project):
78
78
 
79
79
 
80
80
  from trainml.cli.project.secret import secret
81
- from trainml.cli.project.key import key
81
+ from trainml.cli.project.credential import credential
82
82
  from trainml.cli.project.data_connector import data_connector
83
83
  from trainml.cli.project.datastore import datastore
84
84
  from trainml.cli.project.service import service
@@ -0,0 +1,128 @@
1
+ import click
2
+ import os
3
+ import json
4
+ import base64
5
+ from pathlib import Path
6
+ from trainml.cli import pass_config
7
+ from trainml.cli.project import project
8
+
9
+
10
+ @project.group()
11
+ @pass_config
12
+ def credential(config):
13
+ """trainML project credential commands."""
14
+ pass
15
+
16
+
17
+ @credential.command()
18
+ @pass_config
19
+ def list(config):
20
+ """List credentials."""
21
+ data = [
22
+ ["TYPE", "KEY ID", "UPDATED AT"],
23
+ [
24
+ "-" * 80,
25
+ "-" * 80,
26
+ "-" * 80,
27
+ ],
28
+ ]
29
+ project = config.trainml.run(config.trainml.client.projects.get_current())
30
+ credentials = config.trainml.run(project.credentials.list())
31
+
32
+ for credential in credentials:
33
+ data.append(
34
+ [
35
+ credential.type,
36
+ credential.key_id,
37
+ credential.updated_at.isoformat(timespec="seconds"),
38
+ ]
39
+ )
40
+
41
+ for row in data:
42
+ click.echo(
43
+ "{: >13.11} {: >37.35} {: >28.26}" "".format(*row),
44
+ file=config.stdout,
45
+ )
46
+
47
+
48
+ @credential.command()
49
+ @click.argument(
50
+ "type",
51
+ type=click.Choice(
52
+ [
53
+ "aws",
54
+ "azure",
55
+ "docker",
56
+ "gcp",
57
+ "huggingface",
58
+ "kaggle",
59
+ "ngc",
60
+ "wasabi",
61
+ ],
62
+ case_sensitive=False,
63
+ ),
64
+ )
65
+ @pass_config
66
+ def put(config, type):
67
+ """
68
+ Set a credential.
69
+
70
+ A credential is uploaded.
71
+ """
72
+ project = config.trainml.run(config.trainml.client.projects.get_current())
73
+
74
+ tenant = None
75
+
76
+ if type in ["aws", "wasabi"]:
77
+ credential_id = click.prompt(
78
+ "Enter the credential ID", type=str, hide_input=False
79
+ )
80
+ secret = click.prompt("Enter the secret credential", type=str, hide_input=True)
81
+ elif type == "azure":
82
+ credential_id = click.prompt(
83
+ "Enter the Application (client) ID", type=str, hide_input=False
84
+ )
85
+ tenant = click.prompt(
86
+ "Enter the Directory (tenant) ley", type=str, hide_input=False
87
+ )
88
+ secret = click.prompt("Enter the client secret", type=str, hide_input=True)
89
+ elif type in ["docker", "huggingface"]:
90
+ credential_id = click.prompt("Enter the username", type=str, hide_input=False)
91
+ secret = click.prompt("Enter the access token", type=str, hide_input=True)
92
+ elif type in ["gcp", "kaggle"]:
93
+ file_name = click.prompt(
94
+ "Enter the path of the credentials file",
95
+ type=click.Path(
96
+ exists=True, file_okay=True, dir_okay=False, resolve_path=True
97
+ ),
98
+ hide_input=False,
99
+ )
100
+ credential_id = os.path.basename(file_name)
101
+ with open(file_name) as f:
102
+ secret = json.load(f)
103
+ secret = json.dumps(secret)
104
+ elif type == "ngc":
105
+ credential_id = "$oauthtoken"
106
+ secret = click.prompt("Enter the access token", type=str, hide_input=True)
107
+ else:
108
+ raise click.UsageError("Unsupported credential type")
109
+
110
+ return config.trainml.run(
111
+ project.credentials.put(
112
+ type=type, credential_id=credential_id, secret=secret, tenant=tenant
113
+ )
114
+ )
115
+
116
+
117
+ @credential.command()
118
+ @click.argument("name", type=click.STRING)
119
+ @pass_config
120
+ def remove(config, name):
121
+ """
122
+ Remove a credential.
123
+
124
+
125
+ """
126
+ project = config.trainml.run(config.trainml.client.projects.get_current())
127
+
128
+ return config.trainml.run(project.credential.remove(name))
@@ -1,4 +1,5 @@
1
1
  import click
2
+ import os
2
3
  from trainml.cli import pass_config
3
4
  from trainml.cli.project import project
4
5
 
@@ -42,17 +43,25 @@ def list(config):
42
43
 
43
44
 
44
45
  @secret.command()
46
+ @click.option(
47
+ "--file",
48
+ type=click.Path(exists=True, file_okay=True, dir_okay=False, resolve_path=True),
49
+ help="Load the secret value from the file at the provided path",
50
+ )
45
51
  @click.argument("name", type=click.STRING)
46
52
  @pass_config
47
- def put(config, name):
53
+ def put(config, file, name):
48
54
  """
49
55
  Set a secret value.
50
56
 
51
57
  Secret is created with the specified NAME.
52
58
  """
53
59
  project = config.trainml.run(config.trainml.client.projects.get_current())
54
-
55
- value = click.prompt("Enter the secret value", type=str, hide_input=True)
60
+ if file:
61
+ with open(os.path.expanduser(file)) as f:
62
+ value = f.read()
63
+ else:
64
+ value = click.prompt("Enter the secret value", type=str, hide_input=True)
56
65
 
57
66
  return config.trainml.run(project.secrets.put(name=name, value=value))
58
67
 
@@ -0,0 +1,71 @@
1
+ import json
2
+ import logging
3
+ from datetime import datetime
4
+ from dateutil import parser, tz
5
+
6
+
7
+ class ProjectCredentials(object):
8
+ def __init__(self, trainml, project_id):
9
+ self.trainml = trainml
10
+ self.project_id = project_id
11
+
12
+ async def list(self, **kwargs):
13
+ resp = await self.trainml._query(
14
+ f"/project/{self.project_id}/credentials", "GET", kwargs
15
+ )
16
+ credentials = [ProjectCredential(self.trainml, **service) for service in resp]
17
+ return credentials
18
+
19
+ async def put(self, type, key_id, secret, tenant=None, **kwargs):
20
+ data = dict(key_id=key_id, secret=secret, tenant=tenant)
21
+ payload = {k: v for k, v in data.items() if v is not None}
22
+ logging.info(f"Creating Project Credential {type}")
23
+ resp = await self.trainml._query(
24
+ f"/project/{self.project_id}/credential/{type}", "PUT", None, payload
25
+ )
26
+ credential = ProjectCredential(self.trainml, **resp)
27
+ logging.info(f"Created Project Credential {type} in project {self.project_id}")
28
+
29
+ return credential
30
+
31
+ async def remove(self, type, **kwargs):
32
+ await self.trainml._query(
33
+ f"/project/{self.project_id}/credential/{type}", "DELETE", kwargs
34
+ )
35
+
36
+
37
+ class ProjectCredential:
38
+ def __init__(self, trainml, **kwargs):
39
+ self.trainml = trainml
40
+ self._entity = kwargs
41
+ self._type = self._entity.get("type")
42
+ self._project_uuid = self._entity.get("project_uuid")
43
+ self._key_id = self._entity.get("key_id")
44
+ self._updated_at = self._entity.get("updatedAt")
45
+
46
+ @property
47
+ def type(self) -> str:
48
+ return self._type
49
+
50
+ @property
51
+ def project_uuid(self) -> str:
52
+ return self._project_uuid
53
+
54
+ @property
55
+ def key_id(self) -> str:
56
+ return self._key_id
57
+
58
+ @property
59
+ def updated_at(self) -> datetime:
60
+ timestamp = parser.isoparse(self._updated_at)
61
+ timezone = tz.tzlocal()
62
+ return timestamp.astimezone(timezone)
63
+
64
+ def __str__(self):
65
+ return json.dumps({k: v for k, v in self._entity.items()})
66
+
67
+ def __repr__(self):
68
+ return f"ProjectCredential( trainml , **{self._entity.__repr__()})"
69
+
70
+ def __bool__(self):
71
+ return bool(self._type)
@@ -7,6 +7,12 @@ class ProjectDataConnectors(object):
7
7
  self.trainml = trainml
8
8
  self.project_id = project_id
9
9
 
10
+ async def get(self, id, **kwargs):
11
+ resp = await self.trainml._query(
12
+ f"/project/{self.project_id}/data_connectors/{id}", "GET", kwargs
13
+ )
14
+ return ProjectDataConnector(self.trainml, **resp)
15
+
10
16
  async def list(self, **kwargs):
11
17
  resp = await self.trainml._query(
12
18
  f"/project/{self.project_id}/data_connectors", "GET", kwargs
@@ -61,3 +67,13 @@ class ProjectDataConnector:
61
67
 
62
68
  def __bool__(self):
63
69
  return bool(self._id)
70
+
71
+ async def enable(self):
72
+ await self.trainml._query(
73
+ f"/project/{self._project_uuid}/data_connectors/{self._id}/enable", "PATCH"
74
+ )
75
+
76
+ async def disable(self):
77
+ await self.trainml._query(
78
+ f"/project/{self._project_uuid}/data_connectors/{self._id}/disable", "PATCH"
79
+ )
@@ -7,6 +7,12 @@ class ProjectDatastores(object):
7
7
  self.trainml = trainml
8
8
  self.project_id = project_id
9
9
 
10
+ async def get(self, id, **kwargs):
11
+ resp = await self.trainml._query(
12
+ f"/project/{self.project_id}/datastores/{id}", "GET", kwargs
13
+ )
14
+ return ProjectDatastore(self.trainml, **resp)
15
+
10
16
  async def list(self, **kwargs):
11
17
  resp = await self.trainml._query(
12
18
  f"/project/{self.project_id}/datastores", "GET", kwargs
@@ -56,3 +62,13 @@ class ProjectDatastore:
56
62
 
57
63
  def __bool__(self):
58
64
  return bool(self._id)
65
+
66
+ async def enable(self):
67
+ await self.trainml._query(
68
+ f"/project/{self._project_uuid}/datastores/{self._id}/enable", "PATCH"
69
+ )
70
+
71
+ async def disable(self):
72
+ await self.trainml._query(
73
+ f"/project/{self._project_uuid}/datastores/{self._id}/disable", "PATCH"
74
+ )
@@ -3,7 +3,7 @@ import logging
3
3
  from .datastores import ProjectDatastores
4
4
  from .data_connectors import ProjectDataConnectors
5
5
  from .services import ProjectServices
6
- from .keys import ProjectKeys
6
+ from .credentials import ProjectCredentials
7
7
  from .secrets import ProjectSecrets
8
8
 
9
9
 
@@ -26,8 +26,11 @@ class Projects(object):
26
26
  projects = [Project(self.trainml, **project) for project in resp]
27
27
  return projects
28
28
 
29
- async def create(self, name, copy_keys=False, copy_secrets=False, **kwargs):
30
- data = dict(name=name, copy_keys=copy_keys, copy_secrets=copy_secrets)
29
+ async def create(self, name, copy_credentials=False, **kwargs):
30
+ data = dict(
31
+ name=name,
32
+ copy_credentials=copy_credentials,
33
+ )
31
34
  payload = {k: v for k, v in data.items() if v is not None}
32
35
  logging.info(f"Creating Project {name}")
33
36
  resp = await self.trainml._query("/project", "POST", None, payload)
@@ -51,7 +54,7 @@ class Project:
51
54
  self.datastores = ProjectDatastores(self.trainml, self._id)
52
55
  self.data_connectors = ProjectDataConnectors(self.trainml, self._id)
53
56
  self.services = ProjectServices(self.trainml, self._id)
54
- self.keys = ProjectKeys(self.trainml, self._id)
57
+ self.credentials = ProjectCredentials(self.trainml, self._id)
55
58
  self.secrets = ProjectSecrets(self.trainml, self._id)
56
59
 
57
60
  @property
@@ -24,7 +24,7 @@ class ProjectSecrets(object):
24
24
  f"/project/{self.project_id}/secret/{name}", "PUT", None, payload
25
25
  )
26
26
  secret = ProjectSecret(self.trainml, **resp)
27
- logging.info(f"Created Project Key {name} in project {self.project_id}")
27
+ logging.info(f"Created Project Secret {name} in project {self.project_id}")
28
28
  return secret
29
29
 
30
30
  async def remove(self, name, **kwargs):
@@ -7,6 +7,12 @@ class ProjectServices(object):
7
7
  self.trainml = trainml
8
8
  self.project_id = project_id
9
9
 
10
+ async def get(self, id, **kwargs):
11
+ resp = await self.trainml._query(
12
+ f"/project/{self.project_id}/services/{id}", "GET", kwargs
13
+ )
14
+ return ProjectService(self.trainml, **resp)
15
+
10
16
  async def list(self, **kwargs):
11
17
  resp = await self.trainml._query(
12
18
  f"/project/{self.project_id}/services", "GET", kwargs
@@ -61,3 +67,13 @@ class ProjectService:
61
67
 
62
68
  def __bool__(self):
63
69
  return bool(self._id)
70
+
71
+ async def enable(self):
72
+ await self.trainml._query(
73
+ f"/project/{self._project_uuid}/services/{self._id}/enable", "PATCH"
74
+ )
75
+
76
+ async def disable(self):
77
+ await self.trainml._query(
78
+ f"/project/{self._project_uuid}/services/{self._id}/disable", "PATCH"
79
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trainml
3
- Version: 0.5.11
3
+ Version: 0.5.13
4
4
  Summary: trainML client SDK and command line utilities
5
5
  Home-page: https://github.com/trainML/trainml-cli
6
6
  Author: trainML
@@ -8,21 +8,22 @@ tests/integration/test_checkpoints_integration.py,sha256=Giy5Z6WyselfXzskDGR7Z0k
8
8
  tests/integration/test_datasets_integration.py,sha256=zdHOevduuMUWvVxaHBslpmH8AdvPdqEJ95MdqCC5_rw,3499
9
9
  tests/integration/test_environments_integration.py,sha256=0IckhJvQhd8j4Ouiu0hMq2b7iA1dbZpZYmknyfWjsFM,1403
10
10
  tests/integration/test_gpu_types_integration.py,sha256=V2OncokZWWVq_l5FSmKEDM4EsWrmpB-zKiVPt-we0aY,1256
11
- tests/integration/test_jobs_integration.py,sha256=N2peEQGYHteGMd0J7NK4gJaaTyps5jjuiKq2ENnD8SY,25117
11
+ tests/integration/test_jobs_integration.py,sha256=vj-lINOzprUBj61F4i4CBe64MmT0HCDDsPneYsulv3I,25110
12
12
  tests/integration/test_models_integration.py,sha256=u6KVnX-F00TqwiU-gEoZJP1oKfAblqnyRptOc9vNGJ4,2878
13
13
  tests/integration/test_volumes_integration.py,sha256=gOmZpwwFxqeOAVmfKWSTmuyshx8nb2zu_0xv1RUEepM,3270
14
14
  tests/integration/cloudbender/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  tests/integration/cloudbender/test_providers_integration.py,sha256=oV8ydFsosDZ_Z1Dkg2IN-ZhWuIl5e_HkHAORMsOsAJc,1473
16
16
  tests/integration/projects/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- tests/integration/projects/conftest.py,sha256=IaCvq3G_2uBm-DAfqTUF2K_km06af711bzmp-OMwZBs,242
17
+ tests/integration/projects/conftest.py,sha256=sNN1Svq2IO63Yx3DC7-5ZnksaEifGpDZU-3ti9sZhIU,249
18
+ tests/integration/projects/test_projects_credentials_integration.py,sha256=3PnpxNEsedXmyyhqjSb8T4JzupB1Kmwu--3stNTBlN8,1636
18
19
  tests/integration/projects/test_projects_data_connectors_integration.py,sha256=R90v7HVN4i9k-AOEl17AvnbWIwnD9Fl1OK9IGOV847o,1630
19
20
  tests/integration/projects/test_projects_datastores_integration.py,sha256=S9aSvryVjrcoEDezr33x4T5aPjEhUwL9O1-1eyzhQ-s,1469
20
21
  tests/integration/projects/test_projects_integration.py,sha256=HP4jPAyTqGt7pwk42bxQsqGp0olgai6sI-S1XXcXoJs,1241
21
22
  tests/integration/projects/test_projects_keys_integration.py,sha256=O-a9OwBxIM2l0vi__GMlWP8ncNswxGBJvEhgo8PoalQ,1423
22
- tests/integration/projects/test_projects_secrets_integration.py,sha256=XMMov60dVyklZH0FzcHgVKOu5zpNH4z7GriOp-wawgI,1478
23
+ tests/integration/projects/test_projects_secrets_integration.py,sha256=bagLLfSUP805gOOPbn_xCQyifflNzIs8DGUBeUwOhO0,1481
23
24
  tests/integration/projects/test_projects_services_integration.py,sha256=lBnrqFpjsL3zfaJJmFh2rCWfNmmX-TjyOPCR3KobDAc,1530
24
25
  tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- tests/unit/conftest.py,sha256=IIdY88sGlvFuH2ZZHysWi3QCZ1-oAZ1yG6npKMRjCzI,35521
26
+ tests/unit/conftest.py,sha256=hLfECgT0w4pVZABrpK4UUUeaX1aDzQvj8-erWTGBjHA,35588
26
27
  tests/unit/test_auth_unit.py,sha256=nfhlOCR7rUsn_MaD8QQtBc2v0k8pIxqbzGgRAZK1WGc,858
27
28
  tests/unit/test_checkpoints_unit.py,sha256=7bgpEnjkfETgbEHmYApyD_htEWAUVZdposyYVClU3tQ,15965
28
29
  tests/unit/test_connections_unit.py,sha256=FzN2ddQxNpjxzNGUsXhjTk0HnD24wSPelPTL4o_r-Ho,5507
@@ -51,6 +52,7 @@ tests/unit/cli/cloudbender/test_cli_provider_unit.py,sha256=Rm-tRNPbTTB7ZzkkIpLf
51
52
  tests/unit/cli/cloudbender/test_cli_region_unit.py,sha256=iH5AbrzZ-R2EJ-Bd2HFN7FN2lTpkr3-pCLR59ZVvdQU,1262
52
53
  tests/unit/cli/cloudbender/test_cli_service_unit.py,sha256=4LDOJDXygMuho2cdI2K59eq4oyiry9hNaG0avEr0_tw,1311
53
54
  tests/unit/cli/projects/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
+ tests/unit/cli/projects/test_cli_project_credential_unit.py,sha256=gnmEpNbpEG5S9cYQUjSGty2e8mqeC_cCKmIUAJCgRXg,943
54
56
  tests/unit/cli/projects/test_cli_project_data_connector_unit.py,sha256=_NgnxV8zTIycpHKe7dyL6EXq774puFHQjvgCKsiEMO0,993
55
57
  tests/unit/cli/projects/test_cli_project_datastore_unit.py,sha256=E_kLoIZ5U92LQaPcYAKDyUqpjM1Xe6PVPvofU1Yn6Yk,936
56
58
  tests/unit/cli/projects/test_cli_project_key_unit.py,sha256=Ma5HjsZt2RaHKgmMdGY59EIc2WdAgbWKWn2LvlYeDqQ,894
@@ -67,13 +69,14 @@ tests/unit/cloudbender/test_providers_unit.py,sha256=OgxifgC1IqLH8DNMKXy1Ne9_7a7
67
69
  tests/unit/cloudbender/test_regions_unit.py,sha256=BbJICLIQmlotpA1UmLD0KTW_H9g2UW0J8ZYzQk1_Xjc,6299
68
70
  tests/unit/cloudbender/test_services_unit.py,sha256=fYJx-W89HD-EYkO32_v33X40VxipUfWQCy13FZO2fcA,5220
69
71
  tests/unit/projects/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
72
+ tests/unit/projects/test_project_credentials_unit.py,sha256=ObTaJ7_g0MP5N-0qHWdeYips0in1j_4UkOhXXI2FFwo,3480
70
73
  tests/unit/projects/test_project_data_connectors_unit.py,sha256=uQPFx6rwYMWZz1IJkns_LdM5gccyHSIaKb3k8zmfSkY,3385
71
74
  tests/unit/projects/test_project_datastores_unit.py,sha256=kcoaSs54gGqJ9gwPMpP6KHAPRvDJtdJpm49s4aYYt3E,3129
72
75
  tests/unit/projects/test_project_keys_unit.py,sha256=2-w_VwmWxWHoLWBCoBAfg5WozyeYJHV361ZndlA0xk4,3161
73
76
  tests/unit/projects/test_project_secrets_unit.py,sha256=StVlY-ZR3CKxXAt9NL8hTkXUEdgGESH0m6foEPXKE-4,3276
74
77
  tests/unit/projects/test_project_services_unit.py,sha256=ZK5nz78RAmmaCrAwYBd34t87dh6etU-7snLB_xukZHM,3331
75
- tests/unit/projects/test_projects_unit.py,sha256=4Jczapaj5pZOYKmRYN8MEygzyNwULCaOyYSyiNUBsq8,3823
76
- trainml/__init__.py,sha256=vzWg68mF2ggaSj8F_z_riREX-rzGbJcPhGIDE1jG3yE,433
78
+ tests/unit/projects/test_projects_unit.py,sha256=8rJ40bJ7YszEsoL6D02Muey-sgRjqFmMoR-R3IiP_Ig,3810
79
+ trainml/__init__.py,sha256=KVgJtJhufpHLxSIxc6VgC9rtBlScxurtZsM8FibfA3o,433
77
80
  trainml/__main__.py,sha256=JgErYkiskih8Y6oRwowALtR-rwQhAAdqOYWjQraRIPI,59
78
81
  trainml/auth.py,sha256=gruZv27nhttrCbhcVQTH9kZkF2uMm1E06SwA_2pQAHQ,26565
79
82
  trainml/checkpoints.py,sha256=Hg3_Si7ohzsv4_8JIjoj9pMRpHNZRWKC5R2gtgmp01s,8790
@@ -103,12 +106,13 @@ trainml/cli/cloudbender/provider.py,sha256=oFjZWKfFQjNY7OtDu7nUdfv-RTmQc_Huuug96
103
106
  trainml/cli/cloudbender/region.py,sha256=X6-FYOb-pGpOEazn-NbsYSwa9ergB7FGATFkTe4a8Pk,2892
104
107
  trainml/cli/cloudbender/service.py,sha256=Wh6ycEuECiKL7qpFhc4IyO1rR5lvLtIHk3S475_R6pk,3147
105
108
  trainml/cli/job/__init__.py,sha256=ljY-ELeXhXQ7txASbJEKGBom7OXfNyy7sWILz3nxRAE,6545
106
- trainml/cli/job/create.py,sha256=pfOCqs5Vfk4PAI5KZpXHJ1vp3DDe4ccvYzieh0oFexY,34288
107
- trainml/cli/project/__init__.py,sha256=XOBLQMQqlkzMUNoUejXXIP7bY5ebSWKlUn5XGkQVbPw,1904
109
+ trainml/cli/job/create.py,sha256=1YGHgl0bN0LC7EtMStukHT6RvnBheaaOnkqoKsAxuco,34380
110
+ trainml/cli/project/__init__.py,sha256=HDcJUbKMHhz4Thrvpst5hnywFqzsv0XWmvfKNRi8zuo,1918
111
+ trainml/cli/project/credential.py,sha256=gByXKiYf5sJeNRtuXWcercWv8P2IzO5TjT8Ypp4mCR8,3443
108
112
  trainml/cli/project/data_connector.py,sha256=KLDhpNJfwcJkcmyuJRgcVH70Jf73619O9ddYP8vhMvk,1411
109
113
  trainml/cli/project/datastore.py,sha256=IwF0LqsSFn7DrKPRdxQs6kturk9MCI52A1aoWeb7ClA,1336
110
114
  trainml/cli/project/key.py,sha256=kQlCs_N-5c27hOyGkmT22_J47x8U6CZaSardsaPYGbw,3203
111
- trainml/cli/project/secret.py,sha256=LdEd6qJwfRs3JIjoOaNxkDcDuCdYB9GPKHW_vcOBal8,1621
115
+ trainml/cli/project/secret.py,sha256=tHt7bYDt0MNkLTTePTIJFUh9Mn9ogebPcaSCiNRJFNQ,1927
112
116
  trainml/cli/project/service.py,sha256=FzcyGI9MN-UvnjdKW7GmXLTXLUIXtuTFAISR_FmCmJo,1310
113
117
  trainml/cloudbender/__init__.py,sha256=iE29obtC0_9f0IhRvHQcG5aY58fVhVYipTakpjAhdss,64
114
118
  trainml/cloudbender/cloudbender.py,sha256=ekJZHSQ1F4HF8y0sAJ3MDB_hiC8QxPv9-O7U24z_RR4,717
@@ -121,15 +125,16 @@ trainml/cloudbender/providers.py,sha256=22ymUl1KLC8UlyoWMsIrOKhUDOwnhklhHQ3EZ_V6
121
125
  trainml/cloudbender/regions.py,sha256=nfSY9fIWp_AaRE_1Y0qwXX6WVSyPKxpji-zUfM3BNUo,5157
122
126
  trainml/cloudbender/services.py,sha256=KC3VcyljvnazUUG-Tzwm6Ab6d0--yuccXjOaMgYB5uA,5126
123
127
  trainml/projects/__init__.py,sha256=6NKCcHtQMeGB1IyU-djANphfnDX6MEkrXUM5Fyq9fWg,75
124
- trainml/projects/data_connectors.py,sha256=Y8lJNF9K5JZlwfKTtN9gh7eSRAivgiPWe_lx05pGM2U,1662
125
- trainml/projects/datastores.py,sha256=oyRffW8L7Z1tdqspl58Zf1ces0p-Stk0EbnMRaenkUw,1560
128
+ trainml/projects/credentials.py,sha256=6WqHy_-SZZwqE4rULLF8gSyeRVmfsUxqZBuCjBXyxKw,2255
129
+ trainml/projects/data_connectors.py,sha256=WZATdUq4vE3x47Ny5HDwPD7lIUx0syjaSE9BmFWNuEg,2216
130
+ trainml/projects/datastores.py,sha256=qocqD5mGfm2V_wh36CEh3oldnIeJg57ppc6CM129Dkk,2095
126
131
  trainml/projects/keys.py,sha256=qcQAdysTbfVW19tzzxZDvBBWjU9DG0dkViLmG_S0SyM,2157
127
- trainml/projects/projects.py,sha256=mxMGmBppoFbwebMitczZjeNEODrzt0AuNm1LGNegyPo,2755
128
- trainml/projects/secrets.py,sha256=5qNPWITH8qtlXKkPWnFOzH0HPU7Z0K1OeW-9p7haOzM,2157
129
- trainml/projects/services.py,sha256=ZP-6CDXktIe6p89Hshgs91HLWXQPNWeU7VFtoKUPHXo,1679
130
- trainml-0.5.11.dist-info/LICENSE,sha256=s0lpBxhSSUEpMavwde-Vb6K_K7xDCTTvSpNznVqVGR0,1069
131
- trainml-0.5.11.dist-info/METADATA,sha256=z5-C7kUq2eL3_WS_uLwEIILAIBF0FAAErmoI1EYKaiw,7346
132
- trainml-0.5.11.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
133
- trainml-0.5.11.dist-info/entry_points.txt,sha256=OzBDm2wXby1bSGF02jTVxzRFZLejnbFiLHXhKdW3Bds,63
134
- trainml-0.5.11.dist-info/top_level.txt,sha256=Y1kLFRWKUW7RG8BX7cvejHF_yW8wBOaRYF1JQHENY4w,23
135
- trainml-0.5.11.dist-info/RECORD,,
132
+ trainml/projects/projects.py,sha256=0ZghShqjbs5swfn3BsLrMW2NzrdBXpf_M-nyzwYPjpM,2792
133
+ trainml/projects/secrets.py,sha256=TIvBd3rAvd4lF3pm5qR98UslHjldzlnzn_n9yvpmLgg,2160
134
+ trainml/projects/services.py,sha256=W2IHgRUT9BemWThsY7uAot2gbmyPaH41WAii-NQ_cT8,2206
135
+ trainml-0.5.13.dist-info/LICENSE,sha256=s0lpBxhSSUEpMavwde-Vb6K_K7xDCTTvSpNznVqVGR0,1069
136
+ trainml-0.5.13.dist-info/METADATA,sha256=8BjIAywdzYBrUOb_k6PkSdc20fFaVW7pUEKiOPqHzf4,7346
137
+ trainml-0.5.13.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
138
+ trainml-0.5.13.dist-info/entry_points.txt,sha256=OzBDm2wXby1bSGF02jTVxzRFZLejnbFiLHXhKdW3Bds,63
139
+ trainml-0.5.13.dist-info/top_level.txt,sha256=Y1kLFRWKUW7RG8BX7cvejHF_yW8wBOaRYF1JQHENY4w,23
140
+ trainml-0.5.13.dist-info/RECORD,,