Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

use message definitions from proto #16

Merged
merged 5 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

/.ext
/bin
/dist
/cover.out
187 changes: 187 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
before:
hooks:

builds:
- id: cli
main: ./cmd/aserto-idp
binary: aserto-idp
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/pkg/version.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/pkg/version.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/pkg/version.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-aserto
main: ./plugins/aserto/cmd/aserto-idp-plugin-aserto
binary: aserto-idp-plugin-aserto
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/aserto/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-auth0
main: ./plugins/auth0/cmd/aserto-idp-plugin-auth0
binary: aserto-idp-plugin-auth0
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/auth0/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-dummy
main: ./plugins/dummy/cmd/aserto-idp-plugin-dummy
binary: aserto-idp-plugin-dummy
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/dummy/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

- id: aserto-idp-plugin-json
main: ./plugins/json/cmd/aserto-idp-plugin-json
binary: aserto-idp-plugin-json
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore:
- goos: windows
goarch: arm64
ldflags:
- -s
- -w
- -X github.com/aserto-dev/aserto-idp/plugins/json/pkg/config.ver={{.Version}}
- -X github.com/aserto-dev/aserto-idp/plugins/json/pkg/config.commit={{.ShortCommit}}
- -X github.com/aserto-dev/aserto-idp/plugins/json/pkg/config.date={{.Date}}
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true

archives:
- format: zip
replacements:
darwin: darwin
linux: linux
windows: windows
amd64: x86_64
files:
- LICENSE
- README.md
name_template: "aserto-idp{{ .Version }}_{{ .Os }}_{{ .Arch }}"

checksum:
name_template: "checksums.txt"

snapshot:
name_template: "{{ .Tag }}"

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
github:
owner: aserto-dev
name: aserto-idp

draft: false
prerelease: false
name_template: "aserto-idp {{.Tag}}"

brews:
- name: aserto-idp

tap:
owner: aserto-dev
name: aserto-tap
token: "{{ .Env.ASERTO_TAP }}"

url_template: "https://github.com/aserto-dev/aserto-idp/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
download_strategy: CustomGitHubPrivateRepositoryReleaseDownloadStrategy
custom_require: "lib/custom_download_strategy"

commit_author:
name: Aserto Bot
email: github-bot@aserto.com

homepage: "https://aserto.com/"

description: "aserto idp CLI for importing and exporting users to/from IDP providers."

license: "Apache License Version 2.0"

skip_upload: false

test: |
system "#{bin}/aserto-idp version"

install: |
bin.install "aserto-idp"
3 changes: 3 additions & 0 deletions Depfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ go:
golangci-lint:
importPath: "github.com/golangci/golangci-lint/cmd/golangci-lint"
version: "v1.38.0"
goreleaser:
importPath: github.com/goreleaser/goreleaser
version: "v0.174.2"
31 changes: 2 additions & 29 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
package main

import (
"fmt"
"os"
"runtime"
"time"

"github.com/aserto-dev/mage-loot/buf"
"github.com/aserto-dev/mage-loot/common"
"github.com/aserto-dev/mage-loot/deps"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/pkg/errors"
)

