Skip to content

Commit

Permalink
Merge pull request #13 from mastermargie/master
Browse files Browse the repository at this point in the history
Fix #12
  • Loading branch information
tjarrettveracode authored May 11, 2021
2 parents 0e1b1bf + 700bae3 commit d87bb2b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ dmypy.json
cython_debug/
.DS_Store
helpers/__pycache__/api.cpython-37.pyc
test.py
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ The following methods call Veracode REST APIs and return JSON.
- `create_user(email,firstname,lastname,type(opt),username(opt),roles(opt))`: create a user based on the provided information.
- `type`: `"HUMAN"` or `"API"`. Defaults to `"HUMAN"`. If `"API"` specified, must also provide `username`.
- `roles`: list of role names (specified in the Veracode Help Center, for both [human](https://help.veracode.com/go/c_identity_create_human) and [API service account](https://help.veracode.com/go/c_identity_create_api) users). Provide the role names from `get_roles()`.
- `update_user(user_guid, roles)`: update the user identified by `user_guid` with the list of roles passed in `roles`. Because the Identity API does not support adding a single role, the list should be the entire list of existing roles for the user plus whatever new roles. See [veracode-user-bulk-role-assign](https://github.com/tjarrettveracode/veracode-user-bulk-role-assign) for an example.
- `update_user_roles(user_guid, roles)`: update the user identified by `user_guid` with the list of roles passed in `roles`. Because the Identity API does not support adding a single role, the list should be the entire list of existing roles for the user plus whatever new roles. See [veracode-user-bulk-role-assign](https://github.com/tjarrettveracode/veracode-user-bulk-role-assign) for an example.
- `update_user(user_guid,changes)`: update a user based upon the provided information.
- `user_guid`: the unique identifier of the user to be updated.
- `changes`: the attributes of the user to be changed. Must be JSON whose format follows the [Identity API specification](https://app.swaggerhub.com/apis/Veracode/veracode-identity_api/1.0#/ResourceOfUserResource) of a valid user object.
- `disable_user(user_guid)`: set the `Active` flag the user identified by `user_guid` to `False`.
- `delete_user(user_guid)`: delete the user identified by `user_guid`. This is not a reversible action.
- `get_roles()`: get a list of available roles to assign to users.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'veracode_api_py',
packages = ['veracode_api_py'],
version = '0.9.12',
version = '0.9.13',
license='MIT',
description = 'Python helper library for working with the Veracode APIs. Handles retries, pagination, and other features of the modern Veracode REST APIs.',
author = 'Tim Jarrett',
Expand Down
7 changes: 5 additions & 2 deletions veracode_api_py/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ def get_user_by_name(self,username):
def create_user (self,email,firstname,lastname,username=None,type="HUMAN",roles=[],teams=[]):
return Users().create(email,firstname,lastname,username,type,roles,teams)

def update_user (self,user_guid,roles):
return Users().update(user_guid,roles)
def update_user_roles (self,user_guid,roles):
return Users().update_roles(user_guid,roles)

def update_user (self,user_guid,changes):
return Users().update(user_guid,changes)

def disable_user (self,user_guid):
return Users().disable(user_guid)
Expand Down
16 changes: 14 additions & 2 deletions veracode_api_py/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,22 @@ def create(self,email,firstname,lastname,username=None,type="HUMAN",roles=[],tea
payload = json.dumps(user_def)
return APIHelper()._rest_request('api/authn/v2/users','POST',body=payload)

def update(self,user_guid,roles):
def update_roles(self,user_guid,roles):
request_params = {'partial': 'TRUE',"incremental": 'TRUE'}
uri = "api/authn/v2/users/{}".format(user_guid)

rolelist = []
for role in roles:
rolelist.append({"role_name": role})

payload = json.dumps({"roles": rolelist})
return APIHelper()._rest_request(uri,"PUT",request_params,body=payload)

def update(self,user_guid,changes):
request_params = {'partial':'TRUE',"incremental": 'TRUE'}
uri = "api/authn/v2/users/{}".format(user_guid)
return APIHelper()._rest_request(uri,"PUT",request_params,roles)
payload = json.dumps(changes)
return APIHelper()._rest_request(uri,"PUT",request_params,body=payload)

def disable(self,user_guid):
request_params = {'partial':'TRUE'}
Expand Down

0 comments on commit d87bb2b

Please sign in to comment.