A lightweight SDK for the Panorama Cloud API
Project description
panapi
This is a lightweight Python SDK designed to interact with Palo Alto Networks Cloud Management API. It consists of an object-oriented library that simplifies OAuth 2.0 session estalishment, access token validation, and automatic access token refresh. Each configuration API endpoint is represented as unique object instances that provide a common set of create, read, update, delete, and list functions.
Features
- OAuth 2.0 session management (subclassed from requests_oauthlib.Session)
- Supports credential config file (~/panapi/config)
- JSON Web Key Set (JWKS) retrieval
- JWT access token decoding and validation
- Common create, read, update, delete, and list methods for all config objects
- Automatic and transparent access token refresh
Installation
Upgrade to the latest pip
pip install --upgrade pip
Install using pip
$ pip install panapi
Upgrade to the latest version
$ pip install --upgrade panapi
Configuration
The Cloud Management API utilizes OAuth 2.0 to authenticate and authorize incoming API calls. This requires requesting an access token from an Authorization Server. The credentials needed to request an access token can be defined in a configuration located at $HOME/.panapi/config.yml
.
---
#
# my-tenant
#
client_id: apitest@1808050139.iam.panserviceaccount.com
client_secret: feea5864-f557-11ec-b939-0242ac120002
scope: tsg_id:1808050139
token_url: https://auth.apps.paloaltonetworks.com/am/oauth2/access_token
Usage
The following is a brief overview of how to use the pan-api-python
SDK. For comprehensive details on its usage, please refer to the documentation here.
Import the modules
The entire SDK can be imported into your project.
import panapi
Specific modules can be imported as well.
from panapi.config import security, network
Individual classes can also be imported.
from panapi.config.network import RemoteNetwork, IKEGateway, IPSecTunnel
Establish the OAuth 2.0 session
Instantiate the PanApiSession
handler and authenticate to the Authorization Server.
session = panapi.PanApiSession()
session.authenticate()
If successful, the access token will become an attribute of the PanApiSession
instance.
session.access_token
Token validation is done automatically with each API call using the pan-api-python
SDK. However, manual validation of the JWT token claims and cryptographic signature can be done as well.
session.is_valid
Working with configuration objects
Instantiate a new configuration object.
addr1 = panapi.config.objects.Address(
folder = 'Shared',
name = 'server1',
ip_netmask = '10.0.100.150',
description = 'App server 1',
tags = ['production']
)
Create the new configuration on the cloud management tenant.
addr1.create(session)
The HTTP status code resulting from PanApiSession
API transactions attached to the session instance.
result = session.status_code
Retrieve a configuration object by name.
gw1 = panapi.config.network.IKEGateway(
folder = 'Remote Networks',
name = 'Seattle-GW'
)
Display the JSON payload of a configuration object.
json.dumps(gw1.payload, indent=4)
Update elements of a configuration object.
rule = panapi.config.security.SecurityRule(
folder = 'Shared',
named = 'Allow monitoring'
)
rule1.read(session)
rule1.applications = ['snmpv2', 'snmpv3']
rule1.description = 'Allow SNMPv2 and v3 from NOC'
rule1.update(session)
Delete a configuration from the cloud management tenant.
id1 = panapi.config.identity.SAMLProfile(
folder = 'Shared',
name = 'AD-SAML'
)
id1.read(session)
id1.delete(session)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file panapi-0.0.1.tar.gz
.
File metadata
- Download URL: panapi-0.0.1.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cfe7d18bff4e3fba75d068d42c2392a7576690e4b53a825c3fe874a081d04c7 |
|
MD5 | 40159cc14715f9b425f7d75a15232875 |
|
BLAKE2b-256 | ef3f5ba77e76b4c55fb61c8ead9d999b26505c1c9035ad972b68bc4e9322fca2 |
File details
Details for the file panapi-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: panapi-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75ca74eefc75dd81756ebf9b8268150660714ff865c381d7cc52a60bd2bb02aa |
|
MD5 | c65c40081932195d7737b822a06ade5f |
|
BLAKE2b-256 | 2f71c43ef7173fd1c59103f0114afb821525fe66ff44c91ddd8070d143499a97 |