Skip to content

Commit

Permalink
Merge branch 'main' into sc-10374/project-detail-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort authored Nov 18, 2022
2 parents c900971 + 424d29d commit 52bba93
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 18 deletions.
30 changes: 30 additions & 0 deletions pkg/tenant/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ type TenantClient interface {

TopicList(context.Context, *PageQuery) (*TopicPage, error)
TopicCreate(context.Context, *Topic) (*Topic, error)

ProjectAPIKeyList(ctx context.Context, id string, in *PageQuery) (*ProjectAPIKeyPage, error)
ProjectAPIKeyCreate(ctx context.Context, id string, in *APIKey) (*APIKey, error)

APIKeyList(context.Context, *PageQuery) (*APIKeyPage, error)
APIKeyCreate(context.Context, *APIKey) (*APIKey, error)
}

//===========================================================================
Expand Down Expand Up @@ -130,6 +136,30 @@ type TopicPage struct {
NextPageToken string
}

type ProjectAPIKeyPage struct {
ProjectID string `json:"project_id"`
APIKeys []*APIKey
PrevPageToken string
NextPageToken string
}

type APIKey struct {
ID int `json:"id,omitempty"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret,omitempty"`
Name string `json:"name"`
Owner string `json:"owner,omitempty"`
Permissions []string `json:"permissions,omitempty"`
Created string `json:"created,omitempty"`
Modified string `json:"modified,omitempty"`
}

type APIKeyPage struct {
APIKeys []*APIKey
PrevPageToken string
NextPageToken string
}

// ContactInfo allows users to sign up for email notifications from SendGrid and is
// specifically used to allow users to request Ensign Private Beta access.
type ContactInfo struct {
Expand Down
90 changes: 90 additions & 0 deletions pkg/tenant/api/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,96 @@ func (s *APIv1) TopicCreate(ctx context.Context, in *Topic) (out *Topic, err err
return out, err
}

func (s *APIv1) ProjectAPIKeyList(ctx context.Context, id string, in *PageQuery) (out *ProjectAPIKeyPage, err error) {
if id == "" {
return nil, ErrProjectIDRequired
}

path := fmt.Sprintf("/v1/projects/%s/apikeys", id)

var params url.Values
if params, err = query.Values(in); err != nil {
return nil, fmt.Errorf("could not encode query params: %w", err)
}

// Make the HTTP request
var req *http.Request
if req, err = s.NewRequest(ctx, http.MethodGet, path, nil, &params); err != nil {
return nil, err
}

out = &ProjectAPIKeyPage{}
if _, err = s.Do(req, out, true); err != nil {
return nil, err
}
return out, nil
}

func (s *APIv1) ProjectAPIKeyCreate(ctx context.Context, id string, in *APIKey) (out *APIKey, err error) {
if id == "" {
return nil, ErrProjectIDRequired
}

path := fmt.Sprintf("/v1/projects/%s/apikeys", id)

// Make the HTTP Request
var req *http.Request
if req, err = s.NewRequest(ctx, http.MethodPost, path, in, nil); err != nil {
return nil, err
}

// Make the HTTP response
out = &APIKey{}
var rep *http.Response
if rep, err = s.Do(req, out, true); err != nil {
return nil, err
}

if rep.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("expected status created, received %s", rep.Status)
}
return out, nil
}

func (s *APIv1) APIKeyList(ctx context.Context, in *PageQuery) (out *APIKeyPage, err error) {
var params url.Values
if params, err = query.Values(in); err != nil {
return nil, fmt.Errorf("could not encode query params: %w", err)
}

// Make the HTTP request
var req *http.Request
if req, err = s.NewRequest(ctx, http.MethodGet, "/v1/apikeys", nil, &params); err != nil {
return nil, err
}

out = &APIKeyPage{}
if _, err = s.Do(req, out, true); err != nil {
return nil, err
}
return out, nil
}

func (s *APIv1) APIKeyCreate(ctx context.Context, in *APIKey) (out *APIKey, err error) {
// Make the HTTP Request
var req *http.Request
if req, err = s.NewRequest(ctx, http.MethodPost, "/v1/apikeys", in, nil); err != nil {
return nil, err
}

// Make the HTTP response
out = &APIKey{}
var rep *http.Response
if rep, err = s.Do(req, out, true); err != nil {
return nil, err
}

if rep.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("expected status created, received %s", rep.Status)
}
return out, nil
}

//===========================================================================
// Helper Methods
//===========================================================================
Expand Down
Loading

0 comments on commit 52bba93

Please sign in to comment.