Skip to content

Latest commit

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

SD-WAN-GraphQL

make sure you have requirements installed on your host

pip install -r requirements.txt

usage:

join-sdwan-profile.py --gateway <gateway name> --profile "<profile name>"

example:

join-sdwan-profile.py --gateway hq-exl-1 --profile "SD-WAN Gateways"

options:

join-sdwan-profile.py --gateway hq-exl --profile "SD-WAN Gateways" [--debug <reuest | response | both> [--env /path/to/.env]

SD-WAN Automation

Assigns a gateway to an SD-WAN profile via the Check Point Infinity Portal.

All SD-WAN GraphQL calls use the same endpoint. Only the OAuth authentication call uses a different endpoint.

Usage

./join-sdwan-profile.py --gateway "<gateway name>" --profile "SD-WAN Gateways" [--debug request|response|both] [--env /path/to/.env]

Example:

./join-sdwan-profile.py --gateway "branch-gw" --profile "SD-WAN Gateways" --debug both --env .env

Note

To run this automation with SD-WAN, you need to create an Account API Key with admin permission for SD-WAN.

Execution Flow

  1. Get OAuth token

    • Extract token
    • Extract tenant_id
  2. Run getAssets

    • Find and extract the gateway asset ID
  3. Run getSdWanProfiles

    • Find and extract the SD-WAN profile ID
  4. Run updateSdWanProfile

    • Assign the gateway to the profile

    • If the profile is locked:

      • Run discardChanges
      • Retry updateSdWanProfile
  5. Run publishChanges

  6. Run enforcePolicy


API Flow Details

Step 1 — OAuth: Get Bearer Token

Endpoint

POST https://cloudinfra-gw.portal.checkpoint.com/auth/external

Headers

HeaderValue
Content-Typeapplication/json

Request Body

{
"clientId": "<SD_WAN_Client_ID>",
"accessKey": "<SD_WAN_Client_SecretKey>"
}

Response Example

{
"data": {
"token": "<jwt>"
}
}

Extracted Values

FieldPathUsed As
tokendata.tokenBearer token for all subsequent requests
tenant_idJWT claim tid or tenantId decoded from tokenx-tenant-id header

Steps 2–6 — Shared GraphQL Configuration

Shared Endpoint

POST https://cloudinfra-gw.portal.checkpoint.com/app/sd-wan/graphql/v1

Shared Headers

HeaderValue
AuthorizationBearer <token>
Content-Typeapplication/json
Acceptapplication/json
x-tenant-id<tenant_id> — optional, included only when non-empty

Step 2 — getAssets: Find Gateway Asset ID

The script first tries to search for the gateway by name. If no match is found, it can fall back to retrieving all assets.

Request Body — Primary Filtered Search

{
"query": "query GetAssets($matchSearch: String) { getAssets(matchSearch: $matchSearch) { assets { id name } } }",
"variables": {
"matchSearch": "<gateway-name>"
}
}

Request Body — Fallback Search

{
"query": "query { getAssets { assets { id name } } }",
"variables": {}
}

Response Example

{
"data": {
"getAssets": {
"assets": [
{
"id": "abc-123",
"name": "hq-exl"
},
{
"id": "def-456",
"name": "branch-gw"
}
]
}
}
}

Extracted Values

FieldMatch ConditionUsed As
data.getAssets.assets[].idname == gateway_name or gateway_name in namegateway_asset_id passed to updateSdWanProfile

Step 3 — getSdWanProfiles: Find Profile ID

Request Body

{
"query": "query { getSdWanProfiles { id name } }",
"variables": {}
}

Response Example

{
"data": {
"getSdWanProfiles": [
{
"id": "profile-111",
"name": "SD-WAN Gateways"
},
{
"id": "profile-222",
"name": "Branch Profiles"
}
]
}
}

Extracted Values

FieldMatch ConditionUsed As
data.getSdWanProfiles[].idname == profile_name or profile_name in nameprofile_id passed to updateSdWanProfile

Step 4 — updateSdWanProfile: Assign Gateway to Profile

Request Body

{
"query": "mutation UpdateSdWanProfile($id: ID!, $input: SdWanProfileUpdateInput!) { updateSdWanProfile(id: $id input: $input) }",
"variables": {
"id": "<profile_id>",
"input": {
"addSdWanGateways": [
"<gateway_asset_id>"
],
"removeSdWanGateways": []
}
}
}

Success Response

{
"data": {
"updateSdWanProfile": true
}
}

Lock Error Response

{
"errors": [
{
"message": "forbidden-status: profile is locked"
}
]
}

Result Handling

FieldConditionAction
data.updateSdWanProfiletrueSuccess. Continue to publishChanges.
errors[0].messageContains lock or forbidden-statusRun discardChanges, then retry updateSdWanProfile once.
errors[0].messageAny other errorExit with error.

Step 4a — discardChanges

This step is only used when updateSdWanProfile fails because the profile is locked.

Request Body

{
"query": "mutation { discardChanges }",
"variables": {}
}

The response is ignored.

After this call, updateSdWanProfile is retried once using the same request body from Step 4.


Step 5 — publishChanges

Request Body

{
"query": "mutation { publishChanges { isValid } }",
"variables": {}
}

Response Example

{
"data": {
"publishChanges": {
"isValid": true
}
}
}

Result Handling

FieldConditionAction
data.publishChanges.isValidtrueChanges are valid. Continue to enforcePolicy.
data.publishChanges.isValidfalsePrint a warning. This is treated as non-fatal and execution continues.

Step 6 — enforcePolicy

Request Body

{
"query": "mutation { enforcePolicy { id status } }",
"variables": {}
}

Response Example

{
"data": {
"enforcePolicy": {
"id": "task-789",
"status": "pending"
}
}
}

Extracted Values

FieldUsed As
data.enforcePolicy.idPrinted as task tracking reference
data.enforcePolicy.statusPrinted as informational status

Important

This flow does not poll the enforce task after it has been triggered.

In some environments, it may be useful to add task polling after enforcePolicy to verify the final result.


Environment File Example

Create a .env file and store the SD-WAN API credentials there.

SD_WAN_CLIENT_ID="<your-client-id>"SD_WAN_CLIENT_SECRET_KEY="<your-secret-key>"

Make sure the .env file is not committed to Git.

Add it to .gitignore:

.env

Debug Options

The script supports optional debug output.

--debug request
--debug response
--debug both
Debug OptionDescription
requestPrint outgoing request details
responsePrint API response details
bothPrint both request and response details

Summary

This automation performs the following actions:

  1. Authenticates against the Infinity Portal.
  2. Finds the target gateway asset.
  3. Finds the target SD-WAN profile.
  4. Adds the gateway to the SD-WAN profile.
  5. Handles profile lock errors by discarding pending changes and retrying.
  6. Publishes the changes.
  7. Enforces the SD-WAN policy.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages