goCentral

package module
v0.0.0-...-e45967d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 14 Imported by: 0

README

goCentral

goCentral is a Go SDK/package that an interface to the HPE/Aruba Networks Central network management system. This project is at its start and will continue to add functionality over time. It will strive to offer the same functionality for golang as the pyCentral (https://github.com/aruba/pycentral) SDK offers for Python applications.

If you wish to become a contributor and help to grow this SDK, please contact the author.

goCentral provides a token management system to stores the operational token information in an AES encrypted file as to not require the acquisition of a new token each time an application is executed. It will handle the refresh of expired tokens when required, but must first be initialized using the Init_DB function. This function will prompt for the addition of the following information:

  • Central API URL
  • Customer ID
  • Client ID
  • Client secret
  • Access token (this is the current, valid access token)
  • Refresh token

Since the data stored and read by Write_DB and Read_DB is encrypted/decryptes using AES encryption, an encryption passphrase is needed. The library has a default passphrase; however, it is strongly advised to set a unique passphrase when building applications using this library. Setting a passphrase is done by adding the following line in each application:

  • goCentral.Passphrase = "Understanding is a three edged sword. Your side, their side, and the truth. - Kosh"

Once set, the passphrase will be used when reading and writing to the secure storage DB. If multiple applications are using the same secure storage DB, they should all use the same passphrase.

Functions

func Encrypt(data []byte, Passphrase string) []byte
  • Description: Encrypts the provided data using the given passphrase.
  • Parameters:
    • data: The data to be encrypted.
    • Passphrase: The passphrase used for encryption.
  • Returns: The encrypted data as a byte slice.
func Decrypt(data []byte, Passphrase string) []byte
  • Description: Decrypts the provided data using the given passphrase.
  • Parameters:
    • data: The data to be decrypted.
    • Passphrase: The passphrase used for decryption.
  • Returns: The decrypted data as a byte slice.
func RefreshApiToken(central_info Central_struct) (int, string, string, int64)
  • Description: Refreshes the API token for the provided Central_struct.
  • Parameters:
    • central_info: The Central_struct containing the necessary information for refreshing the token.
  • Returns:
    • The HTTP status code.
    • The new access token.
    • The new refresh token.
    • The expiration time in seconds.
func Test_central(central_info Central_struct) (int, string, string)
  • Description: Tests the connectivity to the central API using the provided Central_struct.
  • Parameters:
    • central_info: The Central_struct containing the necessary information for testing the API.
  • Returns:
    • The HTTP status code.
    • The access token.
    • The refresh token.
func Read_DB(filename string) Central_struct
  • Description: Reads the central information from the YAML file specified by filename and returns it as a Central_struct.
  • Parameters:
    • filename: The path to the YAML file containing the central information.
  • Returns: The Central_struct containing the central information.
func Write_DB(filename string, central_info_global Central_struct) int
  • Description: Writes the provided Central_struct to the YAML file specified by filename.
  • Parameters:
    • filename: The path to the YAML file where the central information will be written.
    • central_info_global: The Central_struct containing the central information to be written.
  • Returns: An integer indicating the success or failure of the write operation (0 for success, 1 for failure).
func Init_DB(filename string)
  • Description: Initializes the central database by prompting the user to enter the required information and writing it to the specified YAML file.
  • Parameters:
    • filename: The path to the YAML file where the central information will be written.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Passphrase = "The rain in Spain stays mainly on the plains"

This is default passphrase for encrypting/decrypting the data file. Set it to something unique in your program

Functions

func Decrypt

func Decrypt(data []byte, Passphrase string) []byte

func Encrypt

func Encrypt(data []byte, Passphrase string) []byte

func Init_DB

func Init_DB(filename string)

func RefreshApiToken

func RefreshApiToken(central_info Central_struct) (int, string, string, int64)

--------------------------------------------------------

func Test_central

func Test_central(central_info Central_struct) (int, string, string)

func Write_DB

func Write_DB(filename string, central_info_global Central_struct) int

Types

type Central_struct

type Central_struct struct {
	Base_url      string `yaml:"base_url"`
	Customer_id   string `yaml:"customer_id"`
	Client_id     string `yaml:"client_id"`
	Client_secret string `yaml:"client_secret"`
	Token         string `yaml:"token"`
	Refresh_token string `yaml:"refresh_token"`
}

Structure field names need to be capitalized to be exported (public)

func Read_DB

func Read_DB(filename string) Central_struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL