X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c0f9c128aabb366435d751a3ea1a63b76c177f5b..99ca2640c855e88c7b08c3509b21be9e160ccac8:/sdk/go/arvadosclient/arvadosclient.go diff --git a/sdk/go/arvadosclient/arvadosclient.go b/sdk/go/arvadosclient/arvadosclient.go index 1cce0a7fc9..cc99efdcf4 100644 --- a/sdk/go/arvadosclient/arvadosclient.go +++ b/sdk/go/arvadosclient/arvadosclient.go @@ -78,21 +78,42 @@ type ArvadosClient struct { DiscoveryDoc Dict } -// Create a new ArvadosClient, initialized with standard Arvados environment -// variables ARVADOS_API_HOST, ARVADOS_API_TOKEN, and (optionally) -// ARVADOS_API_HOST_INSECURE. +// APIConfig struct consists of: +// APIToken string +// APIHost string +// APIHostInsecure bool +// ExternalClient bool +type APIConfig struct { + APIToken string + APIHost string + APIHostInsecure bool + ExternalClient bool +} + +// Create a new ArvadosClient, initialized with standard Arvados environment variables +// ARVADOS_API_HOST, ARVADOS_API_TOKEN, ARVADOS_API_HOST_INSECURE, ARVADOS_EXTERNAL_CLIENT. func MakeArvadosClient() (ac ArvadosClient, err error) { + var config APIConfig + config.APIToken = os.Getenv("ARVADOS_API_TOKEN") + config.APIHost = os.Getenv("ARVADOS_API_HOST") + var matchTrue = regexp.MustCompile("^(?i:1|yes|true)$") - insecure := matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) - external := matchTrue.MatchString(os.Getenv("ARVADOS_EXTERNAL_CLIENT")) + config.APIHostInsecure = matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) + config.ExternalClient = matchTrue.MatchString(os.Getenv("ARVADOS_EXTERNAL_CLIENT")) + + return MakeArvadosClientWithConfig(config) +} + +// Create a new ArvadosClient, using the given input parameters. +func MakeArvadosClientWithConfig(config APIConfig) (ac ArvadosClient, err error) { ac = ArvadosClient{ - ApiServer: os.Getenv("ARVADOS_API_HOST"), - ApiToken: os.Getenv("ARVADOS_API_TOKEN"), - ApiInsecure: insecure, + ApiServer: config.APIHost, + ApiToken: config.APIToken, + ApiInsecure: config.APIHostInsecure, Client: &http.Client{Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure}}}, - External: external} + TLSClientConfig: &tls.Config{InsecureSkipVerify: config.APIHostInsecure}}}, + External: config.ExternalClient} if ac.ApiServer == "" { return ac, MissingArvadosApiHost