mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-16 13:38:36 +00:00

# Which Problems Are Solved This PR *partially* addresses #9450 . Specifically, it implements the resource based API for app keys. This PR, together with https://github.com/zitadel/zitadel/pull/10077 completes #9450 . # How the Problems Are Solved - Implementation of the following endpoints: `CreateApplicationKey`, `DeleteApplicationKey`, `GetApplicationKey`, `ListApplicationKeys` - `ListApplicationKeys` can filter by project, app or organization ID. Sorting is also possible according to some criteria. - All endpoints use permissions V2 # TODO - [x] Deprecate old endpoints # Additional Context Closes #9450
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/app/v2beta/convert"
|
|
app "github.com/zitadel/zitadel/pkg/grpc/app/v2beta"
|
|
)
|
|
|
|
func (s *Server) CreateApplicationKey(ctx context.Context, req *app.CreateApplicationKeyRequest) (*app.CreateApplicationKeyResponse, error) {
|
|
domainReq := convert.CreateAPIClientKeyRequestToDomain(req)
|
|
|
|
appKey, err := s.command.AddApplicationKey(ctx, domainReq, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
keyDetails, err := appKey.Detail()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &app.CreateApplicationKeyResponse{
|
|
Id: appKey.KeyID,
|
|
CreationDate: timestamppb.New(appKey.ChangeDate),
|
|
KeyDetails: keyDetails,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) DeleteApplicationKey(ctx context.Context, req *app.DeleteApplicationKeyRequest) (*app.DeleteApplicationKeyResponse, error) {
|
|
deletionDetails, err := s.command.RemoveApplicationKey(ctx,
|
|
strings.TrimSpace(req.GetProjectId()),
|
|
strings.TrimSpace(req.GetApplicationId()),
|
|
strings.TrimSpace(req.GetId()),
|
|
strings.TrimSpace(req.GetOrganizationId()),
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &app.DeleteApplicationKeyResponse{
|
|
DeletionDate: timestamppb.New(deletionDetails.EventDate),
|
|
}, nil
|
|
}
|