Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
feat: configure DNS modules
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Mar 27, 2021
1 parent e0efecd commit a760997
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ansible/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions schemas/cli-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"container": {
"type": "string"
},
"dns": {
"type": "array",
"items": {
"type": "string"
}
},
"plugins": {
"type": "array",
"items": {
Expand Down
6 changes: 6 additions & 0 deletions schemas/examples/cli-config/valid/cli-withdns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
modules:
webserver: nginx
container: docker
dns:
- cloudflare
26 changes: 26 additions & 0 deletions stackhead/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -76,6 +84,9 @@ func GetModuleType(moduleName string) string {
if IsWebserverModule(moduleName) {
return ModuleWebserver
}
if IsDnsModule(moduleName) {
return ModuleDns
}
return ""
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a760997

Please sign in to comment.