def payload(self, **kwargs): payload = PseudoNamespace( name=kwargs.get('name') or 'WorkflowJobTemplate - {}'.format(random_title()), description=kwargs.get('description') or random_title(10)) optional_fields = ("allow_simultaneous", "ask_variables_on_launch", "ask_inventory_on_launch", "ask_scm_branch_on_launch", "ask_limit_on_launch", "limit", "scm_branch", "survey_enabled") update_payload(payload, optional_fields, kwargs) extra_vars = kwargs.get('extra_vars', not_provided) if extra_vars != not_provided: if isinstance(extra_vars, dict): extra_vars = json.dumps(extra_vars) payload.update(extra_vars=extra_vars) if kwargs.get('organization'): payload.organization = kwargs.get('organization').id if kwargs.get('inventory'): payload.inventory = kwargs.get('inventory').id return payload
def payload(self, organization, scm_type='git', **kwargs): payload = PseudoNamespace( name=kwargs.get('name') or 'Project - {}'.format( random_title()), description=kwargs.get('description') or random_title(10), scm_type=scm_type, scm_url=kwargs.get('scm_url') or config.project_urls.get( scm_type, '')) if organization is not None: payload.organization = organization.id if kwargs.get('credential'): payload.credential = kwargs.get('credential').id fields = ( 'scm_branch', 'local_path', 'scm_clean', 'scm_delete_on_update', 'scm_update_cache_timeout', 'scm_update_on_launch', 'scm_refspec', 'allow_override') update_payload(payload, fields, kwargs) return payload
def payload(self, organization, scm_type='git', **kwargs): payload = PseudoNamespace(name=kwargs.get('name') or 'Project - {}'.format(random_title()), description=kwargs.get('description') or random_title(10), scm_type=scm_type, scm_url=kwargs.get('scm_url') or config.project_urls.get(scm_type, '')) if organization is not None: payload.organization = organization.id if kwargs.get('credential'): payload.credential = kwargs.get('credential').id fields = ('scm_branch', 'local_path', 'scm_clean', 'scm_delete_on_update', 'scm_update_cache_timeout', 'scm_update_on_launch', 'scm_refspec', 'allow_override') update_payload(payload, fields, kwargs) for fk_field in ('execution_environment', 'default_environment'): rel_obj = kwargs.get(fk_field) if rel_obj is None: continue elif isinstance(rel_obj, int): payload.update(**{fk_field: int(rel_obj)}) elif hasattr(rel_obj, 'id'): payload.update(**{fk_field: rel_obj.id}) else: raise AttributeError( f'Related field {fk_field} must be either integer of pkid or object' ) return payload
def payload(self, **kwargs): payload = PseudoNamespace( name=kwargs.get('name') or 'OAuth2Application - {}'.format(random_title()), description=kwargs.get('description') or random_title(10), client_type=kwargs.get('client_type', 'public'), authorization_grant_type=kwargs.get('authorization_grant_type', 'password'), ) if kwargs.get('organization'): payload.organization = kwargs['organization'].id optional_fields = ('redirect_uris', 'skip_authorization') update_payload(payload, optional_fields, kwargs) return payload
def payload(self, credential_type, user=None, team=None, organization=None, inputs=None, **kwargs): if not any((user, team, organization)): raise TypeError( '{0.__class__.__name__} requires user, team, and/or organization instances.' .format(self)) if inputs is None: inputs = {} payload = PseudoNamespace( name=kwargs.get('name') or 'Credential - {}'.format(random_title()), description=kwargs.get('description') or random_title(10), credential_type=credential_type.id, inputs=inputs, ) if user: payload.user = user.id if team: payload.team = team.id if organization: payload.organization = organization.id kind, config_cred = kind_and_config_cred_from_credential_type( credential_type) for field in credential_input_fields: field, value = get_payload_field_and_value_from_kwargs_or_config_cred( field, kind, inputs or kwargs, config_cred) if value != not_provided: payload.inputs[field] = value if kind == 'net': payload.inputs.authorize = inputs.get( 'authorize', bool(inputs.get('authorize_password'))) if kind in ('ssh', 'net') and 'ssh_key_data' not in payload.inputs: payload.inputs.ssh_key_data = inputs.get('ssh_key_data', generate_private_key()) return payload
def payload(self, **kwargs): payload = PseudoNamespace( name=kwargs.get('name') or 'WorkflowJobTemplate - {}'.format(random_title()), description=kwargs.get('description') or random_title(10)) optional_fields = ( "allow_simultaneous", "ask_variables_on_launch", "ask_inventory_on_launch", "ask_scm_branch_on_launch", "ask_limit_on_launch", "limit", "scm_branch", "survey_enabled", "webhook_service", "webhook_credential", ) update_payload(payload, optional_fields, kwargs) extra_vars = kwargs.get('extra_vars', not_provided) if extra_vars != not_provided: if isinstance(extra_vars, dict): extra_vars = json.dumps(extra_vars) payload.update(extra_vars=extra_vars) if kwargs.get('organization'): payload.organization = kwargs.get('organization').id if kwargs.get('inventory'): payload.inventory = kwargs.get('inventory').id if kwargs.get('webhook_credential'): webhook_cred = kwargs.get('webhook_credential') if isinstance(webhook_cred, int): payload.update(webhook_credential=int(webhook_cred)) elif hasattr(webhook_cred, 'id'): payload.update(webhook_credential=webhook_cred.id) else: raise AttributeError( "Webhook credential must either be integer of pkid or Credential object" ) return payload