예제 #1
0
def encrypt_credentials(tosca_template_dict):
    logger.info('Encrypting credentials.')
    node_templates = tosca_template_dict['topology_template']['node_templates']
    enc_key = bytes(secret, 'utf-8')
    for node_template_name in node_templates:
        node_template = node_templates[node_template_name]
        credentials = ToscaHelper.extract_credentials_from_node(node_template)
        if credentials:
            for credential in credentials:
                if 'token' not in credential:
                    # This is a tmp fix for the tosca parser. The tosca.datatypes.Credential which requires token
                    credential['token'] = 'dG9rZW4K'
                if 'protocol' in credential and credential['protocol'] == 'ssh':
                    continue
                if 'token' in credential:
                    token = credential['token']
                    credential['token'] = encrypt(token, enc_key)
                if 'keys' in credential:
                    keys = credential['keys']
                    for key_name in keys:
                        token = keys[key_name]
                        keys[key_name] = encrypt(token, enc_key)
    return tosca_template_dict
예제 #2
0
def decrypt_credentials(tosca_template_dict):
    logger.info('Decrypting credentials.')
    node_templates = tosca_template_dict['topology_template']['node_templates']
    enc_key = bytes(secret, 'utf-8')
    for node_template_name in node_templates:
        node_template = node_templates[node_template_name]
        if node_template['type'] == 'tosca.nodes.QC.VM.Compute':
            continue
        credentials = ToscaHelper.extract_credentials_from_node(node_template)

        if credentials:
            for credential in credentials:
                if 'protocol' in credential and credential['protocol'] == 'ssh':
                    continue
                if 'token' in credential:
                    token = credential['token']
                    credential['token'] = decrypt(token, enc_key)
                if 'keys' in credential:
                    keys = credential['keys']
                    for key_name in keys:
                        token = keys[key_name]
                        keys[key_name] = decrypt(token, enc_key)
    return tosca_template_dict
예제 #3
0
 def create_workflow_templates(self,
                               tosca_workflow_step=None,
                               organization_id=None,
                               node_templates=None,
                               step_name=None,
                               workflow_name=None):
     awx_workflow_steps = {}
     tosca_node = node_templates[tosca_workflow_step['target']]
     activities = tosca_workflow_step['activities']
     call_operation = None
     for activity in activities:
         if 'call_operation' in activity:
             call_operation = activity['call_operation']
             break
     if 'interfaces' in tosca_node:
         interfaces = tosca_node['interfaces']
         interface_name = call_operation.split('.')[0]
         tosca_interface_job = call_operation.split('.')[1]
         ancestors = self.tosca_helper.get_interface_ancestors(
             interface_name)
         if 'tosca.interfaces.QC.Ansible' in ancestors:
             workflow_template_node = {}
             template = interfaces[interface_name][tosca_interface_job]
             template_name = workflow_name + '.' + step_name
             logger.info('Creating template: ' + template_name)
             extra_variables = None
             if not 'repository' in template['inputs']:
                 raise Exception('Workflow steps for: ' + template_name +
                                 ' have no repository: ' + str(template))
             if 'inputs' in template and 'repository' in template['inputs']:
                 repository_url = template['inputs']['repository']
                 project_id = self.create_project(
                     project_name=repository_url,
                     scm_url=repository_url,
                     scm_branch='master',
                     scm_type='git',
                     organization_id=organization_id)
                 workflow_template_node[template_name] = {
                     'project': project_id[0]
                 }
                 if not 'inventory' in template['inputs']:
                     raise Exception(tosca_interface_job +
                                     ' has no inventory')
                 inventory = template['inputs']['inventory']
                 inventory_id = self.create_inventory(
                     inventory_name=template_name,
                     inventory=inventory,
                     organization_id=organization_id)
                 workflow_template_node[template_name][
                     'inventory'] = inventory_id
                 logger.info('Created inventory: ' + str(inventory_id) +
                             ' for :' + template_name)
             if 'implementation' in template:
                 if 'extra_variables' in template['inputs']:
                     extra_variables = self.get_variables(
                         extra_variables=template['inputs']
                         ['extra_variables'])
                 workflow_template_node[template_name][
                     'implementation'] = template['implementation']
                 if not workflow_template_node[template_name]['inventory']:
                     raise Exception(template_name +
                                     ' is missing inventory')
                 credentials = ToscaHelper.extract_credentials_from_node(
                     tosca_node)
                 workflow_template_node[template_name][
                     'job_template'] = self.create_job_template(
                         workflow_template_node,
                         credentials=credentials,
                         organization_id=organization_id,
                         extra_vars=extra_variables)[0]
             else:
                 raise Exception(template_name + ' has no implementation!')
             if workflow_template_node:
                 logger.info('Created workflow_template_node: ' +
                             str(workflow_template_node))
                 awx_workflow_steps.update(workflow_template_node)
     return awx_workflow_steps