Skip to content

Commit 82544cb

Browse files
committed
minor fixes
1 parent 08b88f2 commit 82544cb

6 files changed

Lines changed: 48 additions & 24 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ LOCAL_BUILD_ENABLED=False
1111

1212
# docker cmd below
1313
.PHONY: docker-build-doc riotpot-doc riotpot-up riotpot-prod-up riotpot-prod-down riotpot-build riotpot-build-plugins riotpot-builder riotpot-build-local set_container_build set_local_build go_install
14+
prepare_configurations:
15+
cp configs/samples/configuration-template.yml configs/samples/configuration.yml
1416
set_local_build:
1517
@sed -i -e 's/local_build_on: 0/local_build_on: 1/g' configs/samples/configuration.yml
1618
set_container_build:
@@ -48,6 +50,7 @@ riotpot-builder: \
4850
riotpot-build \
4951
riotpot-build-plugins
5052
riotpot-build-local: \
53+
prepare_configurations \
5154
set_local_build \
5255
riotpot-build \
5356
riotpot-build-local-plugin \

configs/samples/configuration-template.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ riotpot:
1313
# list of services desired to be loaded and run at start, and `emulators` with
1414
# the list of available services to the app.
1515
autod: false
16-
local_build_on: 1
17-
1816

1917
# The name of the services is the name of the folder in which the plugin
2018
# is stored, inside the `pkg/` folder.
@@ -67,6 +65,10 @@ riotpot:
6765

6866
# Fill the mode, low, high or hybrid, to be used in containerized mode only
6967
mode: low
68+
69+
# Fill the value manually if running the Riotpot dorectly from configuration files,
70+
# otherwise it will be updated automatically
71+
local_build_on: 0
7072
##################################################################################################
7173

7274
# The `databases` object contains a number of object defined database

configs/samples/configuration.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ riotpot:
1313
# list of services desired to be loaded and run at start, and `emulators` with
1414
# the list of available services to the app.
1515
autod: false
16-
local_build_on: 1
17-
1816

1917
# The name of the services is the name of the folder in which the plugin
2018
# is stored, inside the `pkg/` folder.
@@ -67,6 +65,10 @@ riotpot:
6765

6866
# Fill the mode, low, high or hybrid, to be used in containerized mode only
6967
mode: low
68+
69+
# Fill the value manually if running the Riotpot dorectly from configuration files,
70+
# otherwise it will be updated automatically
71+
local_build_on: 0
7072
##################################################################################################
7173

7274
# The `databases` object contains a number of object defined database

