def create(self, vals):
        """
        Override create to generate a random password for the passord option.

        :param vals: The values used to create the container.
        """
        if 'application_id' in vals and vals['application_id']:
            application = self.env['clouder.application'].browse(
                vals['application_id'])
            if application.type_id.name == 'openldap':
                if 'option_ids' not in vals:
                    vals['options_ids'] = []

                password_option = self.env.ref(
                    'clouder_template_ldap.apptype_openldap_option2').id
                flag = False
                for option in vals['option_ids']:
                    if option[2]['name'] == password_option:
                        if not option[2]['value']:
                            option[2]['value'] = \
                                clouder_model.generate_random_password(20)
                        flag = True

                if not flag:
                    vals['option_ids'].append((0, 0, {
                        'name': password_option,
                        'value': clouder_model.generate_random_password(20)}))
        return super(ClouderContainer, self).create(vals)
Exemple #2
0
    def deploy_post(self):
        """
        Updates the root password after deployment.
        Updates auth methods to allow network connections
        """
        super(ClouderContainer, self).deploy_post()

        if self.application_id.type_id.name == 'mysql':

            self.start()

            self.execute(
                ['sed', '-i', '"/bind-address/d"', '/etc/mysql/my.cnf'])
            if self.options['root_password']['value']:
                password = self.options['root_password']['value']
            else:
                password = clouder_model.generate_random_password(20)
                option_obj = self.env['clouder.container.option']
                options = option_obj.search([('container_id', '=', self),
                                             ('name', '=', 'root_password')])
                if options:
                    options.value = password
                else:
                    type_option_obj = self.env[
                        'clouder.application.type.option']
                    type_options = type_option_obj.search([
                        ('apptype_id.name', '=', 'mysql'),
                        ('name', '=', 'root_password')
                    ])
                    if type_options:
                        option_obj.create({
                            'container_id': self,
                            'name': type_options[0],
                            'value': password
                        })
            self.execute(['mysqladmin', '-u', 'root', 'password', password])

            # Granting network permissions
            self.execute([
                'mysql', '--user=root', '--password=\'' + password + '\'',
                '-e',
                '"GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'%\' IDENTIFIED BY \''
                + password + '\'"'
            ])
Exemple #3
0
 def generate_default(self):
     res = super(ClouderApplicationTypeOption, self).generate_default()
     if self.name == 'token' and self.application_type_id.name == 'gitlab':
         res = model.generate_random_password(20)
     return res
Exemple #4
0
 def generate_default(self):
     res = super(ClouderApplicationTypeOption, self).generate_default()
     if self.name == 'root_password' \
             and self.application_type_id.name == 'mysql':
         res = model.generate_random_password(20)
     return res