Skip to content

OpenVPN/cloudconnexa-go-client

Repository files navigation

Cloud Connexa Go Client

GoDoc Go Report Card codecov Build Status

This Go library enables access to the Cloud Connexa API, as detailed in the Cloud Connexa API Documentation.

Installation Instructions

To install the cloudconnexa-go-client, ensure you are using a modern Go release that supports module mode. With Go set up, execute the following command:

go get github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa

Features

  • Complete Cloud Connexa API coverage
  • Pagination support
  • Rate limiting
  • Automatic token management
  • Concurrent safe

How to Use

In your Go project, you can use the library by importing it as follows:

import "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"

Instantiate a new CloudConnexa client. Subsequently, utilize the diverse services provided by the client to interact with distinct segments of the CloudConnexa API. For instance:

client := cloudconnexa.NewClient("api_url", "client_id", "client_secret")

// List connectors
connectors, _, err := client.Connectors.List()

Authentication

For auth need to pass three parameters:

  1. client_id
  2. client_secret
  3. api_url (example: https://myorg.api.openvpn.com)
package main

import (
    "fmt"
    "log"

    "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
)

func main() {
    client, err := cloudconnexa.NewClient("api_url", "client_id", "client_secret")
    if err != nil {
        log.Fatalf("error creating client: %v", err)
    }

    networkID := "your_network_id"
    routes, err := client.Routes.List(networkID)
    if err != nil {
        log.Fatalf("error getting routes: %v", err)
    }

    fmt.Println("Received routes:", routes)
}

Examples

Creating a Network

network := cloudconnexa.Network{
    Name:           "test-network",
    Description:    "Test network created via API",
    InternetAccess: cloudconnexa.InternetAccessSplitTunnelOn,
    Egress:         false,
}

createdNetwork, err := client.Networks.Create(network)

Managing Users

// List all users
users, err := client.Users.List("", "")

// Create a new user
user := cloudconnexa.User{
    Username: "testuser",
    Email:    "[email protected]",
    GroupID:  "group-id",
}

createdUser, err := client.Users.Create(user)

Listing VPN Regions

// List all VPN regions
regions, err := client.VPNRegions.List()
if err != nil {
    log.Fatalf("error getting VPN regions: %v", err)
}

// Get specific region by ID
region, err := client.VPNRegions.GetByID("region-id")

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

This project is licensed under the Apache License - see the LICENSE file for details.

Security

For security issues, please email [email protected] instead of posting a public issue on GitHub.