class Resource(models.Resource): """A resource for credential types.""" cli_help = 'Manage credential types within Ansible Tower.' endpoint = '/credential_types/' name = models.Field(unique=True) description = models.Field(required=False, display=False) kind = models.Field( help_text= 'The type of credential type being added. Valid options are: ssh, vault, net, scm, ' 'cloud and insights. Note only cloud and net can be used for creating credential types.', type=click.Choice(['ssh', 'vault', 'net', 'scm', 'cloud', 'insights']), ) managed_by_tower = models.Field( type=bool, required=False, read_only=True, help_text='Indicating if the credential type is a tower built-in type.' ) inputs = models.Field( type=types.StructuredInput(), required=False, display=False, ) injectors = models.Field( type=types.StructuredInput(), required=False, display=False, )
class Resource(models.Resource): """A resource for credentials.""" cli_help = 'Manage credentials within Ansible Tower.' endpoint = '/credentials/' identity = ('organization', 'user', 'team', 'name') dependencies = ['organization', 'credential_type'] name = models.Field(unique=True) description = models.Field(required=False, display=False) # Who owns this credential? user = models.Field(display=False, type=types.Related('user'), required=False, no_lookup=True) team = models.Field(display=False, type=types.Related('team'), required=False, no_lookup=True) organization = models.Field(display=False, type=types.Related('organization'), required=False) credential_type = models.Field(type=types.Related('credential_type')) inputs = models.Field(type=types.StructuredInput(), required=False, display=False)
class Resource(models.Resource): """A resource for credentials.""" cli_help = 'Manage credentials within Ansible Tower.' endpoint = '/credentials/' identity = ('organization', 'user', 'team', 'name') name = models.Field(unique=True) description = models.Field(required=False, display=False) # Who owns this credential? user = models.Field(display=False, type=types.Related('user'), required=False) team = models.Field(display=False, type=types.Related('team'), required=False) organization = models.Field(display=False, type=types.Related('organization'), required=False) credential_type = models.Field(type=types.Related('credential_type')) inputs = models.Field(type=types.StructuredInput(), required=False, display=False) @resources.command def create(self, **kwargs): """Create a credential. Fields in the resource's `identity` tuple are used for a lookup; if a match is found, then no-op (unless `force_on_exists` is set) but do not fail (unless `fail_on_found` is set). =====API DOCS===== Create a credential. :param fail_on_found: Flag that if set, the operation fails if an object matching the unique criteria already exists. :type fail_on_found: bool :param force_on_exists: Flag that if set, then if a match is found on unique fields, other fields will be updated to the provided values.; If unset, a match causes the request to be a no-op. :type force_on_exists: bool :param `**kwargs`: Keyword arguements which, all together, will be used as POST body to create the resource object. :returns: A dictionary combining the JSON output of the created resource, as well as two extra fields: "changed", a flag indicating if the resource is created successfully; "id", an integer which is the primary key of the created object. :rtype: dict =====API DOCS===== """ if (kwargs.get('user', False) or kwargs.get('team', False) or kwargs.get('organization', False)): debug.log('Checking Project API Details.', header='details') r = client.options('/credentials/') if 'organization' in r.json()['actions']['POST']: for i in range(len(self.fields)): if self.fields[i].name in ('user', 'team'): self.fields[i].no_lookup = True return super(Resource, self).create(**kwargs)
def test_invalid_json_raises_exception(self): s = 'not valid{"foo":}' p = click.Option(('name', '-n')) f = types.StructuredInput() with self.assertRaises(exc.UsageError): f.convert(s, p, None)
def test_deserialize_valid_input(self): s = '{"foo": "bar"}' p = click.Option(('name', '-n')) f = types.StructuredInput() f_converted = f.convert(s, p, None) self.assertEqual(f_converted, {'foo': 'bar'})