-
Notifications
You must be signed in to change notification settings - Fork 3
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 #93 from Scalr/feature/SCALRCORE-21783
SCALRCORE-21783 Scalr Provider > Token generation
- Loading branch information
Showing
9 changed files
with
299 additions
and
51 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,2 @@ | ||
# Default global owners | ||
* [email protected] [email protected] |
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
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
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
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,77 @@ | ||
package scalr | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
// Compile-time proof of interface implementation. | ||
var _ ServiceAccountTokens = (*serviceAccountTokens)(nil) | ||
|
||
// ServiceAccountTokens describes all the access token related methods that the | ||
// Scalr IACP API supports. | ||
type ServiceAccountTokens interface { | ||
// List service account's access tokens | ||
List(ctx context.Context, serviceAccountID string, options AccessTokenListOptions) (*AccessTokenList, error) | ||
// Create new access token for service account | ||
Create(ctx context.Context, serviceAccountID string, options AccessTokenCreateOptions) (*AccessToken, error) | ||
} | ||
|
||
// serviceAccountTokens implements ServiceAccountTokens. | ||
type serviceAccountTokens struct { | ||
client *Client | ||
} | ||
|
||
// List the access tokens of ServiceAccount. | ||
func (s *serviceAccountTokens) List( | ||
ctx context.Context, serviceAccountID string, options AccessTokenListOptions, | ||
) (*AccessTokenList, error) { | ||
req, err := s.client.newRequest( | ||
"GET", | ||
fmt.Sprintf("service-accounts/%s/access-tokens", url.QueryEscape(serviceAccountID)), | ||
&options, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
atl := &AccessTokenList{} | ||
err = s.client.do(ctx, req, atl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return atl, nil | ||
} | ||
|
||
// Create is used to create a new AccessToken for ServiceAccount. | ||
func (s *serviceAccountTokens) Create( | ||
ctx context.Context, serviceAccountID string, options AccessTokenCreateOptions, | ||
) (*AccessToken, error) { | ||
|
||
// Make sure we don't send a user provided ID. | ||
options.ID = "" | ||
|
||
if !validStringID(&serviceAccountID) { | ||
return nil, errors.New("invalid value for service account ID") | ||
} | ||
|
||
req, err := s.client.newRequest( | ||
"POST", | ||
fmt.Sprintf("service-accounts/%s/access-tokens", url.QueryEscape(serviceAccountID)), | ||
&options, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
at := &AccessToken{} | ||
err = s.client.do(ctx, req, at) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return at, nil | ||
} |
Oops, something went wrong.