aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/google/go-github/github/authorizations.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/google/go-github/github/authorizations.go')
-rw-r--r--vendor/github.com/google/go-github/github/authorizations.go126
1 files changed, 121 insertions, 5 deletions
diff --git a/vendor/github.com/google/go-github/github/authorizations.go b/vendor/github.com/google/go-github/github/authorizations.go
index cfe6349..58fcc4e 100644
--- a/vendor/github.com/google/go-github/github/authorizations.go
+++ b/vendor/github.com/google/go-github/github/authorizations.go
@@ -35,6 +35,9 @@ const (
ScopeReadPublicKey Scope = "read:public_key"
ScopeWritePublicKey Scope = "write:public_key"
ScopeAdminPublicKey Scope = "admin:public_key"
+ ScopeReadGPGKey Scope = "read:gpg_key"
+ ScopeWriteGPGKey Scope = "write:gpg_key"
+ ScopeAdminGPGKey Scope = "admin:gpg_key"
)
// AuthorizationsService handles communication with the authorization related
@@ -44,9 +47,7 @@ const (
// an OAuth token.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/
-type AuthorizationsService struct {
- client *Client
-}
+type AuthorizationsService service
// Authorization represents an individual GitHub authorization.
type Authorization struct {
@@ -82,6 +83,20 @@ func (a AuthorizationApp) String() string {
return Stringify(a)
}
+// Grant represents an OAuth application that has been granted access to an account.
+type Grant struct {
+ ID *int `json:"id,omitempty"`
+ URL *string `json:"url,omitempty"`
+ App *AuthorizationApp `json:"app,omitempty"`
+ CreatedAt *Timestamp `json:"created_at,omitempty"`
+ UpdatedAt *Timestamp `json:"updated_at,omitempty"`
+ Scopes []string `json:"scopes,omitempty"`
+}
+
+func (g Grant) String() string {
+ return Stringify(g)
+}
+
// AuthorizationRequest represents a request to create an authorization.
type AuthorizationRequest struct {
Scopes []Scope `json:"scopes,omitempty"`
@@ -119,7 +134,7 @@ func (a AuthorizationUpdateRequest) String() string {
// List the authorizations for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
-func (s *AuthorizationsService) List(opt *ListOptions) ([]Authorization, *Response, error) {
+func (s *AuthorizationsService) List(opt *ListOptions) ([]*Authorization, *Response, error) {
u := "authorizations"
u, err := addOptions(u, opt)
if err != nil {
@@ -131,7 +146,7 @@ func (s *AuthorizationsService) List(opt *ListOptions) ([]Authorization, *Respon
return nil, nil, err
}
- auths := new([]Authorization)
+ auths := new([]*Authorization)
resp, err := s.client.Do(req, auths)
if err != nil {
return nil, resp, err
@@ -318,3 +333,104 @@ func (s *AuthorizationsService) Revoke(clientID string, token string) (*Response
return s.client.Do(req, nil)
}
+
+// ListGrants lists the set of OAuth applications that have been granted
+// access to a user's account. This will return one entry for each application
+// that has been granted access to the account, regardless of the number of
+// tokens an application has generated for the user.
+//
+// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#list-your-grants
+func (s *AuthorizationsService) ListGrants() ([]*Grant, *Response, error) {
+ req, err := s.client.NewRequest("GET", "applications/grants", nil)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeOAuthGrantAuthorizationsPreview)
+
+ grants := []*Grant{}
+ resp, err := s.client.Do(req, &grants)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return grants, resp, err
+}
+
+// GetGrant gets a single OAuth application grant.
+//
+// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#get-a-single-grant
+func (s *AuthorizationsService) GetGrant(id int) (*Grant, *Response, error) {
+ u := fmt.Sprintf("applications/grants/%d", id)
+ req, err := s.client.NewRequest("GET", u, nil)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeOAuthGrantAuthorizationsPreview)
+
+ grant := new(Grant)
+ resp, err := s.client.Do(req, grant)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return grant, resp, err
+}
+
+// DeleteGrant deletes an OAuth application grant. Deleting an application's
+// grant will also delete all OAuth tokens associated with the application for
+// the user.
+//
+// GitHub API docs: https://developer.github.com/v3/oauth_authorizations/#delete-a-grant
+func (s *AuthorizationsService) DeleteGrant(id int) (*Response, error) {
+ u := fmt.Sprintf("applications/grants/%d", id)
+ req, err := s.client.NewRequest("DELETE", u, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeOAuthGrantAuthorizationsPreview)
+
+ return s.client.Do(req, nil)
+}
+
+// Create an impersonation OAuth token.
+//
+// This requires admin permissions. With the returned Authorization.Token
+// you can e.g. create or delete a user's public SSH key. NOTE: creating a
+// new token automatically revokes an existing one.
+//
+// GitHub API docs: https://developer.github.com/enterprise/2.5/v3/users/administration/#create-an-impersonation-oauth-token
+func (s *AuthorizationsService) CreateImpersonation(username string, authReq *AuthorizationRequest) (*Authorization, *Response, error) {
+ u := fmt.Sprintf("admin/users/%v/authorizations", username)
+ req, err := s.client.NewRequest("POST", u, authReq)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ a := new(Authorization)
+ resp, err := s.client.Do(req, a)
+ if err != nil {
+ return nil, resp, err
+ }
+ return a, resp, err
+}
+
+// Delete an impersonation OAuth token.
+//
+// NOTE: there can be only one at a time.
+//
+// GitHub API docs: https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-an-impersonation-oauth-token
+func (s *AuthorizationsService) DeleteImpersonation(username string) (*Response, error) {
+ u := fmt.Sprintf("admin/users/%v/authorizations", username)
+ req, err := s.client.NewRequest("DELETE", u, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ return s.client.Do(req, nil)
+}