def test_unset_using_mock(monkeypatch):
    passwords = _monkeypatch_keyring(monkeypatch)

    keyring.set("abc", "FOO", "bar")
    assert "bar" == keyring.get("abc", "FOO")
    keyring.unset("abc", "FOO")
    assert keyring.get("abc", "FOO") is None

    assert dict(anaconda=dict()) == passwords

    keyring.reset_keyring_module()
def test_get_set_using_mock(monkeypatch):
    passwords = _monkeypatch_keyring(monkeypatch)

    keyring.set("abc", "FOO", "bar")
    assert "bar" == keyring.get("abc", "FOO")

    assert dict(anaconda={'abc/FOO': 'bar'}) == passwords

    keyring.reset_keyring_module()
def test_get_using_broken(monkeypatch, capsys):
    _monkeypatch_broken_keyring(monkeypatch)

    assert keyring.get("abc", "FOO") is None

    (out, err) = capsys.readouterr()
    assert '' == out
    assert (expected_broken_message % "getting") == err

    keyring.reset_keyring_module()
示例#4
0
    def provide(self, requirement, context):
        """Override superclass to use configured env var (or already-set env var)."""
        errors = []
        logs = []

        # We prefer the values in this order:
        #  - value set in project-local state overrides everything
        #    (otherwise the UI for configuring the value would end
        #    up ignored)
        #  - value in the keyring overrides (treated the same as
        #    anaconda-project-local.yml, but for encrypted variables)
        #  - then anything already set in the environment wins, so you
        #    can override on the command line like `FOO=bar myapp`
        #  - then the anaconda-project.yml default value
        local_state_override = None
        if requirement.encrypted:
            # import keyring locally because it's an optional dependency
            # that prints a warning when it's needed but not found.
            import anaconda_project.internal.keyring as keyring

            env_prefix = self._get_env_prefix(context.environ)
            if env_prefix is not None:
                local_state_override = keyring.get(env_prefix,
                                                   requirement.env_var)

        # we will read encrypted vars from local state, though we never
        # put them in there ourselves
        if local_state_override is None:
            local_state_override = self._local_state_override(
                requirement, context.local_state_file)

        if local_state_override is not None:
            # anaconda-project-local.yml
            #
            # variables:
            #   REDIS_URL: "redis://example.com:1234"
            context.environ[requirement.env_var] = local_state_override
        elif requirement.env_var in context.environ:
            # nothing to do here
            pass
        elif 'default' in requirement.options:
            # anaconda-project.yml
            #
            # variables:
            #   REDIS_URL:
            #     default: "redis://example.com:1234"
            value = requirement.options['default']
            if value is not None:
                context.environ[requirement.env_var] = value
        else:
            pass

        return ProvideResult.empty().copy_with_additions(errors, logs)
示例#5
0
    def _set_encrypted_config_values_as_strings(self, requirement, environ, local_state_file, default_env_spec_name,
                                                overrides, values):
        # import keyring locally because it's an optional dependency
        # that prints a warning when it's needed but not found.
        import anaconda_project.internal.keyring as keyring

        env_prefix = self._get_env_prefix(environ)
        from_keyring = keyring.get(env_prefix, requirement.env_var)
        value_string = values.get('value', from_keyring)

        if value_string is not None:
            if value_string == '':
                keyring.unset(env_prefix, requirement.env_var)
            else:
                keyring.set(env_prefix, requirement.env_var, value_string)
示例#6
0
    def read_config(self, requirement, environ, local_state_file,
                    default_env_spec_name, overrides):
        """Override superclass to read env var value."""
        config = dict()
        value = None
        if requirement.encrypted:
            # import keyring locally because it's an optional dependency
            # that prints a warning when it's needed but not found.
            import anaconda_project.internal.keyring as keyring

            env_prefix = self._get_env_prefix(environ)
            if env_prefix is None:
                value = None
            else:
                value = keyring.get(env_prefix, requirement.env_var)

        # note that we will READ an encrypted value from local
        # state if someone puts it in there by hand, but we won't
        # ever write one there ourselves.
        if value is None:
            value = self._local_state_override(requirement, local_state_file)

        disabled_value = self._disabled_local_state_override(
            requirement, local_state_file)
        was_disabled = value is None and disabled_value is not None
        if was_disabled:
            value = disabled_value

        if value is not None:
            config['value'] = value

        if value is not None and not was_disabled:
            source = 'variables'
        elif requirement.env_var in environ:
            source = 'environ'
            config['value'] = environ[requirement.env_var]
        elif 'default' in requirement.options:
            source = 'default'
        else:
            source = 'unset'
        config['source'] = source
        return config
 def check():
     keyring.set("abc", "FOO", "bar")
     assert "bar" == keyring.get("abc", "FOO")
     keyring.unset("abc", "FOO")
     assert keyring.get("abc", "FOO") is None
 def check():
     keyring.set("abc", "FOO", "bar")
     assert "bar" == keyring.get("abc", "FOO")