Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: OpenVPN/cloudconnexa-go-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.16
Choose a base ref
...
head repository: OpenVPN/cloudconnexa-go-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 10 commits
  • 6 files changed
  • 5 contributors

Commits on Oct 17, 2024

  1. Fix get route perfomance

    vladhanzha committed Oct 17, 2024
    Copy the full SHA
    d201f9a View commit details
  2. Merge pull request #37 from vladhss/feature/fix-get-route-perfomance

    Fix get route performance
    sahaqaa authored Oct 17, 2024
    Copy the full SHA
    d1634d4 View commit details

Commits on Oct 25, 2024

  1. Fixed E2E GitHub Action

    michaelfmnk committed Oct 25, 2024
    Copy the full SHA
    bac4d16 View commit details
  2. Merge pull request #39 from OpenVPN/feature/workflowfix

    Fixed E2E GitHub Action
    sahaqaa authored Oct 25, 2024
    Copy the full SHA
    07ea55e View commit details

Commits on Nov 7, 2024

  1. Bump golang.org/x/time from 0.7.0 to 0.8.0

    Bumps [golang.org/x/time](https://github.com/golang/time) from 0.7.0 to 0.8.0.
    - [Commits](golang/time@v0.7.0...v0.8.0)
    
    ---
    updated-dependencies:
    - dependency-name: golang.org/x/time
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    dependabot[bot] authored Nov 7, 2024
    Copy the full SHA
    7129b17 View commit details

Commits on Nov 24, 2024

  1. Merge pull request #40 from OpenVPN/dependabot/go_modules/golang.org/…

    …x/time-0.8.0
    
    Bump golang.org/x/time from 0.7.0 to 0.8.0
    arslanbekov authored Nov 24, 2024
    Copy the full SHA
    a143150 View commit details

Commits on Nov 25, 2024

  1. Bump github.com/stretchr/testify from 1.9.0 to 1.10.0

    Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.9.0 to 1.10.0.
    - [Release notes](https://github.com/stretchr/testify/releases)
    - [Commits](stretchr/testify@v1.9.0...v1.10.0)
    
    ---
    updated-dependencies:
    - dependency-name: github.com/stretchr/testify
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    dependabot[bot] authored Nov 25, 2024
    Copy the full SHA
    0660547 View commit details

Commits on Dec 2, 2024

  1. Add access groups support

    vladhanzha committed Dec 2, 2024
    Copy the full SHA
    233e448 View commit details

Commits on Dec 3, 2024

  1. Merge pull request #42 from vladhss/feature/access-groups

    Add access groups support
    sahaqaa authored Dec 3, 2024
    Copy the full SHA
    143e4de View commit details
  2. Merge pull request #41 from OpenVPN/dependabot/go_modules/github.com/…

    …stretchr/testify-1.10.0
    
    Bump github.com/stretchr/testify from 1.9.0 to 1.10.0
    sahaqaa authored Dec 3, 2024
    Copy the full SHA
    060504e View commit details
Showing with 186 additions and 13 deletions.
  1. +4 −5 .github/workflows/go.yml
  2. +173 −0 cloudconnexa/access_groups.go
  3. +2 −0 cloudconnexa/cloudconnexa.go
  4. +1 −2 cloudconnexa/routes.go
  5. +2 −2 go.mod
  6. +4 −4 go.sum
9 changes: 4 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: Go build

env:
OVPN_HOST: ${{ vars.OVPN_HOST }}
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}

on:
pull_request:
branches:
@@ -48,3 +43,7 @@ jobs:

- name: E2E Test
run: make e2e
env:
OVPN_HOST: ${{ vars.OVPN_HOST }}
CLOUDCONNEXA_CLIENT_ID: ${{ secrets.CLOUDCONNEXA_CLIENT_ID }}
CLOUDCONNEXA_CLIENT_SECRET: ${{ secrets.CLOUDCONNEXA_CLIENT_SECRET }}
173 changes: 173 additions & 0 deletions cloudconnexa/access_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package cloudconnexa

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

type AccessGroupRequest struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Source []AccessItemRequest `json:"source"`
Destination []AccessItemRequest `json:"destination"`
}

type AccessGroupResponse struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Source []AccessItemResponse `json:"source"`
Destination []AccessItemResponse `json:"destination"`
}

type AccessItemRequest struct {
Type string `json:"type"`
AllCovered bool `json:"allCovered"`
Parent string `json:"parent,omitempty"`
Children []string `json:"children,omitempty"`
}

type AccessItemResponse struct {
Type string `json:"type"`
AllCovered bool `json:"allCovered"`
Parent *Item `json:"parent"`
Children []Item `json:"children"`
}

