Giter Club home page Giter Club logo

veracode-api-py's Introduction

Veracode API Python

Python helper library for working with the Veracode APIs. Handles retries, pagination, and other features of the modern Veracode REST APIs.

Not an official Veracode product. Heavily based on original work by CTCampbell.

Setup

Install from pypi:

pypi veracode_api_py

(Optional) Save Veracode API credentials in ~/.veracode/credentials

[default]
veracode_api_key_id = <YOUR_API_KEY_ID>
veracode_api_key_secret = <YOUR_API_KEY_SECRET>

Use in your applications

Import VeracodeAPI or one of the individual API classes into your code and call the methods. Most methods return JSON or XML depending on the underlying API.

You can find sample scripts for some APIs in the Samples folder.

Docs

For detailed documentation on the available methods, please see the veracode-api-py docs.

Notes

  1. Different API calls require different roles. Consult the Veracode Docs.

  2. This library does not include a complete set of Veracode API methods. In particular, it only provides a handful of XML API methods.

  3. To use this library (or a script based on it) with a proxy server, you can set environment variables with the addresses of the proxies:

    • export HTTP_PROXY='http://10.10.10.10:8000'
    • export HTTPS_PROXY='http://10.10.10.10:1212'
  4. Contributions are welcome. See the Contributions guidelines.

veracode-api-py's People

Contributors

aaronbutler-veracode avatar aszaryk avatar bnreplah avatar dayum avatar dennismedeiros avatar gby56 avatar mastermargie avatar meltingscales avatar nazafur avatar tjarrettveracode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

veracode-api-py's Issues

Add support for SBOM for SCA Agent

The URL for the API should be similar to upload scan with different type:

https://api.Veracode.com/sca/sbom/v1/targets/{projectUuid}/cyclonedx?type=agent

Note that the ProjectUUID must be gotten from a call to the workspaces/<guid>/projects endpoint.

Handle URL encoding for query functions

A few of the APIs perform searches with queries in the URL. We should url-encode the search parameters for these. Specifically:

  • get_app_by_name
  • get_user_by_name
  • get_workspace_by_name

Update Application profiles custom fields

That would be a really useful function, to automate a lot of tagging of resources in the veracode platform.
The current update only has these fields

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

Users.update() throws 500, doesn't parse incoming roles list

Tried updating a user's roles using Users().update() but kept getting a 500. I think it was because the function doesn't parse out the list of roles in the same way that Users().create() does.

I was able to successfully use the function when I passed json.dumps(roles) to it, where roles was something like:
{'roles': [{'role_name': 'extseclead'}, {'role_name': 'extcreator'}]}

I'd love to see this re-written as Users.update_roles() instead, with a more generic Users.update() kept around to be able to change multiple attributes at once.

Add method to delete teams per SCA workspace

def add_team(self,workspace_guid: UUID,team_id: UUID):

I'm building my "state-machine" to be able to define in a single JSON structure the Veracode user/teams/workspace/sast app management.

The JSON will look like:

{
  "TEAM_NAME":{
    "sast_applications": ["sast_app_name", ....],
    "sca_workspaces": ["sca_ws_name", ....],
    "users": ["email", ....],
  }
}

I need to be able to create/delete teams in the workspace, that's missing currently. I'll make a PR it should be simple enough.

Add proxy support

Customer reports:

I need to use proxy to connect to Veracode servers and Veracode Pipeline Mitigation does not allow for that. It uses Python requests module under the hood which allows to use http_proxy and https_proxy env variables. However, proxies are explicitly defined in:

https://github.com/tjarrettveracode/veracode-api-py/blob/master/veracode_api_py/apihelper.py

session.send(prepared_request, proxies=self.proxies)

and because of that fact env variables are not taken into account.

Add option to match including flaw description

For cases where Veracode finds multiple flaws with the same CWE on the same line, the flaw description can be used to achieve a more precise match.

This should be added as an optional argument to the flaw match code so that it isn't used for every match.

Better debug logging

Should add debug logging that includes the following:

  • URL and method being executed
  • x-conversation-id of response

Support for removing a user's team assignments

I think this comes down to the incremental vs partial choice in the api
I managed to add new teams to a users, it was really easy because I just had to give the new team's id and it was added on the existing... but I knew this would probably be a problem if I wanted to remove that after.

