-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces a new Authorizer, which is hookable per KlothoMain. The default one just calls auth.Authorize(), but KlothoMains can provide an alternative, including one that adds flags. resolves #164
- Loading branch information
Yuval Shavit
authored and
Yuval Shavit
committed
Feb 16, 2023
1 parent
627ea64
commit 7d56f89
Showing
3 changed files
with
62 additions
and
9 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 |
---|---|---|
@@ -1,17 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/klothoplatform/klotho/pkg/auth" | ||
"github.com/klothoplatform/klotho/pkg/cli" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func main() { | ||
authRequirement := LocalAuth(false) | ||
km := cli.KlothoMain{ | ||
DefaultUpdateStream: "open:latest", | ||
Version: Version, | ||
PluginSetup: func(psb *cli.PluginSetBuilder) error { | ||
return psb.AddAll() | ||
}, | ||
Authorizer: &authRequirement, | ||
} | ||
|
||
km.Main() | ||
} | ||
|
||
// LocalAuth is an auth.Authorizer that requires login unless its value is true. | ||
type LocalAuth bool | ||
|
||
func (local *LocalAuth) SetUpCliFlags(flags *pflag.FlagSet) { | ||
flags.BoolVar((*bool)(local), "local", bool(*local), "If provided, runs Klotho with a local login (that is, not requiring an authenticated login)") | ||
} | ||
|
||
func (local *LocalAuth) Authorize() error { | ||
if !*local { | ||
return auth.Authorize() | ||
} | ||
return nil | ||
} |
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
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