|
6 | 6 | from linode_api4.groups import Group
|
7 | 7 | from linode_api4.objects import (
|
8 | 8 | AuthorizedApp,
|
| 9 | + MappedObject, |
9 | 10 | PersonalAccessToken,
|
10 | 11 | Profile,
|
| 12 | + ProfileLogin, |
11 | 13 | SSHKey,
|
| 14 | + TrustedDevice, |
12 | 15 | )
|
13 | 16 |
|
14 | 17 |
|
@@ -40,6 +43,181 @@ def __call__(self):
|
40 | 43 | p = Profile(self.client, result["username"], result)
|
41 | 44 | return p
|
42 | 45 |
|
| 46 | + def trusted_devices(self): |
| 47 | + """ |
| 48 | + Returns the Trusted Devices on your profile. |
| 49 | +
|
| 50 | + API Documentation: https://www.linode.com/docs/api/profile/#trusted-devices-list |
| 51 | +
|
| 52 | + :returns: A list of Trusted Devices for this profile. |
| 53 | + :rtype: PaginatedList of TrustedDevice |
| 54 | + """ |
| 55 | + return self.client._get_and_filter(TrustedDevice) |
| 56 | + |
| 57 | + def user_preferences(self): |
| 58 | + """ |
| 59 | + View a list of user preferences tied to the OAuth client that generated the token making the request. |
| 60 | + """ |
| 61 | + |
| 62 | + result = self.client.get( |
| 63 | + "{}/preferences".format(Profile.api_endpoint), model=self |
| 64 | + ) |
| 65 | + |
| 66 | + return MappedObject(**result) |
| 67 | + |
| 68 | + def security_questions(self): |
| 69 | + """ |
| 70 | + Returns a collection of security questions and their responses, if any, for your User Profile. |
| 71 | + """ |
| 72 | + |
| 73 | + result = self.client.get( |
| 74 | + "{}/security-questions".format(Profile.api_endpoint), model=self |
| 75 | + ) |
| 76 | + |
| 77 | + return MappedObject(**result) |
| 78 | + |
| 79 | + def security_questions_answer(self, questions): |
| 80 | + """ |
| 81 | + Adds security question responses for your User. Requires exactly three unique questions. |
| 82 | + Previous responses are overwritten if answered or reset to null if unanswered. |
| 83 | +
|
| 84 | + Example question: |
| 85 | + { |
| 86 | + "question_id": 11, |
| 87 | + "response": "secret answer 3" |
| 88 | + } |
| 89 | + """ |
| 90 | + |
| 91 | + if len(questions) != 3: |
| 92 | + raise ValueError("Exactly 3 security questions are required.") |
| 93 | + |
| 94 | + params = {"security_questions": questions} |
| 95 | + |
| 96 | + result = self.client.post( |
| 97 | + "{}/security-questions".format(Profile.api_endpoint), |
| 98 | + model=self, |
| 99 | + data=params, |
| 100 | + ) |
| 101 | + |
| 102 | + return MappedObject(**result) |
| 103 | + |
| 104 | + def user_preferences_update(self, **preferences): |
| 105 | + """ |
| 106 | + Updates a user’s preferences. |
| 107 | + """ |
| 108 | + |
| 109 | + result = self.client.put( |
| 110 | + "{}/preferences".format(Profile.api_endpoint), |
| 111 | + model=self, |
| 112 | + data=preferences, |
| 113 | + ) |
| 114 | + |
| 115 | + return MappedObject(**result) |
| 116 | + |
| 117 | + def phone_number_delete(self): |
| 118 | + """ |
| 119 | + Delete the verified phone number for the User making this request. |
| 120 | +
|
| 121 | + API Documentation: https://api.linode.com/v4/profile/phone-number |
| 122 | +
|
| 123 | + :returns: Returns True if the operation was successful. |
| 124 | + :rtype: bool |
| 125 | + """ |
| 126 | + |
| 127 | + resp = self.client.delete( |
| 128 | + "{}/phone-number".format(Profile.api_endpoint), model=self |
| 129 | + ) |
| 130 | + |
| 131 | + if "error" in resp: |
| 132 | + raise UnexpectedResponseError( |
| 133 | + "Unexpected response when deleting phone number!", |
| 134 | + json=resp, |
| 135 | + ) |
| 136 | + |
| 137 | + return True |
| 138 | + |
| 139 | + def phone_number_verify(self, otp_code): |
| 140 | + """ |
| 141 | + Verify a phone number by confirming the one-time code received via SMS message |
| 142 | + after accessing the Phone Verification Code Send (POST /profile/phone-number) command. |
| 143 | +
|
| 144 | + API Documentation: https://api.linode.com/v4/profile/phone-number/verify |
| 145 | +
|
| 146 | + :param otp_code: The one-time code received via SMS message after accessing the Phone Verification Code Send |
| 147 | + :type otp_code: str |
| 148 | +
|
| 149 | + :returns: Returns True if the operation was successful. |
| 150 | + :rtype: bool |
| 151 | + """ |
| 152 | + |
| 153 | + if not otp_code: |
| 154 | + raise ValueError("OTP Code required to verify phone number.") |
| 155 | + |
| 156 | + params = {"otp_code": str(otp_code)} |
| 157 | + |
| 158 | + resp = self.client.post( |
| 159 | + "{}/phone-number/verify".format(Profile.api_endpoint), |
| 160 | + model=self, |
| 161 | + data=params, |
| 162 | + ) |
| 163 | + |
| 164 | + if "error" in resp: |
| 165 | + raise UnexpectedResponseError( |
| 166 | + "Unexpected response when verifying phone number!", |
| 167 | + json=resp, |
| 168 | + ) |
| 169 | + |
| 170 | + return True |
| 171 | + |
| 172 | + def phone_number_verification_code_send(self, iso_code, phone_number): |
| 173 | + """ |
| 174 | + Send a one-time verification code via SMS message to the submitted phone number. |
| 175 | +
|
| 176 | + API Documentation: https://api.linode.com/v4/profile/phone-number |
| 177 | +
|
| 178 | + :param iso_code: The two-letter ISO 3166 country code associated with the phone number. |
| 179 | + :type iso_code: str |
| 180 | +
|
| 181 | + :param phone_number: A valid phone number. |
| 182 | + :type phone_number: str |
| 183 | +
|
| 184 | + :returns: Returns True if the operation was successful. |
| 185 | + :rtype: bool |
| 186 | + """ |
| 187 | + |
| 188 | + if not iso_code: |
| 189 | + raise ValueError("ISO Code required to send verification code.") |
| 190 | + |
| 191 | + if not phone_number: |
| 192 | + raise ValueError("Phone Number required to send verification code.") |
| 193 | + |
| 194 | + params = {"iso_code": iso_code, "phone_number": phone_number} |
| 195 | + |
| 196 | + resp = self.client.post( |
| 197 | + "{}/phone-number".format(Profile.api_endpoint), |
| 198 | + model=self, |
| 199 | + data=params, |
| 200 | + ) |
| 201 | + |
| 202 | + if "error" in resp: |
| 203 | + raise UnexpectedResponseError( |
| 204 | + "Unexpected response when sending verification code!", |
| 205 | + json=resp, |
| 206 | + ) |
| 207 | + |
| 208 | + return True |
| 209 | + |
| 210 | + def logins(self): |
| 211 | + """ |
| 212 | + Returns the logins on your profile. |
| 213 | +
|
| 214 | + API Documentation: https://www.linode.com/docs/api/profile/#logins-list |
| 215 | +
|
| 216 | + :returns: A list of logins for this profile. |
| 217 | + :rtype: PaginatedList of ProfileLogin |
| 218 | + """ |
| 219 | + return self.client._get_and_filter(ProfileLogin) |
| 220 | + |
43 | 221 | def tokens(self, *filters):
|
44 | 222 | """
|
45 | 223 | Returns the Person Access Tokens active for this user.
|
|
0 commit comments