Skip to content

Commit

Permalink
Provide logout command and update deps. (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jun 28, 2022
1 parent 296e883 commit 1263978
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 262 deletions.
2 changes: 1 addition & 1 deletion cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Completion) SizeListCompletion(cmd *cobra.Command, args []string, toCom
}
func (c *Completion) SizeImageConstraintListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
param := sizemodel.NewListSizeImageConstraintsParams()
resp, err := c.driver.SizeImageConstraint.ListSizeImageConstraints(param, nil)
resp, err := c.driver.Sizeimageconstraint().ListSizeImageConstraints(param, nil)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
33 changes: 33 additions & 0 deletions cmd/logout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"fmt"

"github.com/metal-stack/metal-lib/auth"
"github.com/metal-stack/metalctl/pkg/api"
"github.com/spf13/cobra"
)

func newLogoutCmd(c *config) *cobra.Command {
logoutCmd := &cobra.Command{
Use: "logout",
Short: "logout user from OIDC SSO session",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := api.MustDefaultContext()

err := auth.Logout(&auth.LogoutParams{
IssuerURL: ctx.IssuerURL,
Logger: c.log,
})
if err != nil {
return err
}

fmt.Println("OIDC session successfully logged out. Token is not revoked and is valid until expiration.")

return nil
},
PreRun: bindPFlags,
}
return logoutCmd
}
11 changes: 9 additions & 2 deletions cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"golang.org/x/exp/slices"

metalgo "github.com/metal-stack/metal-go"
"github.com/metal-stack/metal-go/api/client/machine"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metalctl/cmd/output"
"github.com/metal-stack/metalctl/pkg/api"
Expand Down Expand Up @@ -965,11 +966,17 @@ func (c *config) machineUpdateFirmware(kind metalgo.FirmwareKind, machineID, ven
description = "unknown"
}

resp, err := c.driver.MachineUpdateFirmware(kind, machineID, revision, description)
kindString := string(kind)

resp, err := c.driver.Machine().UpdateFirmware(machine.NewUpdateFirmwareParams().WithID(machineID).WithBody(&models.V1MachineUpdateFirmwareRequest{
Description: &description,
Kind: &kindString,
Revision: &revision,
}), nil)
if err != nil {
return err
}
return output.New().Print(resp.Machine)
return output.New().Print(resp)
}

