Change a Risk Profile Policy by API

Coverity on Polaris

Version
latest
To change an existing Risk Profile Policy use the same URL and request body as for creation of the policy. The difference is that changing the policy requires use of an HTTP PATCH request.

  1. Retrieve the current version of the policy, so you have a starting place.
    
                curl -X GET "https://dev01.dev.cop.blackduck.com/api/risk-profile-service/v0/policies/{policy_id}"\
    -H "accept: application/vnd.api+json" \
    -H 'Authorization: Bearer {JWT} 
                        

    The placeholders in the first and last lines must be replaced with the policy id number and your long-lasting JWT.

    Response:

    {
      "data": {
        "id": "485ec4fb-6eac-46d9-8799-0219bbe78f5b",
        "type": "risk-profile-policy",
        "attributes": {
          "description": "Test Policy for webgoat 061621",
          "tier": "TIER1",
          "phase": "RELEASED",
          "distribution": "OPEN_SOURCE",
          "name": "docs webgoat risk policy 061621",
          "risk-profile-scales": [
            {
              "severity": "LOW",
              "start-range": 10,
              "end-range": 39
            },
            {
              "severity": "MEDIUM",
              "start-range": 40,
              "end-range": 79
            },
            {
              "severity": "HIGH",
              "start-range": 80,
              "end-range": 100
            }
          ],
          "weight-attributes": [
            {
              "attribute-type": "SEVERITY",
              "attribute-name": "HIGH",
              "weight": 3
            },
            {
              "attribute-type": "SEVERITY",
              "attribute-name": "MEDIUM",
              "weight": 3
            },
            {
              "attribute-type": "SEVERITY",
              "attribute-name": "LOW",
              "weight": 1
            },
            {
              "attribute-type": "DOMAIN",
              "attribute-name": "SAST",
              "weight": 1
            }
          ]
        },
        "relationships": {
          "projects": {
            "data": [],
            "meta": {
              "total": 0
            }
          },
          "applications": {
            "data": [],
            "meta": {
              "total": 0
            }
          }
        }
      }
    }
                            
                        
  2. Modify the data object received in the previous request with whatever changes are required, and use it as the request body in the following request.
    curl -X PATCH "https://dev01.dev.cop.blackduck.com/api/risk-profile-service/v0/policies/d176923e-ce35-11eb-b8bc-0242ac130003"\
    -H "accept: */*" \
    -H "Content-Type: application/vnd.api+json" \
    -H 'Authorization: Bearer {JWT}  \
    -d\
    {
      "data": {
        "id": "485ec4fb-6eac-46d9-8799-0219bbe78f5b",
        "type": "risk-profile-policy",
        "attributes": {
          "description": "Test Policy for webgoat 061621 with zero weight for low-severity issues",
          "tier": "TIER1",
          "phase": "RELEASED",
          "distribution": "OPEN_SOURCE",
          "name": "docs webgoat risk policy 061621",
          "risk-profile-scales": [
            {
              "severity": "LOW",
              "start-range": 10,
              "end-range": 39
            },
            {
              "severity": "MEDIUM",
              "start-range": 40,
              "end-range": 79
            },
            {
              "severity": "HIGH",
              "start-range": 80,
              "end-range": 100
            }
          ],
          "weight-attributes": [
            {
              "attribute-type": "SEVERITY",
              "attribute-name": "HIGH",
              "weight": 3
            },
            {
              "attribute-type": "SEVERITY",
              "attribute-name": "MEDIUM",
              "weight": 2
            },
            {
              "attribute-type": "SEVERITY",
              "attribute-name": "LOW",
              "weight": 0
            },
            {
              "attribute-type": "DOMAIN",
              "attribute-name": "SAST",
              "weight": 1
            }
          ]
        },
        "relationships": {
          "projects": {
            "data": [],
            "meta": {
              "total": 0
            }
          },
          "applications": {
            "data": [],
            "meta": {
              "total": 0
            }
          }
        }
      }
    }
             

    The placeholder in the fourth line must be replaced with your long-lasting JWT.

    This example request introduces two changes that make it different from the object received in step one. The description of the policy is updated, and the weight for LOW severity issues is changed from 1 to 0.

    Response:

    The response echoes the request body, confirming that the two changes were made:

    {
        "data": {
            "id": "485ec4fb-6eac-46d9-8799-0219bbe78f5b",
            "type": "risk-profile-policy",
            "attributes": {
                "description": "Test Policy for webgoat 061621 with zero weight for low-severity issues",
                "tier": "TIER1",
                "phase": "RELEASED",
                "distribution": "OPEN_SOURCE",
                "name": "docs webgoat risk policy 061621",
                "risk-profile-scales": [
                    {
                        "severity": "LOW",
                        "start-range": 10,
                        "end-range": 39
                    },
                    {
                        "severity": "MEDIUM",
                        "start-range": 40,
                        "end-range": 79
                    },
                    {
                        "severity": "HIGH",
                        "start-range": 80,
                        "end-range": 100
                    }
                ],
                "weight-attributes": [
                    {
                        "attribute-type": "SEVERITY",
                        "attribute-name": "HIGH",
                        "weight": 3
                    },
                    {
                        "attribute-type": "SEVERITY",
                        "attribute-name": "MEDIUM",
                        "weight": 2
                    },
                    {
                        "attribute-type": "SEVERITY",
                        "attribute-name": "LOW",
                        "weight": 0
                    },
                    {
                        "attribute-type": "DOMAIN",
                        "attribute-name": "SAST",
                        "weight": 1
                    }
                ]
            },
            "relationships": {
                "projects": {
                    "data": [],
                    "meta": {
                        "total": 0
                    }
                },
                "applications": {
                    "data": [],
                    "meta": {
                        "total": 0
                    }
                }
            }
        }
    }