Support Disclaimer
-> Disclaimer: Please refer to our General Support Statement before proceeding with the use of this provider. You can also refer to our troubleshooting guide for guidance on typical problems.
Zscaler SDK GO
This repository contains the ZIA/ZPA/ZDX/ZCC SDK for Golang. This SDK can be
used in your server-side code to interact with the Zscaler platform
For more information about ZIA/ZPA APIs visit:
Need help?
If you run into problems using the SDK, you can
The latest release can always be found on the releases page.
Getting started
To install the Zscaler GO SDK in your project:
-
Create a module file by running go mod init
-
You can skip this step if you already use go mod
-
Run go get github.com/SecurityGeekIO/zscaler-sdk-go/v2@latest
. This will add
the SDK to your go.mod
file.
-
Import the package in your project with import "github.com/SecurityGeekIO/zscaler-sdk-go/v2/zpa"
or
-
Before you begin, make sure you have an administrator account and API Keys in the ZIA and/or ZPA portals.
-
For more information on to create API Keys for ZIA and/or ZPA see the following help guides:
-
Getting Started ZIA API.
-
Getting Started ZPA API
-
Getting Started ZDX API
Installation
To download all packages in the repo with their dependencies, simply run
go get github.com/SecurityGeekIO/zscaler-sdk-go
Getting Started
One can start using Zscaler Go SDK by initializing client and making a request.
Here is an example of creating a ZPA App Connector Group.
package main
import (
"log"
"os"
"github.com/SecurityGeekIO/zscaler-sdk-go/v2/zpa"
"github.com/SecurityGeekIO/zscaler-sdk-go/v2/zpa/services/appconnectorgroup"
)
func main() {
/*
If you set one of the value of the parameters to empty string, the client will fallback to:
- The env variables: ZPA_CLIENT_ID, ZPA_CLIENT_SECRET, ZPA_CUSTOMER_ID, ZPA_CLOUD
- Or if the env vars are not set, the client will try to use the config file which should be placed at $HOME/.zpa/credentials.json on Linux and OS X, or "%USERPROFILE%\.zpa/credentials.json" on windows
with the following format:
{
"zpa_client_id": "",
"zpa_client_secret": "",
"zpa_customer_id": "",
"zpa_cloud": "https://config.private.zscaler.com"
}
*/
zpa_client_id := os.Getenv("ZPA_CLIENT_ID")
zpa_client_secret := os.Getenv("ZPA_CLIENT_SECRET")
zpa_customer_id := os.Getenv("ZPA_CUSTOMER_ID")
zpa_cloud := os.Getenv("ZPA_CLOUD")
config, err := zpa.NewConfig(zpa_client_id, zpa_client_secret, zpa_customer_id, zpa_cloud, "userAgent")
if err != nil {
log.Printf("[ERROR] creating config failed: %v\n", err)
return
}
zpaClient := zpa.NewClient(config)
appConnectorGroupService := appconnectorgroup.New(zpaClient)
app := appconnectorgroup.AppConnectorGroup{
Name: "Example app connector group",
Description: "Example app connector group",
Enabled: true,
CityCountry: "California, US",
CountryCode: "US",
Latitude: "37.3382082",
Longitude: "-121.8863286",
Location: "San Jose, CA, USA",
UpgradeDay: "SUNDAY",
UpgradeTimeInSecs: "66600",
OverrideVersionProfile: true,
VersionProfileID: "0",
DNSQueryType: "IPV4",
}
// Create new app connector group
createdResource, _, err := appConnectorGroupService.Create(app)
if err != nil {
log.Printf("[ERROR] creating app connector group failed: %v\n", err)
return
}
// Update app connector group
createdResource.Description = "New description"
_, err = appConnectorGroupService.Update(createdResource.ID, createdResource)
if err != nil {
log.Printf("[ERROR] updating app connector group failed: %v\n", err)
return
}
// Delete app connector group
_, err = appConnectorGroupService.Delete(createdResource.ID)
if err != nil {
log.Printf("[ERROR] deleting app connector group failed: %v\n", err)
return
}
}
!> WARNING: Hard-coding the ANY Zscaler credentials such as API Keys, client ID, and client Secrets,
works for quick tests, but for real projects you should use a more secure ways of storing these values
(such as environment variables).
Usage guide
These examples will help you understand how to use this library.
Once you initialize a client
, you can call methods to make requests to the
ZPA and/or ZIA APIs. Most methods are grouped by the API endpoint they belong to. For
example, methods that call the ZPA Application Segment
API are organized under
Application Controller
.
Caching
In the default configuration the ZPA and ZIA client utilizes a memory cache that has a time to live on its cached values.
See Configuration Setter Object WithCache(cache bool)
, WithCacheTtl(int32
, and WithCacheCleanWindow(i int32)
.
This helps to keep HTTP requests to the ZPA and ZIA API at a minimum. In the case where the client needs to be certain it is accessing recent data; for instance, list items, delete an item, then list items again; be sure to make use of the refresh next facility to clear the request cache. To completely disable the request
memory cache configure the client with WithCache(false)
or set the following environment variable ZSCALER_SDK_CACHE_DISABLED
to true
.
Configuration Setter Object
The client is configured with a configuration setter object passed to the NewClient
function.
function |
description |
WithCache(cache bool) |
Use request memory cache |
WithCacheTtl(i int32) |
Cache time to live in seconds |
WithCacheCleanWindow(i int32) |
Cache clean up interval in seconds |
Contributing
We're happy to accept contributions and PRs! Please see the contribution
guide to understand how to
structure a contribution.
License
MIT License
=======
Copyright (c) 2022 Zscaler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.