Rename this flag types for consistency.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
parent
a059d8dfce
commit
6efbd81f75
@ -16,20 +16,20 @@ import (
|
|||||||
configv1alpha1 "go.pinniped.dev/generated/latest/apis/concierge/config/v1alpha1"
|
configv1alpha1 "go.pinniped.dev/generated/latest/apis/concierge/config/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// conciergeMode represents the method by which we should connect to the Concierge on a cluster during login.
|
// conciergeModeFlag represents the method by which we should connect to the Concierge on a cluster during login.
|
||||||
// this is meant to be a valid flag.Value implementation.
|
// this is meant to be a valid flag.Value implementation.
|
||||||
type conciergeMode int
|
type conciergeModeFlag int
|
||||||
|
|
||||||
var _ flag.Value = new(conciergeMode)
|
var _ flag.Value = new(conciergeModeFlag)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
modeUnknown conciergeMode = iota
|
modeUnknown conciergeModeFlag = iota
|
||||||
modeTokenCredentialRequestAPI
|
modeTokenCredentialRequestAPI
|
||||||
modeImpersonationProxy
|
modeImpersonationProxy
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *conciergeMode) String() string {
|
func (f *conciergeModeFlag) String() string {
|
||||||
switch *c {
|
switch *f {
|
||||||
case modeImpersonationProxy:
|
case modeImpersonationProxy:
|
||||||
return "ImpersonationProxy"
|
return "ImpersonationProxy"
|
||||||
case modeTokenCredentialRequestAPI:
|
case modeTokenCredentialRequestAPI:
|
||||||
@ -41,29 +41,29 @@ func (c *conciergeMode) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conciergeMode) Set(s string) error {
|
func (f *conciergeModeFlag) Set(s string) error {
|
||||||
if strings.EqualFold(s, "") {
|
if strings.EqualFold(s, "") {
|
||||||
*c = modeUnknown
|
*f = modeUnknown
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if strings.EqualFold(s, "TokenCredentialRequestAPI") {
|
if strings.EqualFold(s, "TokenCredentialRequestAPI") {
|
||||||
*c = modeTokenCredentialRequestAPI
|
*f = modeTokenCredentialRequestAPI
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if strings.EqualFold(s, "ImpersonationProxy") {
|
if strings.EqualFold(s, "ImpersonationProxy") {
|
||||||
*c = modeImpersonationProxy
|
*f = modeImpersonationProxy
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid mode %q, valid modes are TokenCredentialRequestAPI and ImpersonationProxy", s)
|
return fmt.Errorf("invalid mode %q, valid modes are TokenCredentialRequestAPI and ImpersonationProxy", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conciergeMode) Type() string {
|
func (f *conciergeModeFlag) Type() string {
|
||||||
return "mode"
|
return "mode"
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatchesFrontend returns true iff the flag matches the type of the provided frontend.
|
// MatchesFrontend returns true iff the flag matches the type of the provided frontend.
|
||||||
func (c *conciergeMode) MatchesFrontend(frontend *configv1alpha1.CredentialIssuerFrontend) bool {
|
func (f *conciergeModeFlag) MatchesFrontend(frontend *configv1alpha1.CredentialIssuerFrontend) bool {
|
||||||
switch *c {
|
switch *f {
|
||||||
case modeImpersonationProxy:
|
case modeImpersonationProxy:
|
||||||
return frontend.Type == configv1alpha1.ImpersonationProxyFrontendType
|
return frontend.Type == configv1alpha1.ImpersonationProxyFrontendType
|
||||||
case modeTokenCredentialRequestAPI:
|
case modeTokenCredentialRequestAPI:
|
||||||
@ -76,15 +76,15 @@ func (c *conciergeMode) MatchesFrontend(frontend *configv1alpha1.CredentialIssue
|
|||||||
}
|
}
|
||||||
|
|
||||||
// caBundlePathsVar represents a list of CA bundle paths, which load from disk when the flag is populated.
|
// caBundlePathsVar represents a list of CA bundle paths, which load from disk when the flag is populated.
|
||||||
type caBundleVar []byte
|
type caBundleFlag []byte
|
||||||
|
|
||||||
var _ pflag.Value = new(caBundleVar)
|
var _ pflag.Value = new(caBundleFlag)
|
||||||
|
|
||||||
func (c *caBundleVar) String() string {
|
func (f *caBundleFlag) String() string {
|
||||||
return string(*c)
|
return string(*f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *caBundleVar) Set(path string) error {
|
func (f *caBundleFlag) Set(path string) error {
|
||||||
pem, err := ioutil.ReadFile(path)
|
pem, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read CA bundle path: %w", err)
|
return fmt.Errorf("could not read CA bundle path: %w", err)
|
||||||
@ -93,14 +93,14 @@ func (c *caBundleVar) Set(path string) error {
|
|||||||
if !pool.AppendCertsFromPEM(pem) {
|
if !pool.AppendCertsFromPEM(pem) {
|
||||||
return fmt.Errorf("failed to load any CA certificates from %q", path)
|
return fmt.Errorf("failed to load any CA certificates from %q", path)
|
||||||
}
|
}
|
||||||
if len(*c) == 0 {
|
if len(*f) == 0 {
|
||||||
*c = pem
|
*f = pem
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
*c = bytes.Join([][]byte{*c, pem}, []byte("\n"))
|
*f = bytes.Join([][]byte{*f, pem}, []byte("\n"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *caBundleVar) Type() string {
|
func (f *caBundleFlag) Type() string {
|
||||||
return "path"
|
return "path"
|
||||||
}
|
}
|
||||||
|
@ -20,34 +20,34 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestConciergeModeFlag(t *testing.T) {
|
func TestConciergeModeFlag(t *testing.T) {
|
||||||
var m conciergeMode
|
var f conciergeModeFlag
|
||||||
require.Equal(t, "mode", m.Type())
|
require.Equal(t, "mode", f.Type())
|
||||||
require.Equal(t, modeUnknown, m)
|
require.Equal(t, modeUnknown, f)
|
||||||
require.NoError(t, m.Set(""))
|
require.NoError(t, f.Set(""))
|
||||||
require.Equal(t, modeUnknown, m)
|
require.Equal(t, modeUnknown, f)
|
||||||
require.EqualError(t, m.Set("foo"), `invalid mode "foo", valid modes are TokenCredentialRequestAPI and ImpersonationProxy`)
|
require.EqualError(t, f.Set("foo"), `invalid mode "foo", valid modes are TokenCredentialRequestAPI and ImpersonationProxy`)
|
||||||
require.True(t, m.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.TokenCredentialRequestAPIFrontendType}))
|
require.True(t, f.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.TokenCredentialRequestAPIFrontendType}))
|
||||||
require.True(t, m.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.ImpersonationProxyFrontendType}))
|
require.True(t, f.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.ImpersonationProxyFrontendType}))
|
||||||
|
|
||||||
require.NoError(t, m.Set("TokenCredentialRequestAPI"))
|
require.NoError(t, f.Set("TokenCredentialRequestAPI"))
|
||||||
require.Equal(t, modeTokenCredentialRequestAPI, m)
|
require.Equal(t, modeTokenCredentialRequestAPI, f)
|
||||||
require.Equal(t, "TokenCredentialRequestAPI", m.String())
|
require.Equal(t, "TokenCredentialRequestAPI", f.String())
|
||||||
require.True(t, m.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.TokenCredentialRequestAPIFrontendType}))
|
require.True(t, f.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.TokenCredentialRequestAPIFrontendType}))
|
||||||
require.False(t, m.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.ImpersonationProxyFrontendType}))
|
require.False(t, f.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.ImpersonationProxyFrontendType}))
|
||||||
|
|
||||||
require.NoError(t, m.Set("tokencredentialrequestapi"))
|
require.NoError(t, f.Set("tokencredentialrequestapi"))
|
||||||
require.Equal(t, modeTokenCredentialRequestAPI, m)
|
require.Equal(t, modeTokenCredentialRequestAPI, f)
|
||||||
require.Equal(t, "TokenCredentialRequestAPI", m.String())
|
require.Equal(t, "TokenCredentialRequestAPI", f.String())
|
||||||
|
|
||||||
require.NoError(t, m.Set("ImpersonationProxy"))
|
require.NoError(t, f.Set("ImpersonationProxy"))
|
||||||
require.Equal(t, modeImpersonationProxy, m)
|
require.Equal(t, modeImpersonationProxy, f)
|
||||||
require.Equal(t, "ImpersonationProxy", m.String())
|
require.Equal(t, "ImpersonationProxy", f.String())
|
||||||
require.False(t, m.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.TokenCredentialRequestAPIFrontendType}))
|
require.False(t, f.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.TokenCredentialRequestAPIFrontendType}))
|
||||||
require.True(t, m.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.ImpersonationProxyFrontendType}))
|
require.True(t, f.MatchesFrontend(&configv1alpha1.CredentialIssuerFrontend{Type: configv1alpha1.ImpersonationProxyFrontendType}))
|
||||||
|
|
||||||
require.NoError(t, m.Set("impersonationproxy"))
|
require.NoError(t, f.Set("impersonationproxy"))
|
||||||
require.Equal(t, modeImpersonationProxy, m)
|
require.Equal(t, modeImpersonationProxy, f)
|
||||||
require.Equal(t, "ImpersonationProxy", m.String())
|
require.Equal(t, "ImpersonationProxy", f.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCABundleFlag(t *testing.T) {
|
func TestCABundleFlag(t *testing.T) {
|
||||||
@ -60,15 +60,15 @@ func TestCABundleFlag(t *testing.T) {
|
|||||||
testCAPath := filepath.Join(tmpdir, "testca.pem")
|
testCAPath := filepath.Join(tmpdir, "testca.pem")
|
||||||
require.NoError(t, ioutil.WriteFile(testCAPath, testCA.Bundle(), 0600))
|
require.NoError(t, ioutil.WriteFile(testCAPath, testCA.Bundle(), 0600))
|
||||||
|
|
||||||
c := caBundleVar{}
|
f := caBundleFlag{}
|
||||||
require.Equal(t, "path", c.Type())
|
require.Equal(t, "path", f.Type())
|
||||||
require.Equal(t, "", c.String())
|
require.Equal(t, "", f.String())
|
||||||
require.EqualError(t, c.Set("./does/not/exist"), "could not read CA bundle path: open ./does/not/exist: no such file or directory")
|
require.EqualError(t, f.Set("./does/not/exist"), "could not read CA bundle path: open ./does/not/exist: no such file or directory")
|
||||||
require.EqualError(t, c.Set(emptyFilePath), fmt.Sprintf("failed to load any CA certificates from %q", emptyFilePath))
|
require.EqualError(t, f.Set(emptyFilePath), fmt.Sprintf("failed to load any CA certificates from %q", emptyFilePath))
|
||||||
|
|
||||||
require.NoError(t, c.Set(testCAPath))
|
require.NoError(t, f.Set(testCAPath))
|
||||||
require.Equal(t, 1, bytes.Count(c, []byte("BEGIN CERTIFICATE")))
|
require.Equal(t, 1, bytes.Count(f, []byte("BEGIN CERTIFICATE")))
|
||||||
|
|
||||||
require.NoError(t, c.Set(testCAPath))
|
require.NoError(t, f.Set(testCAPath))
|
||||||
require.Equal(t, 2, bytes.Count(c, []byte("BEGIN CERTIFICATE")))
|
require.Equal(t, 2, bytes.Count(f, []byte("BEGIN CERTIFICATE")))
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ type getKubeconfigOIDCParams struct {
|
|||||||
skipBrowser bool
|
skipBrowser bool
|
||||||
sessionCachePath string
|
sessionCachePath string
|
||||||
debugSessionCache bool
|
debugSessionCache bool
|
||||||
caBundle caBundleVar
|
caBundle caBundleFlag
|
||||||
requestAudience string
|
requestAudience string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,9 +84,9 @@ type getKubeconfigConciergeParams struct {
|
|||||||
authenticatorName string
|
authenticatorName string
|
||||||
authenticatorType string
|
authenticatorType string
|
||||||
apiGroupSuffix string
|
apiGroupSuffix string
|
||||||
caBundle caBundleVar
|
caBundle caBundleFlag
|
||||||
endpoint string
|
endpoint string
|
||||||
mode conciergeMode
|
mode conciergeModeFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
type getKubeconfigParams struct {
|
type getKubeconfigParams struct {
|
||||||
@ -383,7 +383,7 @@ func discoverAuthenticatorParams(authenticator metav1.Object, flags *getKubeconf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConciergeFrontend(credentialIssuer *configv1alpha1.CredentialIssuer, mode conciergeMode) (*configv1alpha1.CredentialIssuerFrontend, error) {
|
func getConciergeFrontend(credentialIssuer *configv1alpha1.CredentialIssuer, mode conciergeModeFlag) (*configv1alpha1.CredentialIssuerFrontend, error) {
|
||||||
for _, strategy := range credentialIssuer.Status.Strategies {
|
for _, strategy := range credentialIssuer.Status.Strategies {
|
||||||
// Skip unhealthy strategies.
|
// Skip unhealthy strategies.
|
||||||
if strategy.Status != configv1alpha1.SuccessStrategyStatus {
|
if strategy.Status != configv1alpha1.SuccessStrategyStatus {
|
||||||
|
@ -71,7 +71,7 @@ type oidcLoginFlags struct {
|
|||||||
conciergeEndpoint string
|
conciergeEndpoint string
|
||||||
conciergeCABundle string
|
conciergeCABundle string
|
||||||
conciergeAPIGroupSuffix string
|
conciergeAPIGroupSuffix string
|
||||||
conciergeMode conciergeMode
|
conciergeMode conciergeModeFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
func oidcLoginCommand(deps oidcLoginCommandDeps) *cobra.Command {
|
func oidcLoginCommand(deps oidcLoginCommandDeps) *cobra.Command {
|
||||||
|
@ -47,7 +47,7 @@ type staticLoginParams struct {
|
|||||||
conciergeEndpoint string
|
conciergeEndpoint string
|
||||||
conciergeCABundle string
|
conciergeCABundle string
|
||||||
conciergeAPIGroupSuffix string
|
conciergeAPIGroupSuffix string
|
||||||
conciergeMode conciergeMode
|
conciergeMode conciergeModeFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
func staticLoginCommand(deps staticLoginDeps) *cobra.Command {
|
func staticLoginCommand(deps staticLoginDeps) *cobra.Command {
|
||||||
|
Loading…
Reference in New Issue
Block a user