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

Add a web RPC to update the description of application #1842

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
60 changes: 42 additions & 18 deletions pkg/app/api/grpcapi/web_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,36 +430,60 @@ func (a *WebAPI) AddApplication(ctx context.Context, req *webservice.AddApplicat
}

func (a *WebAPI) UpdateApplication(ctx context.Context, req *webservice.UpdateApplicationRequest) (*webservice.UpdateApplicationResponse, error) {
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
a.logger.Error("failed to authenticate the current user", zap.Error(err))
updater := func(app *model.Application) error {
app.Name = req.Name
app.EnvId = req.EnvId
app.PipedId = req.PipedId
app.Kind = req.Kind
app.CloudProvider = req.CloudProvider
app.Description = req.Description
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateApplicationRequest.Description is added right before, isn't it? If so I think we can sneaky remove it. Or, still it's needed for somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Let me remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

return nil
}

if err := a.updateApplication(ctx, req.ApplicationId, req.PipedId, updater); err != nil {
return nil, err
}
return &webservice.UpdateApplicationResponse{}, nil
}

piped, err := getPiped(ctx, a.pipedStore, req.PipedId, a.logger)
if err != nil {
func (a *WebAPI) UpdateApplicationDescription(ctx context.Context, req *webservice.UpdateApplicationDescriptionRequest) (*webservice.UpdateApplicationDescriptionResponse, error) {
updater := func(app *model.Application) error {
app.Description = req.Description
return nil
}

if err := a.updateApplication(ctx, req.ApplicationId, "", updater); err != nil {
return nil, err
}
return &webservice.UpdateApplicationDescriptionResponse{}, nil
}

if piped.ProjectId != claims.Role.ProjectId {
return nil, status.Error(codes.InvalidArgument, "Requested piped does not belong to your project")
func (a *WebAPI) updateApplication(ctx context.Context, id, pipedID string, updater func(app *model.Application) error) error {
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
a.logger.Error("failed to authenticate the current user", zap.Error(err))
return err
}

err = a.applicationStore.UpdateApplication(ctx, req.ApplicationId, func(app *model.Application) error {
app.Name = req.Name
app.EnvId = req.EnvId
app.PipedId = req.PipedId
app.Kind = req.Kind
app.CloudProvider = req.CloudProvider
app.Description = req.Description
return nil
})
// Ensure that the specified piped is assignable for this application.
if pipedID != "" {
piped, err := getPiped(ctx, a.pipedStore, pipedID, a.logger)
if err != nil {
return err
}

if piped.ProjectId != claims.Role.ProjectId {
return status.Error(codes.InvalidArgument, "Requested piped does not belong to your project")
}
}

err = a.applicationStore.UpdateApplication(ctx, id, updater)
if err != nil {
a.logger.Error("failed to update application", zap.Error(err))
return nil, status.Error(codes.Internal, "Failed to update application")
return status.Error(codes.Internal, "Failed to update application")
}

return &webservice.UpdateApplicationResponse{}, nil
return nil
}

func (a *WebAPI) EnableApplication(ctx context.Context, req *webservice.EnableApplicationRequest) (*webservice.EnableApplicationResponse, error) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/app/api/service/webservice/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ service WebService {
// Application
rpc AddApplication(AddApplicationRequest) returns (AddApplicationResponse) {}
rpc UpdateApplication(UpdateApplicationRequest) returns (UpdateApplicationResponse) {}
rpc UpdateApplicationDescription(UpdateApplicationDescriptionRequest) returns (UpdateApplicationDescriptionResponse) {}
rpc EnableApplication(EnableApplicationRequest) returns (EnableApplicationResponse) {}
rpc DisableApplication(DisableApplicationRequest) returns (DisableApplicationResponse) {}
rpc DeleteApplication(DeleteApplicationRequest) returns (DeleteApplicationResponse) {}
Expand Down Expand Up @@ -207,6 +208,14 @@ message UpdateApplicationRequest {
message UpdateApplicationResponse {
}

message UpdateApplicationDescriptionRequest {
string application_id = 1 [(validate.rules).string.min_len = 1];
string description = 2;
}

message UpdateApplicationDescriptionResponse {
}

message EnableApplicationRequest {
string application_id = 1 [(validate.rules).string.min_len = 1];
}
Expand Down