veracode/veracode-api-py

upload_file api broken???

Closed this issue · 6 comments

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.

In the meantime, this is my workaround:

def upload_file(app_id, file_name):
    # the library is broken, we roll our own
    print('Uploading file to Veracode: ' + file_name + '...')

    endpoint = 'https://analysiscenter.veracode.com/api/5.0/uploadfile.do'
    try:
        multipart_form_data = {
            'file': (file_name, open(file_name, 'rb')),
            'action': (None, 'store'),
            'path': (None, '/' + file_name)
        }
        response = requests.post(endpoint,
                                 files=multipart_form_data,
                                 params={'app_id': app_id, 'save_as': file_name},
                                 auth=RequestsAuthPluginVeracodeHMAC(),
                                 headers=HEADERS)
    except requests.RequestException as e:
        print("Call to " + endpoint + " failed.")
        print("Cannot upload file " + file_name + " and app id" + app_id + " to Veracode.")
        print(EXCEPTION_DETAILS_FOLLOW)
        print(e)
        sys.exit(1)

    if response.ok:
        return response.text
    print("Cannot upload file " + file_name + " and app id" + app_id + " to Veracode.")
    sys.exit(1)

one more thing -- if you run dir on the api object you get this -- with upload_file method missing... Not sure how that is possible -- since its clearly listed in the apil.py file. running 0.9.30 version.

api = veracode_api_py.VeracodeAPI()
print(dir(api))

['__class__', 
 '__delattr__', 
 '__dict__', 
 '__dir__', 
 '__doc__', 
 '__eq__', 
 '__format__', 
 '__ge__', 
 '__getattribute__', 
 '__gt__', 
 '__hash__', 
 '__init__', 
 '__init_subclass__', 
 '__le__', 
 '__lt__', 
 '__module__', 
 '__ne__', 
 '__new__', 
 '__reduce__', 
 '__reduce_ex__', 
 '__repr__', 
 '__setattr__', 
 '__sizeof__', 
 '__str__', 
 '__subclasshook__', 
 '__weakref__', 
 'add_annotation', 
 'add_workspace_team', 
 'baseurl', 
 'connect_error_msg', 
 'create_agent', 
 'create_analysis', 
 'create_app', 
 'create_business_unit', 
 'create_collection', 
 'create_global_scanner_variable', 
 'create_policy', 
 'create_sandbox', 
 'create_team', 
 'create_user', 
 'create_workspace', 
 'delete_analysis', 
 'delete_analysis_scanner_variable', 
 'delete_app', 
 'delete_business_unit', 
 'delete_collection', 
 'delete_dyn_scan', 
 'delete_global_scanner_variable', 
 'delete_policy', 
 'delete_sandbox', 
 'delete_scan_scanner_variable', 
 'delete_team', 
 'delete_user', 
 'delete_workspace', 
 'disable_user', 
 'download_archer', 
 'dyn_setup_auth', 
 'dyn_setup_auth_config', 
 'dyn_setup_blocklist', 
 'dyn_setup_crawl_configuration', 
 'dyn_setup_crawl_script', 
 'dyn_setup_custom_host', 
 'dyn_setup_login_logout_script', 
 'dyn_setup_scan', 
 'dyn_setup_scan_config_request', 
 'dyn_setup_scan_contact_info', 
 'dyn_setup_scan_setting', 
 'dyn_setup_url', 
 'dyn_setup_user_agent', 
 'generate_archer', 
 'get_agent', 
 'get_agent_token', 
 'get_agent_tokens', 
 'get_agents', 
 'get_analyses', 
 'get_analyses_by_name', 
 'get_analyses_by_search_term', 
 'get_analyses_by_target_url', 
 'get_analysis', 
 'get_analysis_audits', 
 'get_analysis_occurrence', 
 'get_analysis_occurrences', 
 'get_analysis_scanner_variables', 
 'get_analysis_scans', 
 'get_app', 
 'get_app_by_name', 
 'get_app_info', 
 'get_app_list', 
 'get_app_sandboxes', 
 'get_apps', 
 'get_build_info', 
 'get_build_list', 
 'get_business_unit', 
 'get_business_units', 
 'get_codegroup', 
 'get_codegroups', 
 'get_collection', 
 'get_collection_assets', 
 'get_collections', 
 'get_collections_by_business_unit', 
 'get_collections_by_name', 
 'get_collections_statistics', 
 'get_component_activity', 
 'get_creds', 
 'get_custom_fields', 
 'get_detailed_report', 
 'get_dyn_scan', 
 'get_dyn_scan_audits', 
 'get_dyn_scan_config', 
 'get_dynamic_configuration', 
 'get_dynamic_flaw_info', 
 'get_dynamic_scan_capacity_summary', 
 'get_findings', 
 'get_global_scanner_variable', 
 'get_global_scanner_variables', 
 'get_issue', 
 'get_issues', 
 'get_libraries', 
 'get_library', 
 'get_license', 
 'get_policies', 
 'get_policy', 
 'get_project', 
 'get_project_issues', 
 'get_project_libraries', 
 'get_projects', 
 'get_roles', 
 'get_sandbox_list', 
 'get_sbom', 
 'get_sbom_project', 
 'get_sca_events', 
 'get_sca_scan', 
 'get_scan_occurrence', 
 'get_scan_occurrence_configuration', 
 'get_scan_occurrence_notes_report', 
 'get_scan_occurrence_screenshots', 
 'get_scan_occurrence_verification_report', 
 'get_scan_occurrences', 
 'get_scan_scanner_variables', 
 'get_static_flaw_info', 
 'get_summary_report', 
 'get_teams', 
 'get_user', 
 'get_user_by_name', 
 'get_user_by_search', 
 'get_user_self', 
 'get_users', 
 'get_vulnerability', 
 'get_workspace_by_name', 
 'get_workspaces', 
 'healthcheck', 
 'match_findings', 
 'proxies', 
 'regenerate_agent_token', 
 'renew_creds', 
 'retry_seconds', 
 'revoke_agent_token', 
 'revoke_creds', 
 'send_password_reset', 
 'set_mitigation_info', 
 'status', 
 'stop_analysis_occurrence', 
 'stop_scan_occurrence', 
 'update_analysis', 
 'update_analysis_scanner_variable', 
 'update_business_unit', 
 'update_collection', 
 'update_dyn_scan', 
 'update_global_scanner_variable', 
 'update_policy', 
 'update_sandbox', 
 'update_scan_scanner_variable', 
 'update_team', 
 'update_user', 
 'update_user_email_address', 
 'update_user_roles']

I'll take a look at the last point, but for the first, if you call it like this it should work:

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

Ah, the last point is because we didn't do a release since the upload_file change was merged in. I will work on releasing an update today/tomorrow and close this ticket when I confirm it works. Thanks for flagging the issue!

OK, cool, thanks for looking into this.
F.

Should work better now on the new release, v._0.9.31