-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init key2jwt util with pipeline (#1)
* feat: init key2jwt util with pipeline * fix: vars * remove dep * version * workdir * mod * add go mod file * add .releaserc.js * add .releaserc.js * try goreleaser * set workdir again * add .goreleaser.yml * move .goreleaser.yml
- Loading branch information
Showing
7 changed files
with
589 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: gomod | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
time: '04:00' | ||
open-pull-requests-limit: 10 | ||
commit-message: | ||
prefix: chore | ||
include: scope | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: weekly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.15 | ||
- name: Cache Go modules | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Tests | ||
run: | | ||
go mod tidy | ||
go test -v ./... | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
# if: success() && startsWith(github.ref, 'refs/tags/') | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
workdir: ./cmd/jwt/ | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
release: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Source checkout | ||
uses: actions/checkout@v2 | ||
- name: Semantic Release | ||
uses: cycjimmy/semantic-release-action@v2 | ||
with: | ||
dry_run: false | ||
semantic_version: 17.0.4 | ||
extra_plugins: | | ||
@semantic-release/exec@5.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
branches: ["master"], | ||
plugins: [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/github" | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This is an example .goreleaser.yml file with some sane defaults. | ||
# Make sure to check the documentation at http://goreleaser.com | ||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod download | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
archives: | ||
- replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
386: i386 | ||
amd64: x86_64 | ||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
project_name: key2jwt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/caos/oidc/pkg/oidc" | ||
"github.com/caos/oidc/pkg/rp" | ||
) | ||
|
||
var ( | ||
keyPath = flag.String("key", "", "path to the key.json") | ||
issuer = flag.String("issuer", "", "issuer where the token will be used (e.g. https://issuer.zitadel.ch)") | ||
outputPath = flag.String("output", "", "path where the generated jwt will be saved; will print to stdout if empty") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if *keyPath == "" || *issuer == "" { | ||
fmt.Println("Please provide at least an issuer and key param:") | ||
flag.PrintDefaults() | ||
return | ||
} | ||
|
||
key, err := ioutil.ReadFile(*keyPath) | ||
if err != nil { | ||
fmt.Printf("error reading key file: %v", err.Error()) | ||
return | ||
} | ||
assertion, err := oidc.NewJWTProfileAssertionFromFileData(key, []string{*issuer}) | ||
if err != nil { | ||
fmt.Printf("error generating assertion: %v", err.Error()) | ||
return | ||
} | ||
jwt, err := rp.GenerateJWTProfileToken(assertion) | ||
if err != nil { | ||
fmt.Printf("error generating key: %v", err.Error()) | ||
return | ||
} | ||
f := os.Stdout | ||
if *outputPath != "" { | ||
f, err = os.OpenFile(*outputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777) | ||
if err != nil { | ||
fmt.Printf("error reading key file: %v", err.Error()) | ||
return | ||
} | ||
} | ||
_, err = f.Write([]byte(jwt)) | ||
if errClose := f.Close(); err == nil { | ||
err = errClose | ||
} | ||
if err != nil { | ||
fmt.Printf("error writing key: %v", err.Error()) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/caos/zitadel-tools | ||
|
||
go 1.15 | ||
|
||
require github.com/caos/oidc v0.13.3 |
Oops, something went wrong.