func init() {
Expand All @@ -38,17 +35,12 @@ func GenerateProto() error {

// Build builds all binaries in ./cmd.
func Build() error {
flags, err := ldflags()
if err != nil {
return err
}

return common.Build(flags...)
return common.BuildReleaser()
}

// Cleans the bin director
func Clean() error {
return os.RemoveAll("bin")
return os.RemoveAll("dist")
}

// BuildAll builds all binaries in ./cmd for
Expand Down Expand Up @@ -79,25 +71,6 @@ func All() error {
return nil
}

func ldflags() ([]string, error) {
commit, err := common.Commit()
if err != nil {
return nil, errors.Wrap(err, "failed to calculate git commit")
}
version, err := common.Version()
if err != nil {
return nil, errors.Wrap(err, "failed to calculate version")
}

date := time.Now().UTC().Format(time.RFC3339)

ldbase := "github.com/aserto-dev/aserto-idp/pkg/version"
ldflags := fmt.Sprintf(`-X %s.ver=%s -X %s.commit=%s -X %s.date=%s`,
ldbase, version, ldbase, commit, ldbase, date)

return []string{"-ldflags", ldflags}, nil
}

func Run() error {
return sh.RunV("./bin/" + runtime.GOOS + "-" + runtime.GOARCH + "/aserto-idp")
}
4 changes: 3 additions & 1 deletion pkg/cc/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ func (c *CC) Dispose() {
for _, provider := range c.providers {
provider.Kill()
}
c.defaultProvider.Kill()
if c.defaultProvider != nil {
c.defaultProvider.Kill()
}
}

// LoadConfig loads the plugin and logger config from a configuration file
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type VersionCmd struct {
func (cmd *VersionCmd) Run(c *cc.CC) error {
fmt.Printf("%s - %s (%s)\n",
x.AppName,
version.GetInfo().String(),
version.GetVersionString(),
x.AppVersionTag,
)
return nil
Expand Down
11 changes: 7 additions & 4 deletions pkg/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aserto-dev/aserto-idp/pkg/cmd/plugin"
"github.com/aserto-dev/aserto-idp/pkg/proto"
"github.com/aserto-dev/aserto-idp/pkg/provider"
api "github.com/aserto-dev/go-grpc/aserto/api/v1"
)

type Plugin struct {
Expand Down Expand Up @@ -47,6 +48,8 @@ func NewPlugin(provider provider.Provider, c *cc.CC) (*Plugin, error) {

plugin.Name = provider.GetName()

c.Log.Info().Msgf("loaded plugin %s - version: %s, commit: %s", plugin.Name, providerInfo.Build.Version, providerInfo.Build.Commit)

for _, config := range providerInfo.Configs {
plugin.Plugins = append(plugin.Plugins, getFlagStruct(config.Name, config.Description, plugin.Name, config.Type))
}
Expand All @@ -56,7 +59,7 @@ func NewPlugin(provider provider.Provider, c *cc.CC) (*Plugin, error) {
return &plugin, nil
}

func getFlagStruct(flagName, flagDescription, groupName string, flagType proto.ConfigElementType) interface{} {
func getFlagStruct(flagName, flagDescription, groupName string, flagType api.ConfigElementType) interface{} {
flag := PluginFlag{}

flagStructType := reflect.TypeOf(flag)
Expand All @@ -67,15 +70,15 @@ func getFlagStruct(flagName, flagDescription, groupName string, flagType proto.C
field := flagStructType.Field(i)

switch flagType {
case proto.ConfigElementType_CONFIG_ELEMENT_TYPE_BOOLEAN:
case api.ConfigElementType_CONFIG_ELEMENT_TYPE_BOOLEAN:
if field.Type == reflect.TypeOf(true) {
field.Tag = reflect.StructTag(fmt.Sprintf(`name:"%s" help:"%s" group:"%s Flags"`, flagName, flagDescription, groupName))
}
case proto.ConfigElementType_CONFIG_ELEMENT_TYPE_STRING:
case api.ConfigElementType_CONFIG_ELEMENT_TYPE_STRING:
if field.Type == reflect.TypeOf("string") {
field.Tag = reflect.StructTag(fmt.Sprintf(`name:"%s" help:"%s" group:"%s Flags"`, flagName, flagDescription, groupName))
}
case proto.ConfigElementType_CONFIG_ELEMENT_TYPE_INTEGER:
case api.ConfigElementType_CONFIG_ELEMENT_TYPE_INTEGER:
if field.Type == reflect.TypeOf(0) {
field.Tag = reflect.StructTag(fmt.Sprintf(`name:"%s" help:"%s" group:"%s Flags"`, flagName, flagDescription, groupName))
}
Expand Down
Loading