Skip to content

Commit

Permalink
feat: read values of application
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-Haeberli committed Sep 5, 2023
1 parent 8f43076 commit cca3669
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 6 additions & 1 deletion momentum-core/models/keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ func ToValueWrapperFromNode(n *tree.Node, valType ValueType) (*ValueWrapper, err

func ToValueFromNode(n *tree.Node) (*Value, error) {

if n == nil {
return nil, errors.New("expected a tree node but was nil")
}

keyValue := new(Value)

keyValue.Id = n.Id
keyValue.Key = n.FullPath()
keyValue.Value = n.Value

parentStage := n
for !parentStage.IsStage() {

for !parentStage.IsStage() && parentStage.Parent != nil {
if parentStage.Kind == tree.File {
keyValue.ParentDeploymentId = parentStage.Id
}
Expand Down
15 changes: 10 additions & 5 deletions momentum-core/routers/value-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import (

const ROUTING_PATH_VALUE_BY_ID = VERSION + "/repository/:repositoryName/value/:valueId"
const ROUTING_PATH_VALUE = VERSION + "/value"
const ROUTING_PATH_VALUE_BY_APPLICATION = VERSION + "/:repositoryName/application/values/:applicationId"
const ROUTING_PATH_VALUE_BY_STAGE = VERSION + "/:repositoryName/stage/values/:stageId"
const ROUTING_PATH_VALUE_BY_DEPLOYMENT = VERSION + "/:repositoryName/deployment/values/:deploymentId"
const ROUTING_PATH_VALUE_BY_APPLICATION = VERSION + "/repository/:repositoryName/application/values/:applicationId"
const ROUTING_PATH_VALUE_BY_STAGE = VERSION + "/repository/:repositoryName/stage/values/:stageId"
const ROUTING_PATH_VALUE_BY_DEPLOYMENT = VERSION + "/repository/:repositoryName/deployment/values/:deploymentId"

type ValueRouter struct {
valueService *services.ValueService
}

func NewValueRouter(valueService *services.ValueService) *ValueRouter {
return new(ValueRouter)

vs := new(ValueRouter)

vs.valueService = valueService

return vs
}

func (vr *ValueRouter) RegisterValueRoutes(server *gin.Engine) {
Expand Down Expand Up @@ -79,7 +84,7 @@ func (vr *ValueRouter) valuesByApplication(c *gin.Context) {
repoName := c.Param("repositoryName")
applicationId := c.Param("applicationId")

result, err := vr.valueService.ValueById(repoName, applicationId, traceId)
result, err := vr.valueService.ValuesByApplication(repoName, applicationId, traceId)
if err != nil {
c.JSON(http.StatusNotFound, models.NewApiError(err, http.StatusNotFound, c, traceId))
config.LOGGER.LogError(err.Error(), err, traceId)
Expand Down
2 changes: 2 additions & 0 deletions momentum-core/services/value-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package services

import (
"errors"
"fmt"
"momentum-core/config"
"momentum-core/models"
"strings"
Expand Down Expand Up @@ -44,6 +45,7 @@ func (vs *ValueService) ValuesByApplication(repositoryName string, applicationId
wrappedValues := make([]*models.ValueWrapper, 0)
files := application.Files()
for _, f := range files {
fmt.Println("File:", f.NormalizedPath())
if strings.EqualFold(f.NormalizedPath(), KUSTOMIZATION_FILE_NAME) {
wrappedKustomization, err := models.ToValueWrapperFromNode(f, models.APPLICATION)
if err != nil {
Expand Down

0 comments on commit cca3669

Please sign in to comment.