Skip to content

Commit

Permalink
add support for app bus owner data (fixes #73)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjarrettveracode committed Oct 3, 2023
1 parent f735d16 commit 177e973
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
6 changes: 4 additions & 2 deletions docs/applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ _Note_: You can also access these methods from the `Applications` class.
- `get_apps(policy_check_after(opt))` : get a list of Veracode applications (JSON format). If provided, returns only applications that have a policy check date on or after `policy_check_after` (format is `yyyy-mm-dd`).
- `get_app(guid(opt),legacy_id(opt))`: get information for a single Veracode application using either the `guid` or the `legacy_id` (integer).
- `get_app_by_name(name)`: get list of applications whose names contain the search string `name`.
- `create_app(app_name, business_criticality, business_unit(opt), teams(opt), policy_guid(opt), custom_fields(opt array))`: create an application profile.
- `create_app(app_name, business_criticality, business_unit(opt), teams(opt), policy_guid(opt), custom_fields(opt array), bus_owner_name(opt), bus_owner_email(opt))`: create an application profile.
- `business_criticality`: one of "VERY HIGH", "HIGH", "MEDIUM", "LOW", "VERY LOW"
- `business_unit`: the GUID of the business unit to which the application should be assigned
- `teams`: a list of the GUIDs of the teams to which the application should be assigned
- `policy_guid`: the GUID of the policy to set for this application.
- `custom_fields`: an array of custom field values for the application
- `update_app(guid, app_name, business_criticality, business_unit(opt), teams(opt), policy_guid(opt), custom_fields(opt array))`: update an application profile. Note that partial updates are NOT supported, so you need to provide all values including those that aren't changing.
- `bus_owner_name`: the name of the business owner of the application
- `bus_owner_email`: the email address of the business owner of the application
- `update_app(guid, app_name, business_criticality, business_unit(opt), teams(opt), policy_guid(opt), custom_fields(opt array), bus_owner_name(opt), bus_owner_email(opt))`: update an application profile. Note that partial updates are NOT supported, so you need to provide all values including those that aren't changing.
- `delete_app(guid)`: delete the application identified by `guid`. This is not a reversible action.
- `get_custom_fields()`: get a list of app profile custom fields available for your organization.
- `policy_guid` The GUID of the policy to set for this application.
Expand Down
9 changes: 5 additions & 4 deletions veracode_api_py/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ def get_app(self, guid: UUID = None, legacy_id=None):
def get_app_by_name(self, appname):
return Applications().get_by_name(appname)

def create_app(self, app_name, business_criticality, business_unit: UUID = None, teams=[], policy_guid = None, custom_fields=[]):
def create_app(self, app_name, business_criticality, business_unit: UUID = None, teams=[],
policy_guid = None, custom_fields=[],bus_owner_name = None, bus_owner_email = None):
return Applications().create(app_name=app_name, business_criticality=business_criticality,
business_unit=business_unit, teams=teams, policy_guid=policy_guid,
custom_fields=custom_fields)
custom_fields=custom_fields, bus_owner_name=bus_owner_name, bus_owner_email=bus_owner_email)

def update_app(self, guid: UUID, app_name, business_criticality, business_unit: UUID = None, teams=[], policy_guid = None, custom_fields=[]):
def update_app(self, guid: UUID, app_name, business_criticality, business_unit: UUID = None, teams=[], policy_guid = None, custom_fields=[], bus_owner_name=None, bus_owner_email=None):
return Applications().update(guid=guid, app_name=app_name, business_criticality=business_criticality,
business_unit=business_unit, teams=teams, policy_guid=policy_guid,
custom_fields=custom_fields)
custom_fields=custom_fields, bus_owner_name=bus_owner_name, bus_owner_email=bus_owner_email)

def delete_app(self, guid: UUID):
return Applications().delete(guid)
Expand Down
29 changes: 22 additions & 7 deletions veracode_api_py/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,28 @@ def get_by_name (self,appname: str):
params = {"name": parse.quote(appname)}
return APIHelper()._rest_paged_request(uri="appsec/v1/applications",method="GET",element="applications",params=params)

def create(self,app_name:str ,business_criticality, business_unit: UUID=None, teams=[], policy_guid:UUID=None, custom_fields=[]):
return self._create_or_update("CREATE",app_name,business_criticality,business_unit,teams, policy_guid, custom_fields)

def update(self,guid: UUID,app_name:str ,business_criticality, business_unit: UUID=None, teams=[], policy_guid:UUID=None, custom_fields=[]):
return self._create_or_update("UPDATE",app_name,business_criticality,business_unit,teams,guid, policy_guid, custom_fields)
def create(self,app_name:str ,business_criticality, business_unit: UUID=None, teams=[], policy_guid:UUID=None,
custom_fields=[], bus_owner_name=None, bus_owner_email=None):
return self._create_or_update("CREATE",app_name=app_name,business_criticality=business_criticality,
business_unit=business_unit,teams=teams, policy_guid=policy_guid,
custom_fields=custom_fields, bus_owner_name=bus_owner_name,
bus_owner_email=bus_owner_email)

def update(self,guid: UUID,app_name:str ,business_criticality, business_unit: UUID=None,
teams=[], policy_guid:UUID=None, custom_fields=[],
bus_owner_name=None,bus_owner_email=None):
return self._create_or_update("UPDATE",app_name=app_name,business_criticality=business_criticality,
business_unit=business_unit,teams=teams,guid=guid,
policy_guid=policy_guid, custom_fields=custom_fields,
bus_owner_name=bus_owner_name,bus_owner_email=bus_owner_email)

def delete(self,guid: UUID):
uri = 'appsec/v1/applications/{}'.format(guid)
return APIHelper()._rest_request(uri,'DELETE')

def _create_or_update(self,method,app_name: str,business_criticality, business_unit: UUID=None, teams=[],guid=None,policy_guid:UUID=None, custom_fields=[]):
def _create_or_update(self,method,app_name: str,business_criticality, business_unit: UUID=None,
teams=[],guid=None,policy_guid:UUID=None, custom_fields=[],
bus_owner_name=None,bus_owner_email=None):
if method == 'CREATE':
uri = 'appsec/v1/applications'
httpmethod = 'POST'
Expand All @@ -68,9 +79,13 @@ def _create_or_update(self,method,app_name: str,business_criticality, business_u
bu = {'business_unit': {'guid': business_unit}}
app_def.update(bu)

if len(custom_fields) > 0:
if (custom_fields != None):
app_def.update({"custom_fields": custom_fields})

if (bus_owner_email != None) & (bus_owner_name != None):
bus_owner = {'business_owners':[ {'email': bus_owner_email, 'name': bus_owner_name } ] }
app_def.update(bus_owner)

payload = json.dumps({"profile": app_def})
return APIHelper()._rest_request(uri,httpmethod,body=payload)

Expand Down

0 comments on commit 177e973

Please sign in to comment.