Use Name instead of ExternalServiceName

This commit is contained in:
gamab
2023-05-23 18:45:32 +02:00
parent 306025c308
commit 1cb3050e2b
3 changed files with 18 additions and 18 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ type KeyOption struct {
// ExternalServiceRegistration represents the registration form to save new OAuth2 client.
type ExternalServiceRegistration struct {
ExternalServiceName string `json:"name"`
Name string `json:"name"`
// Permissions are the permissions that the external service needs its associated service account to have.
Permissions []accesscontrol.Permission `json:"permissions,omitempty"`
// ImpersonatePermissions are the permissions that the external service needs when impersonating a user.
+5 -5
View File
@@ -183,24 +183,24 @@ func (s *OAuth2ServiceImpl) SaveExternalService(ctx context.Context, registratio
s.logger.Warn("RegisterExternalService called without registration")
return nil, nil
}
s.logger.Info("Registering external service", "external service name", registration.ExternalServiceName)
s.logger.Info("Registering external service", "external service name", registration.Name)
// Check if the client already exists in store
client, errFetchExtSvc := s.sqlstore.GetExternalServiceByName(ctx, registration.ExternalServiceName)
client, errFetchExtSvc := s.sqlstore.GetExternalServiceByName(ctx, registration.Name)
if errFetchExtSvc != nil {
var srcError errutil.Error
if errors.As(errFetchExtSvc, &srcError) {
if srcError.MessageID != oauthserver.ErrClientNotFoundMessageID {
s.logger.Error("Error fetching service", "external service", registration.ExternalServiceName, "error", errFetchExtSvc)
s.logger.Error("Error fetching service", "external service", registration.Name, "error", errFetchExtSvc)
return nil, errFetchExtSvc
}
}
}
// Otherwise, create a new client
if client == nil {
s.logger.Debug("External service does not yet exist", "external service name", registration.ExternalServiceName)
s.logger.Debug("External service does not yet exist", "external service name", registration.Name)
client = &oauthserver.Client{
Name: registration.ExternalServiceName,
Name: registration.Name,
ServiceAccountID: oauthserver.NoServiceAccountID,
Audiences: s.cfg.AppURL,
}
@@ -129,8 +129,8 @@ func TestOAuth2ServiceImpl_SaveExternalService(t *testing.T) {
env.OAuthStore.On("SaveExternalService", mock.Anything, mock.Anything).Return(nil)
},
cmd: &oauthserver.ExternalServiceRegistration{
ExternalServiceName: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
Name: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
},
mockChecks: func(t *testing.T, env *TestEnv) {
env.OAuthStore.AssertCalled(t, "GetExternalServiceByName", mock.Anything, mock.MatchedBy(func(name string) bool {
@@ -157,9 +157,9 @@ func TestOAuth2ServiceImpl_SaveExternalService(t *testing.T) {
env.AcStore.On("SaveExternalServiceRole", mock.Anything, mock.Anything).Return(nil)
},
cmd: &oauthserver.ExternalServiceRegistration{
ExternalServiceName: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
Permissions: []ac.Permission{{Action: "users:read", Scope: "users:*"}},
Name: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
Permissions: []ac.Permission{{Action: "users:read", Scope: "users:*"}},
},
mockChecks: func(t *testing.T, env *TestEnv) {
// Check that the client has a service account and the correct grant type
@@ -186,9 +186,9 @@ func TestOAuth2ServiceImpl_SaveExternalService(t *testing.T) {
env.AcStore.On("DeleteExternalServiceRole", mock.Anything, mock.Anything).Return(nil)
},
cmd: &oauthserver.ExternalServiceRegistration{
ExternalServiceName: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
Permissions: []ac.Permission{},
Name: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
Permissions: []ac.Permission{},
},
mockChecks: func(t *testing.T, env *TestEnv) {
// Check that the service has no service account anymore
@@ -217,9 +217,9 @@ func TestOAuth2ServiceImpl_SaveExternalService(t *testing.T) {
env.AcStore.On("SaveExternalServiceRole", mock.Anything, mock.Anything).Return(nil)
},
cmd: &oauthserver.ExternalServiceRegistration{
ExternalServiceName: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
Permissions: []ac.Permission{{Action: "dashboards:create", Scope: "folders:uid:general"}},
Name: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
Permissions: []ac.Permission{{Action: "dashboards:create", Scope: "folders:uid:general"}},
},
mockChecks: func(t *testing.T, env *TestEnv) {
env.AcStore.AssertCalled(t, "SaveExternalServiceRole", mock.Anything,
@@ -239,7 +239,7 @@ func TestOAuth2ServiceImpl_SaveExternalService(t *testing.T) {
env.OAuthStore.On("SaveExternalService", mock.Anything, mock.Anything).Return(nil)
},
cmd: &oauthserver.ExternalServiceRegistration{
ExternalServiceName: serviceName,
Name: serviceName,
Key: &oauthserver.KeyOption{Generate: true},
ImpersonatePermissions: []ac.Permission{{Action: "users:read", Scope: "global.users:self"}},
},