Export controls list for all assets via SAFE APIs
  • 1 Minute to read
  • PDF

Export controls list for all assets via SAFE APIs

  • PDF

Article Summary

About this document


This document explains the procedure to export the control lists for all assets in SAFE in one go using Python script and SAFE APIs.

Pre-requisite


  • Download the Python package.
  • Python Packages - pip install requests
  • Operating System - Mac, Linux, Windows
  • SAFE API credentials. Refer to Accessing SAFE APIs for more details.

Generate SAFE API credentials


To generate the SAFE API credentials:

  1. Login to SAFE.
  2. Navigate to Administration > User Management.
  3. Search for the user for whom you want to create the API credentials.
  4. Click the Edit icon available for the user. The system redirects you to the Edit User page.
    API1
  5. On the Edit User page, click the GenerateAPICredentials button.
  6. On the confirmation screen, click Ok. The system displays the API credentials. These APIs credentials will not work till you click the Submit button and complete the process of generating API credentials.
    API2
  7. Click the Submit button.
Note 
The API credentials will not work till you click the Submit button of Step 7 mentioned above and complete the process of generating API credentials.

SAFE APIs to be used


The following APIs will be used in the script:

  • /api/v3/auth to get the access token
  • /api/v3/assets/?verticalId={vertical} to get asset list for particular vertical
  • /api/v3/assets/{asset}/assessment to get assessment result for particular asset
  • /api/v3/asset-types?verticalId={vertical} to get all asset types for particular vertical
  • /api/v3/controls/?assetTypeId={assetTypeId} to get all controls for particular asset type

Export controls list


To export the controls list, pass the below script.

--vertical [{1,2,3,4,5,6,7,8,9,10,11,14,15,16}]
      Default:- 6, 1. Cloud - SaaS Applications, 2. Databases, 3. Endpoints, 4. Mobile Applications, 5. Network & Security Nodes, 6. Server, 7. Storage, 8. Thick Client
      Applications, 9. Web Applications, 10. Middleware, 11. On Premise Hosted Products, 14. Cloud - AWS, 15. Cloud - Azure, 16. Cloud - GCP
--status [{All,Failed,Qualified,Accepted Failed}]
      Default:- All, Failed, Qualified, Accepted Failed


Example

safe@Admins-MacBook-Pro scripts % python export_asset_list.py --vertical 6 --status Failed

Enter SAFE URL(eg. test.safescore.ai):celatest.safescore.ai

2022-10-14 13:43:14,213 - INFO - Tenant verified successfully

Enter API username:safe-service-account

Enter API password:********************

2022-10-14 13:43:30,793 - INFO - Getting Access Token

2022-10-14 13:43:30,979 - INFO - Access Token successfully received

2022-10-14 13:43:30,979 - INFO - Getting Failed controls

2022-10-14 14:01:44,182 - INFO - Controls sheet has been created successfully for different Asset types

2022-10-14 14:01:44,247 - INFO - Master controls sheet has been created successfully

  • The script will give the controls list in CSV for a particular asset type in a vertical. Users can also pass the status parameters to get a control list for specific statuses like Failed, Qualified, and Accepted Failed.
  • You will get an exportedcontrols directory and log_export_list.log in the exact location once the script is executed.



Was this article helpful?