cruise-automation / daytona

A Vault client, but for containers and servers.
Apache License 2.0
310 stars 33 forks source link

Daytona as a library: importable #52

Open afarbos opened 4 years ago

afarbos commented 4 years ago

Like cloudsql-proxy and many other go binaries, it usually possible to import them within your own go applications. This PR would allow a similar behavior with daytona too, see example below:

package main

import (
    "fmt"
    "log"
    "os"
    "strings"

    cfg "github.com/cruise-automation/daytona/pkg/config"
    "github.com/cruise-automation/daytona/pkg/daytona"
)

func main() {
    os.Setenv("VAULT_SECRETS_FOO_BAR", "secret/foo/bar/")
    config := cfg.DefaultConfig()
    config.AWSAuth = true
    config.SecretEnv = true
    config.VaultAuthRoleName = "awesome-app-vault-role-name"
    if err := daytona.Run(config); err != nil {
        log.Fatalln(err.Error())
    }

    fmt.Println("== env ==")
    for _, e := range os.Environ() {
        pair := strings.SplitN(e, "=", 2)
        fmt.Println(pair[0])
    }
}

A lot of changes are just moving code, there is not actually so much changes more than creating the daytona package.