Skip to content

Commit 262e41c

Browse files
authored
Merge pull request #50 from OpenVPN/added-github-actions
Added GitHub actions
2 parents c07b82c + 55cea27 commit 262e41c

File tree

9 files changed

+219
-22
lines changed

9 files changed

+219
-22
lines changed

.github/workflows/coverage.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test Coverage
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: "1.23"
19+
20+
- name: Run unit tests with coverage
21+
run: |
22+
go test -race -coverprofile=coverage.txt -covermode=atomic ./cloudconnexa/...
23+
24+
- name: Run e2e tests
25+
if: ${{ vars.OVPN_HOST != '' }}
26+
run: |
27+
go test -race ./e2e/...
28+
env:
29+
OVPN_HOST: ${{ vars.OVPN_HOST }}
30+
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
31+
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}
32+
33+
- name: Upload coverage to Codecov
34+
uses: codecov/codecov-action@v3
35+
with:
36+
file: ./coverage.txt
37+
fail_ci_if_error: false

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
strategy:
2424
matrix:
2525
go:
26-
- "1.19"
27-
- "1.20"
2826
- "1.21"
27+
- "1.22"
28+
- "1.23"
2929

3030
steps:
3131
- uses: actions/checkout@v4

.github/workflows/lint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Lint and Format
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: "1.23"
19+
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v3
22+
with:
23+
version: latest
24+
args: --timeout=5m
25+
26+
- name: Check formatting
27+
run: |
28+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
29+
gofmt -s -l .
30+
exit 1
31+
fi

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: "1.23"
18+
19+
- name: Run GoReleaser
20+
uses: goreleaser/goreleaser-action@v4
21+
with:
22+
version: latest
23+
args: release --clean
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/security.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Security Scan
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
- cron: "0 0 * * 0"
10+
11+
jobs:
12+
security:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: "1.23"
21+
22+
- name: Run Gosec Security Scanner
23+
uses: securego/gosec@master
24+
with:
25+
args: ./...
26+
env:
27+
OVPN_HOST: ${{ vars.OVPN_HOST }}
28+
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
29+
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}
30+
31+
- name: Generate dependencies list
32+
run: go list -json -m all > go.list
33+
34+
- name: Run nancy for dependency scanning
35+
uses: sonatype-nexus-community/nancy-github-action@main
36+
with:
37+
goListFile: go.list

README.md

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Cloud Connexa Go Client
22

