diff --git a/pkg/services/serviceaccounts/api/api.go b/pkg/services/serviceaccounts/api/api.go index d4da2814925..5acc84f090c 100644 --- a/pkg/services/serviceaccounts/api/api.go +++ b/pkg/services/serviceaccounts/api/api.go @@ -93,7 +93,7 @@ func (api *ServiceAccountsAPI) CreateServiceAccount(c *models.ReqContext) respon serviceAccount, err := api.store.CreateServiceAccount(c.Req.Context(), c.OrgId, cmd.Name) switch { case errors.Is(err, &database.ErrSAInvalidName{}): - return response.Error(http.StatusBadRequest, "Invalid service account name", err) + return response.Error(http.StatusBadRequest, "Failed due to %s", err) case err != nil: return response.Error(http.StatusInternalServerError, "Failed to create service account", err) } diff --git a/pkg/services/serviceaccounts/database/errors.go b/pkg/services/serviceaccounts/database/errors.go index 3cd555480a6..8001b2bd889 100644 --- a/pkg/services/serviceaccounts/database/errors.go +++ b/pkg/services/serviceaccounts/database/errors.go @@ -17,14 +17,14 @@ func (e *ErrSAInvalidName) Unwrap() error { return models.ErrUserAlreadyExists } -type ErrMisingSAToken struct { +type ErrMissingSAToken struct { } -func (e *ErrMisingSAToken) Error() string { +func (e *ErrMissingSAToken) Error() string { return "service account token not found" } -func (e *ErrMisingSAToken) Unwrap() error { +func (e *ErrMissingSAToken) Unwrap() error { return models.ErrApiKeyNotFound } @@ -44,7 +44,7 @@ type ErrDuplicateSAToken struct { } func (e *ErrDuplicateSAToken) Error() string { - return fmt.Sprintf("service account token %s already exists", e.name) + return fmt.Sprintf("service account token %s already exists in the organization", e.name) } func (e *ErrDuplicateSAToken) Unwrap() error { diff --git a/pkg/services/serviceaccounts/database/token_store.go b/pkg/services/serviceaccounts/database/token_store.go index 320bc2f1ed5..4a4b04f9585 100644 --- a/pkg/services/serviceaccounts/database/token_store.go +++ b/pkg/services/serviceaccounts/database/token_store.go @@ -57,7 +57,7 @@ func (s *ServiceAccountsStoreImpl) DeleteServiceAccountToken(ctx context.Context if err != nil { return err } else if n == 0 { - return &ErrMisingSAToken{} + return &ErrMissingSAToken{} } return nil }) diff --git a/public/app/features/serviceaccounts/ServiceAccountPage.tsx b/public/app/features/serviceaccounts/ServiceAccountPage.tsx index 66e59e0cc83..061e7a0d309 100644 --- a/public/app/features/serviceaccounts/ServiceAccountPage.tsx +++ b/public/app/features/serviceaccounts/ServiceAccountPage.tsx @@ -3,7 +3,7 @@ import { connect, ConnectedProps } from 'react-redux'; import { getNavModel } from 'app/core/selectors/navModel'; import Page from 'app/core/components/Page/Page'; import { ServiceAccountProfile } from './ServiceAccountProfile'; -import { StoreState, ServiceAccountDTO, ApiKey, Role } from 'app/types'; +import { StoreState, ServiceAccountDTO, ApiKey, Role, AccessControlAction } from 'app/types'; import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; import { deleteServiceAccountToken, @@ -114,12 +114,24 @@ const ServiceAccountPageUnconnected = ({
|
- {this.state.editing ? (
+ {!this.props.disabled && this.state.editing ? (
{this.props.onChange && (
|
{formatDate(timeZone, key.created)} | -
- |
+ {contextSrv.hasPermission(AccessControlAction.ServiceAccountsDelete) && (
+
+ |
+ )}
);
})}
@@ -82,7 +86,7 @@ const TokenExpiration = ({ timeZone, token }: TokenExpirationProps) => {
Expired
- + |
+ {displayRolePicker && (
|
- )
+ )}
+
) : (
|