CloudScend Foresight API Guide
CloudScend Foresight API Guide
Introduction
The CloudScend Foresight API provides access to endpoints you can use to integrate into your own tools.
The most important endpoints of the CloudScend Foresight API have been organized below into feature areas.
Base URL
All URLs referenced in the documentation start with a base URL variable which represents the protocol and host name of the applicable CloudScend Foresight API service. For example https://foresight-api-backend.example.com
.
The default baseURL
variable should point to the CloudScend Foresight backend API service. sourceCodeUploaderBaseUrl
should point to the CloudScend Foresight Source Code Uploader API service.
Authentication
All endpoints require authentication and are secured using Keycloak. CloudScend Foresight uses OAuth2 for authentication and authorization of the API. OAuth2 is a protocol designed to let third-party applications authenticate to perform actions as a user, without getting the user's password. There are several libraries available that implement the protocol, and a good list can be found at the OAuth2 home page. Through the use of OAuth2, you'll go through the process of obtaining a token and then you'll use that token in every request made to the CloudScend Foresight API to verify your identity.
CloudScend Foresight API servers accept Bearer tokens through the HTTP Authorization header in requests. Bearer tokens allow requests to authenticate using an access key, such as a JSON Web Token (JWT).
The example below shows how to automate processes by requesting a token from Keycloak, extracting the token, and passing the token to the CloudScend Foresight backend, which would be suitable for a CI/CD pipeline.
#!/bin/bash
echo "Requesting authentication"
RESULT=`curl -s --location --request POST \
"$KEYCLOAK_BASE_URL/auth/realms/appmod/protocol/openid-connect/token" \
--data-urlencode 'grant_type=password' \
--data-urlencode "username=$FORESIGHT_USERNAME" \
--data-urlencode "password=$FORESIGHT_PASSWORD" \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=sage'`
echo $RESULT
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
echo "Extracted token"
echo $TOKEN
curl $FORESIGHT_API_BASE_URL/sage/application/ -H "Authorization: bearer $TOKEN"
Postman Collection
The quickest way to get started is to use our Postman request collection. The following steps will help you get up and running.
Import the CloudScend Foresight Postman Collection
- Download Postman Collection
- From Postman, Import -> Select downloaded Foresight postman collection
Configure Postman Environment
- Setup a new environment in Postman. Click New -> Environment.
- Name the new environment Foresight API
- Add the following variables:
- baseUrl: enter the CloudScend Foresight Backend API URL
- sourceCodeUploaderBaseUrl: enter the CloudScend Foresight Source Code Uploader Base URL
- loginBaseUrl: enter the Keycloak service base url
- Click Add to create
Authenticate
- In the Authorization tab for the collection, select OAuth 2.0 from the Type dropdown list. By default Postman will append the access token to Bearer in the Authorization header for your request.
- To request an access token, fill out the fields in the Configure New Token section. There are several ways to configure based on the Grant Type you want to use. For the Password Credentials grant type enter the following details:
- Access Token URL: {{loginBaseUrl}}/auth/realms/appmod/protocol/openid-connect/token
- Client ID: sage
- Username: {{FORESIGHT_USERNAME}}
- Password: {{FORESIGHT_PASSWORD}}
- Scope: openid email profile
- Client Authentication: Send as Basic Auth header
- Click Get New Access Token
- Click Use Token
- Click Update to save the Authorization details. You can save both the token and the details to generate a token with your request or collection.
- View Postman Documentation on OAuth2 Authentication for more info.
Explore the API
- Execute any of the requests within the collection
- Refer to this documentation for the requirements of each request
Application
This collection describes the important endpoints for working with Applications. Before doing any analysis in CloudScend Foresight you must first create an Application.
Get Applications
Retrieves a list of applications the user has access to.
Example Response
- Body
- Headers
[
{
"id": -83970435,
"applicationId": "voluptate nostrud pariatur veniam adipisicing",
"applicationName": "dolor sit nisi",
"applicationUser": "dolore",
"projectManager": "elit incididunt mollit",
"functional": "ea commodo Ut ullamco",
"applicationLanguage": "TSQL",
"analysisStatus": "CODE_ANALYSIS_ERROR",
"artifactUrl": "enim in tempor eu dolor",
"appOwner": "dolor proident ut",
"surveyStatus": "laboris pariatu",
"cestatus": "CE_NOT_ATTEMPTED",
"programManager": "laborum et fugiat"
},
{
"id": -92365495,
"applicationId": "voluptate commodo velit",
"applicationName": "elit eiusmod esse",
"applicationUser": "in",
"projectManager": "Excepteur adipisicing Ut",
"functional": "officia in",
"applicationLanguage": "TYPESCRIPT",
"analysisStatus": "CODE_ANALYSIS_PROGRESS",
"artifactUrl": "eiusmod elit officia",
"appOwner": "lab",
"surveyStatus": "laborum eu in consectetur",
"cestatus": "CE_READY_WITH_NO_REPORT",
"programManager": "ut incididunt labore est Ut"
}
]
Key | Value |
---|---|
Content-Type | application/json |
Get Application History
Retrieves a list of application versions including the version tag and source code upload timestamp. A new application version is created each time source code is uploaded.
- Params
Path variables
Key | Type | Description |
---|---|---|
app-id | string | (Required) |
Example Response
- Body
- Headers
[
{
"appGlobalId": "tempor aliquip occaecat nulla ipsum",
"id": 38868107,
"gitTag": "mollit cillum",
"uploadTimestamp": "1978-12-24T07:54:29.663Z"
},
{
"appGlobalId": "sed dolor exercitation",
"id": 44339925,
"gitTag": "Excepteur",
"uploadTimestamp": "1949-08-13T12:25:44.757Z"
}
]
Key | Value |
---|---|
Content-Type | application/json |
Source Code
Upload Source Code for an Application
Stores a zip file containing an application's source code. Upon successful upload, check the status of processing the zip file contents using the Get Code Analysis Status endpoint.
- Params
- Headers
- Body
Path variables
Key | Type | Description |
---|---|---|
appGlobalId | Application Id (Required) |
Key | Value |
---|---|
Content-Type | multipart/form-data |
formdata
Param | Value | Type | Description |
---|---|---|---|
file | file | The zip file containing the application source code. |
Example Response
- Body
- Headers
{ "id": "0000-0000-0000-0000", "success": true, "message": "good to go" }
Key | Value |
---|---|
Content-Type | application/json |
Get Code Analysis Status
Returns the current source code analysis status for the latest source code version of an application.
Code | Status | Meaning |
---|---|---|
READY_FOR_CODE_UPLOAD | Ready for source code upload | No source code has been uploaded for the application yet |
CODE_UPLOADED | Source code uploaded | Source code has been successfully uploaded but analysis has not started yet |
CODE_UPLOAD_ERROR | Error uploading source code | An error occurred extracting the source code from the uploaded source code zip file |
CODE_ANALYSIS_PROGRESS | Analysis in progress | Source code analysis is in progress |
CODE_ANALYSIS_DONE | Analysis results ready | Source code analysis is complete |
CODE_ANALYSIS_ERROR | Source code analysis error | Source code analysis failed processing. |
- Params
Path variables
Key | Type | Description |
---|---|---|
appGlobalId | string | (Required) |
Example Response
- Body
- Headers
{
"appGlobalId": "ce791988-8161-4369-b744-57eb77311ef7",
"status": "CODE_ANALYSIS_ERROR"
}
Key | Value |
---|---|
Content-Type | application/json |
Reports
Get analysis reports for application and tag
Retrieves the analysis reports data for a given application and version (tag).
- Params
Path variables
Key | Type | Description |
---|---|---|
app-id | string | (Required) |
git-tag | (Required) |
Example Response
- Body
- Headers
[
{
"applicationId": "<string>",
"reportName": "<string>",
"s3Uri": "<string>",
"toolName": "<string>",
"id": "<long>",
"reportStatus": "<string>",
"effectiveDate": "<dateTime>",
"endDate": "<dateTime>",
"gitTag": "<string>"
},
{
"applicationId": "<string>",
"reportName": "<string>",
"s3Uri": "<string>",
"toolName": "<string>",
"id": "<long>",
"reportStatus": "<string>",
"effectiveDate": "<dateTime>",
"endDate": "<dateTime>",
"gitTag": "<string>"
}
]
Key | Value |
---|---|
Content-Type | application/json |