[chef] Re: Re: REST API, data bag items and the "action" key


Chronological Thread 
  • From: Pietro Giorgianni < >
  • To: chef < >
  • Subject: [chef] Re: Re: REST API, data bag items and the "action" key
  • Date: Tue, 12 Feb 2013 09:55:25 +0100

I opened an issue for this:



On Mon, Feb 11, 2013 at 6:18 PM, Pietro Giorgianni < " target="_blank"> > 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 < " target="_blank"> > 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 < " target="_blank"> > 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.



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






Archive powered by MHonArc 2.6.16.

§