This commit is contained in:
Mikalai Radchuk 2022-12-14 14:20:34 +00:00 коммит произвёл Mikalai Radchuk
Родитель 2268445408
Коммит 6c066e5902
2 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -22,8 +22,8 @@ type servicePrincipalChecker interface {
type checker struct { type checker struct {
log *logrus.Entry log *logrus.Entry
credentialsGetter func(ctx context.Context) (*clusterauthorizer.Credentials, error) credentials func(ctx context.Context) (*clusterauthorizer.Credentials, error)
spValidatorConstructor func(azEnv *azureclient.AROEnvironment) (dynamic.ServicePrincipalValidator, error) newSPValidator func(azEnv *azureclient.AROEnvironment) (dynamic.ServicePrincipalValidator, error)
} }
func newServicePrincipalChecker(log *logrus.Entry, kubernetescli kubernetes.Interface) servicePrincipalChecker { func newServicePrincipalChecker(log *logrus.Entry, kubernetescli kubernetes.Interface) servicePrincipalChecker {
@ -32,10 +32,10 @@ func newServicePrincipalChecker(log *logrus.Entry, kubernetescli kubernetes.Inte
return &checker{ return &checker{
log: log, log: log,
credentialsGetter: func(ctx context.Context) (*clusterauthorizer.Credentials, error) { credentials: func(ctx context.Context) (*clusterauthorizer.Credentials, error) {
return clusterauthorizer.AzCredentials(ctx, kubernetescli) return clusterauthorizer.AzCredentials(ctx, kubernetescli)
}, },
spValidatorConstructor: func(azEnv *azureclient.AROEnvironment) (dynamic.ServicePrincipalValidator, error) { newSPValidator: func(azEnv *azureclient.AROEnvironment) (dynamic.ServicePrincipalValidator, error) {
return dynamic.NewServicePrincipalValidator(log, azEnv, dynamic.AuthorizerClusterServicePrincipal, tokenClient) return dynamic.NewServicePrincipalValidator(log, azEnv, dynamic.AuthorizerClusterServicePrincipal, tokenClient)
}, },
} }
@ -47,12 +47,12 @@ func (r *checker) Check(ctx context.Context, AZEnvironment string) error {
return err return err
} }
azCred, err := r.credentialsGetter(ctx) azCred, err := r.credentials(ctx)
if err != nil { if err != nil {
return err return err
} }
spDynamic, err := r.spValidatorConstructor(&azEnv) spDynamic, err := r.newSPValidator(&azEnv)
if err != nil { if err != nil {
return err return err
} }

Просмотреть файл

@ -74,13 +74,13 @@ func TestCheck(t *testing.T) {
sp := &checker{ sp := &checker{
log: log, log: log,
credentialsGetter: func(ctx context.Context) (*clusterauthorizer.Credentials, error) { credentials: func(ctx context.Context) (*clusterauthorizer.Credentials, error) {
if tt.credentialsExist { if tt.credentialsExist {
return mockCredentials, nil return mockCredentials, nil
} }
return nil, errors.New("fake credentials get error") return nil, errors.New("fake credentials get error")
}, },
spValidatorConstructor: func(azEnv *azureclient.AROEnvironment) (dynamic.ServicePrincipalValidator, error) { newSPValidator: func(azEnv *azureclient.AROEnvironment) (dynamic.ServicePrincipalValidator, error) {
if validatorMock != nil { if validatorMock != nil {
return validatorMock, nil return validatorMock, nil
} }