Skip to content

Commit 44b3608

Browse files
temblekingmuntzerr
andauthored
feat: Add support for access keys (#133)
List, create, disable and enable access keys Co-authored-by: Fede Barcelona <[email protected]> Co-authored-by: muntzerr <[email protected]>
1 parent 3b2bc90 commit 44b3608

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

examples/list_access_keys.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 os
8+
import sys
9+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
10+
from sdcclient import SdcClient
11+
12+
#
13+
# Parse arguments
14+
#
15+
if len(sys.argv) != 2:
16+
print('usage: %s <sysdig-token>' % sys.argv[0])
17+
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
18+
print('For this script to work, the user for the token must have Admin rights')
19+
sys.exit(1)
20+
21+
sdc_token = sys.argv[1]
22+
23+
#
24+
# Instantiate the SDC client
25+
#
26+
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
27+
28+
#
29+
# Get the configuration
30+
#
31+
ok, res = sdclient.list_access_keys()
32+
if ok:
33+
print('Access Keys\n===========')
34+
for access_key in res['customerAccessKeys']:
35+
print(access_key['accessKey'])
36+
else:
37+
print(res)
38+
sys.exit(1)

sdcclient/_common.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,59 @@ def remove_memberships(self, team, users):
10251025
else:
10261026
return [True, None]
10271027

1028+
def list_access_keys(self):
1029+
'''
1030+
**Description**
1031+
List all the access keys enabled and disabled for this instance of Sysdig Monitor/Secure
1032+
1033+
**Reslut**
1034+
A list of access keys objects
1035+
1036+
**Example**
1037+
`examples/list_access_keys.py <https://github.com/draios/python-sdc-client/blob/master/examples/list_access_keys.py>`_
1038+
'''
1039+
res = requests.get(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify)
1040+
return self._request_result(res)
1041+
1042+
def create_access_key(self):
1043+
'''
1044+
**Description**
1045+
Create a new access key for Sysdig Monitor/Secure
1046+
1047+
**Reslut**
1048+
The access keys object
1049+
'''
1050+
res = requests.post(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify)
1051+
return self._request_result(res)
1052+
1053+
def disable_access_key(self, access_key):
1054+
'''
1055+
**Description**
1056+
Disable an existing access key
1057+
1058+
**Arguments**
1059+
- **access_key**: the access key to be disabled
1060+
1061+
**Reslut**
1062+
The access keys object
1063+
'''
1064+
res = requests.post(self.url + '/api/customer/accessKeys/' + access_key + "/disable/", headers=self.hdrs, verify=self.ssl_verify)
1065+
return self._request_result(res)
1066+
1067+
def enable_access_key(self, access_key):
1068+
'''
1069+
**Description**
1070+
Enable an existing access key
1071+
1072+
**Arguments**
1073+
- **access_key**: the access key to be enabled
1074+
1075+
**Reslut**
1076+
The access keys object
1077+
'''
1078+
res = requests.post(self.url + '/api/customer/accessKeys/' + access_key + "/enable/", headers=self.hdrs, verify=self.ssl_verify)
1079+
return self._request_result(res)
1080+
10281081
def get_agents_config(self):
10291082
res = requests.get(self.url + '/api/agents/config', headers=self.hdrs, verify=self.ssl_verify)
10301083
if not self._checkResponse(res):

0 commit comments

Comments
 (0)