sdk-codegen
sdk-codegen copied to clipboard
Allow custom env_prefixes to be used when initialising the SDK
We want to be able to run the same script on multiple Looker instances, and so would need different env variables. We can do this by using different config files as the functions in https://github.com/looker-open-source/sdk-codegen/blob/main/python/looker_sdk/init.py have a config_file argument, but this means storing environment variables in code.
The env_prefix is currently not an option in those function arguments and is hardcoded as constants.environment_prefix. Can this be included as function arguments in the init31, init40 and _settings functions so that the env_prefixes can be changed? I.e. something like
def init31( config_file: str = "looker.ini", env_prefix=constants.environment_prefix, section: Optional[str] = None )
def init31( config_file: str = "looker.ini", env_prefix=constants.environment_prefix, section: Optional[str] = None looks good to me. any chance you could work up a PR for this? Also, FYI on related config change PR https://github.com/looker-open-source/sdk-codegen/pull/996/files#diff-af3c436cd79cbb8cb66d7924ecd7554577078e69d6c41af2823e6a7cf09e8fdd
FWIW, we do have environment prefix support in the TS SDK, so we've at least got a reference implementation.
export const ApiConfigMap = (envPrefix: string): IValueSettings => {
if (!envPrefix) return {} as IValueSettings
return {
base_url: `${envPrefix}_BASE_URL`,
client_id: `${envPrefix}_CLIENT_ID`,
client_secret: `${envPrefix}_CLIENT_SECRET`,
timeout: `${envPrefix}_TIMEOUT`,
verify_ssl: `${envPrefix}_VERIFY_SSL`,
}
}
I have opened a PR for this.