GithubHelp home page GithubHelp logo

dmitryteplov182 / pritunl-api-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nathanielvarona/pritunl-api-go

0.0 0.0 0.0 4.13 MB

Pritunl API Client for Go

Home Page: https://pkg.go.dev/github.com/nathanielvarona/pritunl-api-go

License: MIT License

Go 100.00%

pritunl-api-go's Introduction

pritunl-api-go

Pritunl API Client for Go

A Go client for the Pritunl API, allowing you to interact with Pritunl servers and perform various actions.

Quality Gate Status

Getting Started

Environment Variables

Load your Pritunl API credentials as environment variables:

export PRITUNL_BASE_URL="https://vpn.domain.tld"
export PRITUNL_API_TOKEN="<PRITUNL API TOKEN>"
export PRITUNL_API_SECRET="<PRITUNL API SECRET>"

Installation

Get the Pritunl API Client for Go package/library:

go get github.com/nathanielvarona/pritunl-api-go

Usage

Initialize an API instance and call available feature functions:

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	"github.com/nathanielvarona/pritunl-api-go"
)

func main() {
	// Initialize the Pritunl API client
	client, err := pritunl.NewClient()
	// Alternatively, you can initialize the client with manual arguments
	// client, err := pritunl.NewClient(&pritunl.Client{
	// 	BaseUrl:   "<PRITUNL BASE URL>",
	// 	ApiToken:  "<PRITUNL API TOKEN>",
	// 	ApiSecret: "<PRITUNL API SECRET>",
	// })
	if err != nil {
		log.Fatal(err)
	}

	// Create a context for the request
	ctx := context.Background()

	// Retrieve the server status
	status, err := client.StatusGet(ctx)
	if err != nil {
		log.Fatal(err)
	}

	// Print server status details
	fmt.Println("Server Status:")
	for _, stat := range status {
		fmt.Println("Server Version:", stat.ServerVersion)
		fmt.Println("Local Networks:", stat.LocalNetworks)
		fmt.Println("Host Online:", stat.HostsOnline)
		fmt.Println("------")
	}

	// Marshal server status to JSON
	statusBytes, err := json.MarshalIndent(status, "", "  ")
	if err != nil {
		log.Println("Error marshalling status:", err)
	} else {
		fmt.Println("Server Status in JSON:")
		fmt.Println(string(statusBytes))
	}
}

Examples

Check the _examples folder for code examples demonstrating how to use this package/library.

Features

Core Pritunl API Client

Feature Function Description Status
StatusGet Status of Pritunl Server ✅ Yes
KeyGet Generate or Retrieve a Key for the User ✅ Yes
UserGet Get the Information of Existing User ✅ Yes
UserCreate Create a New User ✅ Yes
UserUpdate Update an Existing User ✅ Yes
UserDelete Delete an User ✅ Yes
OrganizationGet Get the Information of Existing Org ✅ Yes
OrganizationCreate Create a New Org ✅ Yes
OrganizationUpdate Update an Existing Org ✅ Yes
OrganizationDelete Delete an Org ✅ Yes
ServerGet Get the Information of Existing Server ✅ Yes
ServerCreate Create a New Server ✅ Yes
ServerUpdate Update an existing Server ✅ Yes
ServerDelete Delete a Server ✅ Yes
ServerRouteGet Get the Routes for a Server ✅ Yes
ServerRouteCreate Create/Add a Server Route ✅ Yes
ServerRouteUpdate Update a Server Route ✅ Yes
ServerRouteDelete Remove/Delete a Server Route ✅ Yes
ServerOrgAttach Attach an Organization for a Server ✅ Yes
ServerOrgDetach Detach an Organization for a Server ✅ Yes
ServerHostAttach Attach a Host for a Server ✅ Yes
ServerHostDetach Detach a Host for a Server ✅ Yes

Future Enhancements (CLI)

  1. CLI Framework: Consider using a popular framework like spf13/cobra, urfave/cli, or alecthomas/kong to simplify the command structure, argument parsing, and flag handling.
  2. Build Distribution Workflow: Implement a CI/CD workflow (e.g., using GitHub Actions) to automate building and distributing the CLI tool across various platforms (Windows, macOS, Linux) and architectures (32-bit, 64-bit). This will streamline setup for users on different systems.

Alternative API Clients

pritunl-api-go's People

Contributors

nathanielvarona avatar dteplov182 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.