Example #1
0
 def test_parse_env_file_proper(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\nPASS=secret')
     get_parse_env_file = parse_env_file(env_file)
     self.assertEqual(get_parse_env_file,
                      {'USER': '******', 'PASS': '******'})
     os.unlink(env_file)
Example #2
0
 def test_parse_env_file_newline(self):
     env_file = self.generate_tempfile(
         file_content='\nUSER=jdoe\n\n\nPASS=secret')
     get_parse_env_file = parse_env_file(env_file)
     self.assertEqual(get_parse_env_file,
                      {'USER': '******', 'PASS': '******'})
     os.unlink(env_file)
Example #3
0
 def test_parse_env_file_with_equals_character(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\nPASS=sec==ret')
     get_parse_env_file = parse_env_file(env_file)
     self.assertEqual(get_parse_env_file,
                      {'USER': '******', 'PASS': '******'})
     os.unlink(env_file)
Example #4
0
 def prepare_container_options(self, prod):
     """
     Call this function to dump out a single dict ready to be passed to
     docker.Client.create_container
     """
     # FOR WHEN YOU CAN UPGRADE TO 3.5
     # hc = dclient.create_host_config(**self.host_config)
     # return {**self.container, **hc}
     self.logger.debug('startable using 3.4 version')
     self.container['volumes'], self.host_config['binds'] = _split_volumes(
         self.volumes_for(prod))
     self.logger.debug('container: %s', self.container)
     self.logger.debug('host_config: %s', self.host_config)
     hc = dclient.create_host_config(**self.host_config)
     r = self.container.copy()
     r['host_config'] = hc
     if self.env_file and isfile(self.env_file):
         # Apply env vars in this order so that envs defined in
         # the Controlfile take precedence over the envfile
         r['environment'] = dict(
             parse_env_file(self.env_file), **{
                 x[0]: x[2]
                 for x in
                 [x.partition('=') for x in r.get('environment', [])]
             })
     elif self.env_file:
         self.logger.warning('Env file is missing: %s', self.env_file)
     self.logger.debug('combined: %s', r)
     return r
Example #5
0
def build(base_path, *args):
    """Constructs an environment dictionary from the given list of sources. The
    sources may be strings, representing filenames of Docker envfiles to be
    loaded (in the context of the given base_path); they may be lists of
    sources (recursively), or they may be dictionaries of values to add to the
    environment. Sources are consumed in order to offer reliable overrides."""
    env = {}
    for arg in filter(None, args):
        if isinstance(arg, six.string_types):
            envfile = os.path.join(base_path, arg)
            env.update(parse_env_file(envfile))
        elif type(arg) == list:
            env.update(build(base_path, *arg))
        elif type(arg) == dict:
            env.update(arg)
            continue
        else:
            raise ValueError('unhandled env type {}'.format(type(arg)))

    for k, v in env.items():
        if type(v) == list:
            env[k] = _env_list_expand(v)

    return env
Example #6
0
 def test_parse_env_file_invalid_line(self):
     env_file = self.generate_tempfile(file_content='USER jdoe')
     with pytest.raises(DockerException):
         parse_env_file(env_file)
     os.unlink(env_file)
Example #7
0
 def test_parse_env_file_commented_line(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\n#PASS=secret')
     get_parse_env_file = parse_env_file(env_file)
     assert get_parse_env_file == {'USER': '******'}
     os.unlink(env_file)
Example #8
0
 def test_parse_env_file_proper(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\nPASS=secret')
     get_parse_env_file = parse_env_file(env_file)
     assert get_parse_env_file == {'USER': '******', 'PASS': '******'}
     os.unlink(env_file)
Example #9
0
 def test_parse_env_file_commented_line(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\n#PASS=secret')
     get_parse_env_file = parse_env_file((env_file))
     self.assertEqual(get_parse_env_file, {'USER': '******'})
     os.unlink(env_file)
Example #10
0
 def test_parse_env_file_commented_line(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\n#PASS=secret')
     get_parse_env_file = parse_env_file((env_file))
     self.assertEqual(get_parse_env_file, {'USER': '******'})
     os.unlink(env_file)
Example #11
0
 def test_parse_env_file_proper(self):
     env_file = self.generate_tempfile(file_content="USER=jdoe\nPASS=secret")
     get_parse_env_file = parse_env_file(env_file)
     self.assertEqual(get_parse_env_file, {"USER": "******", "PASS": "******"})
     os.unlink(env_file)
Example #12
0
 def test_parse_env_file_invalid_line(self):
     env_file = self.generate_tempfile(
         file_content='USER jdoe')
     with pytest.raises(DockerException):
         parse_env_file(env_file)
     os.unlink(env_file)
Example #13
0
 def test_parse_env_file_newline(self):
     env_file = self.generate_tempfile(
         file_content='\nUSER=jdoe\n\n\nPASS=secret')
     get_parse_env_file = parse_env_file(env_file)
     assert get_parse_env_file == {'USER': '******', 'PASS': '******'}
     os.unlink(env_file)
Example #14
0
 def test_parse_env_file_commented_line(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\n#PASS=secret')
     get_parse_env_file = parse_env_file(env_file)
     assert get_parse_env_file == {'USER': '******'}
     os.unlink(env_file)
Example #15
0
 def test_parse_env_file_with_equals_character(self):
     env_file = self.generate_tempfile(
         file_content='USER=jdoe\nPASS=sec==ret')
     get_parse_env_file = parse_env_file(env_file)
     assert get_parse_env_file == {'USER': '******', 'PASS': '******'}
     os.unlink(env_file)