From a7609974f5795a46ddc53cb92cf4571440cbe481 Mon Sep 17 00:00:00 2001 From: Mario Lubenka Date: Tue, 9 Mar 2021 18:43:06 +0100 Subject: [PATCH] feat: configure DNS modules --- ansible/inventory.go | 6 +++++ schemas/cli-config.schema.json | 6 +++++ .../examples/cli-config/valid/cli-withdns.yml | 6 +++++ stackhead/modules.go | 26 +++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 schemas/examples/cli-config/valid/cli-withdns.yml diff --git a/ansible/inventory.go b/ansible/inventory.go index 28f8adc..1f1d8f2 100644 --- a/ansible/inventory.go +++ b/ansible/inventory.go @@ -19,6 +19,7 @@ type Inventory struct { AnsibleConnection string `yaml:"ansible_connection"` AnsiblePythonInterpreter string `yaml:"ansible_python_interpreter"` StackHeadConfigFolder string `yaml:"stackhead__config_folder"` + StackHeadDns []string `yaml:"stackhead__dns"` StackHeadWebserver string `yaml:"stackhead__webserver"` StackHeadContainer string `yaml:"stackhead__container"` StackHeadPlugins []string `yaml:"stackhead__plugins"` @@ -60,6 +61,11 @@ func CreateInventoryFile(ipAddress string, projectDefinitionFile string) (string return "", err } + conf.All.Vars.StackHeadDns, err = stackhead.GetDnsModules() + if err != nil { + return "", err + } + conf.All.Vars.StackHeadPlugins, err = stackhead.GetPluginModules() if err != nil { return "", err diff --git a/schemas/cli-config.schema.json b/schemas/cli-config.schema.json index b6861fd..285312a 100644 --- a/schemas/cli-config.schema.json +++ b/schemas/cli-config.schema.json @@ -15,6 +15,12 @@ "container": { "type": "string" }, + "dns": { + "type": "array", + "items": { + "type": "string" + } + }, "plugins": { "type": "array", "items": { diff --git a/schemas/examples/cli-config/valid/cli-withdns.yml b/schemas/examples/cli-config/valid/cli-withdns.yml new file mode 100644 index 0000000..d942e71 --- /dev/null +++ b/schemas/examples/cli-config/valid/cli-withdns.yml @@ -0,0 +1,6 @@ +--- +modules: + webserver: nginx + container: docker + dns: + - cloudflare diff --git a/stackhead/modules.go b/stackhead/modules.go index c711600..10a403f 100644 --- a/stackhead/modules.go +++ b/stackhead/modules.go @@ -14,6 +14,8 @@ const ( ModuleContainer = "stackhead_container" // ModulePlugin is the string that identifies a package name as plugin package ModulePlugin = "stackhead_plugin" + // ModuleDns is the string that identifies a package name as dns package + ModuleDns = "stackhead_dns" ) // SplitModuleName splits a given module name into vendor, module type and base name @@ -64,6 +66,12 @@ func IsPluginModule(moduleName string) bool { return strings.HasPrefix(moduleName, ModulePlugin) } +// IsDnsModule checks if the given module is a dns module based on its name +func IsDnsModule(moduleName string) bool { + moduleName = RemoveVendor(moduleName) + return strings.HasPrefix(moduleName, ModuleDns) +} + // GetModuleType returns the module type for the given module according its name // Will return the values of ModulePlugin, ModuleContainer and ModuleWebserver constants. func GetModuleType(moduleName string) string { @@ -76,6 +84,9 @@ func GetModuleType(moduleName string) string { if IsWebserverModule(moduleName) { return ModuleWebserver } + if IsDnsModule(moduleName) { + return ModuleDns + } return "" } @@ -114,6 +125,21 @@ func GetContainerModule() (string, error) { return AutoCompleteModuleName(module, ModuleContainer) } +func GetDnsModules() ([]string, error) { + var plugins = viper.GetStringSlice("modules.dns") + var modules []string + if len(plugins) > 0 { + for _, plugin := range plugins { + moduleName, err := AutoCompleteModuleName(plugin, ModuleDns) + if err != nil { + return []string{}, err + } + modules = append(modules, moduleName) + } + } + return modules, nil +} + func GetPluginModules() ([]string, error) { var plugins = viper.GetStringSlice("modules.plugins") var modules []string