Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit ad282e7

Browse files
Merge pull request #22 from OpenVPN/update-user
Update user, add CI
2 parents 480069b + 022f995 commit ad282e7

File tree

16 files changed

+366
-47
lines changed

16 files changed

+366
-47
lines changed

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: golangci-lint
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
lint:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- uses: actions/setup-go@v3
18+
with:
19+
go-version-file: "go.mod"
20+
cache: true
21+
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@v3
24+
with:
25+
version: latest

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobs:
1818
- name: Set up Go
1919
uses: actions/setup-go@v3
2020
with:
21-
go-version: 1.19
21+
go-version-file: "go.mod"
22+
cache: true
2223

2324
- name: Import GPG key
2425
id: import_gpg

.github/workflows/test.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Tests
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
paths-ignore:
7+
- "README.md"
8+
push:
9+
branches:
10+
- main
11+
paths-ignore:
12+
- "README.md"
13+
# We test at a regular interval to ensure we are alerted to something breaking due
14+
# to an API change, even if the code did not change.
15+
schedule:
16+
- cron: "0 0 * * *"
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
jobs:
21+
# ensure the code builds...
22+
build:
23+
name: Build
24+
runs-on: ubuntu-latest
25+
timeout-minutes: 5
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: actions/setup-go@v3
29+
with:
30+
go-version-file: "go.mod"
31+
cache: true
32+
- name: Get dependencies
33+
run: |
34+
go mod download
35+
- name: Build
36+
run: |
37+
go build -v .
38+
# run acceptance tests in a matrix with Terraform core versions
39+
test:
40+
name: Matrix Test
41+
needs: build
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 15
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
terraform:
48+
- "1.2.*"
49+
- "1.3.*"
50+
steps:
51+
- uses: actions/checkout@v3
52+
- uses: actions/setup-go@v3
53+
with:
54+
go-version-file: "go.mod"
55+
cache: true
56+
57+
- uses: hashicorp/setup-terraform@v2
58+
with:
59+
terraform_version: ${{ matrix.terraform }}
60+
terraform_wrapper: false
61+
62+
- name: Get dependencies
63+
run: |
64+
go mod download
65+
- name: TF acceptance tests
66+
timeout-minutes: 10
67+
env:
68+
TF_ACC: "1"
69+
OPENVPNCLOUD_TEST_ORGANIZATION: "terraform-community"
70+
OPENVPN_CLOUD_CLIENT_ID: ${{ secrets.CVPN_CLIENT_ID }}
71+
OPENVPN_CLOUD_CLIENT_SECRET: ${{ secrets.CVPN_CLIENT_SECRET }}
72+
run: |
73+
go test -v -cover ./openvpncloud

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
issues:
2+
exclude-rules:
3+
- linters:
4+
- errcheck
5+
text: "Error return value of `d.Set` is not checked"

client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"fmt"
88
"golang.org/x/time/rate"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
"time"
1212
)
@@ -39,7 +39,7 @@ func NewClient(baseUrl, clientId, clientSecret string) (*Client, error) {
3939
if err != nil {
4040
return nil, err
4141
}
42-
body, err := ioutil.ReadAll(resp.Body)
42+
body, err := io.ReadAll(resp.Body)
4343
if err != nil {
4444
return nil, err
4545
}
@@ -74,7 +74,7 @@ func (c *Client) DoRequest(req *http.Request) ([]byte, error) {
7474
}
7575
defer res.Body.Close()
7676

77-
body, err := ioutil.ReadAll(res.Body)
77+
body, err := io.ReadAll(res.Body)
7878
if err != nil {
7979
return nil, err
8080
}

client/connector.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func (c *Client) AddConnector(connector Connector, networkItemId string) (*Conne
107107
return nil, err
108108
}
109109
body, err := c.DoRequest(req)
110+
if err != nil {
111+
return nil, err
112+
}
110113
var conn Connector
111114
err = json.Unmarshal(body, &conn)
112115
if err != nil {

client/user.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ import (
88
)
99

1010
type User struct {
11-
Id string `json:"id"`
12-
Username string `json:"username"`
13-
Role string `json:"role"`
14-
Email string `json:"email"`
15-
AuthType string `json:"authType"`
16-
FirstName string `json:"firstName"`
17-
LastName string `json:"lastName"`
18-
GroupId string `json:"groupId"`
19-
Status string `json:"status"`
20-
Devices []Device `json:"devices"`
11+
Id string `json:"id"`
12+
Username string `json:"username"`
13+
Role string `json:"role"`
14+
Email string `json:"email"`
15+
AuthType string `json:"authType"`
16+
FirstName string `json:"firstName"`
17+
LastName string `json:"lastName"`
18+
GroupId string `json:"groupId"`
19+
Status string `json:"status"`
20+
AccountStatus string `json:"accountStatus"`
21+
Devices []Device `json:"devices"`
2122
}
2223

2324
type Device struct {
@@ -88,6 +89,22 @@ func (c *Client) GetUserById(userId string) (*User, error) {
8889
return &u, nil
8990
}
9091

92+
func (c *Client) UpdateUser(user User) error {
93+
userJson, err := json.Marshal(user)
94+
if err != nil {
95+
return err
96+
}
97+
req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("%s/api/beta/users/%s", c.BaseURL, user.Id), bytes.NewBuffer(userJson))
98+
if err != nil {
99+
return err
100+
}
101+
_, err = c.DoRequest(req)
102+
if err != nil {
103+
return err
104+
}
105+
return nil
106+
}
107+
91108
func (c *Client) DeleteUser(userId string) error {
92109
req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/api/beta/users/%s", c.BaseURL, userId), nil)
93110
if err != nil {

client/user_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ func (c *Client) GetUserGroup(name string) (*UserGroup, error) {
3434
return &ug, nil
3535
}
3636
}
37-
return nil, nil
37+
return nil, fmt.Errorf("group %s does not exist", name)
3838
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require (
66
github.com/gruntwork-io/terratest v0.41.6
77
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
8-
github.com/stretchr/testify v1.7.2
8+
github.com/stretchr/testify v1.8.1
99
golang.org/x/time v0.3.0
1010
)
1111

go.sum

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,19 @@ github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
327327
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
328328
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
329329
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
330+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
331+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
330332
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
331333
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
332334
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
333335
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
334336
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
335337
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
336-
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
338+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
337339
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
340+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
341+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
342+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
338343
github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ=
339344
github.com/tmccombs/hcl2json v0.3.3/go.mod h1:Y2chtz2x9bAeRTvSibVRVgbLJhLJXKlUeIvjeVdnm4w=
340345
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=

0 commit comments

Comments
 (0)