type Item struct {
Id string `json:"id"`
}

type AccessGroupPageResponse struct {
Content []AccessGroupResponse `json:"content"`
NumberOfElements int `json:"numberOfElements"`
Page int `json:"page"`
Size int `json:"size"`
Success bool `json:"success"`
TotalElements int `json:"totalElements"`
TotalPages int `json:"totalPages"`
}

type AccessGroupsService service

func (c *AccessGroupsService) GetAccessGroupsByPage(page int, size int) (AccessGroupPageResponse, error) {
endpoint := fmt.Sprintf("%s/api/beta/access-groups/page?page=%d&size=%d", c.client.BaseURL, page, size)
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
if err != nil {
return AccessGroupPageResponse{}, err
}

body, err := c.client.DoRequest(req)
if err != nil {
return AccessGroupPageResponse{}, err
}

var response AccessGroupPageResponse
err = json.Unmarshal(body, &response)
if err != nil {
return AccessGroupPageResponse{}, err
}
return response, nil
}

func (c *AccessGroupsService) List() ([]AccessGroupResponse, error) {
var allGroups []AccessGroupResponse
page := 0
pageSize := 10

for {
response, err := c.GetAccessGroupsByPage(page, pageSize)
if err != nil {
return nil, err
}

allGroups = append(allGroups, response.Content...)
if page >= response.TotalPages {
break
}
page++
}
return allGroups, nil
}

func (c *AccessGroupsService) Get(id string) (*AccessGroupResponse, error) {
groups, err := c.List()
if err != nil {
return nil, err
}

for _, n := range groups {
if n.Id == id {
return &n, nil
}
}
return nil, nil
}

func (c *AccessGroupsService) Create(accessGroup *AccessGroupRequest) (*AccessGroupResponse, error) {
accessGroupJson, err := json.Marshal(accessGroup)
if err != nil {
return nil, err
}

endpoint := fmt.Sprintf("%s/api/beta/access-groups", c.client.BaseURL)

req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewBuffer(accessGroupJson))
if err != nil {
return nil, err
}

body, err := c.client.DoRequest(req)
if err != nil {
return nil, err
}

var s AccessGroupResponse
err = json.Unmarshal(body, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *AccessGroupsService) Update(id string, accessGroup *AccessGroupRequest) (*AccessGroupResponse, error) {
accessGroupJson, err := json.Marshal(accessGroup)
if err != nil {
return nil, err
}

endpoint := fmt.Sprintf("%s/api/beta/access-groups/%s", c.client.BaseURL, id)

req, err := http.NewRequest(http.MethodPut, endpoint, bytes.NewBuffer(accessGroupJson))
if err != nil {
return nil, err
}

body, err := c.client.DoRequest(req)
if err != nil {
return nil, err
}

var s AccessGroupResponse
err = json.Unmarshal(body, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *AccessGroupsService) Delete(id string) error {
endpoint := fmt.Sprintf("%s/api/beta/access-groups/%s", c.client.BaseURL, id)
req, err := http.NewRequest(http.MethodDelete, endpoint, nil)
if err != nil {
return err
}

_, err = c.client.DoRequest(req)
if err != nil {
return err
}
return nil
}
2 changes: 2 additions & 0 deletions cloudconnexa/cloudconnexa.go
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ type Client struct {
UserGroups *UserGroupsService
VPNRegions *VPNRegionsService
LocationContexts *LocationContextsService
AccessGroups *AccessGroupsService
}

type service struct {
@@ -115,6 +116,7 @@ func NewClient(baseURL, clientId, clientSecret string) (*Client, error) {
c.UserGroups = (*UserGroupsService)(&c.common)
c.VPNRegions = (*VPNRegionsService)(&c.common)
c.LocationContexts = (*LocationContextsService)(&c.common)
c.AccessGroups = (*AccessGroupsService)(&c.common)
return c, nil
}

3 changes: 1 addition & 2 deletions cloudconnexa/routes.go
Original file line number Diff line number Diff line change
@@ -91,11 +91,10 @@ func (c *RoutesService) Get(routeId string) (*Route, error) {
}

for _, n := range networks {
routes, err := c.List(n.Id)
if err != nil {
continue
}
for _, r := range routes {
for _, r := range n.Routes {
if r.Id == routeId {
r.NetworkItemId = n.Id
return &r, nil
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ module github.com/openvpn/cloudconnexa-go-client/v2
go 1.21

require (
github.com/stretchr/testify v1.9.0
golang.org/x/time v0.7.0
github.com/stretchr/testify v1.10.0
golang.org/x/time v0.8.0
)

require (
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=