Update docs to provide both object based and API shim calls

The library used to host all functions in a single API layer. It's since been refactored into separate objects, but the documentation doesn't reflect this refactoring.

Update the docs to reflect both the calls on the api object and the actual functional objects - Applications, SCA, etc.

Annotations method fails if called without sandbox

Partial stack trace:

  File "/usr/local/lib/python3.9/site-packages/veracode_api_py/api.py", line 141, in add_annotation
    return Findings().add_annotation(app,issue_list,comment,action,sandbox)
  File "/usr/local/lib/python3.9/site-packages/veracode_api_py/findings.py", line 51, in add_annotation
    return APIHelper()._rest_request(uri,"POST",body=payload,params=params)
UnboundLocalError: local variable 'params' referenced before assignment

Getting xml back from veracode_api.get_app_list()

I ran the following code (with value API token in the right place)

from veracode_api_py import VeracodeAPI
veracode_api = VeracodeAPI()
print(veracode_api.get_app_list())

It works but gives me XML. I was expecting a Python wrapper to give back a list. I'm not having a go at anyone, just want to understand if I'm driving this wrong before I start writing code to parse my responses.

upload_file api broken???

this may be me, or a really weird issue.
after referencing the library
import veracode_api_py
I try to run the method like so:

    api = veracode_api_py.VeracodeAPI()
    api.upload_file(app_id, file_name)

at runtime, I get the following error:

File "blah.py"
    api.upload_file(app_id, file_name)
AttributeError: 'VeracodeAPI' object has no attribute 'upload_file'

super weird, because I run other xml api's like this too, and they work.

SBOM generation doesn't support linked=true

For an application, the SBOM API endpoint allows for parameter "linked=true". This causes the generated SBOM to include components from any linked projects. However, the default value is false and there's no way to set the parameter. Therefore it's not possible for data from a linked project to show up in the generated SBOM for an application.

Add validation where GUIDs are expected

Seeing some confusion between integer app IDs and GUIDs among users of the library. Should look into properly validating when one vs the other is expected.

More argument typing

All UUID type arguments should be distinct from int type arguments so that at least at time of writing it is clear when there are mismatches.

Retried requests do not regenerate auth headers

We use the Python Requests module and urllib3.util.retry to implement retry in the event of a short list of HTTP error codes. Need to ensure that the auth header gets regenerated with each retry. While we're at it, we should ensure that we're honoring the retry-after value in the response headers to deal gracefully with rate limiting.

Error on create_user()

An error is thrown when calling create_user(). Additionally, the default method treats user_name as optional, but it is required by the API.

SCA().get_issue() implementation incorrect

SCA().get_issue() tries to call an endpoint as follows:

self.sca_base_url + '/issues/{}'.format(issue_id)

But the correct syntax for issues is just

'/v3/issues/{}'.format(issue_id)

Get specific team details

https://app.swaggerhub.com/apis/Veracode/veracode-identity_api/1.0#/team/getTeamUsingGET

This is to get the list of members in a team, which is required if we want to easily add/remove people from teams.

Currently:

Adding a user to a team

            VeracodeAPI().update_user(
                user["user_id"],
                {
                    "teams": [
                        {
                            "team_id": team_to_add_id,
                            "team_legacy_id": team_to_add_legacy_id,
                        }
                    ]
                },
            )

Remove a user from a team

You can't, that's because the above API is incremental only so you can only add new things to the user, not remove things.

The alternative we figured was to:

  1. fetch the team members
  2. remove the user you don't want
  3. update the team with that new list
  4. done

But there is no current API that fetches these details per team.

Add a global page size variable for the Agent-based SCA client

Hi @tjarrettveracode !

I'm having a bug currently with the SourceClear API, and the only fix would be to set the pagination size to a bigger one.
Its on the get_projects() function, but it got me thinking, looking at the apihelper.py, the _rest_paged_request() function could maybe inject a page size param, with a setting in the client constructor ?

I'll make a PR to show what I'm thinking about, it would really help

Support parameters for SBOM creation

There are two new parameters for SBOM creation for both CycloneDX and SPDX:

  • vulnerability (T/F) - include or suppress vulnerability information
  • dependency (T/F) - include or suppress dependency information

We should add both as optional arguments for the SBOM methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.