Skip to content

Commit

Permalink
Merge pull request #44 from SuperBuker/release_0.0.4
Browse files Browse the repository at this point in the history
Release 0.0.4
  • Loading branch information
SuperBuker authored Sep 26, 2023
2 parents ba6f4d6 + fc1df82 commit d79f54e
Show file tree
Hide file tree
Showing 26 changed files with 223 additions and 154 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/golang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
strategy:
max-parallel: 1
matrix:
go-version: [ '1.20.x' ] # To extend
go-version: [ '1.21.x' ] # To extend
terraform-version : [ '1.0.x', '1.1.x', '1.2.x', '1.3.x', '1.4.x' ] # To extend

steps:
- uses: actions/checkout@v3.5.2
- uses: actions/checkout@v4.1.0

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4.0.1
uses: actions/setup-go@v4.1.0
with:
go-version: ${{ matrix.go-version }}
cache: true
Expand All @@ -42,7 +42,7 @@ jobs:
run: terraform version

- name: Terraform provider cache
uses: actions/[email protected].1
uses: actions/[email protected].2
with:
key: terraform-provider-dns-he-net
path: ~/.config/terraform-provider-dns-he-net/
Expand All @@ -51,8 +51,9 @@ jobs:
run: go mod download

- name: Run linter
uses: golangci/golangci-lint-action@v3.4.0
uses: golangci/golangci-lint-action@v3.7.0
with:
args: --timeout=10m
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.52.0

Expand All @@ -64,6 +65,7 @@ jobs:
DNSHENET_USER: ${{ secrets.DNSHENET_USER }}
DNSHENET_PASSWD: ${{ secrets.DNSHENET_PASSWD }}
DNSHENET_OTP: ${{ secrets.DNSHENET_OTP }}
DNSHENET_ACCOUNTID: ${{ secrets.DNSHENET_ACCOUNTID }}
TF_ACC: "1"
run: |
go test -v ./... -covermode count -coverprofile coverage.out -json > TestResults-${{ matrix.go-version }}-${{ matrix.terraform-version }}.json || true
Expand All @@ -74,7 +76,7 @@ jobs:
# run: go build -v ./...

- name: Upload Go test results
uses: actions/[email protected].2
uses: actions/[email protected].3
with:
name: Go-results-${{ matrix.go-version }}-${{ matrix.terraform-version }}
path: TestResults-${{ matrix.go-version }}-${{ matrix.terraform-version }}.json
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.5.2
uses: actions/checkout@v4.1.0
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4.0.1
uses: actions/setup-go@v4.1.0
with:
go-version-file: "go.mod"
cache: true

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5.3.0
uses: crazy-max/ghaction-import-gpg@v6.0.0
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4.2.0
uses: goreleaser/goreleaser-action@v5.0.0
with:
version: latest
args: release --clean
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ $ go build -o terraform-provider-dns-he-net

In order to run the full suite of Acceptance tests, the following environment variables must be set:

- `DNSHENET_USER`
- `DNSHENET_PASSWD`
- `DNSHENET_OTP`
- `DNSHENET_USER` (mandatory)
- `DNSHENET_PASSWD` (mandatory)
- `DNSHENET_OTP` (optional, only required if the OTP auth is enabled)
- `DNSHENET_ACCOUNT_ID` (mandatory, used for validating the testing results)

```sh
$ TF_ACC=1 go test -v ./...
Expand Down
6 changes: 3 additions & 3 deletions client/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "github.com/SuperBuker/terraform-provider-dns-he-net/client/auth"

- [Constants](<#constants>)
- [Variables](<#variables>)
- [func addChecksum(data []byte) []byte](<#func-addchecksum>)
- [func addChecksum(data []byte) ([]byte, error)](<#func-addchecksum>)
- [func buildSecret(a *Auth) []byte](<#func-buildsecret>)
- [func configFilePath(a *Auth, cs AuthStore) string](<#func-configfilepath>)
- [func decrypt(a *Auth, cipherData []byte) ([]byte, error)](<#func-decrypt>)
Expand Down Expand Up @@ -65,7 +65,7 @@ var configPath = configdir.LocalConfig("terraform-provider-dns-he-net")
## func [addChecksum](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/auth/blob/master/client/auth/store_utils.go#L135>)

```go
func addChecksum(data []byte) []byte
func addChecksum(data []byte) ([]byte, error)
```

addChecksum prepends a checksum to the given data.
Expand Down Expand Up @@ -108,7 +108,7 @@ func encrypt(a *Auth, data []byte) ([]byte, error)

encrypt the given data using the given Auth, returns new slice and custom error.

## func [extractChecksum](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/auth/blob/master/client/auth/store_utils.go#L145>)
## func [extractChecksum](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/auth/blob/master/client/auth/store_utils.go#L149>)

```go
func extractChecksum(data []byte) ([]byte, error)
Expand Down
5 changes: 4 additions & 1 deletion client/auth/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func encryptedStore() authStore {
return err // Returns custom error
}

