コード例 #1
0
    def test_get_config_path_returns_none_when_not_exist(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        config_path = input_parser.get_config_path()

        # assert
        self.assertIsNone(config_path)
コード例 #2
0
    def test_get_config_path_from_env_var(self):
        # arrange
        args = {}
        input_parser = GlobalInputParser(args)

        # act
        config_path = input_parser.get_config_path()

        # assert
        self.assertEqual(config_path, "some_path")
コード例 #3
0
    def do_remove(self):
        profile_to_remove = self.input_parser.configure_remove.profile
        if not profile_to_remove:
            raise DocoptExit("Please provide a profile name to remove")

        try:
            config_file = GlobalInputParser.get_config_path()
            config_provider = ColonyConfigProvider(config_file)
            config_provider.remove_profile(profile_to_remove)
        except Exception as e:
            logger.exception(e, exc_info=False)
            return self.die()

        return self.success()
コード例 #4
0
    def do_list(self):
        config = None
        try:
            config_file = GlobalInputParser.get_config_path()
            config = ColonyConfigProvider(config_file).load_all()
            result_table = ConfigureListView(config).render()

        except ConfigFileMissingError:
            raise DocoptExit("Config file doesn't exist. Use 'colony configure set' to configure Colony CLI.")
        except Exception as e:
            logger.exception(e, exc_info=False)
            return self.die()

        self.message(result_table)
        return self.success()
コード例 #5
0
    def do_configure(self):
        config_file = GlobalInputParser.get_config_path()
        config_provider = ColonyConfigProvider(config_file)
        config = {}
        try:
            config = config_provider.load_all()
        except Exception:
            pass

        # read profile
        profile = input("Profile Name [default]: ")
        profile = profile or "default"

        # if profile exists set current values from profile
        current_account = config.get(profile, {}).get(ColonyConfigKeys.ACCOUNT, "")
        current_space = config.get(profile, {}).get(ColonyConfigKeys.SPACE, "")
        current_token = config.get(profile, {}).get(ColonyConfigKeys.TOKEN, "")

        # read account
        account = input(f"Colony Account (optional) [{current_account}]: ")
        account = account or current_account

        # read space name
        space = input(f"Colony Space [{current_space}]: ")
        space = space or current_space
        if not space:
            return self.die("Space cannot be empty")

        # read token
        token = getpass.getpass(f"Colony Token [{mask_token(current_token)}]: ")
        token = token or current_token
        if not token:
            return self.die("Token cannot be empty")

        # save user inputs
        config_provider.save_profile(profile, token, space, account)

        return self.success()