Skip to content

Commit 8706647

Browse files
author
Thibaud Baas
committed
FM: Add helper to set cloud credentials
1 parent a971a96 commit 8706647

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

dataikuapi/fm/tenant.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def __init__(self, client, cloud_credentials):
99

1010
def set_cmk_key(self, cmk_key_id):
1111
self.cloud_credentials['awsCMKId'] = cmk_key_id
12+
self.save()
1213

1314
def set_static_license(self, license_file=None, license_string=None):
1415
"""
@@ -28,6 +29,7 @@ def set_static_license(self, license_file=None, license_string=None):
2829
raise ValueError("a valid license_file or license_string needs to be provided")
2930
self.cloud_credentials['licenseMode'] = 'STATIC'
3031
self.cloud_credentials['license'] = json.dumps(license, indent=2)
32+
self.save()
3133

3234
def set_automatically_updated_license(self, license_token):
3335
"""
@@ -39,10 +41,77 @@ def set_automatically_updated_license(self, license_token):
3941
raise ValueError("a valid license_token needs to be provided")
4042
self.cloud_credentials['licenseMode'] = 'AUTO_UPDATE'
4143
self.cloud_credentials['licenseToken'] = license_token
44+
self.save()
45+
46+
def set_authentication(self, authentication):
47+
"""
48+
Set the authentication for the tenant
49+
50+
:param object: a :class:`dataikuapi.fm.tenant.FMCloudAuthentication`
51+
"""
52+
self.cloud_credentials.update(authentication)
53+
self.save()
4254

4355
def save(self):
4456
"""Saves back the settings to the project"""
4557

4658
self.client._perform_tenant_empty("PUT", "/cloud-credentials",
4759
body = self.cloud_credentials)
4860

61+
62+
class FMCloudAuthentication(dict):
63+
def __init__(self, data):
64+
"""
65+
A class holding the Cloud Authentication information
66+
67+
Do not create this directly, use:
68+
- :meth:`dataikuapi.fm.tenant.FMCloudAuthentication.aws_same_as_fm` to use the same authentication as Fleet Manager
69+
- :meth:`dataikuapi.fm.tenant.FMCloudAuthentication.aws_iam_role` to use a custom IAM Role
70+
- :meth:`dataikuapi.fm.tenant.FMCloudAuthentication.aws_keypair` to use a AWS Access key ID and AWS Secret Access Key pair
71+
"""
72+
super(FMCloudAuthentication, self).__init__(data)
73+
74+
@staticmethod
75+
def aws_same_as_fm():
76+
"""
77+
AWS Only: Use the same authentication as Fleet Manager
78+
"""
79+
return FMCloudAuthentication({"awsAuthenticationMode": "SAME_AS_FM"})
80+
81+
@staticmethod
82+
def aws_iam_role(role_arn):
83+
"""
84+
AWS Only: Use an IAM Role
85+
86+
params: str role_arn: ARN of the IAM Role
87+
"""
88+
return FMCloudAuthentication({"awsAuthenticationMode": "IAM_ROLE", "awsIAMRoleARN": role_arn})
89+
90+
@staticmethod
91+
def aws_keypair(access_key_id, secret_access_key):
92+
"""
93+
AWS Only: Use an AWS Access Key
94+
95+
:param str access_key_id: AWS Access Key ID
96+
:param str secret_access_key: AWS Secret Access Key
97+
"""
98+
return FMCloudAuthentication({"awsAuthenticationMode": "KEYPAIR", "awsAccessKeyId": access_key_id, "awsSecretAccessKey": secret_access_key})
99+
100+
@staticmethod
101+
def azure(subscription, tenant_id, environment, client_id):
102+
"""
103+
Azure Only
104+
105+
:param str subscription: Azure Subscription
106+
:param str tenant_id: Azure Tenant Id
107+
:param str environment: Azure Environment
108+
:param str client_id: Azure Client Id
109+
"""
110+
data = {
111+
"azureSubscription": subscription,
112+
"azureTenantId": tenant_id,
113+
"azureEnvironment": environment,
114+
"azureFMAppClientId": client_id
115+
}
116+
117+
return FMCloudAuthentication(data)

0 commit comments

Comments
 (0)