-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_account.go
37 lines (29 loc) · 1.09 KB
/
service_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package handle
import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/MicahParks/magiclinksdev/model"
"github.com/MicahParks/magiclinksdev/network/middleware/ctxkey"
)
// HandleServiceAccountCreate handles the service account creation endpoint.
func (s *Server) HandleServiceAccountCreate(ctx context.Context, args model.ValidServiceAccountCreateRequest) (model.ServiceAccountCreateResponse, error) {
saArgs := args.CreateServiceAccountArgs
createdSA, err := s.Store.CreateSA(ctx, saArgs)
if err != nil {
return model.ServiceAccountCreateResponse{}, fmt.Errorf("failed to create service account: %w", err)
}
serviceAccount, err := s.Store.ReadSA(ctx, createdSA.UUID)
if err != nil {
return model.ServiceAccountCreateResponse{}, fmt.Errorf("failed to get service account as marshallable data structure: %w", err)
}
resp := model.ServiceAccountCreateResponse{
CreateServiceAccountResults: model.ServiceAccountCreateResults{
ServiceAccount: serviceAccount,
},
RequestMetadata: model.RequestMetadata{
UUID: ctx.Value(ctxkey.RequestUUID).(uuid.UUID),
},
}
return resp, nil
}