|
| 1 | +package tokens |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/google/uuid" |
| 5 | + "github.com/microsoft/azure-devops-go-api/azuredevops/v7" |
| 6 | +) |
| 7 | + |
| 8 | +// PatTokenCreateRequest encapsulates the request parameters for creating a new personal access token (PAT) |
| 9 | +type PatTokenCreateRequest struct { |
| 10 | + // True, if this personal access token (PAT) is for all of the user's accessible organizations. False, if otherwise (e.g. if the token is for a specific organization) |
| 11 | + AllOrgs *bool `json:"allOrgs,omitempty"` |
| 12 | + // The token name |
| 13 | + DisplayName *string `json:"displayName,omitempty"` |
| 14 | + // The token scopes for accessing Azure DevOps resources |
| 15 | + Scope *string `json:"scope,omitempty"` |
| 16 | + // The token expiration date. If the "Enforce maximum personal access token lifespan" policy is enabled and the provided token expiration date is past the maximum allowed lifespan, it will return back a PAT with a validTo date equal to the current date + maximum allowed lifespan. |
| 17 | + ValidTo *azuredevops.Time `json:"validTo,omitempty"` |
| 18 | +} |
| 19 | + |
| 20 | +// PatTokenResult contains the resulting personal access token (PAT) and the error (if any) that occurred during the operation |
| 21 | +type PatTokenResult struct { |
| 22 | + // Represents a personal access token (PAT) used to access Azure DevOps resources |
| 23 | + PatToken PatToken `json:"patToken,omitempty"` |
| 24 | + // The error (if any) that occurred |
| 25 | + PatTokenError *PatTokenError `json:"patTokenError,omitempty"` |
| 26 | +} |
| 27 | + |
| 28 | +// PatToken represents a personal access token (PAT) used to access Azure DevOps resources |
| 29 | +type PatToken struct { |
| 30 | + // Unique guid identifier |
| 31 | + AuthorizationId *uuid.UUID `json:"authorizationId,omitempty"` |
| 32 | + // The token name |
| 33 | + DisplayName *string `json:"displayName,omitempty"` |
| 34 | + // The token scopes for accessing Azure DevOps resources |
| 35 | + Scope *string `json:"scope,omitempty"` |
| 36 | + // The organizations for which the token is valid; null if the token applies to all of the user's accessible organizations |
| 37 | + TargetAccounts *[]uuid.UUID `json:"targetAccounts,omitempty"` |
| 38 | + // The unique token string generated at creation |
| 39 | + Token *string `json:"token,omitempty"` |
| 40 | + // The token creation date |
| 41 | + ValidFrom *azuredevops.Time `json:"validFrom,omitempty"` |
| 42 | + // The token expiration date |
| 43 | + ValidTo *azuredevops.Time `json:"validTo,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +// Enumeration of possible errors returned when creating a personal access token (PAT) |
| 47 | +type PatTokenError string |
| 48 | + |
| 49 | +type buildPatTokenErrorType struct { |
| 50 | + None PatTokenError |
| 51 | + DisplayNameRequired PatTokenError |
| 52 | + InvalideDisplayName PatTokenError |
| 53 | + InvalidValidTo PatTokenError |
| 54 | + InvalidScope PatTokenError |
| 55 | + UserIdRequired PatTokenError |
| 56 | + InvalidUserId PatTokenError |
| 57 | + InvalidUserType PatTokenError |
| 58 | + AccessDenied PatTokenError |
| 59 | + FailedToIssueAccessToken PatTokenError |
| 60 | + InvalidClient PatTokenError |
| 61 | + InvalidClientType PatTokenError |
| 62 | + InvalidClientId PatTokenError |
| 63 | + InvalideTargetAccounts PatTokenError |
| 64 | + HostAuthorizationNotFound PatTokenError |
| 65 | + AuthorizationNotFound PatTokenError |
| 66 | + FailedToUpdateAccessToken PatTokenError |
| 67 | + SourceNotSupported PatTokenError |
| 68 | + InvalidSourceIP PatTokenError |
| 69 | + InvalideSource PatTokenError |
| 70 | + DuplicateHash PatTokenError |
| 71 | + SshPolicyDisabled PatTokenError |
| 72 | + InvalidToken PatTokenError |
| 73 | + TokenNotFound PatTokenError |
| 74 | + InvalidAuthorizationId PatTokenError |
| 75 | + FailedToReadTenantPolicy PatTokenError |
| 76 | + GlobalPatPolicyViolation PatTokenError |
| 77 | + FullScopePatPolicyViolation PatTokenError |
| 78 | + PatLifespanPolicyViolation PatTokenError |
| 79 | + InvalidTokenType PatTokenError |
| 80 | + InvalidAudience PatTokenError |
| 81 | + InvalidSubject PatTokenError |
| 82 | + DeploymentHostNotSupported PatTokenError |
| 83 | +} |
| 84 | + |
| 85 | +var PatTokeErrorValues = buildPatTokenErrorType{ |
| 86 | + None: "none", |
| 87 | + DisplayNameRequired: "displayNameRequired", |
| 88 | + InvalideDisplayName: "invalidDisplayName", |
| 89 | + InvalidValidTo: "invalidValidTo", |
| 90 | + InvalidScope: "invalidScope", |
| 91 | + UserIdRequired: "userIdRequired", |
| 92 | + InvalidUserId: "invalidUserId", |
| 93 | + InvalidUserType: "invalidUserType", |
| 94 | + AccessDenied: "accessDenied", |
| 95 | + FailedToIssueAccessToken: "failedToIssueAccessToken", |
| 96 | + InvalidClient: "invalidClient", |
| 97 | + InvalidClientType: "invalidClientType", |
| 98 | + InvalidClientId: "invalidClientId", |
| 99 | + InvalideTargetAccounts: "invalidTargetAccounts", |
| 100 | + HostAuthorizationNotFound: "hostAuthorizationNotFound", |
| 101 | + AuthorizationNotFound: "authorizationNotFound", |
| 102 | + FailedToUpdateAccessToken: "failedToUpdateAccessToken", |
| 103 | + SourceNotSupported: "sourceNotSupported", |
| 104 | + InvalidSourceIP: "invalidSourceIP", |
| 105 | + InvalideSource: "invalidSource", |
| 106 | + DuplicateHash: "duplicateHash", |
| 107 | + SshPolicyDisabled: "sshPolicyDisabled", |
| 108 | + InvalidToken: "invalidToken", |
| 109 | + TokenNotFound: "tokenNotFound", |
| 110 | + InvalidAuthorizationId: "invalidAuthorizationId", |
| 111 | + FailedToReadTenantPolicy: "failedToReadTenantPolicy", |
| 112 | + GlobalPatPolicyViolation: "globalPatPolicyViolation", |
| 113 | + FullScopePatPolicyViolation: "fullScopePatPolicyViolation", |
| 114 | + PatLifespanPolicyViolation: "patLifespanPolicyViolation", |
| 115 | + InvalidTokenType: "invalidTokenType", |
| 116 | + InvalidAudience: "invalidAudience", |
| 117 | + InvalidSubject: "invalidSubject", |
| 118 | + DeploymentHostNotSupported: "deploymentHostNotSupported", |
| 119 | +} |
| 120 | + |
| 121 | +// PatTokenUpdateRequest encapsulates the request parameters for updating a personal access token (PAT) |
| 122 | +type PatTokenUpdateRequest struct { |
| 123 | + // (Optional) True if this personal access token (PAT) is for all of the user's accessible organizations. False if otherwise (e.g. if the token is for a specific organization) |
| 124 | + AllOrgs *bool `json:"allOrgs,omitempty"` |
| 125 | + // The authorizationId identifying a single, unique personal access token (PAT) |
| 126 | + AuthorizationId *uuid.UUID `json:"authorizationId,omitempty"` |
| 127 | + // (Optional) The token name |
| 128 | + DisplayName *string `json:"displayName,omitempty"` |
| 129 | + // (Optional) The token scopes for accessing Azure DevOps resources |
| 130 | + Scope *string `json:"scope,omitempty"` |
| 131 | + // (Optional) The token expiration date. If the \"Enforce maximum personal access token lifespan\" policy is enabled and the provided token expiration date is past the maximum allowed lifespan, it will return back a PAT with a validTo date equal to the date when the PAT was intially created + maximum allowed lifespan. |
| 132 | + ValidTo *azuredevops.Time `json:"validTo,omitempty"` |
| 133 | +} |
| 134 | + |
| 135 | +// Enumerates display filter options for Personal Access Tokens (PATs) |
| 136 | +type DisplayFilterOption string |
| 137 | + |
| 138 | +type buildDisplayFilterOptionType struct { |
| 139 | + Active DisplayFilterOption |
| 140 | + Revoked DisplayFilterOption |
| 141 | + Expired DisplayFilterOption |
| 142 | + All DisplayFilterOption |
| 143 | +} |
| 144 | + |
| 145 | +var DisplayFilterOptionValues = buildDisplayFilterOptionType{ |
| 146 | + Active: "active", |
| 147 | + Revoked: "revoked", |
| 148 | + Expired: "expired", |
| 149 | + All: "all", |
| 150 | +} |
| 151 | + |
| 152 | +// Enumerates sort by options for Personal Access Tokens (PATs) |
| 153 | +type SortByOption string |
| 154 | + |
| 155 | +type buildSortByOptionType struct { |
| 156 | + DisplayName SortByOption |
| 157 | + DisplayDate SortByOption |
| 158 | + Status SortByOption |
| 159 | +} |
| 160 | + |
| 161 | +var SortByOptionValues = buildSortByOptionType{ |
| 162 | + DisplayName: "displayName", |
| 163 | + DisplayDate: "displayDate", |
| 164 | + Status: "status", |
| 165 | +} |
| 166 | + |
| 167 | +// PagedPatResults returned by the List method; contains a list of personal access tokens (PATs) and the continuation token to get the next page of results |
| 168 | +type PagedPatResults struct { |
| 169 | + // "Used to access the next page of results in successive API calls to list personal access tokens (PATs) |
| 170 | + ContinuationToken *string `json:"continuationToken,omitempty"` |
| 171 | + // The list of personal access tokens (PATs) |
| 172 | + PatTokens *[]PatToken `json:"patTokens,omitempty"` |
| 173 | +} |
0 commit comments