12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package main
- import (
- "flag"
- "fmt"
- "log"
- "net/http"
- "os"
- "git.aetherial.dev/aeth/yosai/pkg/cloud/linode"
- "git.aetherial.dev/aeth/yosai/pkg/daemon"
- "git.aetherial.dev/aeth/yosai/pkg/keytags"
- "git.aetherial.dev/aeth/yosai/pkg/secrets/hashicorp"
- "git.aetherial.dev/aeth/yosai/pkg/semaphore"
- )
- const UNIX_DOMAIN_SOCK_PATH = "/tmp/yosaid.sock"
- func main() {
- config := flag.Bool("config-init", false, "pass this to create a blank config at ./.config.tmpl")
- envInit := flag.Bool("env-init", false, "pass this to create a blank env file at ./.env.tmpl")
- flag.Parse()
- if *config {
- err := daemon.BlankConfig("./.config.tmpl")
- if err != nil {
- log.Fatal("Couldnt create blank config: ", err)
- }
- fmt.Println("Blank config created at ./.config.tmpl")
- os.Exit(0)
- }
- if *envInit {
- err := daemon.BlankEnv("./.env.tmpl")
- if err != nil {
- log.Fatal("Couldnt create blank env file: ", err)
- }
- fmt.Println("Blank env file created at ./.env.tmpl")
- os.Exit(0)
- }
- err := daemon.LoadAndVerifyEnv("./.env", daemon.EnvironmentVariables)
- if err != nil {
- log.Fatal("Error loading env file: ", err)
- }
- conf := daemon.ReadConfig(daemon.DefaultConfigLoc)
- apikeyring := daemon.NewKeyRing(conf, keytags.ConstKeytag{})
- // Here we are demonstrating how you add a key to a keyring, in this
- // case it is the top level keyring.
- apikeyring.AddKey(keytags.HASHICORP_VAULT_KEYNAME, daemon.BearerAuth{
- Secret: os.Getenv(keytags.HASHICORP_VAULT_KEYNAME),
- })
- hashiConn := hashicorp.VaultConnection{
- VaultUrl: conf.Service.SecretsBackendUrl,
- HttpProto: "https",
- KeyRing: apikeyring,
- Client: &http.Client{},
- }
- apikeyring.Rungs = append(apikeyring.Rungs, hashiConn)
- err = apikeyring.Bootstrap()
- if err != nil {
- log.Fatal(err)
- }
- // creating the connection client with Hashicorp vault, and using the keyring we created above
- // as this clients keyring. This allows the API key we added earlier to be used when calling the API
- lnConn := linode.LinodeConnection{Client: &http.Client{}, Keyring: apikeyring, Config: conf, KeyTagger: keytags.ConstKeytag{}}
- semaphoreConn := semaphore.NewSemaphoreClient(conf.Service.AnsibleBackendUrl, "https", apikeyring, conf, keytags.ConstKeytag{})
- apikeyring.Rungs = append(apikeyring.Rungs, semaphoreConn)
- ctx := daemon.NewContext(UNIX_DOMAIN_SOCK_PATH, os.Stdout, apikeyring, conf)
- ctx.Register("keyring", apikeyring.KeyringRouter)
- ctx.Register("config", conf.ConfigRouter)
- ctx.Register("config-peer", conf.PeerRouter)
- ctx.Register("config-server", conf.ServerRouter)
- ctx.Register("cloud", lnConn.LinodeRouter)
- ctx.Register("ansible", semaphoreConn.BootstrapHandler)
- ctx.Register("ansible-hosts", semaphoreConn.HostHandler)
- ctx.Register("ansible-projects", semaphoreConn.ProjectHandler)
- ctx.Register("ansible-job", semaphoreConn.TaskHandler)
- ctx.Register("vault", hashiConn.VaultRouter)
- ctx.Register("daemon", ctx.DaemonRouter)
- ctx.ListenAndServe()
- }
|