Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 44 additions & 0 deletions pkg/app/api/grpcapi/web_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,50 @@ func (a *WebAPI) AddApplication(ctx context.Context, req *webservice.AddApplicat
}, nil
}

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))
return nil, err
}

piped, err := getPiped(ctx, a.pipedStore, req.PipedId, a.logger)
if err != nil {
return nil, err
}

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

gitpath, err := makeGitPath(
req.GitPath.Repo.Id,
req.GitPath.Path,
req.GitPath.ConfigFilename,
piped,
a.logger,
)
if err != nil {
return nil, 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.GitPath = gitpath
app.Kind = req.Kind
app.CloudProvider = req.CloudProvider
return nil
})
if err != nil {
a.logger.Error("failed to update application", zap.Error(err))
return nil, status.Error(codes.Internal, "Failed to update application")
Copy link
Member

Choose a reason for hiding this comment

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

Not in the scope of this PR, but I found an issue around this error.
A validation check is done before putting into the database. So in some cases, this is not an Internal error.
https://github.com/pipe-cd/pipe/blob/master/pkg/datastore/deploymentstore.go#L136

Can you please raise an issue for this?

}

return &webservice.UpdateApplicationResponse{}, nil
}

func (a *WebAPI) EnableApplication(ctx context.Context, req *webservice.EnableApplicationRequest) (*webservice.EnableApplicationResponse, error) {
if err := a.updateApplicationEnable(ctx, req.ApplicationId, true); err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/api/service/webservice/service.pb.auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (a *authorizer) Authorize(method string, r model.Role) bool {
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/AddApplication":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/UpdateApplication":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/EnableApplication":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/DisableApplication":
Expand Down
14 changes: 14 additions & 0 deletions pkg/app/api/service/webservice/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ service WebService {

// Application
rpc AddApplication(AddApplicationRequest) returns (AddApplicationResponse) {}
rpc UpdateApplication(UpdateApplicationRequest) returns (UpdateApplicationResponse) {}
rpc EnableApplication(EnableApplicationRequest) returns (EnableApplicationResponse) {}
rpc DisableApplication(DisableApplicationRequest) returns (DisableApplicationResponse) {}
rpc ListApplications(ListApplicationsRequest) returns (ListApplicationsResponse) {}
Expand Down Expand Up @@ -179,6 +180,19 @@ message AddApplicationResponse {
string application_id = 1 [(validate.rules).string.min_len = 1];
}

message UpdateApplicationRequest {
string application_id = 1 [(validate.rules).string.min_len = 1];
string name = 2 [(validate.rules).string.min_len = 1];
string env_id = 3 [(validate.rules).string.min_len = 1];
string piped_id = 4 [(validate.rules).string.min_len = 1];
model.ApplicationGitPath git_path = 5 [(validate.rules).message.required = true];
model.ApplicationKind kind = 6 [(validate.rules).enum.defined_only = true];
string cloud_provider = 7 [(validate.rules).string.min_len = 1];
}

message UpdateApplicationResponse {
}

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