Skip to content

Commit

Permalink
feat(access_key): Implement teamId in create_access_key and implement…
Browse files Browse the repository at this point in the history
… update_access_key (#251)

Signed-off-by: Daniele De Lorenzi <daniele.delorenzi@sysdig.com>
  • Loading branch information
dark-vex authored May 29, 2024
1 parent 25706dd commit 8ca6764
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 2 deletions.
47 changes: 47 additions & 0 deletions examples/create_access_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python
#
# List all the access keys in a Sysdig Monitor environment. The token you provide must
# have Admin rights.
#

import sys

from sdcclient import SdcClient

#
# Parse arguments
#
if len(sys.argv) != 2:
print('usage: %s <sysdig-token>' % sys.argv[0])
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
print('For this script to work, the user for the token must have Admin rights')
sys.exit(1)

sdc_token = sys.argv[1]

# Maximum number of agents allowed to connect for this access key. Set to '' if not required
agent_limit = ''
# 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.
agent_reserved = ''
# Team ID to which to assign the access key. Team ID must be valid. Set to '' if not required.
team_id = ''


#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')

#
# Get the configuration
#
ok, res = sdclient.create_access_key(
agent_limit,
agent_reserved,
team_id)

if ok:
print('Access Key: {}\nTeam ID: {}\nAgent Limit: {}\nAgent Reserved: {}\n==========='.format(res['customerAccessKey']['accessKey'], res['customerAccessKey']['teamId'], res['customerAccessKey']['limit'], res['customerAccessKey']['reservation']))
else:
print(res)
sys.exit(1)
54 changes: 54 additions & 0 deletions examples/update_access_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
#
# List all the access keys in a Sysdig Monitor environment. The token you provide must
# have Admin rights.
#

import sys

from sdcclient import SdcClient

#
# Parse arguments
#
if len(sys.argv) != 2:
print('usage: %s <sysdig-token>' % sys.argv[0])
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
print('For this script to work, the user for the token must have Admin rights')
sys.exit(1)

sdc_token = sys.argv[1]

# Access Key that needs to be updated
accessKey = ''
# Maximum number of agents allowed to connect for this access key. Set to '' if not required
agent_limit = ''
# 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.
agent_reserved = ''
# Team ID to which to assign the access key. Team ID must be valid. Set to '' if not required.
team_id = ''


#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')

#
# Get the configuration
#
if accessKey:
ok, res = sdclient.update_access_key(
accessKey,
agent_limit,
agent_reserved,
team_id)
else:
print('Please specify the Access Key that you would like to be updated')
sys.exit(1)

if ok:
print('Access Key: {}\nTeam ID: {}\nAgent Limit: {}\nAgent Reserved: {}\n==========='.format(res['customerAccessKey']['accessKey'], res['customerAccessKey']['teamId'], res['customerAccessKey']['limit'], res['customerAccessKey']['reservation']))
else:
print(res)
sys.exit(1)
31 changes: 29 additions & 2 deletions sdcclient/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,15 +1044,42 @@ def list_access_keys(self):
res = self.http.get(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify)
return self._request_result(res)

def create_access_key(self):
def create_access_key(self, agent_limit=None, agent_reserved=None, team_id=None):
'''
**Description**
Create a new access key for Sysdig Monitor/Secure
**Reslut**
The access keys object
'''
res = self.http.post(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify)
access_key_payload = {
"customerAccessKey": {
"limit": agent_limit,
"reservation": agent_reserved,
"teamId": team_id
}
}

res = self.http.post(self.url + '/api/customer/accessKeys', headers=self.hdrs, verify=self.ssl_verify, data=json.dumps(access_key_payload))
return self._request_result(res)

def update_access_key(self, access_key, agent_limit=None, agent_reserved=None, team_id=None):
'''
**Description**
Create a new access key for Sysdig Monitor/Secure
**Reslut**
The access keys object
'''
access_key_payload = {
"customerAccessKey": {
"limit": agent_limit,
"reservation": agent_reserved,
"teamId": team_id
}
}

res = self.http.put(self.url + '/api/customer/accessKeys/' + access_key, headers=self.hdrs, verify=self.ssl_verify, data=json.dumps(access_key_payload))
return self._request_result(res)

def disable_access_key(self, access_key):
Expand Down

0 comments on commit 8ca6764

Please sign in to comment.