Beispiel #1
0
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
Beispiel #2
0
def set_cors(context, config: ConfigManager):
    # session settings
    context["CORS_ALLOW_CREDENTIALS"] = True
    allowed_list = config.get_list("POLYAXON_CORS_ALLOWED_ORIGINS",
                                   is_optional=True,
                                   default=[])
    context["CORS_ALLOWED_ORIGINS"] = allowed_list
    context["CORS_ALLOW_ALL_ORIGINS"] = False if allowed_list else True

    context["CORS_ALLOW_HEADERS"] = (default_headers +
                                     PolyaxonServiceHeaders.get_headers())

    ssl_enabled = config.get_boolean("POLYAXON_SSL_ENABLED",
                                     is_optional=True,
                                     default=False)
    ssl_redirect_enabled = config.get_boolean("POLYAXON_SSL_REDIRECT_ENABLED",
                                              is_optional=True,
                                              default=False)
    context["SSL_ENABLED"] = ssl_enabled
    context["PROTOCOL"] = "http"
    context["WS_PROTOCOL"] = "ws"
    if ssl_enabled:
        context["SESSION_COOKIE_SECURE"] = True
        context["CSRF_COOKIE_SECURE"] = True
        context["SECURE_PROXY_SSL_HEADER"] = ("HTTP_X_FORWARDED_PROTO",
                                              "https")
        context["PROTOCOL"] = "https"
        context["WS_PROTOCOL"] = "wss"
    if ssl_redirect_enabled:
        context["SECURE_SSL_REDIRECT"] = True
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
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