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

Fixed service/project scoping issues #200

Merged
merged 1 commit into from
Dec 12, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.0.32] - 2024-12-12

### Fixed
- issue with scoping where Project would not be loaded when `serviceId` flag was used

## [v1.0.27] - 2024-10-03

### Fixed
Expand Down
11 changes: 10 additions & 1 deletion src/cmd/scope/scopeProject.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func (p *project) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm
var project *entity.Project
var err error

// service scope is set - use project from it
if cmdData.Service != nil {
project, err := repository.GetProjectById(ctx, cmdData.RestApiClient, cmdData.Service.ProjectID)
if err == nil {
cmdData.Project = project
return nil
}
}

// project scope is set
if cmdData.CliStorage.Data().ScopeProjectId.Filled() {
projectId, _ := cmdData.CliStorage.Data().ScopeProjectId.Get()
Expand Down Expand Up @@ -68,7 +77,7 @@ func (p *project) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm
infoText = i18n.SelectedProject
}

// service id is passed as a flag
// project id is passed as a flag
if projectId := cmdData.Params.GetString(ProjectArgName); projectId != "" {
project, err = repository.GetProjectById(ctx, cmdData.RestApiClient, uuid.ProjectId(projectId))
if err != nil {
Expand Down
15 changes: 10 additions & 5 deletions src/cmd/scope/scopeService.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ func (s *service) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm
}
}

// now we have to load project, because we need projectId going forwards
if service == nil {
if serviceIdOrName, exists := cmdData.Args[ServiceArgName]; exists && service == nil {
// we have to load project, because we need projectId
if err := s.parent.LoadSelectedScope(ctx, cmd, cmdData); err != nil {
return err
}
}

if serviceIdOrName, exists := cmdData.Args[ServiceArgName]; exists && service == nil {
service, err = repository.GetServiceByIdOrName(ctx, cmdData.RestApiClient, cmdData.Project.ID, serviceIdOrName[0])
if err != nil {
return err
Expand All @@ -77,5 +74,13 @@ func (s *service) LoadSelectedScope(ctx context.Context, cmd *cmdBuilder.Cmd, cm

cmdData.Service = service
cmdData.UxBlocks.PrintInfo(styles.InfoWithValueLine(i18n.T(infoText), cmdData.Service.Name.String()))

// Load parent scope from selected service if it wasn't loaded already above
if cmdData.Project == nil {
if err := s.parent.LoadSelectedScope(ctx, cmd, cmdData); err != nil {
return err
}
}

return nil
}
2 changes: 2 additions & 0 deletions src/entity/repository/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func GetNonSystemServicesByProject(
func serviceFromEsSearch(esServiceStack output.EsServiceStack) entity.Service {
return entity.Service{
ID: esServiceStack.Id,
ProjectID: esServiceStack.ProjectId,
ClientId: esServiceStack.ClientId,
Name: esServiceStack.Name,
Status: esServiceStack.Status,
Expand All @@ -142,6 +143,7 @@ func serviceFromEsSearch(esServiceStack output.EsServiceStack) entity.Service {
func serviceFromApiOutput(service output.ServiceStack) entity.Service {
return entity.Service{
ID: service.Id,
ProjectID: service.ProjectId,
ClientId: service.Project.ClientId,
Name: service.Name,
Status: service.Status,
Expand Down
1 change: 1 addition & 0 deletions src/entity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

type Service struct {
ID uuid.ServiceStackId
ProjectID uuid.ProjectId
ClientId uuid.ClientId
Name types.String
Status enum.ServiceStackStatusEnum
Expand Down
Loading