Skip to content

Commit

Permalink
feat: init key2jwt util with pipeline (#1)
Browse files Browse the repository at this point in the history
* 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
livio-a committed Feb 3, 2021
1 parent 87bc572 commit 36b62f4
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
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
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
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
8 changes: 8 additions & 0 deletions .releaserc.js
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"
]
};
32 changes: 32 additions & 0 deletions cmd/jwt/.goreleaser.yml
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
59 changes: 59 additions & 0 deletions cmd/jwt/key2jwt.go
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
}
}
5 changes: 5 additions & 0 deletions go.mod
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
Loading

0 comments on commit 36b62f4

Please sign in to comment.