REST API, data bag items and the "action" key

Hi,

I’m manipulating data bag items using the REST API through a custom,
non-ruby client, as documented here:
http://docs.opscode.com/api_chef_server.html

When I try to create or update a data bag item containing the key "action"
at the main level, that key is thrown away, and I don’t see it in the item.

Here’s a gist: https://gist.github.com/giorgian/4754737

In practice, I post the following JSON to /data/foo
{
“id”: “bar”,
“key”: “value”,
“action”: “remove”
}

Then, /data/foo/bar contains this:
{
“id”: “bar”,
“key”: “value”
}

Of course, creating a data bag item with the “action” key using knife works
fine; I patched the gem to add some logging, and what I found out is that
knife sends this body:
{
“name”: “data_bag_item_foo_bar”,
“json_class”: “Chef::DataBagItem”,
“chef_type”: “data_bag_item”,
“data_bag”: “foo”,
“raw_data”: {
“id”: “bar”,
“key”: “value”,
“action”: “remove”
}
}

I couldn’t find any mention of this behavior on the Chef documentation.

I’d be happy to go on and implement my code to act as knife does, but I
need to know if this is a well known, stable thing or just a temporary
glitch.

Any clues?

pietro

Chef wraps the body of data bag items in an envelope of sorts.

If you look at Chef::DatabagItem's self.json_create method, you can see
what it does to transform what you read from disk. This pattern is repeated
with other Chef objects like nodes, roles, etc.

HTH!

On Mon, Feb 11, 2013 at 7:07 AM, Pietro Giorgianni <
pietro.giorgianni@zephirworks.com> wrote:

Hi,

I'm manipulating data bag items using the REST API through a custom,
non-ruby client, as documented here:
Chef Infra Server API

When I try to create or update a data bag item containing the key "action"
at the main level, that key is thrown away, and I don't see it in the item.

Here's a gist: Trying to create (or update) a data bag item via Chef REST API (using a non-ruby client), a key `action` gets removed · GitHub

In practice, I post the following JSON to /data/foo
{
"id": "bar",
"key": "value",
"action": "remove"
}

Then, /data/foo/bar contains this:
{
"id": "bar",
"key": "value"
}

Of course, creating a data bag item with the "action" key using knife
works fine; I patched the gem to add some logging, and what I found out is
that knife sends this body:
{
"name": "data_bag_item_foo_bar",
"json_class": "Chef::DataBagItem",
"chef_type": "data_bag_item",
"data_bag": "foo",
"raw_data": {
"id": "bar",
"key": "value",
"action": "remove"
}
}

I couldn't find any mention of this behavior on the Chef documentation.

I'd be happy to go on and implement my code to act as knife does, but I
need to know if this is a well known, stable thing or just a temporary
glitch.

Any clues?

pietro

Thank you Erik, I'll have a look at those methods.

My problem, though, is: is all that "official" and, what matters to me
most, stable? Implementation may change at any time; I'd rather base my own
code on what is public, so that I don't end up having to change my code
every now and then to keep up with private implementations of things.

This doesn't seem to be documented at all (if it is, please throw me a
link), and I spent quite some time debugging my code to find out why it
wasn't working.

pietro

On Mon, Feb 11, 2013 at 5:59 PM, Erik Hollensbe erik@hollensbe.org wrote:

Chef wraps the body of data bag items in an envelope of sorts.

If you look at Chef::DatabagItem's self.json_create method, you can see
what it does to transform what you read from disk. This pattern is repeated
with other Chef objects like nodes, roles, etc.

HTH!

On Mon, Feb 11, 2013 at 7:07 AM, Pietro Giorgianni <
pietro.giorgianni@zephirworks.com> wrote:

Hi,

I'm manipulating data bag items using the REST API through a custom,
non-ruby client, as documented here:
Chef Infra Server API

When I try to create or update a data bag item containing the key
"action" at the main level, that key is thrown away, and I don't see it in
the item.

Here's a gist: Trying to create (or update) a data bag item via Chef REST API (using a non-ruby client), a key `action` gets removed · GitHub

In practice, I post the following JSON to /data/foo
{
"id": "bar",
"key": "value",
"action": "remove"
}

Then, /data/foo/bar contains this:
{
"id": "bar",
"key": "value"
}

Of course, creating a data bag item with the "action" key using knife
works fine; I patched the gem to add some logging, and what I found out is
that knife sends this body:
{
"name": "data_bag_item_foo_bar",
"json_class": "Chef::DataBagItem",
"chef_type": "data_bag_item",
"data_bag": "foo",
"raw_data": {
"id": "bar",
"key": "value",
"action": "remove"
}
}

I couldn't find any mention of this behavior on the Chef documentation.

I'd be happy to go on and implement my code to act as knife does, but I
need to know if this is a well known, stable thing or just a temporary
glitch.

Any clues?

pietro

I opened an issue for this:

http://tickets.opscode.com/browse/CHEF-3866

On Mon, Feb 11, 2013 at 6:18 PM, Pietro Giorgianni <
pietro.giorgianni@zephirworks.com> wrote:

Thank you Erik, I'll have a look at those methods.

My problem, though, is: is all that "official" and, what matters to me
most, stable? Implementation may change at any time; I'd rather base my own
code on what is public, so that I don't end up having to change my code
every now and then to keep up with private implementations of things.

This doesn't seem to be documented at all (if it is, please throw me a
link), and I spent quite some time debugging my code to find out why it
wasn't working.

pietro

On Mon, Feb 11, 2013 at 5:59 PM, Erik Hollensbe erik@hollensbe.orgwrote:

Chef wraps the body of data bag items in an envelope of sorts.

If you look at Chef::DatabagItem's self.json_create method, you can see
what it does to transform what you read from disk. This pattern is repeated
with other Chef objects like nodes, roles, etc.

HTH!

On Mon, Feb 11, 2013 at 7:07 AM, Pietro Giorgianni <
pietro.giorgianni@zephirworks.com> wrote:

Hi,

I'm manipulating data bag items using the REST API through a custom,
non-ruby client, as documented here:
http://docs.opscode.com/api_chef_server.html

When I try to create or update a data bag item containing the key
"action" at the main level, that key is thrown away, and I don't see it in
the item.

Here's a gist: Trying to create (or update) a data bag item via Chef REST API (using a non-ruby client), a key `action` gets removed · GitHub

In practice, I post the following JSON to /data/foo
{
"id": "bar",
"key": "value",
"action": "remove"
}

Then, /data/foo/bar contains this:
{
"id": "bar",
"key": "value"
}

Of course, creating a data bag item with the "action" key using knife
works fine; I patched the gem to add some logging, and what I found out is
that knife sends this body:
{
"name": "data_bag_item_foo_bar",
"json_class": "Chef::DataBagItem",
"chef_type": "data_bag_item",
"data_bag": "foo",
"raw_data": {
"id": "bar",
"key": "value",
"action": "remove"
}
}

I couldn't find any mention of this behavior on the Chef documentation.

I'd be happy to go on and implement my code to act as knife does, but I
need to know if this is a well known, stable thing or just a temporary
glitch.

Any clues?

pietro