Example #1
0
    def _login(self):
        import getpass
        import requests
        from os.path import expanduser, join
        import yaml
        from foundations_contrib.utils import foundations_home

        username = self._arguments.username
        password = self._arguments.password

        if username is None or password is None:
            username = input("Username: "******"Password: "******"{self._arguments.host}/api/v2beta/auth/cli_login",
            auth=(username, password),
        )
        if resp.status_code == 200:
            credential_filepath = expanduser(
                join(foundations_home(), "credentials.yaml"))
            with open(credential_filepath, "w") as creds_file:
                creds = {"default": {"token": resp.json()["access_token"]}}
                yaml.dump(creds, creds_file, default_flow_style=False)
            print("\nLogin Succeeded!")
        else:
            print("\nLogin Failed!")
            print(f"Error response: {resp.text}")
Example #2
0
    def _get_global_environments(self):
        from glob import glob
        from os.path import expanduser, join
        from foundations_contrib.utils import foundations_home

        global_config_directory = expanduser(
            join(foundations_home(), 'config', 'submission'))
        search_path = join(global_config_directory, '*.config.yaml')
        return glob(search_path)
Example #3
0
    def _get_local_environments(self):
        from glob import glob
        from os.path import expanduser, join
        from foundations_contrib.utils import foundations_home

        config_directory = expanduser(
            join(foundations_home(), 'config', 'execution'))
        search_path = join(config_directory, 'default.config.yaml')
        return glob(search_path)
    def test_job_bundle_is_saved(self):
        import os.path
        from foundations_contrib.utils import foundations_home

        path = os.path.expanduser(foundations_home() + '/job_data/archive')
        main_exists = os.path.exists(f'{path}/{self.job_id}/artifacts/main.py')
        self.assertTrue(main_exists)

        artifact_exists = os.path.exists(
            f'{path}/{self.job_id}/artifacts/thomas_text.txt')
        self.assertTrue(artifact_exists)
    def set_up(self):
        self.mock_expand_home.return_when(self.expanded_foundations_home,
                                          foundations_home())
        self.mock_listing_constructor.return_when(self.local_config_listing,
                                                  self.local_config_root)
        self.mock_listing_constructor.return_when(
            self.foundations_config_listing, self.foundations_config_root)
        self.local_config_listing.config_path.return_value = None
        self.foundations_config_listing.config_path.return_value = None
        self.local_config_listing.config_data.return_value = None
        self.foundations_config_listing.config_data.return_value = None

        self.mock_translate.return_when(self.translated_config,
                                        self.foundations_mock_config)
def user_token():
    from foundations_contrib.utils import foundations_home
    from os.path import expanduser, join
    import yaml
    import os

    token = os.getenv('FOUNDATIONS_TOKEN', None)

    if not token:
        credential_filepath = expanduser(
            join(foundations_home(), "credentials.yaml"))
        if not os.path.isfile(credential_filepath):
            return None
        with open(credential_filepath, "r") as file:
            credential_dict = yaml.load(file, Loader=yaml.FullLoader)
        if "default" not in credential_dict:
            return None
        if "token" not in credential_dict["default"]:
            return None
        token = credential_dict["default"]["token"]

    return token
Example #7
0
    def job_root(self):
        from foundations_contrib.utils import foundations_home
        from os.path import expanduser

        return expanduser(foundations_home() + '/job_data')
    def _log_path(self):
        import os.path
        from foundations_contrib.utils import foundations_home

        return os.path.expanduser(foundations_home() + '/logs')
    def test_foundations_home_returns_default_home(self):
        override_environment = {}
        self.patch('os.environ', override_environment)

        self.assertEqual('~/.foundations', foundations_home())
    def test_foundations_home_returns_environment_home_when_specified(self):
        override_environment = {'FOUNDATIONS_HOME': self.override_home}
        self.patch('os.environ', override_environment)

        self.assertEqual(self.override_home, foundations_home())
def _get_default_archive_end_point():
    from foundations_contrib.utils import foundations_home
    from os.path import expanduser
    from os.path import join

    return join(expanduser(foundations_home()), "job_data")
Example #12
0
 def set_up(self):
     credential_filepath = expanduser(
         join(foundations_home(), "credentials.yaml"))
     if os.path.exists(credential_filepath):
         os.remove(credential_filepath)