github.com/blend/go-sdk@v1.20220411.3/configmeta/paths.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package configmeta 9 10 import ( 11 "context" 12 "fmt" 13 14 "github.com/blend/go-sdk/configutil" 15 "github.com/blend/go-sdk/env" 16 ) 17 18 // EnvVars 19 const ( 20 EnvVarProjectConfigPath = "PROJECT_CONFIG_PATH" 21 EnvVarConfigPath = "CONFIG_PATH" 22 ) 23 24 // Defaults 25 const ( 26 DefaultConfigFileName = "config.yml" 27 ) 28 29 // Paths returns a configutil option that adds known default config locations. 30 func Paths() configutil.Option { 31 return PathsFile(DefaultConfigFileName) 32 } 33 34 // PathsFile returns a configutil option that adds known default config locations. 35 func PathsFile(filename string) configutil.Option { 36 return PathsFileContext(context.Background(), filename) 37 } 38 39 // PathsFileContext returns a configutil option that adds known default config locations. 40 func PathsFileContext(ctx context.Context, filename string) configutil.Option { 41 projectName := env.GetVars(ctx).String(env.VarProjectName, env.GetVars(ctx).ServiceName()) 42 fallbackProjectConfigPath := fmt.Sprintf("/var/secrets/projects/%s/%s", projectName, filename) 43 fallbackConfigPath := fmt.Sprintf("/var/secrets/%s", filename) 44 45 knownProjectPath := env.GetVars(ctx).String(EnvVarProjectConfigPath, fallbackProjectConfigPath) 46 knownPath := env.GetVars(ctx).String(EnvVarConfigPath, fallbackConfigPath) 47 48 return configutil.OptPaths( 49 knownProjectPath, 50 knownPath, 51 ) 52 }