Esempio n. 1
0
    def get_config_from_env(cls, **kwargs) -> ClientConfig:
        tmp_path = os.path.join(CONTEXT_TMP_POLYAXON_PATH, cls.CONFIG_FILE_NAME)
        user_path = os.path.join(CONTEXT_USER_POLYAXON_PATH, cls.CONFIG_FILE_NAME)

        config = ConfigManager.read_configs(
            [
                ConfigSpec(tmp_path, config_type=".json", check_if_exists=False),
                ConfigSpec(user_path, config_type=".json", check_if_exists=False),
                os.environ,
            ]
        )
        return ClientConfig.from_dict(config.data)
Esempio n. 2
0
    def get_config_from_env(cls) -> AgentConfig:
        tmp_path = os.path.join(CONTEXT_TMP_POLYAXON_PATH, ".agent")
        user_path = os.path.join(CONTEXT_USER_POLYAXON_PATH, ".agent")

        config_paths = [
            os.environ,
            ConfigSpec(tmp_path, config_type=".json", check_if_exists=False),
            ConfigSpec(user_path, config_type=".json", check_if_exists=False),
            {
                "dummy": "dummy"
            },
        ]

        agent_config = ConfigManager.read_configs(config_paths)
        return AgentConfig.from_dict(agent_config.data)
Esempio n. 3
0
 def get_config_from_env(cls) -> AccessTokenConfig:
     tmp_path = os.path.join(CONTEXT_TMP_POLYAXON_PATH,
                             cls.CONFIG_FILE_NAME)
     user_path = os.path.join(CONTEXT_USER_POLYAXON_PATH,
                              cls.CONFIG_FILE_NAME)
     auth_config = ConfigManager.read_configs([
         os.environ,
         ConfigSpec(tmp_path, config_type=".json", check_if_exists=False),
         ConfigSpec(user_path, config_type=".json", check_if_exists=False),
         ConfigSpec(CONTEXT_MOUNT_AUTH,
                    config_type=".json",
                    check_if_exists=False),
         {
             "dummy": "dummy"
         },
     ])
     return AccessTokenConfig.from_dict(auth_config.data)
Esempio n. 4
0
    def test_reads_non_existing_file(self):
        # Raises by default
        with self.assertRaises(PolyaxonSchemaError):
            reader.read("tests/fixtures/parsing/no_file.yml")

        with self.assertRaises(PolyaxonSchemaError):
            reader.read("tests/fixtures/parsing/no_file.json")

        with self.assertRaises(PolyaxonSchemaError):
            reader.read(ConfigSpec("tests/fixtures/parsing/no_file"))

        with self.assertRaises(PolyaxonSchemaError):
            reader.read(ConfigSpec("tests/fixtures/parsing/no_file.yml"))

        with self.assertRaises(PolyaxonSchemaError):
            reader.read(ConfigSpec("tests/fixtures/parsing/no_file.json"))

        # Does not raise if set to ignore
        assert (reader.read(
            ConfigSpec("tests/fixtures/parsing/no_file",
                       check_if_exists=False)) == {})

        assert (reader.read(
            ConfigSpec("tests/fixtures/parsing/no_file.yml",
                       check_if_exists=False)) == {})

        assert (reader.read(
            ConfigSpec("tests/fixtures/parsing/no_file.json",
                       check_if_exists=False)) == {})
Esempio n. 5
0
 def test_reads_json_files_without_extension(self):
     config = reader.read(
         ConfigSpec("tests/fixtures/parsing/json_file",
                    config_type=".json"))
     assert config == {"x": 1, "y": 2, "foo": "bar", "type": "json"}
Esempio n. 6
0
 def test_reads_yaml_files_without_extension(self):
     config = reader.read(
         ConfigSpec("tests/fixtures/parsing/yaml_file", config_type=".yml"))
     assert config == {"x": 10, "y": 20, "foo": "bar", "type": "yaml"}
Esempio n. 7
0
)
from polyaxon.schemas.api.authentication import AccessTokenConfig
from polyaxon.schemas.cli.client_configuration import ClientConfig

TMP_POLYAXON_PATH = "/tmp/.polyaxon/"
USER_POLYAXON_PATH = polyaxon_user_path()

TMP_AUTH_PATH = os.path.join(TMP_POLYAXON_PATH, ".polyaxonauth")
TMP_CLIENT_CONFIG_PATH = os.path.join(TMP_POLYAXON_PATH, ".polyaxonclient")

USER_AUTH_PATH = os.path.join(USER_POLYAXON_PATH, ".polyaxonauth")
USER_CLIENT_CONFIG_PATH = os.path.join(USER_POLYAXON_PATH, ".polyaxonclient")

auth_config = ConfigManager.read_configs([
    os.environ,
    ConfigSpec(TMP_AUTH_PATH, config_type=".json", check_if_exists=False),
    ConfigSpec(USER_AUTH_PATH, config_type=".json", check_if_exists=False),
    ConfigSpec(CONTEXT_MOUNT_AUTH, config_type=".json", check_if_exists=False),
    {
        "dummy": "dummy"
    },
])
config = ConfigManager.read_configs([
    os.environ,
    ConfigSpec(TMP_CLIENT_CONFIG_PATH,
               config_type=".json",
               check_if_exists=False),
    ConfigSpec(USER_CLIENT_CONFIG_PATH,
               config_type=".json",
               check_if_exists=False),
])