sdk-codegen icon indicating copy to clipboard operation
sdk-codegen copied to clipboard

Allow custom env_prefixes to be used when initialising the SDK

Open ianatkinson-ee opened this issue 3 years ago • 3 comments

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 )

ianatkinson-ee avatar Feb 21 '22 11:02 ianatkinson-ee

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

joeldodge79 avatar Feb 22 '22 15:02 joeldodge79

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`,
  }
}

jkaster avatar Mar 18 '22 18:03 jkaster

I have opened a PR for this.

ianatkinson-ee avatar Mar 21 '22 14:03 ianatkinson-ee