33
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/openvpn/cloudconnexa-go-client)](https://goreportcard.com/report/github.com/openvpn/cloudconnexa-go-client)
5+
[![codecov](https://codecov.io/gh/openvpn/cloudconnexa-go-client/branch/main/graph/badge.svg)](https://codecov.io/gh/openvpn/cloudconnexa-go-client)
6+
[![Build Status](https://github.com/openvpn/cloudconnexa-go-client/workflows/Go%20build/badge.svg)](https://github.com/openvpn/cloudconnexa-go-client/actions)
47

58
This Go library enables access to the Cloud Connexa API, as detailed in the [Cloud Connexa API Documentation](https://openvpn.net/cloud-docs/developer/cloudconnexa-api.html).
69

@@ -12,6 +15,14 @@ To install the cloudconnexa-go-client, ensure you are using a modern Go release
1215
go get github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa
1316
```
1417

18+
## Features
19+
20+
- Complete Cloud Connexa API coverage
21+
- Pagination support
22+
- Rate limiting
23+
- Automatic token management
24+
- Concurrent safe
25+
1526
## How to Use
1627

1728
In your Go project, you can use the library by importing it as follows:
@@ -32,6 +43,7 @@ connectors, _, err := client.Connectors.List()
3243
## Authentication
3344

3445
For auth need to pass three parameters:
46+
3547
1. client_id
3648
2. client_secret
3749
3. api_url (example: `https://myorg.api.openvpn.com`)
@@ -40,24 +52,69 @@ For auth need to pass three parameters:
4052
package main
4153

4254
import (
43-
"fmt"
44-
"log"
55+
"fmt"
56+
"log"
4557

46-
"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
58+
"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
4759
)
4860

4961
func main() {
50-
client, err := cloudconnexa.NewClient("api_url", "client_id", "client_secret")
51-
if err != nil {
52-
log.Fatalf("error creating client: %v", err)
53-
}
54-
55-
networkId := "your_network_id"
56-
routes, err := client.Routes.List(networkId)
57-
if err != nil {
58-
log.Fatalf("error getting routes: %v", err)
59-
}
60-
61-
fmt.Println("Received routes:", routes)
62+
client, err := cloudconnexa.NewClient("api_url", "client_id", "client_secret")
63+
if err != nil {
64+
log.Fatalf("error creating client: %v", err)
65+
}
66+
67+
networkId := "your_network_id"
68+
routes, err := client.Routes.List(networkId)
69+
if err != nil {
70+
log.Fatalf("error getting routes: %v", err)
71+
}
72+
73+
fmt.Println("Received routes:", routes)
74+
}
75+
```
76+
77+
## Examples
78+
79+
### Creating a Network
80+
81+
```go
82+
network := cloudconnexa.Network{
83+
Name: "test-network",
84+
Description: "Test network created via API",
85+
InternetAccess: cloudconnexa.InternetAccessSplitTunnelOn,
86+
Egress: false,
6287
}
88+
89+
createdNetwork, err := client.Networks.Create(network)
6390
```
91+
92+
### Managing Users
93+
94+
```go
95+
// List all users
96+
users, err := client.Users.List("", "")
97+
98+
// Create a new user
99+
user := cloudconnexa.User{
100+
Username: "testuser",
101+
102+
GroupId: "group-id",
103+
}
104+
105+
createdUser, err := client.Users.Create(user)
106+
```
107+
108+
## Contributing
109+
110+
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.
111+
112+
Please make sure to update tests as appropriate.
113+
114+
## License
115+
116+
This project is licensed under the Apache License - see the [LICENSE](LICENSE) file for details.
117+
118+
## Security
119+
120+
For security issues, please email [[email protected]](mailto:[email protected]?subject=Security%20Issue%20in%20cloudconnexa-go-client%20github%20repository) instead of posting a public issue on GitHub.

cloudconnexa/networks.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"net/http"
88
)
99

10+
const (
11+
InternetAccessSplitTunnelOn = "SPLIT_TUNNEL_ON"
12+
InternetAccessSplitTunnelOff = "SPLIT_TUNNEL_OFF"
13+
InternetAccessRestrictedInternet = "RESTRICTED_INTERNET"
14+
)
15+
1016
type Network struct {
1117
Connectors []NetworkConnector `json:"connectors"`
1218
Description string `json:"description"`

e2e/client_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"testing"
7+
"time"
78

89
"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
910
"github.com/stretchr/testify/assert"
@@ -56,9 +57,12 @@ func TestListConnectors(t *testing.T) {
5657

5758
func TestCreateNetwork(t *testing.T) {
5859
c := setUpClient(t)
60+
timestamp := time.Now().Unix()
61+
testName := fmt.Sprintf("test-%d", timestamp)
62+
5963
connector := cloudconnexa.NetworkConnector{
6064
Description: "test",
61-
Name: "test",
65+
Name: testName,
6266
VpnRegionId: "it-mxp",
6367
}
6468
route := cloudconnexa.Route{
@@ -69,8 +73,8 @@ func TestCreateNetwork(t *testing.T) {
6973
network := cloudconnexa.Network{
7074
Description: "test",
7175
Egress: false,
72-
Name: "test",
73-
InternetAccess: "LOCAL",
76+
Name: testName,
77+
InternetAccess: cloudconnexa.InternetAccessSplitTunnelOn,
7478
Connectors: []cloudconnexa.NetworkConnector{connector},
7579
}
7680
response, err := c.Networks.Create(network)
@@ -87,7 +91,7 @@ func TestCreateNetwork(t *testing.T) {
8791
Value: "10.189.253.64/30",
8892
}
8993
service := cloudconnexa.IPService{
90-
Name: "test",
94+
Name: testName,
9195
Description: "test",
9296
NetworkItemId: response.Id,
9397
Type: "IP_SOURCE",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/openvpn/cloudconnexa-go-client/v2
22

3-
go 1.21
3+
go 1.23
44

55
require (
66
github.com/stretchr/testify v1.10.0

0 commit comments

Comments
 (0)