github.com/go-chef/chef@v0.30.1/cookbook_artifacts.go (about)

     1  package chef
     2  
     3  import "fmt"
     4  
     5  // CBAService  is the service for interacting with chef server cookbook_artifacts endpoint
     6  type CBAService struct {
     7  	client *Client
     8  }
     9  
    10  // CBAGetResponse is returned from the chef-server for Get Requests to /cookbook_artifacts
    11  type CBAGetResponse map[string]CBA
    12  type CBA struct {
    13  	Url         string       `json:"url,omitempty"`
    14  	CBAVersions []CBAVersion `json:"versions,omitempty"`
    15  }
    16  type CBAVersion struct {
    17  	Url        string `json:"url,omitempty"`
    18  	Identifier string `json:"identifier,omitempty"`
    19  }
    20  
    21  // CBADetail represents the detail for a specific cookbook_artifact
    22  type CBADetail struct {
    23  	Version     string         `json:"version"`
    24  	Name        string         `json:"name"`
    25  	Identifier  string         `json:"identifier"`
    26  	RootFiles   []CookbookItem `json:"root_files,omitempty"`
    27  	Providers   []CookbookItem `json:"providers,omitempty"`
    28  	Resources   []CookbookItem `json:"resources,omitempty"`
    29  	Libraries   []CookbookItem `json:"libraries,omitempty"`
    30  	Attributes  []CookbookItem `json:"attributes,omitempty"`
    31  	Recipes     []CookbookItem `json:"recipes,omitempty"`
    32  	Definitions []CookbookItem `json:"definitions,omitempty"`
    33  	Files       []CookbookItem `json:"files,omitempty"`
    34  	Templates   []CookbookItem `json:"templates,omitempty"`
    35  	Frozen      bool           `json:"frozen?,omitempty"`
    36  	ChefType    string         `json:"chef_type,omitempty"`
    37  	Metadata    CBAMeta        `json:"metadata,omitempty"`
    38  }
    39  
    40  // CBAMeta represents the cookbook_artifacts metadata information
    41  type CBAMeta struct {
    42  	Name            string                 `json:"name,omitempty"`
    43  	Version         string                 `json:"version,omitempty"`
    44  	Description     string                 `json:"description,omitempty"`
    45  	LongDescription string                 `json:"long_description,omitempty"`
    46  	Maintainer      string                 `json:"maintainer,omitempty"`
    47  	MaintainerEmail string                 `json:"maintainer_email,omitempty"`
    48  	License         string                 `json:"license,omitempty"`
    49  	Platforms       map[string]string      `json:"platforms,omitempty"`
    50  	Depends         map[string]string      `json:"dependencies,omitempty"`
    51  	Reccomends      map[string]string      `json:"recommendations,omitempty"`
    52  	Suggests        map[string]string      `json:"suggestions,omitempty"`
    53  	Conflicts       map[string]string      `json:"conflicting,omitempty"`
    54  	Provides        map[string]string      `json:"providing,omitempty"`
    55  	Replaces        map[string]string      `json:"replacing,omitempty"`
    56  	Attributes      map[string]interface{} `json:"attributes,omitempty"`
    57  	Groupings       map[string]interface{} `json:"groupings,omitempty"`
    58  	Recipes         map[string]string      `json:"recipes,omitempty"`
    59  	SourceURL       string                 `json:"source_url,omitempty"`
    60  	IssuesURL       string                 `json:"issues_url,omitempty"`
    61  	Privacy         bool                   `json:"privacy,omitempty"`
    62  	ChefVersions    [][]string             `json:"chef_versions,omitempty"`
    63  	OhaiVersions    []string               `json:"ohai_versions,omitempty"`
    64  	Gems            [][]string             `json:"gems,omitempty"`
    65  }
    66  
    67  // List lists the Cookbook_Artifacts in the Chef server.
    68  //
    69  //	GET /cookbook_artifacts
    70  func (c *CBAService) List() (data CBAGetResponse, err error) {
    71  	err = c.client.magicRequestDecoder("GET", "cookbook_artifacts", nil, &data)
    72  	return
    73  }
    74  
    75  // Get returns details for a specific cookbook artifact
    76  //
    77  //	GET /cookbook_artifacts/name
    78  func (c *CBAService) Get(name string) (data CBAGetResponse, err error) {
    79  	path := fmt.Sprintf("cookbook_artifacts/%s", name)
    80  	err = c.client.magicRequestDecoder("GET", path, nil, &data)
    81  	return
    82  }
    83  
    84  // GetVersion fetches a specific version of a cookbook_artifact from the server api
    85  //
    86  //	GET /cookbook_artifacts/foo/1ef062de1bc4cb14e4a78fb739e104eb9508473e
    87  func (c *CBAService) GetVersion(name, id string) (data CBADetail, err error) {
    88  	url := fmt.Sprintf("cookbook_artifacts/%s/%s", name, id)
    89  	err = c.client.magicRequestDecoder("GET", url, nil, &data)
    90  	return
    91  }