feat: creation of service account (#44913)

* feat: creation of service account

* added back button for the details page

* refactor: remove unused file, renamed fields

* oppps
This commit is contained in:
Eric Leijonmarck
2022-02-07 14:12:39 +01:00
committed by GitHub
parent a8e9369084
commit 334c29eebf
8 changed files with 101 additions and 15 deletions

View File

@@ -71,8 +71,11 @@ func (api *ServiceAccountsAPI) CreateServiceAccount(c *models.ReqContext) respon
case err != nil:
return response.Error(http.StatusInternalServerError, "Failed to create service account", err)
}
return response.JSON(http.StatusCreated, user)
result := models.UserIdDTO{
Message: "Service account created",
Id: user.Id,
}
return response.JSON(http.StatusCreated, result)
}
func (api *ServiceAccountsAPI) DeleteServiceAccount(ctx *models.ReqContext) response.Response {

View File

@@ -27,9 +27,10 @@ func NewServiceAccountsStore(store *sqlstore.SQLStore) *ServiceAccountsStoreImpl
func (s *ServiceAccountsStoreImpl) CreateServiceAccount(ctx context.Context, sa *serviceaccounts.CreateServiceaccountForm) (user *models.User, err error) {
// create a new service account - "user" with empty permissions
generatedLogin := "Service-Account-" + uuid.New().String()
cmd := models.CreateUserCommand{
Login: "Service-Account-" + uuid.New().String(),
Name: sa.Name + "-Service-Account-" + uuid.New().String(),
Login: generatedLogin,
Name: sa.Name,
OrgId: sa.OrgID,
IsServiceAccount: true,
}

View File

@@ -19,8 +19,6 @@ type ServiceAccount struct {
}
type CreateServiceaccountForm struct {
OrgID int64 `json:"-"`
Name string `json:"name" binding:"Required"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
OrgID int64 `json:"-"`
Name string `json:"name" binding:"Required"`
}