deployments/interactive_deployer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func main() {
3030
a.Greeting()
3131
a.Settings.Riotpot.Start = arrays.StringToArray(a.Settings.Riotpot.Boot_plugins)
3232

33-
a.RegisterPlugins()
33+
supported_plugins := arrays.StringToArray(a.Settings.Riotpot.Boot_plugins)
34+
fmt.Printf("[+] Plugins available to run ")
35+
fmt.Println(supported_plugins)
3436
a.DiscoverImages()
3537
a.DiscoverRunningMode()
3638
a.SetLoadedPlugins()
@@ -48,22 +50,22 @@ func main() {
4850
target_change = "s/boot_plugins: "+a.Settings.Riotpot.Boot_plugins+"/boot_plugins: "+strings.Join(plugins_selected, " ")+"/g"
4951
environ.ExecuteCmd("sed","-i", "-e", target_change, "../configs/samples/configuration.yml")
5052
} else if input_mode == "high" {
51-
fmt.Printf("\nDocker containers available to run ")
53+
fmt.Printf("\nDocker containers available to run are ")
5254
fmt.Println(sett.GetDockerImages())
5355
fmt.Printf("\n")
5456
images := a.GetContainersFromUser()
5557
target_change = "s/start_images: "+a.Settings.Riotpot.Start_images+"/start_images: "+strings.Join(images, " ")+"/g"
5658
environ.ExecuteCmd("sed","-i", "-e", target_change, "../configs/samples/configuration.yml")
5759
FillConfig(images, &a)
5860
} else if input_mode == "hybrid" {
59-
fmt.Printf("Plugins available to run %q\n", a.Settings.Riotpot.Start)
61+
fmt.Printf("Plugins available to run are %q\n", a.Settings.Riotpot.Start)
6062

6163
// user decided to provide plugins manually
6264
plugins_selected := a.GetPluginsFromUser()
6365
target_change = "s/boot_plugins: "+a.Settings.Riotpot.Boot_plugins+"/boot_plugins: "+strings.Join(plugins_selected, " ")+"/g"
6466
environ.ExecuteCmd("sed","-i", "-e", target_change, "../configs/samples/configuration.yml")
6567

66-
fmt.Printf("\nDocker containers available to run ")
68+
fmt.Printf("\nDocker containers available to run are")
6769
fmt.Println(sett.GetDockerImages())
6870
fmt.Printf("\n")
6971
images := a.GetContainersFromUser()

internal/configuration/autopilot.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (a *Autopilot) Start() {
5555

5656
// loads the services which are available for user to run
5757
a.SetLoadedPlugins()
58+
5859
a.plugins_to_run = a.Settings.Riotpot.Start
5960

6061
// check if the build is local or containerized
@@ -70,12 +71,11 @@ func (a *Autopilot) Start() {
7071
if running_mode_decision == "manual" { // User has decided to provide plugins to run in interactive/manual way
7172

7273
// user needs to choose which plugins to choose from this list
73-
fmt.Printf("Plugins available to run ")
74+
fmt.Printf("Plugins available to run are ")
7475
fmt.Println(a.loaded_plugins)
7576

7677
// user inputs the plugins to run
7778
a.plugins_to_run = a.GetPluginsFromUser()
78-
fmt.Println(a.plugins_to_run)
7979
} else {
8080
a.plugins_to_run = a.Settings.Riotpot.Start
8181
fmt.Printf("\nPlugins to run are ")
@@ -91,7 +91,7 @@ func (a *Autopilot) Start() {
9191
running_mode_decision := a.CheckRunningMode()
9292

9393
if running_mode_decision == "manual" {
94-
fmt.Printf("\nDocker containers available to run ")
94+
fmt.Printf("\nDocker containers available to run are ")
9595
fmt.Println(a.loaded_containers)
9696
fmt.Printf("\n")
9797

@@ -116,12 +116,12 @@ func (a *Autopilot) Start() {
116116
// Hybrid mode
117117
running_mode_decision := a.CheckRunningMode()
118118
if running_mode_decision == "manual" {
119-
fmt.Printf("\nPlugins available to run ")
119+
fmt.Printf("\nPlugins available to run are ")
120120
fmt.Println(a.loaded_plugins)
121121
fmt.Printf("\n")
122122
a.plugins_to_run = a.GetPluginsFromUser()
123123

124-
fmt.Printf("\nDocker containers available to run ")
124+
fmt.Printf("\nDocker containers available to run are ")
125125
fmt.Println(a.loaded_containers)
126126
fmt.Printf("\n")
127127
a.containers_to_run = a.GetContainersFromUser()
@@ -155,6 +155,8 @@ func (a *Autopilot) Start() {
155155
fmt.Printf("\nPlugins to run are ")
156156
fmt.Println(a.plugins_to_run)
157157

158+
a.plugins_to_run = arrays.StringToArray(strings.ToLower(arrays.ArrayToString(a.plugins_to_run)))
159+
158160
if !a.ValidatePlugin(a.plugins_to_run) {
159161
log.Fatalf("\nPlease check the config file, and try again\n")
160162
}
@@ -167,7 +169,7 @@ func (a *Autopilot) Start() {
167169
if !a.ValidateContainers(a.containers_to_run) {
168170
log.Fatalf("\nPlease check the config file, and try again\n")
169171
}
170-
172+
a.containers_to_run = arrays.StringToArray(strings.ToLower(arrays.ArrayToString(a.containers_to_run)))
171173
// glider forwards all the traffic on specific port to the respective service container
172174
a.DeployGlider()
173175

@@ -181,10 +183,14 @@ func (a *Autopilot) Start() {
181183
if !a.ValidatePlugin(a.plugins_to_run) {
182184
log.Fatalf("\nPlease check the config file, and try again\n")
183185
}
186+
a.plugins_to_run = arrays.StringToArray(strings.ToLower(arrays.ArrayToString(a.plugins_to_run)))
184187

185188
if !a.ValidateContainers(a.containers_to_run) {
186189
log.Fatalf("\nPlease check the config file, and try again\n")
187190
}
191+
192+
a.containers_to_run = arrays.StringToArray(strings.ToLower(arrays.ArrayToString(a.containers_to_run)))
193+
188194
a.DeployGlider()
189195
}
190196
}
@@ -251,7 +257,7 @@ func (a *Autopilot) RegisterPlugins() {
251257
func (a *Autopilot) DiscoverImages() {
252258
a.loaded_containers = a.Settings.GetDockerImages()
253259
fmt.Printf("[+] Found %d docker images \n", len(a.loaded_containers))
254-
fmt.Printf("[+] Allowed Docker images ")
260+
fmt.Printf("[+] Available Docker images are ")
255261
fmt.Println(a.loaded_containers)
256262
}
257263

@@ -364,12 +370,14 @@ func (a *Autopilot) CheckInteractionMode() (decision string) {
364370
// Validates if the plugins to run matches the available plugins
365371
// TODO: print all the invalid plugins not just the first one encountered
366372
func (a *Autopilot) ValidatePlugin(in_plugins []string) (validated bool){
367-
if arrays.HasDuplicateItems(in_plugins){
373+
if arrays.HaveDuplicateItems(in_plugins){
368374
fmt.Printf("\n[-] Entered plugins has duplicate entries, please enter again\n")
369375
return false
370376
}
377+
371378
for _, plugin := range in_plugins {
372-
validated := arrays.Contains(a.loaded_plugins, strings.Title(strings.ToLower(plugin)))
379+
validated = arrays.Contains(a.loaded_plugins, plugin)
380+
373381
if !validated {
374382
fmt.Printf("\n[-] Entered plugin \"%s\" doesn't exist, please enter plugins again... \n", plugin)
375383
return false
@@ -382,13 +390,13 @@ func (a *Autopilot) ValidatePlugin(in_plugins []string) (validated bool){
382390
// Validates if the containers to run matches the loaded containers
383391
// TODO: print all the invalid containers not just the first one encountered
384392
func (a *Autopilot) ValidateContainers(in_containers []string) (validated bool){
385-
if arrays.HasDuplicateItems(in_containers){
393+
if arrays.HaveDuplicateItems(in_containers){
386394
fmt.Printf("\n[-] Entered containers has duplicate entries, please enter again\n")
387395
return false
388396
}
389397

390398
for _, container := range in_containers {
391-
validated := arrays.Contains( a.loaded_containers, strings.ToLower(container))
399+
validated := arrays.Contains( a.loaded_containers, container)
392400
if !validated {
393401
fmt.Printf("\n[-] Entered container \"%s\" doesn't exist, please enter plugins again... \n", container)
394402
return false
@@ -407,7 +415,7 @@ func (a *Autopilot) GetPluginsFromUser() (plugins []string) {
407415
for {
408416
fmt.Print("Enter the plugins to run separated by space: ")
409417

410-
input := a.ReadInput()
418+
input := strings.ToLower(a.ReadInput())
411419
plugins = arrays.StringToArray(input)
412420

413421
validated := a.ValidatePlugin(plugins)
@@ -424,7 +432,7 @@ func (a *Autopilot) GetPluginsFromUser() (plugins []string) {
424432
func (a *Autopilot) GetContainersFromUser() (containers []string) {
425433
for {
426434
fmt.Print("Enter the containers to run separated by space: ")
427-
input := a.ReadInput()
435+
input := strings.ToLower(a.ReadInput())
428436
containers = arrays.StringToArray(input)
429437
validated := a.ValidateContainers(containers)
430438

@@ -439,7 +447,11 @@ func (a *Autopilot) GetContainersFromUser() (containers []string) {
439447

440448
// Gives which plugins user wants to load in RIoTPot
441449
func (a *Autopilot) SetLoadedPlugins() {
442-
a.loaded_plugins = a.services.GetServicesNames(a.services.GetServices())
450+
if a.Settings.Riotpot.Local_build_on == "1" {
451+
a.loaded_plugins = a.services.GetServicesNames(a.services.GetServices())
452+
} else {
453+
a.loaded_plugins = arrays.StringToArray(a.Settings.Riotpot.Boot_plugins)
454+
}
443455
}
444456

445457
// Validates if the given docker context exists and if it is set to default

tools/arrays/array.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77
func Contains(in []string, str string) bool {
88
for _, v := range in {
9-
if v == str {
9+
if strings.ToLower(v) == strings.ToLower(str) {
1010
return true
1111
}
1212
}
@@ -40,7 +40,7 @@ func AddSuffix(in string, suffix string) string {
4040
return (in+suffix)
4141
}
4242

43-
func HasDuplicateItems(array []string) bool {
43+
func HaveDuplicateItems(array []string) bool {
4444
array_map := make(map[string]bool)
4545

4646
for _, item := range array {
@@ -52,3 +52,6 @@ func HasDuplicateItems(array []string) bool {
5252
return false
5353
}
5454

55+
func ArrayToString(array []string) (string) {
56+
return strings.Join(array, " ")
57+
}

0 commit comments

Comments
 (0)