Skip to content

Commit

Permalink
Fixed service/project scoping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Saloň committed Dec 12, 2024
1 parent cbe07f2 commit 1d9f370
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
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

0 comments on commit 1d9f370

Please sign in to comment.