Skip to content

Commit 8ca6764

Browse files
authoredMay 29, 2024··
feat(access_key): Implement teamId in create_access_key and implement update_access_key (#251)
Signed-off-by: Daniele De Lorenzi <[email protected]>
1 parent 25706dd commit 8ca6764

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed
 

‎examples/create_access_keys.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
#
3+
# List all the access keys in a Sysdig Monitor environment. The token you provide must
4+
# have Admin rights.
5+
#
6+
7+
import sys
8+
9+
from sdcclient import SdcClient
10+
11+
#
12+
# Parse arguments
13+
#
14+
if len(sys.argv) != 2:
15+
print('usage: %s <sysdig-token>' % sys.argv[0])
16+
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
17+
print('For this script to work, the user for the token must have Admin rights')
18+
sys.exit(1)
19+
20+
sdc_token = sys.argv[1]
21+
22+
# Maximum number of agents allowed to connect for this access key. Set to '' if not required
23+
agent_limit = ''
24+
# Number of agent licenses that are ALWAYS available to this access key. This directly counts against the maximum number of available licenses. Set to '' if not required.
25+
agent_reserved = ''
26+
# Team ID to which to assign the access key. Team ID must be valid. Set to '' if not required.
27+
team_id = ''
28+
29+
30+
#
31+
# Instantiate the SDC client
32+
#
33+
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
34+
35+
#
36+
# Get the configuration
37+
#
38+
ok, res = sdclient.create_access_key(
39+
agent_limit,
40+
agent_reserved,
41+
team_id)
42+
43+
if ok:
44+
print('Access Key: {}\nTeam ID: {}\nAgent Limit: {}\nAgent Reserved: {}\n==========='.format(res['customerAccessKey']['accessKey'], res['customerAccessKey']['teamId'], res['customerAccessKey']['limit'], res['customerAccessKey']['reservation']))
45+
else:
46+
print(res)
47+
sys.exit(1)

‎examples/update_access_keys.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
#
3+
# List all the access keys in a Sysdig Monitor environment. The token you provide must
4+
# have Admin rights.
5+
#
6+
7+
import sys
8+
9+
from sdcclient import SdcClient
10+
11+
#
12+
# Parse arguments
13+
#
14+
if len(sys.argv) != 2:
15+
print('usage: %s <sysdig-token>' % sys.argv[0])
16+
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
17+
print('For this script to work, the user for the token must have Admin rights')
18+
sys.exit(1)
19+
20+
sdc_token = sys.argv[1]
21+
22+
# Access Key that needs to be updated
23+
accessKey = ''
24+
# Maximum number of agents allowed to connect for this access key. Set to '' if not required
25+
agent_limit = ''
26+
# Number of agent licenses that are ALWAYS available to this access key. This directly counts against the maximum number of available licenses. Set to '' if not required.
27+
agent_reserved = ''
28+
# Team ID to which to assign the access key. Team ID must be valid. Set to '' if not required.
29+
team_id = ''
30+
31+
32+
#
33+
# Instantiate the SDC client
34+
#
35+
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
36+
37+
#
38+
# Get the configuration
39+
#
40+
if accessKey:
41+
ok, res = sdclient.update_access_key(
42+
accessKey,
43+
agent_limit,
44+
agent_reserved,
45+
team_id)
46+
else:
47+
print('Please specify the Access Key that you would like to be updated')
48+
sys.exit(1)
49+
50+
if ok:
51+
print('Access Key: {}\nTeam ID: {}\nAgent Limit: {}\nAgent Reserved: {}\n==========='.format(res['customerAccessKey']['accessKey'], res['customerAccessKey']['teamId'], res['customerAccessKey']['limit'], res['customerAccessKey']['reservation']))
52+
else:
53+
print(res)
54+
sys.exit(1)

‎sdcclient/_common.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -1044,15 +1044,42 @@ def list_access_keys(self):
10441044
res = self.http.get(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify)
10451045
return self._request_result(res)
10461046

1047-
def create_access_key(self):
1047+
def create_access_key(self, agent_limit=None, agent_reserved=None, team_id=None):
10481048
'''
10491049
**Description**
10501050
Create a new access key for Sysdig Monitor/Secure
10511051
10521052
**Reslut**
10531053
The access keys object
10541054
'''
1055-
res = self.http.post(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify)
1055+
access_key_payload = {
1056+
"customerAccessKey": {
1057+
"limit": agent_limit,
1058+
"reservation": agent_reserved,
1059+
"teamId": team_id
1060+
}
1061+
}
1062+
1063+
res = self.http.post(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify, data=json.dumps(access_key_payload))
1064+
return self._request_result(res)
1065+
1066+
def update_access_key(self, access_key, agent_limit=None, agent_reserved=None, team_id=None):
1067+
'''
1068+
**Description**
1069+
Create a new access key for Sysdig Monitor/Secure
1070+
1071+
**Reslut**
1072+
The access keys object
1073+
'''
1074+
access_key_payload = {
1075+
"customerAccessKey": {
1076+
"limit": agent_limit,
1077+
"reservation": agent_reserved,
1078+
"teamId": team_id
1079+
}
1080+
}
1081+
1082+
res = self.http.put(self.url + '/api/customer/accessKeys/' + access_key, headers=self.hdrs, verify=self.ssl_verify, data=json.dumps(access_key_payload))
10561083
return self._request_result(res)
10571084

10581085
def disable_access_key(self, access_key):

0 commit comments

Comments
 (0)
Please sign in to comment.