File: principal.go

package info (click to toggle)
golang-github-go-chef-chef 0.0.1%2Bgit20161023.60.deb8c38-1.2~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 372 kB
  • sloc: sh: 14; makefile: 7
file content (33 lines) | stat: -rw-r--r-- 818 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package chef

import "fmt"

type PrincipalService struct {
	client *Client
}

// Principal represents the native Go version of the deserialized Principal type
type Principal struct {
	Name      string `json:"name"`
	Type      string `json:"type"`
	PublicKey string `json:"public_key"`
	AuthzId   string `json:"authz_id"`
	OrgMember bool   `json:"org_member"`
}

func NewPrincipal(name, typ, publicKey string) Principal {
	return Principal{
		Name:      name,
		Type:      typ,
		PublicKey: publicKey,
	}
}

// Get gets a principal from the Chef server.
//
// Chef API docs: https://docs.chef.io/api_chef_server.html#id64
func (e *PrincipalService) Get(name string) (principal Principal, err error) {
	url := fmt.Sprintf("principals/%s", name)
	err = e.client.magicRequestDecoder("GET", url, nil, &principal)
	return
}