forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Implement API changes for 4.129.0 (linode#265)
* Implement API changes for 4.129 * Use regexp for URLs
- Loading branch information
Showing
15 changed files
with
514 additions
and
4 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
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,84 @@ | ||
package linodego | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// SendPhoneNumberVerificationCodeOptions fields are those accepted by SendPhoneNumberVerificationCode | ||
type SendPhoneNumberVerificationCodeOptions struct { | ||
ISOCode string `json:"iso_code"` | ||
PhoneNumber string `json:"phone_number"` | ||
} | ||
|
||
// VerifyPhoneNumberOptions fields are those accepted by VerifyPhoneNumber | ||
type VerifyPhoneNumberOptions struct { | ||
OTPCode string `json:"otp_code"` | ||
} | ||
|
||
// SendPhoneNumberVerificationCode sends a one-time verification code via SMS message to the submitted phone number. | ||
func (c *Client) SendPhoneNumberVerificationCode(ctx context.Context, opts SendPhoneNumberVerificationCodeOptions) error { | ||
var body string | ||
e, err := c.ProfilePhoneNumber.Endpoint() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req := c.R(ctx) | ||
|
||
if bodyData, err := json.Marshal(opts); err == nil { | ||
body = string(bodyData) | ||
} else { | ||
return NewError(err) | ||
} | ||
|
||
if _, err := coupleAPIErrors(req. | ||
SetBody(body). | ||
Post(e)); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// DeletePhoneNumber deletes the verified phone number for the User making this request. | ||
func (c *Client) DeletePhoneNumber(ctx context.Context) error { | ||
e, err := c.ProfilePhoneNumber.Endpoint() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req := c.R(ctx) | ||
|
||
if _, err := coupleAPIErrors(req. | ||
Delete(e)); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// VerifyPhoneNumber verifies a phone number by confirming the one-time code received via SMS message after accessing the Phone Verification Code Send command. | ||
func (c *Client) VerifyPhoneNumber(ctx context.Context, opts VerifyPhoneNumberOptions) error { | ||
var body string | ||
e, err := c.ProfilePhoneNumber.Endpoint() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
e = fmt.Sprintf("%s/verify", e) | ||
|
||
req := c.R(ctx) | ||
|
||
if bodyData, err := json.Marshal(opts); err == nil { | ||
body = string(bodyData) | ||
} else { | ||
return NewError(err) | ||
} | ||
|
||
if _, err := coupleAPIErrors(req. | ||
SetBody(body). | ||
Post(e)); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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,65 @@ | ||
package linodego | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
type SecurityQuestion struct { | ||
ID int `json:"id"` | ||
Question string `json:"question"` | ||
Response string `json:"response"` | ||
} | ||
|
||
type SecurityQuestionsListResponse struct { | ||
SecurityQuestions []SecurityQuestion `json:"security_questions"` | ||
} | ||
|
||
type SecurityQuestionsAnswerQuestion struct { | ||
QuestionID int `json:"question_id"` | ||
Response string `json:"response"` | ||
} | ||
|
||
type SecurityQuestionsAnswerOptions struct { | ||
SecurityQuestions []SecurityQuestionsAnswerQuestion `json:"security_questions"` | ||
} | ||
|
||
// SecurityQuestionsList returns a collection of security questions and their responses, if any, for your User Profile. | ||
func (c *Client) SecurityQuestionsList(ctx context.Context) (*SecurityQuestionsListResponse, error) { | ||
e, err := c.ProfileSecurityQuestions.Endpoint() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req := c.R(ctx).SetResult(&SecurityQuestionsListResponse{}) | ||
|
||
r, err := coupleAPIErrors(req.Get(e)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return r.Result().(*SecurityQuestionsListResponse), nil | ||
} | ||
|
||
// SecurityQuestionsAnswer adds security question responses for your User. | ||
func (c *Client) SecurityQuestionsAnswer(ctx context.Context, opts SecurityQuestionsAnswerOptions) error { | ||
var body string | ||
e, err := c.ProfileSecurityQuestions.Endpoint() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req := c.R(ctx) | ||
|
||
if bodyData, err := json.Marshal(opts); err == nil { | ||
body = string(bodyData) | ||
} else { | ||
return NewError(err) | ||
} | ||
|
||
if _, err := coupleAPIErrors(req. | ||
SetBody(body). | ||
Post(e)); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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,114 @@ | ||
package linodego | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/linode/linodego/internal/parseabletime" | ||
) | ||
|
||
// TwoFactorSecret contains fields returned by CreateTwoFactorSecret | ||
type TwoFactorSecret struct { | ||
Expiry *time.Time `json:"expiry"` | ||
Secret string `json:"secret"` | ||
} | ||
|
||
// ConfirmTwoFactorOptions contains fields used by ConfirmTwoFactor | ||
type ConfirmTwoFactorOptions struct { | ||
TFACode string `json:"tfa_code"` | ||
} | ||
|
||
// ConfirmTwoFactorResponse contains fields returned by ConfirmTwoFactor | ||
type ConfirmTwoFactorResponse struct { | ||
Scratch string `json:"scratch"` | ||
} | ||
|
||
func (s *TwoFactorSecret) UnmarshalJSON(b []byte) error { | ||
type Mask TwoFactorSecret | ||
|
||
p := struct { | ||
*Mask | ||
Expiry *parseabletime.ParseableTime `json:"expiry"` | ||
}{ | ||
Mask: (*Mask)(s), | ||
} | ||
|
||
if err := json.Unmarshal(b, &p); err != nil { | ||
return err | ||
} | ||
|
||
s.Expiry = (*time.Time)(p.Expiry) | ||
|
||
return nil | ||
} | ||
|
||
// CreateTwoFactorSecret generates a Two Factor secret for your User. | ||
func (c *Client) CreateTwoFactorSecret(ctx context.Context) (*TwoFactorSecret, error) { | ||
e, err := c.Profile.Endpoint() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
e = fmt.Sprintf("%s/tfa-enable", e) | ||
|
||
req := c.R(ctx).SetResult(&TwoFactorSecret{}) | ||
|
||
r, err := coupleAPIErrors(req. | ||
Post(e)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return r.Result().(*TwoFactorSecret), nil | ||
} | ||
|
||
// DisableTwoFactor disables Two Factor Authentication for your User. | ||
func (c *Client) DisableTwoFactor(ctx context.Context) error { | ||
e, err := c.Profile.Endpoint() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
e = fmt.Sprintf("%s/tfa-disable", e) | ||
|
||
req := c.R(ctx) | ||
|
||
_, err = coupleAPIErrors(req. | ||
Post(e)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConfirmTwoFactor confirms that you can successfully generate Two Factor codes and enables TFA on your Account. | ||
func (c *Client) ConfirmTwoFactor(ctx context.Context, opts ConfirmTwoFactorOptions) (*ConfirmTwoFactorResponse, error) { | ||
var body string | ||
|
||
e, err := c.Profile.Endpoint() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
e = fmt.Sprintf("%s/tfa-enable-confirm", e) | ||
|
||
if bodyData, err := json.Marshal(opts); err == nil { | ||
body = string(bodyData) | ||
} else { | ||
return nil, NewError(err) | ||
} | ||
|
||
req := c.R(ctx).SetResult(&ConfirmTwoFactorResponse{}) | ||
|
||
r, err := coupleAPIErrors(req. | ||
SetBody(body). | ||
Post(e)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return r.Result().(*ConfirmTwoFactorResponse), nil | ||
} |
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
Oops, something went wrong.