Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Object Definition CRUD #15

Merged
merged 3 commits into from
Aug 31, 2017
Merged

Generic Object Definition CRUD #15

merged 3 commits into from
Aug 31, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Aug 10, 2017

manageiq-api version of ManageIQ/manageiq#15374

This PR adds:

GET /api/generic_object_definitions/
GET /api/generic_object_definitions/:id
GET /api/generic_object_definitions/:name

DELETE /api/generic_object_definitions/:id
DELETE /api/generic_object_definitions/:name
POST /api/generic_object_definitions/:id      action: "delete"
POST /api/generic_object_definitions/:name    action: "delete"
POST /api/generic_object_definitions          action: "delete" (works with name, id, href)

POST /api/generic_object_definitions

POST /api/generic_object_definitions/:id      action: "edit"
POST /api/generic_object_definitions/:name    action: "edit"
POST /api/generic_object_definitions          action: "edit" (works with name, id, href)

Example of create:

POST /api/generic_object_definitions
{
  "name"        : "LoadBalancer",
  "description" : "LoadBalancer description",
  "properties"  : {
    "attributes"   : {
      "address"      : "string",
      "last_restart" : "datetime"
    },
    "associations" : {
      "vms"      : "Vm",
      "services" : "Service"
    },
    "methods"      : [
      "add_vm",
      "remove_vm"
    ]
  }
}

Editing a generic object definition. Properties will be updated as is - IE if you remove "methods" as in the below example, properties will no longer have methods and contain the attributes and associations passed in.

POST /api/generic_object_definitions/:id
{
 "action"       : "edit",
  "name"        : "LoadBalancer",
  "description" : "LoadBalancer description",
  "properties"  : {
    "attributes"   : {
      "address"      : "string",
      "last_restart" : "datetime"
    },
    "associations" : {
      "vms"      : "Vm",
      "services" : "Service"
    }
  }
}

@miq-bot add_label enhancement, wip
@miq-bot assign @abellotti

@jntullo jntullo changed the title [WIP] add generic object definition querying [WIP] Generic Object Definition CRUD Aug 16, 2017
@@ -0,0 +1,286 @@
# rubocop:disable Style/WordArray
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling as I prefer that the sample requests not use word arrays to better align with how the request will look.

@jntullo
Copy link
Author

jntullo commented Aug 17, 2017

@miq-bot remove_label wip

@miq-bot miq-bot changed the title [WIP] Generic Object Definition CRUD Generic Object Definition CRUD Aug 17, 2017
@miq-bot miq-bot removed the wip label Aug 17, 2017
hash_including('href' => a_string_matching(generic_object_definitions_url(object_def.compressed_id)))
]
}
run_get(generic_object_definitions_url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does expand=resources do the right thing? Could we add a test for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, tiny nit, but can you group all the verification code together and separately from the execution step(s)? 🍨

@abellotti
Copy link
Member

If you can in the PR comments, create and update examples with sample data showing the properties, methods, etc. Thanks!!

@abellotti
Copy link
Member

Looks good @jntullo, minor updates noted. Thanks!!

def fetch_generic_object_definition(id)
klass = collection_class(:generic_object_definitions)
klass.find_by(:name => id) || klass.find(id)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add Rbac.filtered_object before returning it.


def fetch_generic_object_definition(id)
klass = collection_class(:generic_object_definitions)
klass.find_by(:name => id) || klass.find(id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leverage ApplicationRecord.compressed_id?(id) and leverage resource_search for id based.


def fetch_generic_object_definition(id)
klass = collection_class(:generic_object_definitions)
go_def = klass.find_by(:name => id) || klass.find(id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want logic separation, i.e. check if id is compressed_id? to do a klass.find otherwise do the find_by :name, (just in case someone named one as a numeric string).

@miq-bot
Copy link
Member

miq-bot commented Aug 23, 2017

Checked commits jntullo/manageiq-api@55db55e~...25b9576 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks fine. ⭐

@abellotti
Copy link
Member

Thanks @jntullo for this enhancement, LGTM!!. 😍

@abellotti abellotti merged commit caa246d into ManageIQ:master Aug 31, 2017
@abellotti abellotti added this to the Sprint 68 Ending Sep 4, 2017 milestone Aug 31, 2017
@jntullo jntullo mentioned this pull request Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants