aws-oidc/aws-oidc.go
Jeremy Stott f8a7c0986f Added TOML cofiguration file support
* configuration file located at ~/.aws-oidc/config
 * sets default parameters, but can still be overridden on the cli
 * named AuthProviders are accessible via the auth [name] command
Renamed exec command to auth. Upgraded auth command to take defaults from the config file.
Added new command exec, that puts the temporary credentials as environment variables in the specified command
Automatically append URL to end of auth command if not specified
2019-04-24 15:34:01 +12:00

55 lines
1.1 KiB
Go

package main
import (
"io"
"log"
"os"
"github.com/BurntSushi/toml"
"github.com/stoggi/aws-oidc/cli"
"gopkg.in/alecthomas/kingpin.v2"
)
// Version is provided at compile time
var Version = "dev"
func main() {
run(os.Args[1:], os.Exit)
}
func run(args []string, exit func(int)) {
f, err := os.OpenFile(GetLogPath(), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
wrt := io.MultiWriter(os.Stderr, f)
log.SetOutput(wrt)
// Default configuration, values are overridden by command line options.
config := cli.GlobalConfig{}
if _, err := toml.DecodeFile(GetConfigFilePath(), &config); err != nil {
if !os.IsNotExist(err) {
log.Printf("Error decoding TOML: %v\n", err)
}
}
app := kingpin.New(
"aws-oidc",
"Assume roles in AWS using an OIDC identity provider",
)
app.Version(Version)
app.Terminate(exit)
app.UsageWriter(os.Stdout)
app.ErrorWriter(wrt)
cli.ConfigureGlobal(app, &config)
cli.ConfigureAuth(app, &config)
cli.ConfigureExec(app, &config)
cli.ConfigureList(app, &config)
kingpin.MustParse(app.Parse(args))
}