Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Josh/cf 3243 run granted auth login automatically if auth is expired #680

Closed
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
12 changes: 11 additions & 1 deletion cmd/granted/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/common-fate/granted/pkg/assume"
"github.com/common-fate/granted/pkg/granted"
"github.com/common-fate/updatecheck"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -50,12 +51,21 @@ func main() {

err := app.Run(os.Args)
if err != nil {
// if the error is an instance of clierr.PrintCLIErrorer then print the error accordingly
// if the error is an instance of clierr.PrintCLIErrorer then print the error accordingly and exit
// if it is a regular error, print it and then check if it wraps any clierrs and print those
// this way we don't lose the embedded messages in the clierrs if we wrap them
if cliError, ok := err.(clierr.PrintCLIErrorer); ok {
cliError.PrintCLIError()
os.Exit(1)
} else {
clio.Error(err.Error())
}
for err != nil {
if cliError, ok := err.(clierr.PrintCLIErrorer); ok {
cliError.PrintCLIError()
}
err = errors.Unwrap(err)
}
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/common-fate/clio v1.2.3
github.com/common-fate/common-fate v0.15.13
github.com/common-fate/glide-cli v0.6.0
github.com/common-fate/sdk v1.37.0
github.com/common-fate/sdk v1.37.1-0.20240605070211-f95b1df60097
github.com/fatih/color v1.16.0
github.com/lithammer/fuzzysearch v1.1.5
github.com/schollz/progressbar/v3 v3.13.1
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ github.com/common-fate/iso8601 v1.1.0 h1:nrej9shsK1aB4IyOAjZl68xGk8yDuUxVwQjoDzx
github.com/common-fate/iso8601 v1.1.0/go.mod h1:DU4mvUEkkWZUUSJq2aCuNqM1luSb0Pwyb2dLzXS+img=
github.com/common-fate/sdk v1.37.0 h1:pn4S2MkwbYFglYg5/bMY/55qMclUamui1H1g8/KftkA=
github.com/common-fate/sdk v1.37.0/go.mod h1:WXoPe1Lh7wPmwZj9nXOGVrOU+c5FLUbj7e7Mz4lxSUg=
github.com/common-fate/sdk v1.37.1-0.20240605062033-0405c9575ef4 h1:hPJ+VFToh1OS5LetsG3MQu5gM5Xd14s2Ee8wpyYl7EM=
github.com/common-fate/sdk v1.37.1-0.20240605062033-0405c9575ef4/go.mod h1:WXoPe1Lh7wPmwZj9nXOGVrOU+c5FLUbj7e7Mz4lxSUg=
github.com/common-fate/sdk v1.37.1-0.20240605062614-7dbab5061f2c h1:BZlPXHBQCmvHISgBC+uzZFZshekaWL7GOidgkhN9zvQ=
github.com/common-fate/sdk v1.37.1-0.20240605062614-7dbab5061f2c/go.mod h1:WXoPe1Lh7wPmwZj9nXOGVrOU+c5FLUbj7e7Mz4lxSUg=
github.com/common-fate/sdk v1.37.1-0.20240605063815-ce1c73ffc417 h1:QO1+626XT6ENb0mhvSTzxHFzO1yLHkFFua4BgKBlls0=
github.com/common-fate/sdk v1.37.1-0.20240605063815-ce1c73ffc417/go.mod h1:WXoPe1Lh7wPmwZj9nXOGVrOU+c5FLUbj7e7Mz4lxSUg=
github.com/common-fate/sdk v1.37.1-0.20240605065134-56ff88bbdf6e h1:v9ECmBUY7lt74dCyF6qCeOPqI6IckrgeuoLD+qdspak=
github.com/common-fate/sdk v1.37.1-0.20240605065134-56ff88bbdf6e/go.mod h1:WXoPe1Lh7wPmwZj9nXOGVrOU+c5FLUbj7e7Mz4lxSUg=
github.com/common-fate/sdk v1.37.1-0.20240605070211-f95b1df60097 h1:9llRWv9xWLskd/4qbB7iuRoPawqFkC6ENP27fsrbBxQ=
github.com/common-fate/sdk v1.37.1-0.20240605070211-f95b1df60097/go.mod h1:WXoPe1Lh7wPmwZj9nXOGVrOU+c5FLUbj7e7Mz4lxSUg=
github.com/common-fate/updatecheck v0.3.5 h1:UGIKMnYwuHjbhhCaisLz1pNPg8Z1nXEoWcfqT+4LkAg=
github.com/common-fate/updatecheck v0.3.5/go.mod h1:fru9yoUXmM3QVAUdDDqKQeDoln20Pkji/7EH64gVHMs=
github.com/common-fate/useragent v0.1.0 h1:RLmkIiJXcOUJAUyXWc/zCaGbrGmlCbHBGMx99ztQ3ZU=
Expand Down
11 changes: 10 additions & 1 deletion pkg/cfcfg/cfcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/common-fate/clio"
"github.com/common-fate/granted/pkg/cfaws"
"github.com/common-fate/sdk/cli"
sdkconfig "github.com/common-fate/sdk/config"
)

Expand Down Expand Up @@ -53,7 +54,15 @@ func Load(ctx context.Context, profile *cfaws.Profile) (*sdkconfig.Context, erro
} else {
// if we can't load the Common Fate SDK config (e.g. if `~/.cf/config` is not present)
// we can't request access through the Common Fate platform.
return sdkconfig.LoadDefault(ctx)
return sdkconfig.New(ctx, sdkconfig.Opts{
HttpClientWrapper: func(c sdkconfig.Doer, t sdkconfig.TokenStore) sdkconfig.Doer {
return &cli.ErrorHandlingClient{
Client: c,
LoginHint: "granted auth login",
TokenStore: t,
}
},
})

}
}
Loading