-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (69 loc) · 2.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
//"encoding/json"
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
. "github.com/hackwave/textui/color"
//"github.com/scrambleshell/wormholes/domains"
"github.com/scrambleshell/wormholes/domains/providers/namecheap"
)
type Config struct {
Debug bool `json:"debug" yaml:"debug"`
Namecheap namecheap.Config `json:"namecheap" yaml:"namecheap"`
}
type Application struct {
Name string
Version string
Description string
ConfigFilepath string
Config `json:"config" yaml:"config"`
}
func main() {
// TODO: Get i18n translations and strings loading from JSON or YAML early, so its not
// a difficult transition later.
app := Application{
Name: "Wormholes",
Version: "0.1.0",
Description: "Diverse end point management",
ConfigFilepath: "./config.yaml",
}
fmt.Println(Magenta(app.Name), Gray(":"), Blue(app.Description))
fmt.Println(Gray("=========================="))
fmt.Println(Gray("[Config]"), "loading YAML configuration file: ", app.ConfigFilepath)
yamlFile, err := ioutil.ReadFile(app.ConfigFilepath)
if err != nil {
fmt.Println(Red("[Fatal Error]"), err)
os.Exit(1)
}
err = yaml.Unmarshal(yamlFile, &app.Config)
if err != nil {
fmt.Println(Red("[Fatal Error]"), err)
os.Exit(1)
}
fmt.Println(Green("[Config]"), "Configuration successfully loaded.")
if app.Config.Namecheap.Username != "" &&
app.Config.Namecheap.API.Username != "" &&
app.Config.Namecheap.API.Token != "" {
fmt.Println(Gray("[Config]"), "Namecheap Domain Provider API configuration found, initializing an API connection to the domain provider...")
nc := namecheap.NamecheapProvider{
Config: namecheap.Config{
Debug: app.Config.Debug,
Username: app.Config.Namecheap.Username,
API: namecheap.API{
Username: app.Config.Namecheap.API.Username,
Token: app.Config.Namecheap.API.Token,
},
},
}
nc = nc.InitAPI()
fmt.Println("NC as string: ", nc)
fmt.Println(Green("[Domains:Namecheap:API]"), "API connection successfully Established.")
fmt.Println(Gray("[Domains:Namecheap:API"), "Query API for all registered domains with domain provider...")
domainNames := nc.RegisteredDomains()
fmt.Println("Domain name count returned from domains names is: ", len(domainNames))
} else {
fmt.Println(Red("[Fatal Error]"), Gray("No domain provider configuration found, modify the loaded configuration so it contains the API information needed to connect to the domain provider API."))
}
}