Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ABresting committed Aug 24, 2021
1 parent 08b88f2 commit 82544cb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ LOCAL_BUILD_ENABLED=False

# docker cmd below
.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
prepare_configurations:
cp configs/samples/configuration-template.yml configs/samples/configuration.yml
set_local_build:
@sed -i -e 's/local_build_on: 0/local_build_on: 1/g' configs/samples/configuration.yml
set_container_build:
Expand Down Expand Up @@ -48,6 +50,7 @@ riotpot-builder: \
riotpot-build \
riotpot-build-plugins
riotpot-build-local: \
prepare_configurations \
set_local_build \
riotpot-build \
riotpot-build-local-plugin \
Expand Down
6 changes: 4 additions & 2 deletions configs/samples/configuration-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ riotpot:
# list of services desired to be loaded and run at start, and `emulators` with
# the list of available services to the app.
autod: false
local_build_on: 1


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

# Fill the mode, low, high or hybrid, to be used in containerized mode only
mode: low

# Fill the value manually if running the Riotpot dorectly from configuration files,
# otherwise it will be updated automatically
local_build_on: 0
##################################################################################################

# The `databases` object contains a number of object defined database
Expand Down
6 changes: 4 additions & 2 deletions configs/samples/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ riotpot:
# list of services desired to be loaded and run at start, and `emulators` with
# the list of available services to the app.
autod: false
local_build_on: 1


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

# Fill the mode, low, high or hybrid, to be used in containerized mode only
mode: low

# Fill the value manually if running the Riotpot dorectly from configuration files,
# otherwise it will be updated automatically
local_build_on: 0
##################################################################################################