sumData := addChecksum(data)
sumData, err := addChecksum(data)
if err != nil {
return err // Returns custom error
}

cipherData, err := encrypt(a, sumData)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions client/auth/store_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@ func encrypt(a *Auth, data []byte) ([]byte, error) {
}

// addChecksum prepends a checksum to the given data.
func addChecksum(data []byte) []byte {
func addChecksum(data []byte) ([]byte, error) {
if len(data) > 64*1024*1024 {
return nil, &ErrFileEncryption{errors.New("data too large")}
}

out := make([]byte, sha256.Size+len(data))
sum := sha256.Sum256(data)
copy(out, sum[:])
copy(out[sha256.Size:], data)

return out
return out, nil
}

// extractChecksum given data, returns new slice and error.
Expand Down
3 changes: 2 additions & 1 deletion client/auth/store_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func TestChecksum(t *testing.T) {
err := initIV(data)
require.NoError(t, err)

dataSum := addChecksum(data)
dataSum, err := addChecksum(data)
require.NoError(t, err)

data2, err := extractChecksum(dataSum)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions client/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ SetRecord creates or updates a record, then returns it, or an error.
func (c *Client) authBasic(ctx context.Context, client *resty.Client) ([]*http.Cookie, error)
```

### func \(\*Client\) [authOTP](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/client/blob/master/client/client/client_auth.go#L96>)
### func \(\*Client\) [authOTP](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/client/blob/master/client/client/client_auth.go#L109>)

```go
func (c *Client) authOTP(ctx context.Context, client *resty.Client) error
Expand All @@ -222,7 +222,7 @@ func (c *Client) autheticate(ctx context.Context) ([]*http.Cookie, error)

autheticate authenticates the client against the API on a separated go\-resty client, then returns the cookies.

### func \(\*Client\) [setAccount](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/client/blob/master/client/client/client_auth.go#L116>)
### func \(\*Client\) [setAccount](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/client/blob/master/client/client/client_auth.go#L129>)

```go
func (c *Client) setAccount(resp *resty.Response)
Expand Down
15 changes: 14 additions & 1 deletion client/client/client_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,20 @@ func (c *Client) autheticate(ctx context.Context) ([]*http.Cookie, error) {
func (c *Client) authBasic(ctx context.Context, client *resty.Client) ([]*http.Cookie, error) {
c.log.Debug(ctx, "auth request - basic creds")

// Dummy request to initialise session and generate session cookies
resp, err := client.R().
SetContext(ctx).
Get(endpoint)

if !errors.Is(err, &status.ErrNoAuth{}) {
// Unexpected error response
return nil, err
}

cookies := resp.Cookies()
client.SetCookies(cookies)

resp, err = client.R().
SetContext(ctx).
SetFormData(authx.Creds(c.auth)).
Post(endpoint)
Expand All @@ -90,7 +103,7 @@ func (c *Client) authBasic(ctx context.Context, client *resty.Client) ([]*http.C
return nil, err
}

return resp.Cookies(), err
return cookies, err
}

func (c *Client) authOTP(ctx context.Context, client *resty.Client) error {
Expand Down
7 changes: 4 additions & 3 deletions client/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestClientAuth(t *testing.T) {
user := os.Getenv("DNSHENET_USER")
password := os.Getenv("DNSHENET_PASSWD")
otp := os.Getenv("DNSHENET_OTP")
accountID := os.Getenv("DNSHENET_ACCOUNT_ID")

t.Run("Client auth.Simple", func(t *testing.T) {
authObj, err := auth.NewAuth(user, password, otp, auth.Simple)
Expand All @@ -26,7 +27,7 @@ func TestClientAuth(t *testing.T) {
cli, err := NewClient(context.TODO(), authObj, logging.NewZerolog(zerolog.DebugLevel, false))
require.NoError(t, err)

assert.Equal(t, "v6643873d8c41428.97783691", cli.GetAccount())
assert.Equal(t, accountID, cli.GetAccount())

for _, cookie := range cli.client.Cookies {
cookie.Value = "" // clear cookie value
Expand All @@ -41,7 +42,7 @@ func TestClientAuth(t *testing.T) {

assert.Equal(t, 3, len(zones))

assert.Equal(t, "v6643873d8c41428.97783691", cli.GetAccount())
assert.Equal(t, accountID, cli.GetAccount())

// Not onboarded record
records, err := cli.GetRecords(context.TODO(), 1096291)
Expand All @@ -64,7 +65,7 @@ func TestClientAuth(t *testing.T) {

assert.Equal(t, "user-agent test", cli.client.Header.Get("User-Agent"))

assert.Equal(t, "v6643873d8c41428.97783691", cli.GetAccount())
assert.Equal(t, accountID, cli.GetAccount())

zones, err := cli.GetZones(context.TODO())
require.NoError(t, err)
Expand Down
18 changes: 9 additions & 9 deletions client/models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ func (r SPF) Serialise() map[string]string
func (r SPF) Type() string
```

## type [SRV](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L9-L18>)
## type [SRV](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L10-L19>)

```go
type SRV struct {
Expand All @@ -1173,49 +1173,49 @@ type SRV struct {
}
```

### func [ToSRV](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L42>)
### func [ToSRV](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L46>)

```go
func ToSRV(r Record) (SRV, error)
```

### func [parseSRVData](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L20>)
### func [parseSRVData](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L21>)

```go
func parseSRVData(data string) (SRV, error)
```

### func \(SRV\) [Equals](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L64>)
### func \(SRV\) [Equals](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L68>)

```go
func (r SRV) Equals(rx RecordX) bool
```

### func \(SRV\) [GetID](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L111>)
### func \(SRV\) [GetID](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L115>)

```go
func (r SRV) GetID() (uint, bool)
```

### func \(SRV\) [GetZoneID](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L119>)
### func \(SRV\) [GetZoneID](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L123>)

```go
func (r SRV) GetZoneID() uint
```

### func \(SRV\) [Refs](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L104>)
### func \(SRV\) [Refs](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L108>)

```go
func (r SRV) Refs() map[string]string
```

### func \(SRV\) [Serialise](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L90>)
### func \(SRV\) [Serialise](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L94>)

```go
func (r SRV) Serialise() map[string]string
```

### func \(SRV\) [Type](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L123>)
### func \(SRV\) [Type](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/models/blob/master/client/models/record_SRV.go#L127>)

```go
func (r SRV) Type() string
Expand Down
4 changes: 4 additions & 0 deletions client/models/record_SRV.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"fmt"
"math"
"strconv"
"strings"
)
Expand Down Expand Up @@ -31,6 +32,9 @@ func parseSRVData(data string) (SRV, error) {
for i, x := range []*uint16{&srv.Weight, &srv.Port} {
if a, err := strconv.Atoi(s[i]); err != nil {
return SRV{}, err
} else if a < 0 || a > math.MaxUint16 {
field := []string{"Weight", "Port"}[i]
return SRV{}, &ErrFormat{field, "value out of range"}
} else {
*x = uint16(a)
}
Expand Down
4 changes: 2 additions & 2 deletions client/parsers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func GetAccount(doc *html.Node) (string, error)

GetAccount returns the account name from the HTML body.

## func [GetRecords](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/parsers/blob/master/client/parsers/records.go#L165>)
## func [GetRecords](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/parsers/blob/master/client/parsers/records.go#L166>)

```go
func GetRecords(doc *html.Node) ([]models.Record, error)
Expand Down Expand Up @@ -134,7 +134,7 @@ func errParsingNode(path, field string, err error) error

errParsingNode returns a tailored ErrParsing error.

## func [parseRecordNode](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/parsers/blob/master/client/parsers/records.go#L15>)
## func [parseRecordNode](<https://github.com/SuperBuker/terraform-provider-dns-he-net/tree/master/common/client/parsers/blob/master/client/parsers/records.go#L16>)

```go
func parseRecordNode(node *html.Node) (record models.Record, err error)
Expand Down
3 changes: 2 additions & 1 deletion client/parsers/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package parsers

import (
"fmt"
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -116,7 +117,7 @@ func parseRecordNode(node *html.Node) (record models.Record, err error) {
} else if htmlquery.SelectAttr(c, "align") == "center" {
p := htmlquery.InnerText(c)
var priority int
if priority, err = strconv.Atoi(p); err == nil {
if priority, err = strconv.Atoi(p); priority >= 0 && priority < math.MaxUint16 && err == nil {
p := uint16(priority)
record.Priority = &p
} else if p != "-" {
Expand Down
1 change: 1 addition & 0 deletions client/utils/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

func ApplyToSlice[T any](fn func(T) T, slice []T) []T {
for i, v := range slice {
v := v // To deprecate in Go v1.22
slice[i] = fn(v)
}

Expand Down
Loading

0 comments on commit d79f54e

Please sign in to comment.