Skip to content

Commit 4039f86

Browse files
authored
Merge pull request #56 from OpenVPN/dependabot/github_actions/github-actions-5714300483
Bump golangci/golangci-lint-action from 6 to 7 in the github-actions group
2 parents dd7a93c + 2aaa39e commit 4039f86

23 files changed

+331
-31
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
strategy:
2424
matrix:
2525
go:
26-
- "1.21"
2726
- "1.22"
2827
- "1.23"
28+
- "1.24"
2929

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

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
go-version: "1.23"
1919

2020
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v8
2222
with:
23-
version: latest
23+
version: v2.1
2424
args: --timeout=5m
2525

2626
- name: Check formatting

.golangci.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
version: "2"
2+
3+
run:
4+
timeout: 5m
5+
tests: true
6+
go: "1.23"
7+
18
linters:
29
enable:
3-
- gofmt
4-
- govet
5-
- revive
6-
- gosimple
7-
- staticcheck
810
- errcheck
9-
- ineffassign
1011
- gosec
12+
- govet
13+
- ineffassign
1114
- misspell
15+
- revive
16+
- staticcheck
1217
- unconvert
13-
14-
run:
15-
timeout: 5m
16-
tests: true
17-
18-
issues:
19-
exclude-rules:
20-
- path: _test\.go
21-
linters:
22-
- gosec
18+
- unused
19+
exclusions:
20+
rules:
21+
- path: _test\.go
22+
linters:
23+
- gosec

cloudconnexa/access_groups.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package cloudconnexa provides a Go client library for the CloudConnexa API.
2+
// It offers comprehensive functionality for managing VPN networks, hosts, connectors,
3+
// routes, users, and other CloudConnexa resources through a simple Go interface.
14
package cloudconnexa
25

