class Chef

DEPRECATION NOTE

This code will be removed in Chef 13 in favor of the code in Chef::ApiClientV1, which will be moved to this namespace. New development should occur in Chef::ApiClientV1 until the time before Chef 13.

COMPATIBILITY NOTE

This ApiClientV1 code attempts to make API V1 requests and falls back to API V0 requests when it fails. New development should occur here instead of Chef::ApiClient as this will replace that namespace when Chef 13 is released.

If you need to default to API V0 behavior (i.e. you need GET client to return a public key, etc), please use Chef::ApiClient and update your code to support API V1 before you pull in Chef 13.

Author

Steven Murawski (<smurawski@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

ChefFS was designed to be a near-1:1 translation between Chef server endpoints and local data, so that it could be used for:

  1. User editing, diffing and viewing of server content locally

  2. knife download, upload and diff (supporting the above scenario)

  3. chef-client -z (serving user repository directly)

This is the translation between chef-zero data stores (which correspond closely to server endpoints) and the ChefFS repository format.

|———————————–|———————————–| | chef-zero DataStore | ChefFS (repository) | |———————————–|———————————–| | <root> | org.json | | association_requests/NAME | invitations.json | | clients/NAME | clients/NAME.json | | cookbooks/NAME/VERSION | cookbooks/NAME/metadata.rb | | containers/NAME | containers/NAME.json | | data/BAG/ITEM | data_bags/BAG/ITEM.json | | environments/NAME | environments/NAME.json | | groups/NAME | groups/NAME.json | | nodes/NAME | nodes/NAME.json | | policies/NAME/REVISION | policies/NAME-REVISION.json | | policy_groups/NAME/policies/PNAME | policy_groups/NAME.json | | roles/NAME | roles/NAME.json | | sandboxes/ID | <not stored on disk, just memory> | | users/NAME | members.json | | file_store/COOKBOOK/VERSION/PATH | cookbooks/COOKBOOK/PATH | | **/_acl | acls/**.json | |———————————–|———————————–|

## The Code

There are two main entry points to ChefFS:

Because these two map to a common directory structure, diff, upload, download, and other filesystem operations, can easily be done in a generic manner.

These are instantiated by Chef::ChefFS::Config's `chef_fs` and `local_fs` methods.

Author

Thom May (<thom@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This class implements an InSpec fetcher for Chef Server. The implementation is based on the Chef Compliance fetcher and only adapts the calls to redirect the requests via Chef Server.

This implementation depends on chef-client runtime, therefore it is only executable inside of a chef-client run

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

John Keiser <jkeiser@chef.io>

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Daniel DeLeo (<dan@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Christopher Walters (<cw@chef.io>)

Author

Tim Hinderliter (<tim@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

John Keiser <jkeiser@chef.io>

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Structured deprecations have a unique URL associated with them, which must exist before the deprecation is merged.

Author

Serdar Sutay (<serdar@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

John Keiser (<jkeiser@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Helper functions to access the windows registry from within recipes and the not_if/only_if blocks in resources. This only exposes the methods in the chef/win32/registry class which are reasonably side-effect-free. The actual modification of the registry should be done via the registry_key resource in a more idempotent way.

imported from github.com/chef-cookbooks/habitat

Author

Lamont Granquist (<lamont@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

PURPOSE: This strategy preserves the inode, and will preserve modes + ownership

even if the user running chef cannot create that ownership (but has
rights to the file).  It is vulnerable to crashes in the middle of
writing the file which could result in corruption or zero-length files.
Author

Lamont Granquist (<lamont@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Tyler Cloke (tyler@chef.io)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Adam Jacob (<adam@chef.io>)

Author

Christopher Walters (<cw@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Adam Jacob (<adam@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Adam Jacob (<adam@chef.io>)

Author

Steve Midgley (www.misuse.org/science)

Copyright

Copyright © Chef Software Inc.

Copyright

Copyright 2008-2016, Steve Midgley

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Daniel DeLeo (<dan@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This is lifted from rails activesupport (note the copyright above): github.com/rails/rails/blob/9f84e60ac9d7bf07d6ae1bc94f3941f5b8f1a228/activesupport/lib/active_support/descendants_tracker.rb

Author

Mark Mzyk <mmzyk@chef.io>

Author

Seth Chisamore <schisamo@chef.io>

Author

Bryan McLellan <btm@chef.io>

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Adam Jacob (<adam@chef.io>)

Author

Christopher Walters (<cw@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

mixin to make this syntax work without specifying a source:

gem_package “/tmp/foo-x.y.z.gem” rpm_package “/tmp/foo-x.y-z.rpm” dpkg_package “/tmp/foo-x.y.z.deb”

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The powershell_exec mixin provides in-process access to the PowerShell engine.

powershell_exec is initialized with a string that should be set to the script to run and also takes an optional interpreter argument which must be either :powershell (Windows PowerShell which is the default) or :pwsh (PowerShell Core). It will return a Chef::PowerShell object that provides 5 methods:

.result - returns a hash representing the results returned by executing the

PowerShell script block

.verbose - this is an array of string containing any messages written to the

PowerShell verbose stream during execution

.errors - this is an array of string containing any messages written to the

PowerShell error stream during execution

.error? - returns true if there were error messages written to the PowerShell

error stream during execution

.error! - raise Chef::PowerShell::CommandFailed if there was an error

Some examples of usage:

> powershell_exec(“(Get-Item c:\windows\system32\w32time.dll).VersionInfo”

 ).result["FileVersion"]
=> "10.0.14393.0 (rs1_release.160715-1616)"

> powershell_exec(“(get-process ruby).Mainmodule”).result

=> C:\\opscode\\chef\\embedded\\bin\\ruby.exe"

> powershell_exec(“$a = $true; $a”).result

=> true

> powershell_exec(“$PSVersionTable”, :pwsh).result

=> "Core"

> powershell_exec(“not-found”).errors

=> ["ObjectNotFound: (not-found:String) [], CommandNotFoundException: The
term 'not-found' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again. (at <ScriptBlock>,
 <No file>: line 1)"]

> powershell_exec(“not-found”).error?

=> true

> powershell_exec(“get-item c:\notfound -erroraction stop”) WIN32OLERuntimeError: (in OLE method `ExecuteScript': )

OLE error code:80131501 in System.Management.Automation
  The running command stopped because the preference variable
  "ErrorActionPreference" or common parameter is set to Stop: Cannot find
  path 'C:\notfound' because it does not exist.

*Why use this and not powershell_out?* Startup time to invoke the PowerShell engine is much faster (over 7X faster in tests) than writing the PowerShell to disk, shelling out to powershell.exe and retrieving the .stdout or .stderr methods afterwards. Additionally we are able to have a higher fidelity conversation with PowerShell because we are now working with the objects that are returned by the script, rather than having to parse the stdout of powershell.exe to get a result.

*How does this work?* In .NET terms, when you run a PowerShell script block through the engine, behind the scenes you get a Collection<PSObject> returned and simply we are serializing this, adding any errors that were generated to a custom JSON string transferred in memory to Ruby. The easiest way to develop for this approach is to imagine that the last thing that happens in your PowerShell script block is “ConvertTo-Json”. That's exactly what we are doing here behind the scenes.

There are a handful of current limitations with this approach:

Author

Adam Edwards (<adamed@chef.io>)

Author

Jay Mundrawala (<jdm@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Seth Chisamore (<schisamo@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Adam Jacob (<adam@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Jay Mundrawala (<jdm@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Dan DeLeo ( <dan@chef.io> )

Author

Marc Paradise ( <marc@chef.io> )

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Jay Mundrawala(<jdm@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Daniel DeLeo (<dan@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The Tao of File Providers:

- the content provider must always return a tempfile that we can delete/mv
- do_create_file shall always create the file first and obey umask when perms are not specified
- do_contents_changes may assume the destination file exists (simplifies exception checking,
  and always gives us something to diff against)
- do_contents_changes must restore the perms to the dest file and not obliterate them with
  random tempfile permissions
- do_acl_changes may assume perms were not modified between lcr and when it runs (although the
  file may have been created)
Author

Dreamcat4 (<dreamcat4@gmail.com>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

AJ Christensen (<aj@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Dan Crosta (<dcrosta@late.am>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Stephen Haynes (<sh@nomitor.com>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Thom May (<thom@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Bring in needed shared methods

BUGGY AND DEPRECATED: This ruby code is known to not match the python implementation for version comparisons. The APIs here should probably be converted to talk to the PythonHelper or just abandoned completely.

e.g. this should just use Chef::Provider::Package::Yum::PythonHelper.instance.compare_versions(x,y)

The python_helper could be extended to support additional APIs in here to remove the ruby code entirely.

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

These are largely historical APIs, the YumCache object no longer exists and this is a facade over the python helper class. It should be considered deprecated-lite and no new APIs should be added and should be added to the python_helper instead.

Author

Jesse Campbell (<hikeit@gmail.com>)

Author

Lamont Granquist (<lamont@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Adam Jacob (<adam@chef.io>)

Author

AJ Christensen (<aj@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Phil Dibowitz (<phild@fb.com>)

Copyright

Copyright 2013-2016, Facebook

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Matt Wrock (<mwrock@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Xabier de Zuazo (<xabier@onddo.com>)

Copyright

Copyright 2013-2016, Onddo Labs, SL.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Antony Thomas (<antonydeepak@gmail.com>)

Copyright

Copyright © Facebook, Inc. and its affiliates.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Adam Jacob (<adam@chef.io>)

Author

Tyler Cloke (<tyler@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Phil Dibowitz (<phild@fb.com>)

Copyright

Copyright 2013-2016, Facebook

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

John McCrae (<jmccrae@chef.io>)

Author

Davin Taddeo (<davin@chef.io>)

Copyright

Copyright © Chef Software Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Matt Clifton (spartacus003@hotmail.com)

Author

Matt Stratton (matt.stratton@gmail.com)

Author

Tor Magnus Rakvåg (tor.magnus@outlook.com)

Author

Tim Smith (tsmith@chef.io)

Copyright

2013-2015 Matt Clifton

Copyright

Copyright © Chef Software Inc.

Copyright

2018, Intility AS

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

NOTE: this was extracted from the Recipe DSL mixin, relevant specs are in spec/unit/recipe_spec.rb

ResourceCollection currently handles two tasks: 1) Keeps an ordered list of resources to use when converging the node 2) Keeps a unique list of resources (keyed as `type`) used for notifications

This class keeps the list of all known Resources in the order they are to be executed in. It also keeps a pointer to the most recently executed resource so we can add resources-to-execute after this point.

Author

Daniel DeLeo (<dan@kallistec.com>)

Copyright

Copyright 2009-2016, Daniel DeLeo

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Daniel DeLeo (<dan@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Why does this class exist? Why did we not just modify RunList/RunListItem?

TODO DEPRECATION NOTE This class will be replaced by Chef::UserV1 in Chef 13. It is the code to support the User object corresponding to the Open Source Chef Server 11 and only still exists to support users still on OSC 11.

Chef::UserV1 now supports Chef Server 12 and will be moved to this namespace in Chef 13.

New development should occur in Chef::UserV1. This file and corresponding osc_user knife files should be removed once client support for Open Source Chef Server 11 expires.

OSC 11 BACKWARDS COMPATIBILITY NOTE (remove after OSC 11 support ends)

In general, Chef::UserV1 is no longer expected to support Open Source Chef 11 Server requests. The object that handles those requests remain in the Chef::User namespace. This code will be moved to the Chef::User namespace as of Chef 13.

Exception: self.list is backwards compatible with OSC 11

Author

Lamont Granquist (<lamont@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Some portions of this file are derived from material in the diff-lcs project licensed under the terms of the MIT license, provided below.

Copyright

Copyright 2004-2016, Austin Ziegler

License

MIT

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of this Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OTHER DEALINGS IN THE SOFTWARE.

Author

Chris Bandy (<bandy.chris@gmail.com>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

Doug MacEachern (<dougm@vmware.com>)

Copyright

Copyright 2010-2016, VMware, Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

this strictly wants x, x.y, or x.y.z version constraints in the target and will fail hard if it does not match. the semantics that we need here is that it must always do the best job that it can do and consume as much of the offered version as it can. since we accept arbitrarily parsed strings into node out of dozens or potentially hundreds of operating systems this parsing code needs to be fixed to never raise. the Gem::Version class is a better model, and in fact it might be a substantially better approach to base this class on Gem::Version and then do pre-mangling of things like windows version strings via e.g. `.gsub(/R/, '.')`. the raising behavior of this parser however, breaks the ProviderResolver in a not just buggy but a “completely unfit for purpose” way.

TL;DR: MUST follow the second part of “Be conservative in what you send, be liberal in what you accept”

Author

Seth Falcon (<seth@chef.io>)

Author

Christopher Walters (<cw@chef.io>)

Copyright

Copyright © Chef Software Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

NOTE: this is fairly badly broken for its purpose and should not be used

unless it gets fixed.  see chef/version/platform.

Constants

CHEF_ROOT
Config
NOT_PASSED
VERSION
VersionString
Win32EventLogLoaded
WorkstationConfigLoader

Attributes

node[R]

Get the node object

@return [Chef::Node] node object of the chef-client run

run_context[R]

Get the run context

@return [Chef::RunContext] run_context of the chef-client run

Public Class Methods

deprecated(type, message, location = nil) click to toggle source

Emit a deprecation message.

@param type [Symbol] The message to send. This should refer to a class

defined in Chef::Deprecated

@param message [String, nil] An explicit message to display, rather than

the generic one associated with the deprecation.

@param location [String, nil] The location. Defaults to the caller who

called you (since generally the person who triggered the check is the one
that needs to be fixed).

@return [void]

@example

Chef.deprecated(:my_deprecation, message: "This is deprecated!")

@api private this will likely be removed in favor of an as-yet unwritten

`Chef.log`
# File lib/chef/chef_class.rb, line 216
def deprecated(type, message, location = nil)
  location ||= Chef::Log.caller_location
  deprecation = Chef::Deprecated.create(type, message, location)
  # `run_context.events` is the primary deprecation target if we're in a
  # run. If we are not yet in a run, print to `Chef::Log`.
  if run_context && run_context.events
    run_context.events.deprecation(deprecation, location)
  elsif !deprecation.silenced?
    Chef::Log.deprecation(deprecation.to_s)
  end
end
event_handler(&block) click to toggle source

Register an event handler with user specified block

@return handler object

# File lib/chef/chef_class.rb, line 60
def event_handler(&block)
  dsl = Chef::EventDispatch::DSL.new("Chef client DSL")
  dsl.instance_eval(&block)
end
get_provider_priority_array(resource_name) click to toggle source

Get the array of providers associated with a resource_name for the current node

@param resource_name [Symbol] name of the resource as a symbol

@return [Array<Class>] Priority Array of Provider Classes to use for the resource_name on the node

# File lib/chef/chef_class.rb, line 71
def get_provider_priority_array(resource_name)
  result = provider_priority_map.get_priority_array(node, resource_name.to_sym)
  result = result.dup if result
  result
end
get_resource_priority_array(resource_name) click to toggle source

Get the array of resources associated with a resource_name for the current node

@param resource_name [Symbol] name of the resource as a symbol

@return [Array<Class>] Priority Array of Resource Classes to use for the resource_name on the node

# File lib/chef/chef_class.rb, line 84
def get_resource_priority_array(resource_name)
  result = resource_priority_map.get_priority_array(node, resource_name.to_sym)
  result = result.dup if result
  result
end
log_deprecation(message, location = nil) click to toggle source

Log a generic deprecation warning that doesn't have a specific class in Chef::Deprecated.

This should generally not be used, as the user will not be given a link to get more information on fixing the deprecation warning.

@see deprecated

# File lib/chef/chef_class.rb, line 235
def log_deprecation(message, location = nil)
  location ||= Chef::Log.caller_location
  Chef.deprecated(:generic, message, location)
end
provider_handler_map() click to toggle source

@api private

# File lib/chef/chef_class.rb, line 190
def provider_handler_map
  @provider_handler_map ||= Chef::Platform::ProviderHandlerMap.instance
end
provider_priority_map() click to toggle source

@api private

# File lib/chef/chef_class.rb, line 179
def provider_priority_map
  # these slurp in the resource+provider world, so be exceedingly lazy about requiring them
  @provider_priority_map ||= Chef::Platform::ProviderPriorityMap.instance
end
reset!() click to toggle source

Resets the internal state

@api private

# File lib/chef/chef_class.rb, line 169
def reset!
  @run_context = nil
  @node = nil
  @provider_priority_map = nil
  @resource_priority_map = nil
  @provider_handler_map = nil
  @resource_handler_map = nil
end
resource_handler_map() click to toggle source

@api private

# File lib/chef/chef_class.rb, line 195
def resource_handler_map
  @resource_handler_map ||= Chef::Platform::ResourceHandlerMap.instance
end
resource_priority_map() click to toggle source

@api private

# File lib/chef/chef_class.rb, line 185
def resource_priority_map
  @resource_priority_map ||= Chef::Platform::ResourcePriorityMap.instance
end
set_node(node) click to toggle source

Sets the node object

@api private @param node [Chef::Node]

# File lib/chef/chef_class.rb, line 151
def set_node(node)
  @node = node
end
set_provider_priority_array(resource_name, priority_array, **filter, &block) click to toggle source

Set the array of providers associated with a resource_name for the current node

@param resource_name [Symbol] name of the resource as a symbol @param priority_array [Class, Array<Class>] Class or Array of Classes to set as the priority for resource_name on the node @param filter [Hash] Chef::Nodearray-style filter

@return [Array<Class>] Modified Priority Array of Provider Classes to use for the resource_name on the node

# File lib/chef/chef_class.rb, line 99
def set_provider_priority_array(resource_name, priority_array, **filter, &block)
  result = provider_priority_map.set_priority_array(resource_name.to_sym, priority_array, **filter, &block)
  result = result.dup if result
  result
end
set_provider_priority_map(provider_priority_map) click to toggle source

Sets the provider_priority_map

@param provider_priority_map [Chef::Platform::providerPriorityMap]

@api private

# File lib/chef/chef_class.rb, line 142
def set_provider_priority_map(provider_priority_map)
  @provider_priority_map = provider_priority_map
end
set_resource_priority_array(resource_name, priority_array, **filter, &block) click to toggle source

Get the array of resources associated with a resource_name for the current node

@param resource_name [Symbol] name of the resource as a symbol @param priority_array [Class, Array<Class>] Class or Array of Classes to set as the priority for resource_name on the node @param filter [Hash] Chef::Nodearray-style filter

@return [Array<Class>] Modified Priority Array of Resource Classes to use for the resource_name on the node

# File lib/chef/chef_class.rb, line 114
def set_resource_priority_array(resource_name, priority_array, **filter, &block)
  result = resource_priority_map.set_priority_array(resource_name.to_sym, priority_array, **filter, &block)
  result = result.dup if result
  result
end
set_resource_priority_map(resource_priority_map) click to toggle source

Sets the resource_priority_map

@param resource_priority_map [Chef::Platform::ResourcePriorityMap]

@api private

# File lib/chef/chef_class.rb, line 132
def set_resource_priority_map(resource_priority_map)
  @resource_priority_map = resource_priority_map
end
set_run_context(run_context) click to toggle source

Sets the run_context object

@param run_context [Chef::RunContext]

@api private

# File lib/chef/chef_class.rb, line 161
def set_run_context(run_context)
  @run_context = run_context
end