Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
go test -race -coverprofile=coverage.txt -covermode=atomic ./cloudconnexa/...

- name: Run e2e tests
if: ${{ vars.OVPN_HOST != '' }}
if: ${{ vars.CLOUDCONNEXA_BASE_URL != '' }}
run: |
go test -race ./e2e/...
env:
OVPN_HOST: ${{ vars.OVPN_HOST }}
CLOUDCONNEXA_BASE_URL: ${{ vars.CLOUDCONNEXA_BASE_URL }}
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ jobs:
- name: E2E Test
run: make e2e
env:
OVPN_HOST: ${{ vars.OVPN_HOST }}
CLOUDCONNEXA_BASE_URL: ${{ vars.CLOUDCONNEXA_BASE_URL }}
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}
2 changes: 1 addition & 1 deletion .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
args: ./...
env:
OVPN_HOST: ${{ vars.OVPN_HOST }}
CLOUDCONNEXA_BASE_URL: ${{ vars.CLOUDCONNEXA_BASE_URL }}
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}

Expand Down
21 changes: 19 additions & 2 deletions cloudconnexa/access_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cloudconnexa
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
)
Expand Down Expand Up @@ -76,10 +77,9 @@ func (c *AccessGroupsService) GetAccessGroupsByPage(page int, size int) (AccessG
func (c *AccessGroupsService) List() ([]AccessGroup, error) {
var allGroups []AccessGroup
page := 0
pageSize := 10

for {
response, err := c.GetAccessGroupsByPage(page, pageSize)
response, err := c.GetAccessGroupsByPage(page, defaultPageSize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -114,6 +114,23 @@ func (c *AccessGroupsService) Get(id string) (*AccessGroup, error) {
return &accessGroup, nil
}

// GetByName retrieves an access group by its name
// name: The name of the access group to retrieve
// Returns the access group and any error that occurred
func (c *AccessGroupsService) GetByName(name string) (*AccessGroup, error) {
items, err := c.List()
if err != nil {
return nil, err
}

for _, item := range items {
if item.Name == name {
return &item, nil
}
}
return nil, errors.New("access group not found")
}

// Create creates a new access group in the CloudConnexa API.
// It returns the created access group with its assigned ID.
func (c *AccessGroupsService) Create(accessGroup *AccessGroup) (*AccessGroup, error) {
Expand Down
3 changes: 2 additions & 1 deletion cloudconnexa/cloudconnexa.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
)

const (
userAgent = "cloudconnexa-go"
userAgent = "cloudconnexa-go"
defaultPageSize = 100
)

// Client represents a CloudConnexa API client with all service endpoints.
Expand Down
6 changes: 2 additions & 4 deletions cloudconnexa/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ func (d *DevicesService) GetByPage(page int, pageSize int) (*DevicePageResponse,
func (d *DevicesService) ListAll() ([]DeviceDetail, error) {
var allDevices []DeviceDetail
page := 0
pageSize := 100 // Use maximum page size for efficiency

for {
response, err := d.GetByPage(page, pageSize)
response, err := d.GetByPage(page, defaultPageSize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -232,13 +231,12 @@ func (d *DevicesService) Update(deviceID string, updateRequest DeviceUpdateReque
func (d *DevicesService) ListByUserID(userID string) ([]DeviceDetail, error) {
var allDevices []DeviceDetail
page := 0
pageSize := 100

for {
options := DeviceListOptions{
UserID: userID,
Page: page,
Size: pageSize,
Size: defaultPageSize,
}

response, err := d.List(options)
Expand Down
4 changes: 2 additions & 2 deletions cloudconnexa/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestDevicesService_List(t *testing.T) {
},
NumberOfElements: 2,
Page: 0,
Size: 10,
Size: 100,
Success: true,
TotalElements: 2,
TotalPages: 1,
Expand All @@ -71,7 +71,7 @@ func TestDevicesService_List(t *testing.T) {
// Test the List method
options := DeviceListOptions{
Page: 0,
Size: 10,
Size: 100,
}
result, err := client.Devices.List(options)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cloudconnexa/dns_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ func (c *DNSRecordsService) GetByID(recordID string) (*DNSRecord, error) {
// GetDNSRecord retrieves a specific DNS record by ID using pagination search.
// Deprecated: Use GetByID() instead for better performance with the direct API endpoint.
func (c *DNSRecordsService) GetDNSRecord(recordID string) (*DNSRecord, error) {
pageSize := 10
page := 0

for {
response, err := c.GetByPage(page, pageSize)
response, err := c.GetByPage(page, defaultPageSize)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions cloudconnexa/dns_records_direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudconnexa

import (
"encoding/json"
"golang.org/x/time/rate"
"net/http"
"net/http/httptest"
"testing"

"golang.org/x/time/rate"
)

// createTestDNSClient creates a test client with the given server for DNS testing
Expand Down Expand Up @@ -114,7 +115,7 @@ func TestDNSRecordsService_GetByID_vs_GetDNSRecord(t *testing.T) {
{ID: "record-123", Domain: "example.com"},
},
Page: 0,
Size: 10,
Size: 100,
TotalPages: 1,
}
w.Header().Set("Content-Type", "application/json")
Expand Down
28 changes: 26 additions & 2 deletions cloudconnexa/host_applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudconnexa
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
)
Expand Down Expand Up @@ -86,10 +87,9 @@ func (c *HostApplicationsService) GetApplicationsByPage(page int, pageSize int)
func (c *HostApplicationsService) List() ([]ApplicationResponse, error) {
var allApplications []ApplicationResponse
page := 0
pageSize := 10

for {
response, err := c.GetApplicationsByPage(page, pageSize)
response, err := c.GetApplicationsByPage(page, defaultPageSize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -124,6 +124,30 @@ func (c *HostApplicationsService) Get(id string) (*ApplicationResponse, error) {
return &application, nil
}

// GetByName retrieves an application by its name
// name: The name of the application to retrieve
// Returns the application and any error that occurred
func (c *HostApplicationsService) GetByName(name string) (*ApplicationResponse, error) {
items, err := c.List()
if err != nil {
return nil, err
}

filtered := make([]ApplicationResponse, 0)
for _, item := range items {
if item.Name == name {
filtered = append(filtered, item)
}
}
if len(filtered) > 1 {
return nil, errors.New("different host applications found with name: " + name)
}
if len(filtered) == 1 {
return &filtered[0], nil
}
return nil, errors.New("host application not found")
}

// Create creates a new host application.
func (c *HostApplicationsService) Create(application *Application) (*ApplicationResponse, error) {
applicationJSON, err := json.Marshal(application)
Expand Down
28 changes: 26 additions & 2 deletions cloudconnexa/host_connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudconnexa
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
)
Expand Down Expand Up @@ -101,10 +102,9 @@ func (c *HostConnectorsService) List() ([]HostConnector, error) {
func (c *HostConnectorsService) ListByHostID(hostID string) ([]HostConnector, error) {
var allConnectors []HostConnector
page := 0
pageSize := 10

for {
response, err := c.GetByPageAndHostID(page, pageSize, hostID)
response, err := c.GetByPageAndHostID(page, defaultPageSize, hostID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -140,6 +140,30 @@ func (c *HostConnectorsService) GetByID(id string) (*HostConnector, error) {
return &connector, nil
}

// GetByName retrieves a connector by its name
// name: The name of the connector to retrieve
// Returns the connector and any error that occurred
func (c *HostConnectorsService) GetByName(name string) (*HostConnector, error) {
items, err := c.List()
if err != nil {
return nil, err
}

filtered := make([]HostConnector, 0)
for _, item := range items {
if item.Name == name {
filtered = append(filtered, item)
}
}
if len(filtered) > 1 {
return nil, errors.New("different host connectors found with name: " + name)
}
if len(filtered) == 1 {
return &filtered[0], nil
}
return nil, errors.New("host connector not found")
}

// GetProfile retrieves the profile configuration for a host connector.
func (c *HostConnectorsService) GetProfile(id string) (string, error) {
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/hosts/connectors/%s/profile", c.client.GetV1Url(), id), nil)
Expand Down
28 changes: 26 additions & 2 deletions cloudconnexa/host_ip_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudconnexa
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
)
Expand Down Expand Up @@ -97,10 +98,9 @@ func (c *HostIPServicesService) GetIPByPage(page int, pageSize int) (HostIPServi
func (c *HostIPServicesService) List() ([]HostIPServiceResponse, error) {
var allIPServices []HostIPServiceResponse
page := 0
pageSize := 10

for {
response, err := c.GetIPByPage(page, pageSize)
response, err := c.GetIPByPage(page, defaultPageSize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -135,6 +135,30 @@ func (c *HostIPServicesService) Get(id string) (*HostIPServiceResponse, error) {
return &service, nil
}

// GetByName retrieves an IP Service by its name
// name: The name of the IP Service to retrieve
// Returns the IP Service and any error that occurred
func (c *HostIPServicesService) GetByName(name string) (*HostIPServiceResponse, error) {
items, err := c.List()
if err != nil {
return nil, err
}

filtered := make([]HostIPServiceResponse, 0)
for _, item := range items {
if item.Name == name {
filtered = append(filtered, item)
}
}
if len(filtered) > 1 {
return nil, errors.New("different host IP services found with name: " + name)
}
if len(filtered) == 1 {
return &filtered[0], nil
}
return nil, errors.New("host IP service not found")
}

// Create creates a new IP service.
func (c *HostIPServicesService) Create(ipService *IPService) (*HostIPServiceResponse, error) {
ipServiceJSON, err := json.Marshal(ipService)
Expand Down
7 changes: 4 additions & 3 deletions cloudconnexa/host_ip_services_dto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cloudconnexa

import (
"encoding/json"
"golang.org/x/time/rate"
"net/http"
"net/http/httptest"
"testing"

"golang.org/x/time/rate"
)

// createTestHostIPServicesClient creates a test client with the given server for host IP services testing
Expand Down Expand Up @@ -151,7 +152,7 @@ func TestHostIPServicesService_List_UpdatedDTO(t *testing.T) {
},
NumberOfElements: 2,
Page: 0,
Size: 10,
Size: 100,
Success: true,
TotalElements: 2,
TotalPages: 1,
Expand All @@ -165,7 +166,7 @@ func TestHostIPServicesService_List_UpdatedDTO(t *testing.T) {
client := createTestHostIPServicesClient(server)

// Test the GetIPByPage method directly to avoid pagination issues
result, err := client.HostIPServices.GetIPByPage(0, 10)
result, err := client.HostIPServices.GetIPByPage(0, 100)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
Expand Down
21 changes: 19 additions & 2 deletions cloudconnexa/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudconnexa
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
)
Expand Down Expand Up @@ -55,11 +56,10 @@ func (c *HostsService) GetHostsByPage(page int, size int) (HostPageResponse, err
// List retrieves all hosts.
func (c *HostsService) List() ([]Host, error) {
var allHosts []Host
pageSize := 10
page := 0

for {
response, err := c.GetHostsByPage(page, pageSize)
response, err := c.GetHostsByPage(page, defaultPageSize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -95,6 +95,23 @@ func (c *HostsService) Get(id string) (*Host, error) {
return &host, nil
}

// GetByName retrieves a host by its name
// name: The name of the host to retrieve
// Returns the host and any error that occurred
func (c *HostsService) GetByName(name string) (*Host, error) {
items, err := c.List()
if err != nil {
return nil, err
}

for _, item := range items {
if item.Name == name {
return &item, nil
}
}
return nil, errors.New("host not found")
}

// Create creates a new host.
func (c *HostsService) Create(host Host) (*Host, error) {
hostJSON, err := json.Marshal(host)
Expand Down
Loading
Loading