Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the commander by the logged in username #541

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions pkg/app/api/api/web_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (a *WebAPI) AddEnvironment(ctx context.Context, req *webservice.AddEnvironm
if err != nil {
return nil, err
}

env := model.Environment{
Id: uuid.New().String(),
Name: req.Name,
Expand All @@ -98,6 +99,7 @@ func (a *WebAPI) ListEnvironments(ctx context.Context, req *webservice.ListEnvir
if err != nil {
return nil, err
}

opts := datastore.ListOptions{
Filters: []datastore.ListFilter{
{
Expand Down Expand Up @@ -328,6 +330,7 @@ func (a *WebAPI) updateApplicationEnable(ctx context.Context, appID string, enab
if err != nil {
return err
}

app, err := a.getApplication(ctx, appID)
if err != nil {
return err
Expand Down Expand Up @@ -427,15 +430,16 @@ func (a *WebAPI) ListApplications(ctx context.Context, req *webservice.ListAppli
}

func (a *WebAPI) SyncApplication(ctx context.Context, req *webservice.SyncApplicationRequest) (*webservice.SyncApplicationResponse, error) {
app, err := a.getApplication(ctx, req.ApplicationId)
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
return nil, err
}

claims, err := rpcauth.ExtractClaims(ctx)
app, err := a.getApplication(ctx, req.ApplicationId)
if err != nil {
return nil, err
}

if app.ProjectId != claims.Role.ProjectId {
return nil, status.Error(codes.PermissionDenied, "The current project does not have requested application")
}
Expand All @@ -446,7 +450,7 @@ func (a *WebAPI) SyncApplication(ctx context.Context, req *webservice.SyncApplic
PipedId: app.PipedId,
ApplicationId: app.Id,
Type: model.Command_SYNC_APPLICATION,
Commander: "anonymous", // TODO: Getting value from login user.
Commander: claims.Subject,
SyncApplication: &model.Command_SyncApplication{
ApplicationId: req.ApplicationId,
},
Expand Down Expand Up @@ -494,6 +498,7 @@ func (a *WebAPI) ListDeployments(ctx context.Context, req *webservice.ListDeploy
if err != nil {
return nil, err
}

// TODO: Support pagination for Deployment list
orders := []datastore.Order{
{
Expand Down Expand Up @@ -593,6 +598,11 @@ func (a *WebAPI) GetStageLog(ctx context.Context, req *webservice.GetStageLogReq
}

func (a *WebAPI) CancelDeployment(ctx context.Context, req *webservice.CancelDeploymentRequest) (*webservice.CancelDeploymentResponse, error) {
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
return nil, err
}

deployment, err := a.getDeployment(ctx, req.DeploymentId)
if err != nil {
return nil, err
Expand All @@ -608,7 +618,7 @@ func (a *WebAPI) CancelDeployment(ctx context.Context, req *webservice.CancelDep
ApplicationId: deployment.ApplicationId,
DeploymentId: req.DeploymentId,
Type: model.Command_CANCEL_DEPLOYMENT,
Commander: "anonymous",
Commander: claims.Subject,
CancelDeployment: &model.Command_CancelDeployment{
DeploymentId: req.DeploymentId,
WithoutRollback: req.WithoutRollback,
Expand All @@ -623,6 +633,11 @@ func (a *WebAPI) CancelDeployment(ctx context.Context, req *webservice.CancelDep
}

func (a *WebAPI) ApproveStage(ctx context.Context, req *webservice.ApproveStageRequest) (*webservice.ApproveStageResponse, error) {
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
return nil, err
}

deployment, err := a.getDeployment(ctx, req.DeploymentId)
if err != nil {
return nil, err
Expand All @@ -643,7 +658,7 @@ func (a *WebAPI) ApproveStage(ctx context.Context, req *webservice.ApproveStageR
DeploymentId: req.DeploymentId,
StageId: req.StageId,
Type: model.Command_APPROVE_STAGE,
Commander: "anonymous",
Commander: claims.Subject,
ApproveStage: &model.Command_ApproveStage{
DeploymentId: req.DeploymentId,
StageId: req.StageId,
Expand Down Expand Up @@ -676,8 +691,7 @@ func (a *WebAPI) GetProject(ctx context.Context, req *webservice.GetProjectReque
func (a *WebAPI) GetMe(ctx context.Context, req *webservice.GetMeRequest) (*webservice.GetMeResponse, error) {
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
a.logger.Error("detected a request that passed JWT interceptor but not including a claims", zap.Error(err))
return nil, status.Error(codes.Internal, "internal error")
return nil, err
}

return &webservice.GetMeResponse{
Expand Down