def get_service_env_vars( header: str, service_header: str, include_secret_key: bool, include_internal_token: bool, include_agent_token: bool, authentication_type: str, polyaxon_default_secret_ref: str, polyaxon_agent_secret_ref: str, api_host: str, api_version: str, run_instance: str, ) -> List[k8s_schemas.V1EnvVar]: env_vars = get_base_env_vars() + [ get_env_var(name=POLYAXON_KEYS_HOST, value=api_host), get_env_var(name=POLYAXON_KEYS_IS_MANAGED, value=True), get_env_var(name=POLYAXON_KEYS_API_VERSION, value=api_version), get_run_instance_env_var(run_instance), ] if header: env_vars.append( get_env_var( name=POLYAXON_KEYS_HEADER, value=PolyaxonServiceHeaders.get_header(header), )) if service_header: env_vars.append( get_env_var(name=POLYAXON_KEYS_HEADER_SERVICE, value=service_header)) if include_secret_key: env_vars.append( get_from_secret( key_name=POLYAXON_KEYS_SECRET_KEY, secret_key_name=POLYAXON_KEYS_SECRET_KEY, secret_ref_name=polyaxon_default_secret_ref, )) internal = False if include_internal_token and polyaxon_default_secret_ref: internal = True env_vars.append( get_from_secret( POLYAXON_KEYS_SECRET_INTERNAL_TOKEN, POLYAXON_KEYS_SECRET_INTERNAL_TOKEN, secret_ref_name=polyaxon_default_secret_ref, )) if include_agent_token and polyaxon_agent_secret_ref: if internal: raise PolypodException( "A service cannot have internal token and agent token.") env_vars.append( get_from_secret( POLYAXON_KEYS_AUTH_TOKEN, POLYAXON_KEYS_AUTH_TOKEN, secret_ref_name=polyaxon_agent_secret_ref, )) if authentication_type: env_vars.append( get_env_var(name=POLYAXON_KEYS_AUTHENTICATION_TYPE, value=authentication_type)) return env_vars
def set_agent_header(self): self.header = PolyaxonServiceHeaders.get_header( PolyaxonServiceHeaders.SERVICE) self.header_service = PolyaxonServices.AGENT self.client_header["header_name"] = self.header self.client_header["header_value"] = self.header_service
def set_cli_header(self): self.header = PolyaxonServiceHeaders.get_header( PolyaxonServiceHeaders.SERVICE) self.header_service = VERSION self.client_header["header_name"] = self.header self.client_header["header_value"] = self.header_service
def get_service_env_vars( header: str, service_header: str, include_secret_key: bool, include_internal_token: bool, include_agent_token: bool, authentication_type: str, polyaxon_default_secret_ref: str, polyaxon_agent_secret_ref: str, api_host: str, api_version: str, run_instance: str, ) -> List[k8s_schemas.V1EnvVar]: env_vars = [ get_env_var(name=POLYAXON_KEYS_HOST, value=api_host), get_env_var( name=POLYAXON_KEYS_API_HOST, value=api_host ), # TODO: Remove in v1.2 get_env_var(name=POLYAXON_KEYS_IS_MANAGED, value=True), get_env_var(name=POLYAXON_KEYS_API_VERSION, value=api_version), # Pod info get_from_field_ref( name=POLYAXON_KEYS_K8S_NODE_NAME, field_path="spec.nodeName" ), get_from_field_ref( name=POLYAXON_KEYS_K8S_NAMESPACE, field_path="metadata.namespace" ), get_from_field_ref(name=POLYAXON_KEYS_K8S_POD_ID, field_path="metadata.name"), get_run_instance_env_var(run_instance), ] if header: env_vars.append( get_env_var( name=POLYAXON_KEYS_HEADER, value=PolyaxonServiceHeaders.get_header(header), ) ) if service_header: env_vars.append( get_env_var(name=POLYAXON_KEYS_HEADER_SERVICE, value=service_header) ) if include_secret_key: env_vars.append( get_from_secret( key_name=POLYAXON_KEYS_SECRET_KEY, secret_key_name=POLYAXON_KEYS_SECRET_KEY, secret_ref_name=polyaxon_default_secret_ref, ) ) internal = False if include_internal_token and polyaxon_default_secret_ref: internal = True env_vars.append( get_from_secret( POLYAXON_KEYS_SECRET_INTERNAL_TOKEN, POLYAXON_KEYS_SECRET_INTERNAL_TOKEN, secret_ref_name=polyaxon_default_secret_ref, ) ) if include_agent_token and polyaxon_agent_secret_ref: if internal: raise PolypodException( "A service cannot have internal token and agent token." ) env_vars.append( get_from_secret( POLYAXON_KEYS_AUTH_TOKEN, POLYAXON_KEYS_AUTH_TOKEN, secret_ref_name=polyaxon_agent_secret_ref, ) ) if authentication_type: env_vars.append( get_env_var( name=POLYAXON_KEYS_AUTHENTICATION_TYPE, value=authentication_type ) ) return env_vars