Skip to content

Commit

Permalink
[OCTRL-209] Add cases for rest of conf commands on no-version
Browse files Browse the repository at this point in the history
  • Loading branch information
graduta authored and teo committed Mar 18, 2020
1 parent 4b8bced commit 630b8fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion coconut/cmd/configuration_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var configurationListCmd = &cobra.Command{
Aliases: []string{"l", "ls"},
Example: `coconut conf list
coconut conf list <component>
coconut conf list <component> -t <timestamp>`,
coconut conf list <component> -t`,
Short: "List all existing O² components in Consul",
Long: `The configuration list command requests all components
from O² Configuration as a list and displays it on the standard output`,
Expand Down
6 changes: 5 additions & 1 deletion coconut/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ func Show(cfg *configuration.ConsulSource, cmd *cobra.Command, args []string, o
return err, emptyData
}
}
key = componentcfg.ConfigComponentsPath + component + "/" + entry + "/" + timestamp
key = componentcfg.ConfigComponentsPath + component + "/" + entry
if timestamp != "0" {
//versioned entry
key += "/" + timestamp
}
cfgPayload, err = cfg.Get(key)
if err != nil {
return err, connectionError
Expand Down
9 changes: 8 additions & 1 deletion coconut/configuration/configurationutil.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* === This file is part of ALICE O² ===
*
* Copyright 2019 CERN and copyright holders of ALICE O².
* Copyright 2020 CERN and copyright holders of ALICE O².
* Author: George Raduta <george.raduta@cern.ch>
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -74,6 +74,10 @@ func getListOfComponentsAndOrWithTimestamps(keys []string, keyPrefix string, use
componentsFullName := strings.TrimPrefix(key, keyPrefix)
componentParts := strings.Split(componentsFullName, "/")
componentTimestamp := componentParts[len(componentParts) - 1]

if len(componentParts) == 1 {
componentTimestamp = "unversioned"
}
if useTimestamp {
componentsFullName = strings.TrimSuffix(componentsFullName, "/" +componentTimestamp)
} else {
Expand Down Expand Up @@ -110,6 +114,9 @@ func drawTableHistoryConfigs(headers []string, history []string, max int, o io.W
if err != nil {
prettyTimestamp = timestamp
}
if prettyTimestamp == "unversioned" {
prettyTimestamp = red(prettyTimestamp)
}
configName := red(component) + "/" + blue(entry) + "@" + timestamp
table.Append([]string{configName, prettyTimestamp})
}
Expand Down
6 changes: 5 additions & 1 deletion configuration/componentcfg/componentcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func GetComponentEntryTimestampFromConsul(key string)(string, string, string) {
key = strings.TrimPrefix(key, "/'")
key = strings.TrimSuffix(key, "/")
elements := strings.Split(key, "/")
return elements[0], elements[1], elements[2]
if len(elements) == 3 {
return elements[0], elements[1], elements[2]
} else {
return elements[0], elements[1], "unversioned"
}
}


Expand Down

0 comments on commit 630b8fa

Please sign in to comment.