# The `databases` object contains a number of object defined database
Expand Down
10 changes: 6 additions & 4 deletions deployments/interactive_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func main() {
a.Greeting()
a.Settings.Riotpot.Start = arrays.StringToArray(a.Settings.Riotpot.Boot_plugins)

a.RegisterPlugins()
supported_plugins := arrays.StringToArray(a.Settings.Riotpot.Boot_plugins)
fmt.Printf("[+] Plugins available to run ")
fmt.Println(supported_plugins)
a.DiscoverImages()
a.DiscoverRunningMode()
a.SetLoadedPlugins()
Expand All @@ -48,22 +50,22 @@ func main() {
target_change = "s/boot_plugins: "+a.Settings.Riotpot.Boot_plugins+"/boot_plugins: "+strings.Join(plugins_selected, " ")+"/g"
environ.ExecuteCmd("sed","-i", "-e", target_change, "../configs/samples/configuration.yml")
} else if input_mode == "high" {
fmt.Printf("\nDocker containers available to run ")
fmt.Printf("\nDocker containers available to run are ")
fmt.Println(sett.GetDockerImages())
fmt.Printf("\n")
images := a.GetContainersFromUser()
target_change = "s/start_images: "+a.Settings.Riotpot.Start_images+"/start_images: "+strings.Join(images, " ")+"/g"
environ.ExecuteCmd("sed","-i", "-e", target_change, "../configs/samples/configuration.yml")
FillConfig(images, &a)
} else if input_mode == "hybrid" {
fmt.Printf("Plugins available to run %q\n", a.Settings.Riotpot.Start)
fmt.Printf("Plugins available to run are %q\n", a.Settings.Riotpot.Start)

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

fmt.Printf("\nDocker containers available to run ")
fmt.Printf("\nDocker containers available to run are")
fmt.Println(sett.GetDockerImages())
fmt.Printf("\n")
images := a.GetContainersFromUser()
Expand Down
40 changes: 26 additions & 14 deletions internal/configuration/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (a *Autopilot) Start() {

// loads the services which are available for user to run
a.SetLoadedPlugins()

a.plugins_to_run = a.Settings.Riotpot.Start

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

// user needs to choose which plugins to choose from this list
fmt.Printf("Plugins available to run ")
fmt.Printf("Plugins available to run are ")
fmt.Println(a.loaded_plugins)

// user inputs the plugins to run
a.plugins_to_run = a.GetPluginsFromUser()
fmt.Println(a.plugins_to_run)
} else {
a.plugins_to_run = a.Settings.Riotpot.Start
fmt.Printf("\nPlugins to run are ")
Expand All @@ -91,7 +91,7 @@ func (a *Autopilot) Start() {
running_mode_decision := a.CheckRunningMode()

if running_mode_decision == "manual" {
fmt.Printf("\nDocker containers available to run ")
fmt.Printf("\nDocker containers available to run are ")
fmt.Println(a.loaded_containers)
fmt.Printf("\n")

Expand All @@ -116,12 +116,12 @@ func (a *Autopilot) Start() {
// Hybrid mode
running_mode_decision := a.CheckRunningMode()
if running_mode_decision == "manual" {
fmt.Printf("\nPlugins available to run ")
fmt.Printf("\nPlugins available to run are ")
fmt.Println(a.loaded_plugins)
fmt.Printf("\n")
a.plugins_to_run = a.GetPluginsFromUser()

fmt.Printf("\nDocker containers available to run ")
fmt.Printf("\nDocker containers available to run are ")
fmt.Println(a.loaded_containers)
fmt.Printf("\n")
a.containers_to_run = a.GetContainersFromUser()
Expand Down Expand Up @@ -155,6 +155,8 @@ func (a *Autopilot) Start() {
fmt.Printf("\nPlugins to run are ")
fmt.Println(a.plugins_to_run)

a.plugins_to_run = arrays.StringToArray(strings.ToLower(arrays.ArrayToString(a.plugins_to_run)))

if !a.ValidatePlugin(a.plugins_to_run) {
log.Fatalf("\nPlease check the config file, and try again\n")
}
Expand All @@ -167,7 +169,7 @@ func (a *Autopilot) Start() {
if !a.ValidateContainers(a.containers_to_run) {
log.Fatalf("\nPlease check the config file, and try again\n")
}

a.containers_to_run = arrays.StringToArray(strings.ToLower(arrays.ArrayToString(a.containers_to_run)))
// glider forwards all the traffic on specific port to the respective service container
a.DeployGlider()

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

if !a.ValidateContainers(a.containers_to_run) {
log.Fatalf("\nPlease check the config file, and try again\n")
}

a.containers_to_run = arrays.StringToArray(strings.ToLower(arrays.ArrayToString(a.containers_to_run)))

a.DeployGlider()
}
}
Expand Down Expand Up @@ -251,7 +257,7 @@ func (a *Autopilot) RegisterPlugins() {
func (a *Autopilot) DiscoverImages() {
a.loaded_containers = a.Settings.GetDockerImages()
fmt.Printf("[+] Found %d docker images \n", len(a.loaded_containers))
fmt.Printf("[+] Allowed Docker images ")
fmt.Printf("[+] Available Docker images are ")
fmt.Println(a.loaded_containers)
}

Expand Down Expand Up @@ -364,12 +370,14 @@ func (a *Autopilot) CheckInteractionMode() (decision string) {
// Validates if the plugins to run matches the available plugins
// TODO: print all the invalid plugins not just the first one encountered
func (a *Autopilot) ValidatePlugin(in_plugins []string) (validated bool){
if arrays.HasDuplicateItems(in_plugins){
if arrays.HaveDuplicateItems(in_plugins){
fmt.Printf("\n[-] Entered plugins has duplicate entries, please enter again\n")
return false
}

for _, plugin := range in_plugins {
validated := arrays.Contains(a.loaded_plugins, strings.Title(strings.ToLower(plugin)))
validated = arrays.Contains(a.loaded_plugins, plugin)

if !validated {
fmt.Printf("\n[-] Entered plugin \"%s\" doesn't exist, please enter plugins again... \n", plugin)
return false
Expand All @@ -382,13 +390,13 @@ func (a *Autopilot) ValidatePlugin(in_plugins []string) (validated bool){
// Validates if the containers to run matches the loaded containers
// TODO: print all the invalid containers not just the first one encountered
func (a *Autopilot) ValidateContainers(in_containers []string) (validated bool){
if arrays.HasDuplicateItems(in_containers){
if arrays.HaveDuplicateItems(in_containers){
fmt.Printf("\n[-] Entered containers has duplicate entries, please enter again\n")
return false
}

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

input := a.ReadInput()
input := strings.ToLower(a.ReadInput())
plugins = arrays.StringToArray(input)

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

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

// Gives which plugins user wants to load in RIoTPot
func (a *Autopilot) SetLoadedPlugins() {
a.loaded_plugins = a.services.GetServicesNames(a.services.GetServices())
if a.Settings.Riotpot.Local_build_on == "1" {
a.loaded_plugins = a.services.GetServicesNames(a.services.GetServices())
} else {
a.loaded_plugins = arrays.StringToArray(a.Settings.Riotpot.Boot_plugins)
}
}

// Validates if the given docker context exists and if it is set to default
Expand Down
7 changes: 5 additions & 2 deletions tools/arrays/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)
func Contains(in []string, str string) bool {
for _, v := range in {
if v == str {
if strings.ToLower(v) == strings.ToLower(str) {
return true
}
}
Expand Down Expand Up @@ -40,7 +40,7 @@ func AddSuffix(in string, suffix string) string {
return (in+suffix)
}

func HasDuplicateItems(array []string) bool {
func HaveDuplicateItems(array []string) bool {
array_map := make(map[string]bool)

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

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

0 comments on commit 82544cb

Please sign in to comment.