1// 2// Copyright (c) 2018, Joyent, Inc. All rights reserved. 3// 4// This Source Code Form is subject to the terms of the Mozilla Public 5// License, v. 2.0. If a copy of the MPL was not distributed with this 6// file, You can obtain one at http://mozilla.org/MPL/2.0/. 7// 8 9package triton 10 11import ( 12 "os" 13 14 "github.com/joyent/triton-go/authentication" 15) 16 17// Universal package used for defining configuration used across all client 18// constructors. 19 20// ClientConfig is a placeholder/input struct around the behavior of configuring 21// a client constructor through the implementation's runtime environment 22// (SDC/MANTA env vars). 23type ClientConfig struct { 24 TritonURL string 25 MantaURL string 26 AccountName string 27 Username string 28 Signers []authentication.Signer 29} 30 31var envPrefixes = []string{"TRITON", "SDC"} 32 33// GetEnv looks up environment variables using the preferred "TRITON" prefix, 34// but falls back to the retired "SDC" prefix. For example, looking up "USER" 35// will search for "TRITON_USER" followed by "SDC_USER". If the environment 36// variable is not set, an empty string is returned. GetEnv() is used to aid in 37// the transition and deprecation of the "SDC_*" environment variables. 38func GetEnv(name string) string { 39 for _, prefix := range envPrefixes { 40 if val, found := os.LookupEnv(prefix + "_" + name); found { 41 return val 42 } 43 } 44 45 return "" 46} 47