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

Commit a760997

Browse files
committed
feat: configure DNS modules
1 parent e0efecd commit a760997

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

ansible/inventory.go

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Inventory struct {
1919
AnsibleConnection string `yaml:"ansible_connection"`
2020
AnsiblePythonInterpreter string `yaml:"ansible_python_interpreter"`
2121
StackHeadConfigFolder string `yaml:"stackhead__config_folder"`
22+
StackHeadDns []string `yaml:"stackhead__dns"`
2223
StackHeadWebserver string `yaml:"stackhead__webserver"`
2324
StackHeadContainer string `yaml:"stackhead__container"`
2425
StackHeadPlugins []string `yaml:"stackhead__plugins"`
@@ -60,6 +61,11 @@ func CreateInventoryFile(ipAddress string, projectDefinitionFile string) (string
6061
return "", err
6162
}
6263

64+
conf.All.Vars.StackHeadDns, err = stackhead.GetDnsModules()
65+
if err != nil {
66+
return "", err
67+
}
68+
6369
conf.All.Vars.StackHeadPlugins, err = stackhead.GetPluginModules()
6470
if err != nil {
6571
return "", err

schemas/cli-config.schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
"container": {
1616
"type": "string"
1717
},
18+
"dns": {
19+
"type": "array",
20+
"items": {
21+
"type": "string"
22+
}
23+
},
1824
"plugins": {
1925
"type": "array",
2026
"items": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
modules:
3+
webserver: nginx
4+
container: docker
5+
dns:
6+
- cloudflare

stackhead/modules.go

+26
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const (
1414
ModuleContainer = "stackhead_container"
1515
// ModulePlugin is the string that identifies a package name as plugin package
1616
ModulePlugin = "stackhead_plugin"
17+
// ModuleDns is the string that identifies a package name as dns package
18+
ModuleDns = "stackhead_dns"
1719
)
1820

1921
// SplitModuleName splits a given module name into vendor, module type and base name
@@ -64,6 +66,12 @@ func IsPluginModule(moduleName string) bool {
6466
return strings.HasPrefix(moduleName, ModulePlugin)
6567
}
6668

69+
// IsDnsModule checks if the given module is a dns module based on its name
70+
func IsDnsModule(moduleName string) bool {
71+
moduleName = RemoveVendor(moduleName)
72+
return strings.HasPrefix(moduleName, ModuleDns)
73+
}
74+
6775
// GetModuleType returns the module type for the given module according its name
6876
// Will return the values of ModulePlugin, ModuleContainer and ModuleWebserver constants.
6977
func GetModuleType(moduleName string) string {
@@ -76,6 +84,9 @@ func GetModuleType(moduleName string) string {
7684
if IsWebserverModule(moduleName) {
7785
return ModuleWebserver
7886
}
87+
if IsDnsModule(moduleName) {
88+
return ModuleDns
89+
}
7990
return ""
8091
}
8192

@@ -114,6 +125,21 @@ func GetContainerModule() (string, error) {
114125
return AutoCompleteModuleName(module, ModuleContainer)
115126
}
116127

128+
func GetDnsModules() ([]string, error) {
129+
var plugins = viper.GetStringSlice("modules.dns")
130+
var modules []string
131+
if len(plugins) > 0 {
132+
for _, plugin := range plugins {
133+
moduleName, err := AutoCompleteModuleName(plugin, ModuleDns)
134+
if err != nil {
135+
return []string{}, err
136+
}
137+
modules = append(modules, moduleName)
138+
}
139+
}
140+
return modules, nil
141+
}
142+
117143
func GetPluginModules() ([]string, error) {
118144
var plugins = viper.GetStringSlice("modules.plugins")
119145
var modules []string

0 commit comments

Comments
 (0)