Skip to content

Commit

Permalink
Merge pull request #2 from yodaluca23/Release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
yodaluca23 authored Dec 25, 2023
2 parents 1874c24 + 9f0064a commit e52626e
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 83 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.API_GITHUB_TOKEN }}

Expand All @@ -26,7 +26,7 @@ jobs:
uses: docker/[email protected]

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.9.1
uses: docker/setup-buildx-action@v3.0.0

- name: Login to DockerHub
uses: docker/[email protected]
Expand All @@ -35,7 +35,7 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v4.1.1
uses: docker/build-push-action@v5.1.0
with:
push: true
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
Expand All @@ -47,7 +47,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.API_GITHUB_TOKEN }}

Expand All @@ -63,7 +63,7 @@ jobs:
go-version: "${{ env.go_version }}"

- name: Binaries Release
uses: goreleaser/goreleaser-action@v4.4.0
uses: goreleaser/goreleaser-action@v5.0.0
with:
version: ~> 1.16.2
args: release --rm-dist
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
steps:
- name: Checkout with token
if: github.event_name != 'pull_request'
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.API_GITHUB_TOKEN }}

- name: Checkout without token
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Fetch Go version
run: |
Expand All @@ -36,14 +36,14 @@ jobs:
run: go test ./...

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.9.1
uses: docker/setup-buildx-action@v3.0.0

- name: Docker Build Test
run: docker buildx build --load --tag test:test --file ./Dockerfile ./

- name: Version
if: github.event_name != 'pull_request'
uses: cycjimmy/semantic-release-action@v3.4.2
uses: cycjimmy/semantic-release-action@v4.0.0
with:
semantic_version: 19.0.2
env:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.0-alpine AS builder
FROM golang:1.21.4-alpine AS builder

WORKDIR /src
COPY . .
Expand All @@ -7,7 +7,7 @@ RUN apk add --no-cache git && \
go mod download && \
CGO_ENABLED=0 go build -ldflags="-s -w" -o "wgcf"

FROM alpine:3.18.3
FROM alpine:3.18.4

WORKDIR /

Expand Down
16 changes: 4 additions & 12 deletions cloudflare/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,16 @@ func GetAccount(ctx *config.Context) (*Account, error) {
return &castResult, err
}

func UpdateLicenseKey(ctx *config.Context, newPublicKey string) (*openapi.UpdateAccount200Response, *Device, error) {
func UpdateLicenseKey(ctx *config.Context) (*openapi.UpdateAccount200Response, error) {
result, _, err := globalClientAuth(ctx.AccessToken).DefaultApi.
UpdateAccount(nil, ctx.DeviceId, ApiVersion).
UpdateAccountRequest(openapi.UpdateAccountRequest{License: ctx.LicenseKey}).
Execute()
if err != nil {
return nil, nil, err
}
// change public key as per official client
result2, _, err := globalClientAuth(ctx.AccessToken).DefaultApi.
UpdateSourceDevice(nil, ApiVersion, ctx.DeviceId).
UpdateSourceDeviceRequest(openapi.UpdateSourceDeviceRequest{Key: newPublicKey}).
Execute()
castResult := Device(result2)
if err != nil {
return nil, nil, err
return nil, err
}
return &result, &castResult, nil

return &result, nil
}

type BoundDevice openapi.GetBoundDevices200Response
Expand Down
16 changes: 1 addition & 15 deletions cmd/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
. "github.com/ViRb3/wgcf/cmd/shared"
"github.com/ViRb3/wgcf/config"
"github.com/ViRb3/wgcf/util"
"github.com/ViRb3/wgcf/wireguard"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var deviceName string
Expand Down Expand Up @@ -82,17 +80,8 @@ func ensureLicenseKeyUpToDate(ctx *config.Context, thisDevice *cloudflare.Device
}

func updateLicenseKey(ctx *config.Context) (*cloudflare.Account, *cloudflare.Device, error) {
newPrivateKey, err := wireguard.NewPrivateKey()
if err != nil {
return nil, nil, err
}
newPublicKey := newPrivateKey.Public()
if _, _, err := cloudflare.UpdateLicenseKey(ctx, newPublicKey.String()); err != nil {
return nil, nil, err
}

viper.Set(config.PrivateKey, newPrivateKey.String())
if err := viper.WriteConfig(); err != nil {
if _, err := cloudflare.UpdateLicenseKey(ctx); err != nil {
return nil, nil, err
}

Expand All @@ -108,9 +97,6 @@ func updateLicenseKey(ctx *config.Context) (*cloudflare.Account, *cloudflare.Dev
if account.License != ctx.LicenseKey {
return nil, nil, errors.New("failed to update license key")
}
if thisDevice.Key != newPublicKey.String() {
return nil, nil, errors.New("failed to update public key")
}

return account, thisDevice, nil
}
29 changes: 17 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ require (
github.com/ViRb3/wgcf/openapi v0.0.0-20220420142358-3d8d5a81187d
github.com/manifoldco/promptui v0.9.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
golang.org/x/crypto v0.12.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
golang.org/x/crypto v0.15.0
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -31,18 +31,23 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e52626e

Please sign in to comment.