diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4155996 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 + +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..a052b0d --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,25 @@ +name: build-test + +on: + push: + branches: + - "main" + - "release-**" + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.22" + - name: Run Test + run: make test + - name: Build + run: make build diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..c3c6542 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,21 @@ +name: golangci-lint + +on: + push: + pull_request: + +jobs: + golangci: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.22" + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.58 diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..a524de2 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,31 @@ +name: goreleaser + +on: + create: + tags: + - v* + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - + name: Set Up Go + uses: actions/setup-go@v5 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13ab009 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +dist/ +tmp/ +releases/ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..9d0ade9 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,17 @@ +run: + timeout: 10m + +linters: + disable-all: true + enable: + - gofmt + - gosimple + - govet + - misspell + - revive + - unused + - staticcheck + +linters-settings: + gofmt: + simplify: true \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..6468145 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,24 @@ +version: 2 + +builds: + - main: ./cmd/zoraauth + binary: zoraauth + env: + - CGO_ENABLED=0 + goos: + - darwin + - linux + - windows + goarch: + - amd64 + - arm64 +archives: + - id: archive + format: tar.gz + files: + - README.md + - LICENSE + - plugin.yaml + - scripts/install_plugin.sh +checksum: + name_template: 'checksums.txt' diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1fda5de --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +HELM_PLUGIN_NAME := zoraauth +LDFLAGS := "-X main.version=${VERSION}" +MOD_PROXY_URL ?= https://goproxy.io + +.PHONY: build +build: + export CGO_ENABLED=0 && \ + go build -o bin/${HELM_PLUGIN_NAME} -ldflags $(LDFLAGS) ./cmd/${HELM_PLUGIN_NAME} + +.PHONY: bootstrap +bootstrap: + export GO111MODULE=on && \ + export GOPROXY=$(MOD_PROXY_URL) && \ + go mod download + +.PHONY: test +test: + go test -v ./... + +.PHONY: tag +tag: + @scripts/tag.sh diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000..b04b0bd --- /dev/null +++ b/OWNERS @@ -0,0 +1,2 @@ +maintainers: + - knrc diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c9e878 --- /dev/null +++ b/README.md @@ -0,0 +1,83 @@ +# Helm zoraauth Plugin + +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![Go Report Card](https://goreportcard.com/badge/github.com/undistro/helm-zoraauth)](https://goreportcard.com/report/github.com/undistro/helm-zoraauth) +[![Release](https://img.shields.io/github/release/undistro/helm-zoraauth.svg?style=flat-square)](https://github.com/undistro/helm-zoraauth/releases/latest) +[![Build Status](https://github.com/undistro/helm-zoraauth/workflows/build-test/badge.svg)](https://github.com/undistro/helm-zoraauth/actions?workflow=build-test) + +`zoraauth` is a Helm v3 plugin for handling the [OAuth2.0 Device Authorization Grant](https://oauth.net/2/device-flow/) process, creating a values file for use during `helm install`. + +## Install + +Based on the version in `plugin.yaml`, release binary will be downloaded from GitHub: + +```console +$ helm plugin install https://github.com/undistro/helm-zoraauth +Downloading and installing helm-zoraauth v0.1.0 ... +https://github.com/undistro/helm-zoraauth/releases/download/v0.1.0/helm-zoraauth_0.1.0_darwin_amd64.tar.gz +Installed plugin: zoraauth +``` + +### For Windows (using WSL) + +Helm's plugin install hook system relies on `/bin/sh`, regardless of the operating system present. Windows users can work around this by using Helm under [WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10). +``` +$ wget https://get.helm.sh/helm-v3.0.0-linux-amd64.tar.gz +$ tar xzf helm-v3.0.0-linux-amd64.tar.gz +$ ./linux-amd64/helm plugin install https://github.com/undistro/helm-zoraauth +``` + +## Usage + +Handle the OAuth 2.0 Device Authorization Grant process, creating a values.yaml file containing details of the `access_token`, `refresh_token` and `token_type`. + +```console +$ helm zoraauth [flags] + +Flags: + --audience string OAuth audience + --client-id string OAuth client ID + --domain string OAuth domain (e.g. Auth0 domain) + --output string Output file for tokens in YAML format (default "tokens.yaml") +``` + +Example Output: + +```console +$ helm zoraauth --audience "" --client-id="" --domain="" + +Initiating Device Authorization Flow... +Please visit https:///activate and enter code: ABCD-EFGH, or visit: https:///activate?user_code=ABCD-EFGH +Tokens saved to tokens.yaml +``` + +The output file will take the form + +```yaml +zoraauth: + access_token: + refresh_token: + token_type: +``` + +## Developer (From Source) Install + +If you would like to handle the build yourself, this is the recommended way to do it. + +You must first have [Go v1.22+](http://golang.org) installed, and then you run: + +```console +$ mkdir -p ${GOPATH}/src/github.com +$ cd $_ +$ git clone git@github.com:undistro/helm-zoraauth.git +$ cd helm-zoraauth +$ make +$ export HELM_LINTER_PLUGIN_NO_INSTALL_HOOK=true +$ helm plugin install /helm-zoraauth +``` + +That last command will use the binary that you built. + +## Notes + +The structure of this repository is based on the [helm-mapkubeapis](https://github.com/helm/helm-mapkubeapis) repository. diff --git a/cmd/zoraauth/main.go b/cmd/zoraauth/main.go new file mode 100644 index 0000000..7251eab --- /dev/null +++ b/cmd/zoraauth/main.go @@ -0,0 +1,158 @@ +package main + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + "os" + "time" + + "github.com/spf13/pflag" + "gopkg.in/yaml.v2" +) + +// Struct to parse the device code response +type DeviceCodeResponse struct { + DeviceCode string `json:"device_code"` + UserCode string `json:"user_code"` + VerificationURI string `json:"verification_URI"` + VerificationURIComplete string `json:"verification_URI_complete"` + ExpiresIn int `json:"expires_in"` + Interval int `json:"interval"` +} + +// Struct to parse the token response +type TokenResponse struct { + AccessToken string `json:"access_token" yaml:"access_token"` + RefreshToken string `json:"refresh_token" yaml:"refresh_token"` + TokenType string `json:"token_type" yaml:"token_type"` +} + +type ZoraAuthResponse struct { + ZoraAuth *TokenResponse `json:"zoraauth" yaml:"zoraauth"` +} + +// Function to request the device code +func requestDeviceCode(domain, clientID, audience string) (*DeviceCodeResponse, error) { + url := fmt.Sprintf("https://%s/oauth/device/code", domain) + data := fmt.Sprintf("client_id=%s&scope=profile%%20email%%20offline_access&audience=%s", clientID, audience) + + resp, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewBufferString(data)) + if err != nil { + return nil, fmt.Errorf("failed to request device code: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("unexpected response status: %s", resp.Status) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } + + var deviceCodeResponse DeviceCodeResponse + if err := json.Unmarshal(body, &deviceCodeResponse); err != nil { + return nil, fmt.Errorf("failed to parse JSON response: %w", err) + } + + return &deviceCodeResponse, nil +} + +// Function to poll for token +func pollForToken(domain, clientID, deviceCode string, interval, expiresIn int) (*TokenResponse, error) { + url := fmt.Sprintf("https://%s/oauth/token", domain) + data := fmt.Sprintf("client_id=%s&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=%s", clientID, deviceCode) + + timer := 0 + for timer < expiresIn { + time.Sleep(time.Duration(interval) * time.Second) + timer += interval + + resp, err := http.Post(url, "application/x-www-form-urlencoded", bytes.NewBufferString(data)) + if err != nil { + return nil, fmt.Errorf("failed to poll for token: %w", err) + } + defer resp.Body.Close() + + if resp.StatusCode == http.StatusOK { + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } + + var tokenResponse TokenResponse + if err := json.Unmarshal(body, &tokenResponse); err != nil { + return nil, fmt.Errorf("failed to parse JSON response: %w", err) + } + + return &tokenResponse, nil + } + } + + return nil, errors.New("failed to retrieve tokens within the expiration time") +} + +// Function to write token information to a YAML file +func writeTokensToYaml(filename string, tokens *TokenResponse) error { + oauth := ZoraAuthResponse{tokens} + yamlData, err := yaml.Marshal(oauth) + if err != nil { + return fmt.Errorf("failed to marshal tokens to YAML: %w", err) + } + + if err := os.WriteFile(filename, yamlData, 0644); err != nil { + return fmt.Errorf("failed to write tokens to file: %w", err) + } + + return nil +} + +func main() { + // Define command-line flags using pflag + domain := pflag.String("domain", "", "OAuth domain (e.g. Auth0 domain)") + clientID := pflag.String("client-id", "", "OAuth client ID") + audience := pflag.String("audience", "", "OAuth audience") + outputFile := pflag.String("output", "tokens.yaml", "Output file for tokens in YAML format") + + // Parse flags + pflag.Parse() + + // Ensure required flags are provided + if *domain == "" || *clientID == "" || *audience == "" { + fmt.Println("Error: domain, client-id, and audience must be provided.") + pflag.Usage() + os.Exit(1) + } + + // Step 1: Request device code + fmt.Println("Initiating Device Authorization Flow...") + deviceInfo, err := requestDeviceCode(*domain, *clientID, *audience) + if err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(1) + } + + // Step 2: Display instructions to the user + fmt.Printf("Please visit %s and enter code: %s, or visit: %s\n", + deviceInfo.VerificationURI, deviceInfo.UserCode, deviceInfo.VerificationURIComplete) + + // Step 3: Poll for token + tokens, err := pollForToken(*domain, *clientID, deviceInfo.DeviceCode, deviceInfo.Interval, deviceInfo.ExpiresIn) + if err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(2) + } + + // Step 4: Output tokens to a YAML file + if err := writeTokensToYaml(*outputFile, tokens); err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(3) + } + + fmt.Printf("Tokens saved to %s\n", *outputFile) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cb34bed --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/undistro/helm-zoraauth + +go 1.22.0 + +require gopkg.in/yaml.v2 v2.4.0 + +require ( + github.com/kr/pretty v0.3.1 // indirect + github.com/rogpeppe/go-internal v1.10.0 // indirect + github.com/spf13/pflag v1.0.5 + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8664273 --- /dev/null +++ b/go.sum @@ -0,0 +1,19 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/plugin.yaml b/plugin.yaml new file mode 100644 index 0000000..3f1a03e --- /dev/null +++ b/plugin.yaml @@ -0,0 +1,8 @@ +name: "zoraauth" +version: "0.1.0" +usage: "Handle Device Authorization Workflow on behalf of Zora Operator" +description: "Handle Device Authorization Workflow on behalf of Zora Operator" +command: "$HELM_PLUGIN_DIR/bin/zoraauth" +hooks: + install: "cd $HELM_PLUGIN_DIR; scripts/install_plugin.sh" + update: "cd $HELM_PLUGIN_DIR; scripts/install_plugin.sh" diff --git a/scripts/install_plugin.sh b/scripts/install_plugin.sh new file mode 100755 index 0000000..fde3574 --- /dev/null +++ b/scripts/install_plugin.sh @@ -0,0 +1,46 @@ +#!/bin/sh -e + +if [ -n "${HELM_LINTER_PLUGIN_NO_INSTALL_HOOK}" ]; then + echo "Development mode: not downloading versioned release." + exit 0 +fi + +# shellcheck disable=SC2002 +version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)" +echo "Downloading and installing helm-zoraauth v${version} ..." + +url="" +if [ "$(uname)" = "Darwin" ]; then + if [ "$(uname -m)" = "arm64" ]; then + url="https://github.com/undistro/helm-zoraauth/releases/download/v${version}/helm-zoraauth_${version}_darwin_arm64.tar.gz" + else + url="https://github.com/undistro/helm-zoraauth/releases/download/v${version}/helm-zoraauth_${version}_darwin_amd64.tar.gz" + fi +elif [ "$(uname)" = "Linux" ] ; then + if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then + url="https://github.com/undistro/helm-zoraauth/releases/download/v${version}/helm-zoraauth_${version}_linux_arm64.tar.gz" + else + url="https://github.com/undistro/helm-zoraauth/releases/download/v${version}/helm-zoraauth_${version}_linux_amd64.tar.gz" + fi +else + url="https://github.com/undistro/helm-zoraauth/releases/download/v${version}/helm-zoraauth_${version}_windows_amd64.tar.gz" +fi + +echo "$url" + +mkdir -p "bin" +mkdir -p "releases/v${version}" + +# Download with curl if possible. +# shellcheck disable=SC2230 +if [ -x "$(which curl 2>/dev/null)" ]; then + curl -sSL "${url}" -o "releases/v${version}.tar.gz" +else + wget -q "${url}" -O "releases/v${version}.tar.gz" +fi +tar xzf "releases/v${version}.tar.gz" -C "releases/v${version}" +mv "releases/v${version}/zoraauth" "bin/zoraauth" || \ + mv "releases/v${version}/zoraauth.exe" "bin/zoraauth" +mv "releases/v${version}/plugin.yaml" . +mv "releases/v${version}/README.md" . +mv "releases/v${version}/LICENSE" . diff --git a/scripts/tag.sh b/scripts/tag.sh new file mode 100755 index 0000000..516e5c4 --- /dev/null +++ b/scripts/tag.sh @@ -0,0 +1,10 @@ +#!/bin/sh -e + +# shellcheck disable=SC2002 +tag="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)" +echo "Tagging helm-zoraauth with v${tag} ..." + +git checkout main +git pull +git tag -a -m "Release v$tag" "v$tag" +git push origin refs/tags/v"$tag"