Upload cookbooks and roles
Uploads cookbooks from a git repository, chef supermarket, or local repository to the pattern manager.
POST /v1/upload/chef
Description
Uploads cookbooks from a git repository, Chef supermarket, or local repository to the pattern manager. Valid sources are the chef supermarket, github.com, gitlab.com, and local repository on the pattern manager file system. To ensure the latest updates are available on your pattern manager, call this API every time there is an update to the cookbooks and roles in your repository.
The pattern manager access token is required to perform this request.
Directory Structure
For cookbooks that are loaded from a git or local repository, it is assumed that they are in a folder named cookbooks. This cookbooks folder can either be at the root directory of your repository or in a folder named Chef that is at the root directory of your repository. Similarly, it is assumed that roles are in a folder named roles, which is either at the root directory of your repository or in a folder named chef within the root directory of your repository.
Directory Structure Example
The following code block depicts an example directory structure:
.
|-- github.ibm.com
|-- example_org
|-- example_repository
|-- chef
|-- cookbooks
|-- README.md
|-- attributes.json
|-- components.json
|-- cookbook_metadata.json
|-- metadata.rb
|-- recipes.json
|-- roles
|-- create_user.json
|-- database_v10_install.json
|-- database_v15_install.json
Parameters
The following table lists the parameters that are used to upload cookbooks and roles to the pattern manager:
Type | Name | Description | Schema | Default | Required |
---|---|---|---|---|---|
Body | authorization | JSON object containing a personal_access_token property | JSON object | Yes for git repository | |
Body | cookbook_name | Name of the cookbook to load when uploading from the chef supermarket. Only valid when setting source_repos to chef_supermarket | String | Yes, when using chef supermarket | |
Body | cookbook_version | Version of the cookbook to load when uploading from the chef supermarket. Only valid when setting source_repos to chef_supermarket | String | No | |
Body | deps | JSON array of dependencies required for the cookbook being installed from the chef supermarket. Each item must contain the cookbook_name and an optional cookbook_version parameter. Only valid when setting source_repos to chef_supermarket | JSON array | No | |
Body | personal_access_token | GitHub personal access token | String | Yes for git repository | |
Body | cookbooks | States whether cookbooks should be uploaded | Boolean | True | No |
Body | org | Organization where your repositories reside. For GitLab, this is your group name | String | Yes for git repository | |
Body | branch | GitHub branch for your repositories | String | master | No |
Body | repos | For git or local repositories, the regular expression to filter repositories (GitHub) or projects (GitLab) where you want to search for cookbooks and roles | String | .* | No |
Body | repos_hostname | The hostname or IP address of your git repository if it does not match the value in source_repos | String | Value of source_repos | No |
Body | repos_protocol | The protocol (http or https) used by your git repository | String | https | No |
Body | roles | States whether roles should be uploaded | Boolean | False when source_repos is set to chef_supermarket, True otherwise | No |
Body | source_repos | Hostname of the git repository. Valid options include chef_supermarket, github.com, gitlab.com, or a path to your local repository in file URI scheme. | String | Yes |
Example
The following example shows the request that would be used to import all cookbooks and roles from the preceding example directory structure.
POST /v1/upload/chef
Header: Authorization = Bearer $ACCESS_TOKEN
{
"authorization": {
"personal_access_token": "38eab5732f7411bedb976afcc90a25432d798bda"
},
"cookbooks": "True",
"source_repos": "github.com",
"org": "example_org",
"repos": "example_.*",
"roles": "True"
}
This example shows a request to import from a GitLab repository that is hosted somewhere other than the gitlab.com. The value specified for org is the GitLab group name and the repos regular expression will filter projects belonging to that group.
POST /v1/upload/chef
Header: Authorization = Bearer $ACCESS_TOKEN
{
"authorization": {
"personal_access_token": "7411bedb9738eab5732f6afc32d798bdac90a254"
},
"cookbooks": "True",
"source_repos": "gitlab.com",
"org": "production_group",
"repos": "cookbooks_.*",
"roles": "True",
"repos_hostname": "gitlab-pc.ibm.com",
"protocol": "http"
}
This example shows a request to import the Java cookbook from the chef supermarket. The Java cookbook is dependent on the four other cookbooks listed in the deps
parameter. If a cookbook in the dep
array already exists
on the Chef server and the overwrite_existing
parameter is set to true, then it gets overwritten.
POST /v1/upload/chef
Header: Authorization = Bearer $ACCESS_TOKEN
{
"cookbook_name": "java",
"cookbook_version": "1.50.0",
"source_repos": "chef_supermarket",
"deps": [
{
"cookbook_name": "apt",
"cookbook_version": "6.1.4"
},
{
"cookbook_name": "homebrew",
"overwrite_existing": "true"
},
{
"cookbook_name": "windows"
},
{
"cookbook_name": "ohai"
}
]
}
This example shows a request to import cookbooks and roles from the pattern manager local filesystem.
POST /v1/upload/chef
Header: Authorization = Bearer $ACCESS_TOKEN
{
"cookbooks": "True",
"roles": "True",
"source_repos": "file:///var/local_repo"
}
Responses
The following table lists responses that are returned for a request to upload cookbooks and roles to the pattern manager:
HTTP Code | Description | Schema |
---|---|---|
200 | OK | No content |
400 | Bad Request | |
403 | The requester has not specified the correct access token in the Authorization HTTP header | |
500 | Internal server error |