func (c *config) machineBootBios(args []string) error {
Expand Down
32 changes: 30 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
metalgo "github.com/metal-stack/metal-go"
"github.com/metal-stack/metalctl/cmd/completion"
"github.com/metal-stack/metalctl/pkg/api"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
Expand Down Expand Up @@ -103,6 +105,7 @@ metalctl machine list -o template --template "{{ .id }}:{{ .size.id }}"
rootCmd.AddCommand(newHealthCmd(c))
rootCmd.AddCommand(newVersionCmd(c))
rootCmd.AddCommand(newLoginCmd())
rootCmd.AddCommand(newLogoutCmd(c))
rootCmd.AddCommand(newWhoamiCmd())
rootCmd.AddCommand(newContextCmd(c))

Expand All @@ -118,6 +121,7 @@ type config struct {
driverURL string
comp *completion.Completion
driver *metalgo.Driver
log *zap.SugaredLogger
}

func getConfig(name string) *config {
Expand Down Expand Up @@ -152,6 +156,12 @@ func getConfig(name string) *config {
}

ctx := api.MustDefaultContext()

logger, err := newLogger()
if err != nil {
log.Fatalf("error creating logger: %v", err)
}

driverURL := viper.GetString("url")
if driverURL == "" && ctx.ApiURL != "" {
driverURL = ctx.ApiURL
Expand All @@ -172,8 +182,7 @@ func getConfig(name string) *config {
}
}

var err error
driver, err := metalgo.NewDriver(driverURL, apiToken, hmacKey)
_, driver, err := metalgo.NewDriver(driverURL, apiToken, hmacKey)
if err != nil {
log.Fatal(err)
}
Expand All @@ -183,5 +192,24 @@ func getConfig(name string) *config {
comp: completion.NewCompletion(driver),
driver: driver,
driverURL: driverURL,
log: logger,
}
}

func newLogger() (*zap.SugaredLogger, error) {
cfg := zap.NewProductionConfig()
if viper.GetBool("debug") {
cfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
} else {
cfg.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
}
cfg.EncoderConfig.TimeKey = "timestamp"
cfg.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder

l, err := cfg.Build()
if err != nil {
return nil, err
}

return l.Sugar(), nil
}
12 changes: 6 additions & 6 deletions cmd/sizeimageconstraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Example:

func (c *config) sizeImageConstraintList() error {
param := sizemodel.NewListSizeImageConstraintsParams()
resp, err := c.driver.SizeImageConstraint.ListSizeImageConstraints(param, nil)
resp, err := c.driver.Sizeimageconstraint().ListSizeImageConstraints(param, nil)
if err != nil {
return err
}
Expand All @@ -116,7 +116,7 @@ func (c *config) sizeImageConstraintDescribe(args []string) error {
id := args[0]
param := sizemodel.NewFindSizeImageConstraintParams()
param.SetID(id)
resp, err := c.driver.SizeImageConstraint.FindSizeImageConstraint(param, nil)
resp, err := c.driver.Sizeimageconstraint().FindSizeImageConstraint(param, nil)
if err != nil {
return err
}
Expand All @@ -142,7 +142,7 @@ func (c *config) sizeImageConstraintApply() error {
sic := sic
param := sizemodel.NewFindSizeImageConstraintParams()
param.SetID(*sic.ID)
p, err := c.driver.SizeImageConstraint.FindSizeImageConstraint(param, nil)
p, err := c.driver.Sizeimageconstraint().FindSizeImageConstraint(param, nil)
if err != nil {
fmt.Printf("Error:%#v", err)
var r *sizemodel.FindSizeImageConstraintDefault
Expand All @@ -156,7 +156,7 @@ func (c *config) sizeImageConstraintApply() error {
if p == nil {
param := sizemodel.NewCreateSizeImageConstraintParams()
param.SetBody(&sic)
resp, err := c.driver.SizeImageConstraint.CreateSizeImageConstraint(param, nil)
resp, err := c.driver.Sizeimageconstraint().CreateSizeImageConstraint(param, nil)
if err != nil {
return err
}
Expand All @@ -172,7 +172,7 @@ func (c *config) sizeImageConstraintApply() error {
}
uparam := sizemodel.NewUpdateSizeImageConstraintParams()
uparam.SetBody(sicur)
resp, err := c.driver.SizeImageConstraint.UpdateSizeImageConstraint(uparam, nil)
resp, err := c.driver.Sizeimageconstraint().UpdateSizeImageConstraint(uparam, nil)
if err != nil {
return err
}
Expand All @@ -188,7 +188,7 @@ func (c *config) sizeImageConstraintDelete(args []string) error {
id := args[0]
param := sizemodel.NewDeleteSizeImageConstraintParams()
param.ID = id
resp, err := c.driver.SizeImageConstraint.DeleteSizeImageConstraint(param, nil)
resp, err := c.driver.Sizeimageconstraint().DeleteSizeImageConstraint(param, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion crush/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type runner struct {
}

func NewRunner(url, bearer, hmac string) *runner {
driver, err := metalgo.NewDriver(url, bearer, hmac)
_, driver, err := metalgo.NewDriver(url, bearer, hmac)
if err != nil {
fmt.Print(err)
os.Exit(1)
Expand Down
72 changes: 35 additions & 37 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,46 @@ go 1.18
require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.13.0
github.com/metal-stack/masterdata-api v0.8.11
github.com/metal-stack/metal-go v0.17.0
github.com/metal-stack/metal-lib v0.9.0
github.com/metal-stack/masterdata-api v0.8.12
github.com/metal-stack/metal-go v0.18.5
github.com/metal-stack/metal-lib v0.9.2
github.com/metal-stack/updater v1.1.3
github.com/metal-stack/v v1.0.3
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.11.0
github.com/stretchr/testify v1.7.1
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
golang.org/x/exp v0.0.0-20220428152302-39d4317da171
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.7.5
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cheggaaa/pb/v3 v3.0.8 // indirect
github.com/coreos/go-oidc/v3 v3.1.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/coreos/go-oidc/v3 v3.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/analysis v0.21.2 // indirect
github.com/go-openapi/errors v0.20.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/loads v0.21.1 // indirect
github.com/go-openapi/runtime v0.23.3 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/runtime v0.24.1 // indirect
github.com/go-openapi/spec v0.20.6 // indirect
github.com/go-openapi/strfmt v0.21.2 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-openapi/validate v0.21.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/goccy/go-json v0.9.4 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-github/v32 v32.1.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand All @@ -56,38 +55,37 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.0 // indirect
github.com/lestrrat-go/httpcc v1.0.0 // indirect
github.com/lestrrat-go/iter v1.0.1 // indirect
github.com/lestrrat-go/jwx v1.2.18 // indirect
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx v1.2.25 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/metal-stack/security v0.6.3 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/metal-stack/security v0.6.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.mongodb.org/mongo-driver v1.8.3 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
go.mongodb.org/mongo-driver v1.9.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/net v0.0.0-20220622184535-263ec571b305 // indirect
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
Expand Down
Loading

0 comments on commit 1263978

Please sign in to comment.