github.com/aiven/aiven-go-client@v1.36.0/account_authentications.go (about) 1 package aiven 2 3 import ( 4 "errors" 5 "time" 6 ) 7 8 type ( 9 // AccountAuthenticationsHandler Aiven go-client handler for Account Authentications 10 AccountAuthenticationsHandler struct { 11 client *Client 12 } 13 14 // AccountAuthenticationMethodCreate request object for AccountAuthenticationMethodCreate 15 // https://api.aiven.io/doc/#operation/AccountAuthenticationMethodCreate 16 AccountAuthenticationMethodCreate struct { 17 AuthenticationMethodName string `json:"authentication_method_name"` 18 AuthenticationMethodType string `json:"authentication_method_type"` 19 AutoJoinTeamID string `json:"auto_join_team_id,omitempty"` 20 SAMLCertificate string `json:"saml_certificate,omitempty"` 21 SAMLDigestAlgorithm string `json:"saml_digest_algorithm,omitempty"` 22 SAMLEntityID string `json:"saml_entity_id,omitempty"` 23 SAMLFieldMapping *SAMLFieldMapping `json:"saml_field_mapping,omitempty"` 24 SAMLIdpLoginAllowed bool `json:"saml_idp_login_allowed,omitempty"` 25 SAMLIdpURL string `json:"saml_idp_url,omitempty"` 26 SAMLSignatureAlgorithm string `json:"saml_signature_algorithm,omitempty"` 27 SAMLVariant string `json:"saml_variant,omitempty"` 28 } 29 30 // AccountAuthenticationMethodUpdate request object for AccountAuthenticationMethodUpdate 31 // https://api.aiven.io/doc/#operation/AccountAuthenticationMethodUpdate 32 AccountAuthenticationMethodUpdate struct { 33 AuthenticationMethodEnabled bool `json:"authentication_method_enabled,omitempty"` 34 AuthenticationMethodName string `json:"authentication_method_name"` 35 AutoJoinTeamID string `json:"auto_join_team_id,omitempty"` 36 SAMLCertificate string `json:"saml_certificate,omitempty"` 37 SAMLDigestAlgorithm string `json:"saml_digest_algorithm,omitempty"` 38 SAMLEntity string `json:"saml_entity_id,omitempty"` 39 SAMLFieldMapping *SAMLFieldMapping `json:"saml_field_mapping,omitempty"` 40 SAMLIdpLoginAllowed bool `json:"saml_idp_login_allowed,omitempty"` 41 SAMLIdpURL string `json:"saml_idp_url,omitempty"` 42 SAMLSignatureAlgorithm string `json:"saml_signature_algorithm,omitempty"` 43 SAMLVariant string `json:"saml_variant,omitempty"` 44 } 45 46 // AccountAuthenticationMethod response object for AccountAuthenticationMethodUpdate 47 // https://api.aiven.io/doc/#operation/AccountAuthenticationMethodUpdate 48 AccountAuthenticationMethod struct { 49 AccountID string `json:"account_id"` 50 AuthenticationMethodEnabled bool `json:"authentication_method_enabled"` 51 AuthenticationMethodID string `json:"authentication_method_id"` 52 AuthenticationMethodName string `json:"authentication_method_name"` 53 AuthenticationMethodType string `json:"authentication_method_type"` 54 AutoJoinTeamID string `json:"auto_join_team_id"` 55 CreateTime *time.Time `json:"create_time"` 56 DeleteTime *time.Time `json:"delete_time"` 57 SAMLAcsURL string `json:"saml_acs_url,omitempty"` 58 SAMLCertificate string `json:"saml_certificate,omitempty"` 59 SAMLCertificateIssuer string `json:"saml_certificate_issuer,omitempty"` 60 SAMLCertificateNotValidAfter string `json:"saml_certificate_not_valid_after,omitempty"` 61 SAMLCertificateNotValidBefore string `json:"saml_certificate_not_valid_before,omitempty"` 62 SAMLCertificateSubject string `json:"saml_certificate_subject,omitempty"` 63 SAMLDigestAlgorithm string `json:"saml_digest_algorithm,omitempty"` 64 SAMLEntityID string `json:"saml_entity_id,omitempty"` 65 SAMLFieldMapping *SAMLFieldMapping `json:"saml_field_mapping,omitempty"` 66 SAMLIdpLoginAllowed bool `json:"saml_idp_login_allowed,omitempty"` 67 SAMLIdpURL string `json:"saml_idp_url,omitempty"` 68 SAMLMetadataURL string `json:"saml_metadata_url,omitempty"` 69 SAMLSignatureAlgorithm string `json:"saml_signature_algorithm,omitempty"` 70 SAMLVariant string `json:"saml_variant,omitempty"` 71 State string `json:"state"` 72 UpdateTime *time.Time `json:"update_time"` 73 } 74 75 SAMLFieldMapping struct { 76 Email string `json:"email,omitempty"` 77 FirstName string `json:"first_name,omitempty"` 78 Identity string `json:"identity,omitempty"` 79 LastName string `json:"last_name,omitempty"` 80 RealName string `json:"real_name,omitempty"` 81 } 82 83 // AccountAuthenticationListResponse represents account list of available authentication methods API response 84 AccountAuthenticationListResponse struct { 85 APIResponse 86 AuthenticationMethods []AccountAuthenticationMethod `json:"authentication_methods"` 87 } 88 89 // AccountAuthenticationResponse represents account an available authentication method API response 90 AccountAuthenticationResponse struct { 91 APIResponse 92 AuthenticationMethod AccountAuthenticationMethod `json:"authentication_method"` 93 } 94 ) 95 96 // List returns a list of all available account authentication methods 97 func (h AccountAuthenticationsHandler) List(accountId string) (*AccountAuthenticationListResponse, error) { 98 if accountId == "" { 99 return nil, errors.New("cannot get a list of account authentication methods when account id is empty") 100 } 101 102 path := buildPath("account", accountId, "authentication") 103 bts, err := h.client.doGetRequest(path, nil) 104 if err != nil { 105 return nil, err 106 } 107 108 var rsp AccountAuthenticationListResponse 109 if errR := checkAPIResponse(bts, &rsp); errR != nil { 110 return nil, errR 111 } 112 113 return &rsp, nil 114 } 115 116 // Get returns a list of all available account authentication methods 117 func (h AccountAuthenticationsHandler) Get(accountId, authId string) (*AccountAuthenticationResponse, error) { 118 if accountId == "" || authId == "" { 119 return nil, errors.New("cannot get an account authentication method when account id or auth id is empty") 120 } 121 122 path := buildPath("account", accountId, "authentication", authId) 123 bts, err := h.client.doGetRequest(path, nil) 124 if err != nil { 125 return nil, err 126 } 127 128 var rsp AccountAuthenticationResponse 129 if errR := checkAPIResponse(bts, &rsp); errR != nil { 130 return nil, errR 131 } 132 133 return &rsp, nil 134 } 135 136 // Create creates an account authentication method 137 func (h AccountAuthenticationsHandler) Create(accountId string, a AccountAuthenticationMethodCreate) (*AccountAuthenticationResponse, error) { 138 if accountId == "" { 139 return nil, errors.New("cannot create an account authentication method when account id is empty") 140 } 141 142 path := buildPath("account", accountId, "authentication") 143 bts, err := h.client.doPostRequest(path, a) 144 if err != nil { 145 return nil, err 146 } 147 148 var rsp AccountAuthenticationResponse 149 if errR := checkAPIResponse(bts, &rsp); errR != nil { 150 return nil, errR 151 } 152 153 return &rsp, nil 154 } 155 156 // Update updates an account authentication method empty fields are omitted, acts like PATCH 157 func (h AccountAuthenticationsHandler) Update(accountId, accountAuthMethID string, a AccountAuthenticationMethodUpdate) (*AccountAuthenticationResponse, error) { 158 if accountId == "" || accountAuthMethID == "" { 159 return nil, errors.New("cannot update an account authentication method when account id or auth id is empty") 160 } 161 162 path := buildPath("account", accountId, "authentication", accountAuthMethID) 163 bts, err := h.client.doPutRequest(path, a) 164 if err != nil { 165 return nil, err 166 } 167 168 var rsp AccountAuthenticationResponse 169 if errR := checkAPIResponse(bts, &rsp); errR != nil { 170 return nil, errR 171 } 172 173 return &rsp, nil 174 } 175 176 // Delete deletes an account authentication method 177 func (h AccountAuthenticationsHandler) Delete(accountId, authId string) error { 178 if accountId == "" || authId == "" { 179 return errors.New("cannot delete an account authentication method when account id or auth id is empty") 180 } 181 182 path := buildPath("account", accountId, "authentication", authId) 183 bts, err := h.client.doDeleteRequest(path, nil) 184 if err != nil { 185 return err 186 } 187 188 return checkAPIResponse(bts, nil) 189 }