Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nathanielvarona/pritunl-api-go
Pritunl API Client for Go
https://github.com/nathanielvarona/pritunl-api-go
go go-package hacktoberfest pritunl pritunl-api pritunl-server pritunl-servers pritunl-vpn
Last synced: 19 days ago
JSON representation
Pritunl API Client for Go
- Host: GitHub
- URL: https://github.com/nathanielvarona/pritunl-api-go
- Owner: nathanielvarona
- License: mit
- Created: 2024-04-05T08:27:21.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-01T18:03:18.000Z (8 months ago)
- Last Synced: 2024-06-19T18:01:38.780Z (6 months ago)
- Topics: go, go-package, hacktoberfest, pritunl, pritunl-api, pritunl-server, pritunl-servers, pritunl-vpn
- Language: Go
- Homepage: https://pkg.go.dev/github.com/nathanielvarona/pritunl-api-go
- Size: 4.05 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# pritunl-api-go
Pritunl API Client for Go
A [Go](https://go.dev/) client for the Pritunl API, allowing you to interact with [Pritunl](https://pritunl.com/) servers and perform various actions.
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nathanielvarona_pritunl-api-go&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=nathanielvarona_pritunl-api-go)
## Getting Started
### Environment Variables
Load your Pritunl API credentials as environment variables:
```bash
export PRITUNL_BASE_URL="https://vpn.domain.tld"
export PRITUNL_API_TOKEN=""
export PRITUNL_API_SECRET=""
```### Installation
Get the Pritunl API Client for Go package/library:
```bash
go get github.com/nathanielvarona/pritunl-api-go
```### Usage
Initialize an API instance and call available feature functions:
```go
package mainimport (
"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: "",
// ApiToken: "",
// ApiSecret: "",
// })
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](./_examples) folder for code examples demonstrating how to use this package/library.## Contributing
We welcome your contributions to pritunl-api-go. This guide outlines the process for contributing effectively.
### Fork & Pull Requests
#### Workflow:
1. **Fork the repository:** Visit the [pritunl-api-go](https://github.com/nathanielvarona/pritunl-api-go) repository on GitHub and click "`Fork`". This creates your own copy.
2. **Clone your forked repository:** Use git clone to clone your forked copy to your local development environment.
3. **Create a Branch:** Use a descriptive branch name following the convention `/`.
- ``: Choose from `breaking`, `feature`, `improvement`, `automation`, or `documentation`.
- Refer to the [.github/labels.yml](./.github/labels.yml) and [.github/pr-labeler.yml](./.github/pr-labeler.yml) file for valid `` options and label descriptions. (e.g., `improvement/start-stop-a-server`)
4. **Make your changes:** Implement your code modifications, ensuring they adhere to Go coding conventions [gofmt](https://go.dev/blog/gofmt) and consider adding ~~unit tests~~ ref* for new features.
5. **Commit your changes:** Stage and commit your changes with clear and concise commit messages.
6. **Push your branch and Create a Pull Request:** Push your local branch to your forked repository on GitHub and create a pull request with a detailed description of your changes.#### Additional Tips:
* ref* Include `examples` where relevant to illustrate your changes.
* **Simplify your development workflow!** We recommend using a `Go workspace` when contributing to `pritunl-api-go`. Go workspaces provide a clean and efficient way to manage dependencies.
- Refer to the official guide for setting up a workspace: https://go.dev/doc/tutorial/workspaces### Rebasing and Squashing Commits
Before submitting your `pull request`, we recommend cleaning up your commit history to make it easier to review. This involves `rebasing` your branch on top of the `main` branch and `combining` your commits into a `single`, `clear` commit. Additionally, please ensure that your `commit author name` and `email` are consistent with your `GitHub account`, as this will help us keep a clear record of contributions.
**We appreciate your contributions to the project!**
By following these guidelines, you'll help us maintain a high-quality codebase and make it easier for others to contribute. Thank you for taking the time to contribute to `pritunl-api-go`!
## Features
### Core Pritunl API Client
| Feature Function | Description | Status |
|--------------------|-----------------------------------------|------------------------|
| StatusGet | Status of Pritunl Server | :white_check_mark: Yes |
| KeyGet | Generate or Retrieve a Key for the User | :white_check_mark: Yes |
| UserGet | Get the Information of Existing User | :white_check_mark: Yes |
| UserCreate | Create a New User | :white_check_mark: Yes |
| UserUpdate | Update an Existing User | :white_check_mark: Yes |
| UserDelete | Delete an User | :white_check_mark: Yes |
| OrganizationGet | Get the Information of Existing Org | :white_check_mark: Yes |
| OrganizationCreate | Create a New Org | :white_check_mark: Yes |
| OrganizationUpdate | Update an Existing Org | :white_check_mark: Yes |
| OrganizationDelete | Delete an Org | :white_check_mark: Yes |
| ServerGet | Get the Information of Existing Server | :white_check_mark: Yes |
| ServerCreate | Create a New Server | :white_check_mark: Yes |
| ServerUpdate | Update an existing Server | :white_check_mark: Yes |
| ServerDelete | Delete a Server | :white_check_mark: Yes |
| ServerStart | Start an existing Server | :white_check_mark: Yes |
| ServerStop | Start an existing Server | :white_check_mark: Yes |
| ServerRestart | Restart an existing Server | :white_check_mark: Yes |
| ServerRouteGet | Get the Routes for a Server | :white_check_mark: Yes |
| ServerRouteCreate | Create/Add a Server Route | :white_check_mark: Yes |
| ServerRouteUpdate | Update a Server Route | :white_check_mark: Yes |
| ServerRouteDelete | Remove/Delete a Server Route | :white_check_mark: Yes |
| ServerOrgAttach | Attach an Organization for a Server | :white_check_mark: Yes |
| ServerOrgDetach | Detach an Organization for a Server | :white_check_mark: Yes |
| ServerHostAttach | Attach a Host for a Server | :white_check_mark: Yes |
| ServerHostDetach | Detach a Host for a Server | :white_check_mark: Yes |### Future Enhancements (CLI)
1. **CLI Framework:** Consider using a popular framework like [spf13/cobra](https://github.com/spf13/cobra), [urfave/cli](https://github.com/urfave/cli), or [alecthomas/kong](https://github.com/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
* Python - [Pritunl API Client for Python](https://github.com/nathanielvarona/pritunl-api-python) by [@nathanielvarona](https://github.com/nathanielvarona)
- _fork from [Pritunl API client for Python 3](https://github.com/ijat/pritunl-api-python) by [@ijat](https://github.com/ijat)_
* Ruby - [Pritunl API Client](https://github.com/eterry1388/pritunl_api_client) by [@eterry1388](https://github.com/eterry1388)