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

Implement rpc interfaces that update the project data. #620

Merged
merged 3 commits into from
Aug 14, 2020
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
16 changes: 16 additions & 0 deletions pkg/app/api/api/fake_web_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,22 @@ func (a *FakeWebAPI) GetProject(ctx context.Context, req *webservice.GetProjectR
return nil, status.Error(codes.Unimplemented, "")
}

func (a *FakeWebAPI) UpdateProjectStaticAdmin(ctx context.Context, req *webservice.UpdateProjectStaticAdminRequest) (*webservice.UpdateProjectStaticAdminResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

func (a *FakeWebAPI) EnableStaticAdmin(ctx context.Context, req *webservice.EnableStaticAdminRequest) (*webservice.EnableStaticAdminResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

func (a *FakeWebAPI) DisableStaticAdmin(ctx context.Context, req *webservice.DisableStaticAdminRequest) (*webservice.DisableStaticAdminResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

func (a *FakeWebAPI) UpdateProjectSingleSignOn(ctx context.Context, req *webservice.UpdateProjectSingleSignOnRequest) (*webservice.UpdateProjectSingleSignOnResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

func (a *FakeWebAPI) GetMe(ctx context.Context, req *webservice.GetMeRequest) (*webservice.GetMeResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}
Expand Down
27 changes: 25 additions & 2 deletions pkg/app/api/api/web_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,11 @@ func (a *WebAPI) GetApplicationLiveState(ctx context.Context, req *webservice.Ge

// GetProject gets the specified porject without sensitive data.
func (a *WebAPI) GetProject(ctx context.Context, req *webservice.GetProjectRequest) (*webservice.GetProjectResponse, error) {
project, err := a.getProject(ctx, req.ProjectId)
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
return nil, err
}
project, err := a.getProject(ctx, claims.Role.ProjectId)
if err != nil {
return nil, err
}
Expand All @@ -763,13 +767,32 @@ func (a *WebAPI) getProject(ctx context.Context, projectID string) (*model.Proje
return project, nil
}

// UpdateProjectStaticAdmin updates the static admin user settings.
func (a *WebAPI) UpdateProjectStaticAdmin(ctx context.Context, req *webservice.UpdateProjectStaticAdminRequest) (*webservice.UpdateProjectStaticAdminResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

// EnableStaticAdmin enables static admin login.
func (a *WebAPI) EnableStaticAdmin(ctx context.Context, req *webservice.EnableStaticAdminRequest) (*webservice.EnableStaticAdminResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

// DisableStaticAdmin disables static admin login.
func (a *WebAPI) DisableStaticAdmin(ctx context.Context, req *webservice.DisableStaticAdminRequest) (*webservice.DisableStaticAdminResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

// UpdateProjectSingleSignOn updates the sso settings.
func (a *WebAPI) UpdateProjectSingleSignOn(ctx context.Context, req *webservice.UpdateProjectSingleSignOnRequest) (*webservice.UpdateProjectSingleSignOnResponse, error) {
return nil, status.Error(codes.Unimplemented, "")
}

// GetMe gets information about the current user.
func (a *WebAPI) GetMe(ctx context.Context, req *webservice.GetMeRequest) (*webservice.GetMeResponse, error) {
claims, err := rpcauth.ExtractClaims(ctx)
if err != nil {
return nil, err
}

return &webservice.GetMeResponse{
Subject: claims.Subject,
AvatarUrl: claims.AvatarURL,
Expand Down
8 changes: 8 additions & 0 deletions pkg/app/api/service/webservice/service.pb.auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func (a *authorizer) Authorize(method string, r model.Role) bool {
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/DisableApplication":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/UpdateProjectStaticAdmin":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/EnableStaticAdmin":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/DisableStaticAdmin":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/UpdateProjectSingleSignOn":
return isAdmin(r)
case "/pipe.api.service.webservice.WebService/ListEnvironments":
return isAdmin(r) || isEditor(r)
case "/pipe.api.service.webservice.WebService/ListPipeds":
Expand Down
32 changes: 31 additions & 1 deletion pkg/app/api/service/webservice/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ service WebService {

// Account
rpc GetProject(GetProjectRequest) returns (GetProjectResponse) {}
rpc UpdateProjectStaticAdmin(UpdateProjectStaticAdminRequest) returns (UpdateProjectStaticAdminResponse) {}
rpc EnableStaticAdmin(EnableStaticAdminRequest) returns (EnableStaticAdminResponse) {}
rpc DisableStaticAdmin(DisableStaticAdminRequest) returns (DisableStaticAdminResponse) {}
rpc UpdateProjectSingleSignOn(UpdateProjectSingleSignOnRequest) returns (UpdateProjectSingleSignOnResponse) {}
rpc GetMe(GetMeRequest) returns (GetMeResponse) {}

// Command
Expand Down Expand Up @@ -269,13 +273,39 @@ message GetApplicationLiveStateResponse {
}

message GetProjectRequest {
string project_id = 1 [(validate.rules).string.min_len = 1];
}

message GetProjectResponse {
model.Project project = 1;
}

message UpdateProjectStaticAdminRequest {
string username = 1 [(validate.rules).string.min_len = 1];
string password = 2 [(validate.rules).string.min_len = 1];
}

message UpdateProjectStaticAdminResponse {
}

message UpdateProjectSingleSignOnRequest {
model.ProjectSingleSignOn sso = 1 [(validate.rules).message.required = true];
}

message EnableStaticAdminRequest {
}

message EnableStaticAdminResponse {
}

message DisableStaticAdminRequest {
}

message DisableStaticAdminResponse {
}

message UpdateProjectSingleSignOnResponse {
}

message GetMeRequest {
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/datastore/projectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var projectFactory = func() interface{} {

type ProjectStore interface {
AddProject(ctx context.Context, proj *model.Project) error
UpdateProject(ctx context.Context, id string, updater func(project *model.Project) error) error
GetProject(ctx context.Context, id string) (*model.Project, error)
ListProjects(ctx context.Context, opts ListOptions) ([]model.Project, error)
}
Expand Down Expand Up @@ -61,6 +62,18 @@ func (s *projectStore) AddProject(ctx context.Context, proj *model.Project) erro
return s.ds.Create(ctx, projectModelKind, proj.Id, proj)
}

func (s *projectStore) UpdateProject(ctx context.Context, id string, updater func(project *model.Project) error) error {
now := s.nowFunc().Unix()
return s.ds.Update(ctx, projectModelKind, id, projectFactory, func(e interface{}) error {
p := e.(*model.Project)
if err := updater(p); err != nil {
return err
}
p.UpdatedAt = now
return p.Validate()
})
}

func (s *projectStore) GetProject(ctx context.Context, id string) (*model.Project, error) {
var entity model.Project
if err := s.ds.Get(ctx, projectModelKind, id, &entity); err != nil {
Expand Down