Skip to content

Commit

Permalink
Merge pull request #51 from aiven/savciuci-accounts2
Browse files Browse the repository at this point in the history
Add accounts support 2

#51
  • Loading branch information
rikonen authored Feb 1, 2020
2 parents 443d599 + 2e70551 commit 568b2a4
Show file tree
Hide file tree
Showing 22 changed files with 2,041 additions and 54 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ bootstrap:
#################################################
# Testing and linting
#################################################
testacc:
AIVEN_ACC=1 go test -v --cover -timeout 30m .

test:
go test -v --cover ./... -timeout 15m

Expand Down
141 changes: 141 additions & 0 deletions account_authentications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package aiven

import (
"errors"
"time"
)

type (
// AccountAuthenticationsHandler Aiven go-client handler for Account Authentications
AccountAuthenticationsHandler struct {
client *Client
}

// AccountAuthenticationMethod represents account authentication method
AccountAuthenticationMethod struct {
AccountId string `json:"account_id,omitempty"`
Enabled bool `json:"authentication_method_enabled,omitempty"`
Id string `json:"authentication_method_id,omitempty"`
Name string `json:"authentication_method_name"`
Type string `json:"authentication_method_type"`
AutoJoinTeamId string `json:"auto_join_team_id,omitempty"`
State string `json:"state,omitempty"`
SAMLCertificate string `json:"saml_certificate,omitempty"`
SAMLIdpUrl string `json:"saml_idp_url,omitempty"`
SAMLEntity string `json:"saml_entity_id,omitempty"`
SAMLCertificateIssuer string `json:"saml_certificate_issuer,omitempty"`
SAMLCertificateSubject string `json:"saml_certificate_subject,omitempty"`
SAMLCertificateNotValidAfter *time.Time `json:"saml_certificate_not_valid_after,omitempty"`
SAMLCertificateNotValidBefore *time.Time `json:"saml_certificate_not_valid_before,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
DeleteTime *time.Time `json:"delete_time,omitempty"`
}

// AccountAuthenticationsResponse represents account list of available authentication methods API response
AccountAuthenticationsResponse struct {
APIResponse
AuthenticationMethods []AccountAuthenticationMethod `json:"authentication_methods"`
}

// AccountAuthenticationResponse represents account an available authentication method API response
AccountAuthenticationResponse struct {
APIResponse
AuthenticationMethod AccountAuthenticationMethod `json:"authentication_method"`
}
)

// List returns a list of all available account authentication methods
func (h AccountAuthenticationsHandler) List(accountId string) (*AccountAuthenticationsResponse, error) {
if accountId == "" {
return nil, errors.New("cannot get a list of account authentication methods when account id is empty")
}

path := buildPath("account", accountId, "authentication")
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}

var rsp AccountAuthenticationsResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}

return &rsp, nil
}

// Get returns a list of all available account authentication methods
func (h AccountAuthenticationsHandler) Get(accountId, authId string) (*AccountAuthenticationResponse, error) {
if accountId == "" || authId == "" {
return nil, errors.New("cannot get an account authentication method when account id or auth id is empty")
}

path := buildPath("account", accountId, "authentication", authId)
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}

var rsp AccountAuthenticationResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}

return &rsp, nil
}

// Create creates an account authentication method
func (h AccountAuthenticationsHandler) Create(accountId string, a AccountAuthenticationMethod) (*AccountAuthenticationResponse, error) {
if accountId == "" {
return nil, errors.New("cannot create an account authentication method when account id is empty")
}

path := buildPath("account", accountId, "authentication")
bts, err := h.client.doPostRequest(path, a)
if err != nil {
return nil, err
}

var rsp AccountAuthenticationResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}

return &rsp, nil
}

// Update updates an account authentication method
func (h AccountAuthenticationsHandler) Update(accountId string, a AccountAuthenticationMethod) (*AccountAuthenticationResponse, error) {
if accountId == "" || a.Id == "" {
return nil, errors.New("cannot update an account authentication method when account id or auth id is empty")
}

path := buildPath("account", accountId, "authentication", a.Id)
bts, err := h.client.doPutRequest(path, a)
if err != nil {
return nil, err
}

var rsp AccountAuthenticationResponse
if errR := checkAPIResponse(bts, &rsp); errR != nil {
return nil, errR
}

return &rsp, nil
}

// Delete deletes an account authentication method
func (h AccountAuthenticationsHandler) Delete(accountId, authId string) error {
if accountId == "" || authId == "" {
return errors.New("cannot delete an account authentication method when account id or auth id is empty")
}

path := buildPath("account", accountId, "authentication", authId)
bts, err := h.client.doDeleteRequest(path, nil)
if err != nil {
return err
}

return checkAPIResponse(bts, nil)
}
Loading

0 comments on commit 568b2a4

Please sign in to comment.