chef-boneyard/chef-api

`update` method in Resource::Group cannot update resouces.

Opened this issue · 0 comments

Description

update method in Resource::Group cannot update resouces.

ChefDK Version

I don't use chefdk when I reproduce this issue.
I use chef-api gem version 0.10.7.

Platform Version

  • macOS High Sierra(10.13.6/17G11023)
  • chef-api 0.10.7

Replication Case

This issue seems like that difference schema between GET and PUT is caused.
GET /organizations/NAME/groups/GROUP_NAME: https://docs.chef.io/api_chef_server/#get-36
PUT /organizations/NAME/groups/GROUP_NAME: https://docs.chef.io/api_chef_server/#put-9

GET endpoint returns actors, users, clients and groups on root. However PUT endpoint require actors nested users, clients and groups.

I wrote the following verification code.

require 'chef-api'

con = ChefAPI::Connection.new(
    client: 'pivotal',
    endpoint: 'https://<my_chef_server>/organizations/<my_org>',
    flavor: :enterprise,
    key: './pivotal.pem'
)

# Match schema of `GET` endpoint
p con.groups.update('admins', groups: ['test_group'])
p con.groups.fetch('admins')

# Match schema of `PUT` endpoint
p con.groups.update('admins', {actors: {groups: ['test_group']}})
p con.groups.fetch('admins')

The output of this code is following. But, test_groups does not belong to admins group after updating.

#<Resource::Group groupname: "admins", name: "admins", orgname: "<my_org>", actors: ["pivotal", "<my_account>"], users: ["pivotal", "<my_account>"], clients: [], groups: ["test_group"]>
#<Resource::Group groupname: "admins", name: "admins", orgname: "<my_org>", actors: ["pivotal", "<my_account>"], users: ["pivotal", "<my_account>"], clients: [], groups: []>
#<Resource::Group groupname: "admins", name: "admins", orgname: "<my_org>", actors: {:groups=>["test_group"]}, users: ["pivotal", "<my_account>"], clients: [], groups: []>
#<Resource::Group groupname: "admins", name: "admins", orgname: "<my_org>", actors: ["pivotal", "<my_account>"], users: ["pivotal", "<my_account>"], clients: [], groups: []>

Stacktrace

Validation is fixed as #89. So I patched that resources/base.rb#L709 replace false to raise and ran above the verification code.

con.groups.update('admins', {actors: {groups: ['test_group']}}) is correct request, but it was failed validation.

#<Resource::Group groupname: "admins", name: "admins", orgname: "<my_org>", actors: ["pivotal", "<my_account>"], users: ["pivotal", "<my_account>"], clients: [], groups: ["test_group"]>
#<Resource::Group groupname: "admins", name: "admins", orgname: "<my_org>", actors: ["pivotal", "<my_account>"], users: ["pivotal", "<my_account>"], clients: [], groups: []>
Traceback (most recent call last):
	4: from test.rb:15:in `<main>'
	3: from /Users/<my_account>/Workspace/chef-api-test/vendor/bundle/ruby/2.5.0/gems/chef-api-0.10.7/lib/chef-api/resources/base.rb:343:in `update'
	2: from /Users/<my_account>/Workspace/chef-api-test/vendor/bundle/ruby/2.5.0/gems/chef-api-0.10.7/lib/chef-api/resources/base.rb:707:in `save'
	1: from /Users/<my_account>/Workspace/chef-api-test/vendor/bundle/ruby/2.5.0/gems/chef-api-0.10.7/lib/chef-api/resources/base.rb:680:in `save!'
/Users/<my_account>/Workspace/chef-api-test/vendor/bundle/ruby/2.5.0/gems/chef-api-0.10.7/lib/chef-api/resources/base.rb:779:in `validate!': There were errors saving your resource: `actors' must be a kind of [Array] (ChefAPI::Error::InvalidResource)