-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from go-chef/master
Merging changes from the upstream project
- Loading branch information
Showing
129 changed files
with
4,147 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Golang CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-go/ for more details | ||
version: 2 | ||
workflows: | ||
version: 2 | ||
merge-to-master: | ||
jobs: | ||
- tester | ||
- update_tag: | ||
requires: | ||
- tester | ||
filters: | ||
branches: | ||
only: /master/ | ||
jobs: | ||
update_tag: | ||
docker: | ||
- image: circleci/golang:1.13.1 | ||
working_directory: /go/src/github.com/go-chef/chefi | ||
steps: | ||
- add_ssh_keys: | ||
fingerprints: | ||
- ${TAG_TOKEN} | ||
- checkout | ||
- run: curl -s https://api.github.com/repos/pantheon-systems/autotag/releases/latest | grep browser_download | grep Linux | cut -d '"' -f 4 | xargs curl -o ./autotag -L && chmod 755 ./autotag | ||
- run: ./autotag | ||
- run: git push --tags origin | ||
tester: | ||
docker: | ||
- image: circleci/golang:1.9 | ||
#### TEMPLATE_NOTE: go expects specific checkout path representing url | ||
#### expecting it in the form of | ||
#### /go/src/github.com/circleci/go-tool | ||
#### /go/src/bitbucket.org/circleci/go-tool | ||
working_directory: /go/src/github.com/go-chef/chef | ||
steps: | ||
- add_ssh_keys: | ||
fingerprints: | ||
- 35:v45:41:ba:cf:3f:7f:d5:00:0f:11:6b:4d:c0:a1:90 | ||
- checkout | ||
# specify any bash command here prefixed with `run: ` | ||
- run: pwd | ||
- run: env | ||
- run: ls -Rl | ||
- run: go get | ||
- run: go get github.com/ctdk/goiardi/chefcrypto | ||
- run: go get github.com/r3labs/diff | ||
- run: go get github.com/smartystreets/goconvey/convey | ||
- run: go get github.com/stretchr/testify/assert | ||
- run: go vet | ||
- run: go test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ _testmain.go | |
|
||
# vim | ||
*.swp | ||
|
||
# cookbook | ||
*.kitchen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package chef | ||
|
||
// import "fmt" | ||
import "errors" | ||
|
||
type AssociationService struct { | ||
client *Client | ||
} | ||
|
||
// Chef API docs: https://docs.chef.io/api_chef_server.html#association-requests | ||
// https://github.com/chef/chef-server/blob/master/src/oc_erchef/apps/oc_chef_wm/src/oc_chef_wm_org_invites.erl Invitation implementation | ||
// https://github.com/chef/chef-server/blob/master/src/oc_erchef/apps/oc_chef_wm/src/oc_chef_wm_org_associations.erl user org associations | ||
|
||
// Association represents the response from creating an invitation to join an organization | ||
// POST /organization/NAME/association_requests | ||
type Association struct { | ||
Uri string `json:"uri"` // the last part of the uri is the invitation id | ||
OrganizationUser struct { | ||
UserName string `json:"username,omitempty"` | ||
} `json:"organization_user"` | ||
Organization struct { | ||
Name string `json:"name,omitempty"` | ||
} `json:"organization"` | ||
User struct { | ||
Email string `json:"email,omitempty"` | ||
FirstName string `json:"first_name,omitempty"` | ||
} `json:"user"` | ||
} | ||
|
||
// RescindInvite respresents the response from deleting an invitation | ||
// DELETE /organization/NAME/association_requests/ID | ||
type RescindInvite struct { | ||
Id string `json:"id,omitempty"` | ||
Orgname string `json:"orgname,omitempty"` | ||
Username string `json:"username,omitempty"` | ||
} | ||
|
||
// Invite represents an entry in the array of responses listing the outstanding invitations | ||
// GET /organization/NAME/association_requests | ||
type Invite struct { | ||
Id string `json:"id,omitempty"` | ||
UserName string `json:"username,omitempty"` | ||
} | ||
|
||
// Request represents the body of the request to invite a user to an organization | ||
// POST /organization/NAME/association_requests | ||
type Request struct { | ||
User string `json:"user"` | ||
} | ||
|
||
// AddNow represents the body of the request to add a user to an organization | ||
// POST /organization/NAME/users | ||
type AddNow struct { | ||
Username string `json:"username"` | ||
} | ||
|
||
// Invite represents an entry in the array of responses listing the users in an organization | ||
// GET /organization/NAME/association_requests | ||
type OrgUserListEntry struct { | ||
User struct { | ||
Username string `json:"username,omitempty"` | ||
} `json:"user,omitempty"` | ||
} | ||
|
||
// OrgUser represents the detailed information about a user in an organization | ||
// GET /organization/NAME/user/NAME | ||
// DELETE /organization/NAME/user/NAME | ||
type OrgUser struct { | ||
Username string `json:"username,omitempty"` | ||
Email string `json:"email,omitempty"` | ||
DisplayName string `json:"display_name,omitempty"` | ||
FirstName string `json:"first_name,omitempty"` | ||
LastName string `json:"last_name,omitempty"` | ||
PublicKey string `json:"public_key,omitempty"` | ||
} | ||
|
||
// ListInvites gets a list of the pending invitations for an organization. | ||
func (e *AssociationService) ListInvites() (invitelist []Invite, err error) { | ||
err = e.client.magicRequestDecoder("GET", "association_requests", nil, &invitelist) | ||
return | ||
} | ||
|
||
// Invite creates an invitation for a user to join an organization on the chef server | ||
func (e *AssociationService) Invite(invite Request) (data Association, err error) { | ||
body, err := JSONReader(invite) | ||
if err != nil { | ||
return | ||
} | ||
err = e.client.magicRequestDecoder("POST", "association_requests/", body, &data) | ||
return | ||
} | ||
|
||
// DeleteInvite removes a pending invitation to an organization | ||
func (e *AssociationService) DeleteInvite(id string) (rescind RescindInvite, err error) { | ||
err = e.client.magicRequestDecoder("DELETE", "association_requests/"+id, nil, &rescind) | ||
return | ||
} | ||
|
||
// InviteID Finds an invitation id for a user | ||
func (e *AssociationService) InviteId(user string) (id string, err error) { | ||
var invitelist []Invite | ||
err = e.client.magicRequestDecoder("GET", "association_requests", nil, &invitelist) | ||
if err != nil { | ||
return | ||
} | ||
// Find an invite for the user or return err | ||
for _, in := range invitelist { | ||
if in.UserName == user { | ||
id = in.Id | ||
} | ||
} | ||
if id == "" { | ||
err = errors.New("User request not found") | ||
} | ||
return | ||
} | ||
|
||
// AcceptInvite Accepts an invitation | ||
// TODO: Gets a 405, code is in knife is it part of erchef? | ||
func (e *AssociationService) AcceptInvite(id string) (data string, err error) { | ||
body, err := JSONReader("{ \"accept\" }") | ||
if err != nil { | ||
return | ||
} | ||
err = e.client.magicRequestDecoder("PUT", "association_requests/"+id, body, &data) | ||
return | ||
} | ||
|
||
// List gets a list of the users in an organization | ||
func (e *AssociationService) List() (data []OrgUserListEntry, err error) { | ||
err = e.client.magicRequestDecoder("GET", "users", nil, &data) | ||
return | ||
} | ||
|
||
// Add a user immediately | ||
func (e *AssociationService) Add(addme AddNow) (err error) { | ||
body, err := JSONReader(addme) | ||
if err != nil { | ||
return | ||
} | ||
err = e.client.magicRequestDecoder("POST", "users", body, nil) | ||
return | ||
} | ||
|
||
// Get the details of a user in an organization | ||
func (e *AssociationService) Get(name string) (data OrgUser, err error) { | ||
err = e.client.magicRequestDecoder("GET", "users/"+name, nil, &data) | ||
return | ||
} | ||
|
||
// Delete removes a user from an organization | ||
func (e *AssociationService) Delete(name string) (data OrgUser, err error) { | ||
err = e.client.magicRequestDecoder("DELETE", "users/"+name, nil, &data) | ||
return | ||
} |
Oops, something went wrong.