36
import (
@@ -7,6 +10,8 @@ import (
710
"net/http"
811
)
912

13+
// AccessGroup represents a group of access rules that define network access permissions.
14+
// It contains source and destination rules that determine what resources can access each other.
1015
type AccessGroup struct {
1116
ID string `json:"id"`
1217
Name string `json:"name"`
@@ -15,17 +20,22 @@ type AccessGroup struct {
1520
Destination []AccessItem `json:"destination"`
1621
}
1722

23+
// AccessItem represents a single access rule item that can be either a source or destination.
24+
// It defines what resources are covered by the access rule and their relationships.
1825
type AccessItem struct {
1926
Type string `json:"type"`
2027
AllCovered bool `json:"allCovered"`
2128
Parent string `json:"parent,omitempty"`
2229
Children []string `json:"children,omitempty"`
2330
}
2431

32+
// Item represents a basic resource with an identifier.
2533
type Item struct {
2634
ID string `json:"id"`
2735
}
2836

37+
// AccessGroupPageResponse represents a paginated response from the CloudConnexa API
38+
// containing a list of access groups and pagination metadata.
2939
type AccessGroupPageResponse struct {
3040
Content []AccessGroup `json:"content"`
3141
NumberOfElements int `json:"numberOfElements"`
@@ -36,8 +46,11 @@ type AccessGroupPageResponse struct {
3646
TotalPages int `json:"totalPages"`
3747
}
3848

49+
// AccessGroupsService handles communication with the CloudConnexa API for access group operations.
3950
type AccessGroupsService service
4051

52+
// GetAccessGroupsByPage retrieves a paginated list of access groups from the CloudConnexa API.
53+
// It returns the access groups for the specified page and page size.
4154
func (c *AccessGroupsService) GetAccessGroupsByPage(page int, size int) (AccessGroupPageResponse, error) {
4255
endpoint := fmt.Sprintf("%s/access-groups?page=%d&size=%d", c.client.GetV1Url(), page, size)
4356
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
@@ -58,6 +71,8 @@ func (c *AccessGroupsService) GetAccessGroupsByPage(page int, size int) (AccessG
5871
return response, nil
5972
}
6073

74+
// List retrieves all access groups from the CloudConnexa API.
75+
// It handles pagination internally and returns a complete list of access groups.
6176
func (c *AccessGroupsService) List() ([]AccessGroup, error) {
6277
var allGroups []AccessGroup
6378
page := 0
@@ -78,6 +93,7 @@ func (c *AccessGroupsService) List() ([]AccessGroup, error) {
7893
return allGroups, nil
7994
}
8095

96+
// Get retrieves a specific access group by its ID from the CloudConnexa API.
8197
func (c *AccessGroupsService) Get(id string) (*AccessGroup, error) {
8298
endpoint := fmt.Sprintf("%s/access-groups/%s", c.client.GetV1Url(), id)
8399
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
@@ -98,6 +114,8 @@ func (c *AccessGroupsService) Get(id string) (*AccessGroup, error) {
98114
return &accessGroup, nil
99115
}
100116

117+
// Create creates a new access group in the CloudConnexa API.
118+
// It returns the created access group with its assigned ID.
101119
func (c *AccessGroupsService) Create(accessGroup *AccessGroup) (*AccessGroup, error) {
102120
accessGroupJSON, err := json.Marshal(accessGroup)
103121
if err != nil {
@@ -124,6 +142,8 @@ func (c *AccessGroupsService) Create(accessGroup *AccessGroup) (*AccessGroup, er
124142
return &s, nil
125143
}
126144

145+
// Update updates an existing access group in the CloudConnexa API.
146+
// It returns the updated access group.
127147
func (c *AccessGroupsService) Update(id string, accessGroup *AccessGroup) (*AccessGroup, error) {
128148
accessGroupJSON, err := json.Marshal(accessGroup)
129149
if err != nil {
@@ -150,6 +170,7 @@ func (c *AccessGroupsService) Update(id string, accessGroup *AccessGroup) (*Acce
150170
return &s, nil
151171
}
152172

173+
// Delete removes an access group from the CloudConnexa API by its ID.
153174
func (c *AccessGroupsService) Delete(id string) error {
154175
endpoint := fmt.Sprintf("%s/access-groups/%s", c.client.GetV1Url(), id)
155176
req, err := http.NewRequest(http.MethodDelete, endpoint, nil)

cloudconnexa/cloudconnexa.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
userAgent = "cloudconnexa-go"
1818
)
1919

20+
// Client represents a CloudConnexa API client with all service endpoints.
2021
type Client struct {
2122
client *http.Client
2223

@@ -49,10 +50,12 @@ type service struct {
4950
client *Client
5051
}
5152

53+
// Credentials represents the OAuth2 token response from CloudConnexa API.
5254
type Credentials struct {
5355
AccessToken string `json:"access_token"`
5456
}
5557

58+
// ErrClientResponse represents an error response from the CloudConnexa API.
5659
type ErrClientResponse struct {
5760
status int
5861
body string
@@ -62,6 +65,8 @@ func (e ErrClientResponse) Error() string {
6265
return fmt.Sprintf("status code: %d, response body: %s", e.status, e.body)
6366
}
6467

68+
// NewClient creates a new CloudConnexa API client with the given credentials.
69+
// It authenticates using OAuth2 client credentials flow and returns a configured client.
6570
func NewClient(baseURL, clientID, clientSecret string) (*Client, error) {
6671
if clientID == "" || clientSecret == "" {
6772
return nil, ErrCredentialsRequired
@@ -88,7 +93,13 @@ func NewClient(baseURL, clientID, clientSecret string) (*Client, error) {
8893
return nil, err
8994
}
9095

91-
defer resp.Body.Close()
96+
defer func() {
97+
if closeErr := resp.Body.Close(); closeErr != nil {
98+
// Log the error if you have a logger, otherwise this is acceptable for library code
99+
_ = closeErr
100+
}
101+
}()
102+
92103
body, err := io.ReadAll(resp.Body)
93104
if err != nil {
94105
return nil, err
@@ -126,6 +137,8 @@ func NewClient(baseURL, clientID, clientSecret string) (*Client, error) {
126137
return c, nil
127138
}
128139

140+
// DoRequest executes an HTTP request with authentication and rate limiting.
141+
// It automatically adds the Bearer token, sets headers, and handles errors.
129142
func (c *Client) DoRequest(req *http.Request) ([]byte, error) {
130143
err := c.RateLimiter.Wait(context.Background())
131144
if err != nil {
@@ -140,7 +153,12 @@ func (c *Client) DoRequest(req *http.Request) ([]byte, error) {
140153
if err != nil {
141154
return nil, err
142155
}
143-
defer res.Body.Close()
156+
defer func() {
157+
if closeErr := res.Body.Close(); closeErr != nil {
158+
// Log the error if you have a logger, otherwise this is acceptable for library code
159+
_ = closeErr
160+
}
161+
}()
144162

145163
body, err := io.ReadAll(res.Body)
146164
if err != nil {
@@ -154,6 +172,7 @@ func (c *Client) DoRequest(req *http.Request) ([]byte, error) {
154172
return body, nil
155173
}
156174

175+
// GetV1Url returns the base URL for CloudConnexa API v1 endpoints.
157176
func (c *Client) GetV1Url() string {
158177
return c.BaseURL + "/api/v1"
159178
}

cloudconnexa/cloudconnexa_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"golang.org/x/time/rate"
1212
)
1313

14+
// setupMockServer creates a test HTTP server that simulates the CloudConnexa API endpoints
15+
// for testing purposes. It handles token authentication and basic endpoint responses.
1416
func setupMockServer() *httptest.Server {
1517
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1618
switch r.URL.Path {
@@ -36,6 +38,9 @@ func setupMockServer() *httptest.Server {
3638
return server
3739
}
3840

41+
// TestNewClient tests the creation of a new CloudConnexa client with various credential combinations.
42+
// It verifies that the client is properly initialized with valid credentials and returns
43+
// appropriate errors for invalid credentials.
3944
func TestNewClient(t *testing.T) {
4045
server := setupMockServer()
4146
defer server.Close()
@@ -66,6 +71,9 @@ func TestNewClient(t *testing.T) {
6671
}
6772
}
6873

74+
// TestDoRequest tests the DoRequest method of the CloudConnexa client.
75+
// It verifies that the client correctly handles various HTTP requests and responses,
76+
// including valid requests, invalid endpoints, and incorrect HTTP methods.
6977
func TestDoRequest(t *testing.T) {
7078
server := setupMockServer()
7179
defer server.Close()

cloudconnexa/dns_records.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
)
1010

1111
var (
12+
// ErrDNSRecordNotFound is returned when a DNS record is not found.
1213
ErrDNSRecordNotFound = errors.New("dns record not found")
1314
)
1415

16+
// DNSRecord represents a DNS record in CloudConnexa.
1517
type DNSRecord struct {
1618
ID string `json:"id"`
1719
Domain string `json:"domain"`
@@ -20,6 +22,7 @@ type DNSRecord struct {
2022
IPV6Addresses []string `json:"ipv6Addresses"`
2123
}
2224

25+
// DNSRecordPageResponse represents a paginated response of DNS records.
2326
type DNSRecordPageResponse struct {
2427
Content []DNSRecord `json:"content"`
2528
NumberOfElements int `json:"numberOfElements"`
@@ -30,8 +33,10 @@ type DNSRecordPageResponse struct {
3033
TotalPages int `json:"totalPages"`
3134
}
3235

36+
// DNSRecordsService provides methods for managing DNS records.
3337
type DNSRecordsService service
3438

39+
// GetByPage retrieves DNS records using pagination.
3540
func (c *DNSRecordsService) GetByPage(page int, pageSize int) (DNSRecordPageResponse, error) {
3641
endpoint := fmt.Sprintf("%s/dns-records?page=%d&size=%d", c.client.GetV1Url(), page, pageSize)
3742
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
@@ -52,6 +57,7 @@ func (c *DNSRecordsService) GetByPage(page int, pageSize int) (DNSRecordPageResp
5257
return response, nil
5358
}
5459

60+
// GetDNSRecord retrieves a specific DNS record by ID.
5561
func (c *DNSRecordsService) GetDNSRecord(recordID string) (*DNSRecord, error) {
5662
pageSize := 10
5763
page := 0
@@ -76,6 +82,7 @@ func (c *DNSRecordsService) GetDNSRecord(recordID string) (*DNSRecord, error) {
7682
return nil, ErrDNSRecordNotFound
7783
}
7884

85+
// Create creates a new DNS record.
7986
func (c *DNSRecordsService) Create(record DNSRecord) (*DNSRecord, error) {
8087
recordJSON, err := json.Marshal(record)
8188
if err != nil {
@@ -100,6 +107,7 @@ func (c *DNSRecordsService) Create(record DNSRecord) (*DNSRecord, error) {
100107
return &d, nil
101108
}
102109

110+
// Update updates an existing DNS record.
103111
func (c *DNSRecordsService) Update(record DNSRecord) error {
104112
recordJSON, err := json.Marshal(record)
105113
if err != nil {
@@ -115,6 +123,7 @@ func (c *DNSRecordsService) Update(record DNSRecord) error {
115123
return err
116124
}
117125

126+
// Delete deletes a DNS record by ID.
118127
func (c *DNSRecordsService) Delete(recordID string) error {
119128
req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/dns-records/%s", c.client.GetV1Url(), recordID), nil)
120129
if err != nil {

cloudconnexa/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package cloudconnexa
22

33
import "errors"
44

5+
// ErrCredentialsRequired is returned when client ID or client secret is missing.
56
var ErrCredentialsRequired = errors.New("both client_id and client_secret credentials must be specified")

0 commit comments

Comments
 (0)