|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +package gitpod |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "fmt" |
| 8 | + "net/http" |
| 9 | + |
| 10 | + "github.com/stainless-sdks/gitpod-go/internal/apijson" |
| 11 | + "github.com/stainless-sdks/gitpod-go/internal/param" |
| 12 | + "github.com/stainless-sdks/gitpod-go/internal/requestconfig" |
| 13 | + "github.com/stainless-sdks/gitpod-go/option" |
| 14 | +) |
| 15 | + |
| 16 | +// IdentityService contains methods and other services that help with interacting |
| 17 | +// with the gitpod API. |
| 18 | +// |
| 19 | +// Note, unlike clients, this service does not read variables from the environment |
| 20 | +// automatically. You should not instantiate this service directly, and instead use |
| 21 | +// the [NewIdentityService] method instead. |
| 22 | +type IdentityService struct { |
| 23 | + Options []option.RequestOption |
| 24 | +} |
| 25 | + |
| 26 | +// NewIdentityService generates a new service that applies the given options to |
| 27 | +// each request. These options are applied after the parent client's options (if |
| 28 | +// there is one), and before any request-specific options. |
| 29 | +func NewIdentityService(opts ...option.RequestOption) (r *IdentityService) { |
| 30 | + r = &IdentityService{} |
| 31 | + r.Options = opts |
| 32 | + return |
| 33 | +} |
| 34 | + |
| 35 | +// ExchangeToken trades an exchange token for a new access token. |
| 36 | +func (r *IdentityService) ExchangeToken(ctx context.Context, params IdentityExchangeTokenParams, opts ...option.RequestOption) (res *IdentityExchangeTokenResponse, err error) { |
| 37 | + if params.ConnectProtocolVersion.Present { |
| 38 | + opts = append(opts, option.WithHeader("Connect-Protocol-Version", fmt.Sprintf("%s", params.ConnectProtocolVersion))) |
| 39 | + } |
| 40 | + if params.ConnectTimeoutMs.Present { |
| 41 | + opts = append(opts, option.WithHeader("Connect-Timeout-Ms", fmt.Sprintf("%s", params.ConnectTimeoutMs))) |
| 42 | + } |
| 43 | + opts = append(r.Options[:], opts...) |
| 44 | + path := "gitpod.v1.IdentityService/ExchangeToken" |
| 45 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) |
| 46 | + return |
| 47 | +} |
| 48 | + |
| 49 | +// GetAuthenticatedIdentity allows to retrieve the current identity. |
| 50 | +func (r *IdentityService) GetAuthenticatedIdentity(ctx context.Context, params IdentityGetAuthenticatedIdentityParams, opts ...option.RequestOption) (res *IdentityGetAuthenticatedIdentityResponse, err error) { |
| 51 | + if params.ConnectProtocolVersion.Present { |
| 52 | + opts = append(opts, option.WithHeader("Connect-Protocol-Version", fmt.Sprintf("%s", params.ConnectProtocolVersion))) |
| 53 | + } |
| 54 | + if params.ConnectTimeoutMs.Present { |
| 55 | + opts = append(opts, option.WithHeader("Connect-Timeout-Ms", fmt.Sprintf("%s", params.ConnectTimeoutMs))) |
| 56 | + } |
| 57 | + opts = append(r.Options[:], opts...) |
| 58 | + path := "gitpod.v1.IdentityService/GetAuthenticatedIdentity" |
| 59 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) |
| 60 | + return |
| 61 | +} |
| 62 | + |
| 63 | +// GetIDToken returns a token that can be used to authenticate the user against the |
| 64 | +// other services. |
| 65 | +func (r *IdentityService) GetIDToken(ctx context.Context, params IdentityGetIDTokenParams, opts ...option.RequestOption) (res *IdentityGetIDTokenResponse, err error) { |
| 66 | + if params.ConnectProtocolVersion.Present { |
| 67 | + opts = append(opts, option.WithHeader("Connect-Protocol-Version", fmt.Sprintf("%s", params.ConnectProtocolVersion))) |
| 68 | + } |
| 69 | + if params.ConnectTimeoutMs.Present { |
| 70 | + opts = append(opts, option.WithHeader("Connect-Timeout-Ms", fmt.Sprintf("%s", params.ConnectTimeoutMs))) |
| 71 | + } |
| 72 | + opts = append(r.Options[:], opts...) |
| 73 | + path := "gitpod.v1.IdentityService/GetIDToken" |
| 74 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) |
| 75 | + return |
| 76 | +} |
| 77 | + |
| 78 | +type IdentityExchangeTokenResponse struct { |
| 79 | + // access_token is the new access token |
| 80 | + AccessToken string `json:"accessToken"` |
| 81 | + JSON identityExchangeTokenResponseJSON `json:"-"` |
| 82 | +} |
| 83 | + |
| 84 | +// identityExchangeTokenResponseJSON contains the JSON metadata for the struct |
| 85 | +// [IdentityExchangeTokenResponse] |
| 86 | +type identityExchangeTokenResponseJSON struct { |
| 87 | + AccessToken apijson.Field |
| 88 | + raw string |
| 89 | + ExtraFields map[string]apijson.Field |
| 90 | +} |
| 91 | + |
| 92 | +func (r *IdentityExchangeTokenResponse) UnmarshalJSON(data []byte) (err error) { |
| 93 | + return apijson.UnmarshalRoot(data, r) |
| 94 | +} |
| 95 | + |
| 96 | +func (r identityExchangeTokenResponseJSON) RawJSON() string { |
| 97 | + return r.raw |
| 98 | +} |
| 99 | + |
| 100 | +type IdentityGetAuthenticatedIdentityResponse struct { |
| 101 | + OrganizationID string `json:"organizationId"` |
| 102 | + // subject is the identity of the current user |
| 103 | + Subject IdentityGetAuthenticatedIdentityResponseSubject `json:"subject"` |
| 104 | + JSON identityGetAuthenticatedIdentityResponseJSON `json:"-"` |
| 105 | +} |
| 106 | + |
| 107 | +// identityGetAuthenticatedIdentityResponseJSON contains the JSON metadata for the |
| 108 | +// struct [IdentityGetAuthenticatedIdentityResponse] |
| 109 | +type identityGetAuthenticatedIdentityResponseJSON struct { |
| 110 | + OrganizationID apijson.Field |
| 111 | + Subject apijson.Field |
| 112 | + raw string |
| 113 | + ExtraFields map[string]apijson.Field |
| 114 | +} |
| 115 | + |
| 116 | +func (r *IdentityGetAuthenticatedIdentityResponse) UnmarshalJSON(data []byte) (err error) { |
| 117 | + return apijson.UnmarshalRoot(data, r) |
| 118 | +} |
| 119 | + |
| 120 | +func (r identityGetAuthenticatedIdentityResponseJSON) RawJSON() string { |
| 121 | + return r.raw |
| 122 | +} |
| 123 | + |
| 124 | +// subject is the identity of the current user |
| 125 | +type IdentityGetAuthenticatedIdentityResponseSubject struct { |
| 126 | + // id is the UUID of the subject |
| 127 | + ID string `json:"id"` |
| 128 | + // Principal is the principal of the subject |
| 129 | + Principal IdentityGetAuthenticatedIdentityResponseSubjectPrincipal `json:"principal"` |
| 130 | + JSON identityGetAuthenticatedIdentityResponseSubjectJSON `json:"-"` |
| 131 | +} |
| 132 | + |
| 133 | +// identityGetAuthenticatedIdentityResponseSubjectJSON contains the JSON metadata |
| 134 | +// for the struct [IdentityGetAuthenticatedIdentityResponseSubject] |
| 135 | +type identityGetAuthenticatedIdentityResponseSubjectJSON struct { |
| 136 | + ID apijson.Field |
| 137 | + Principal apijson.Field |
| 138 | + raw string |
| 139 | + ExtraFields map[string]apijson.Field |
| 140 | +} |
| 141 | + |
| 142 | +func (r *IdentityGetAuthenticatedIdentityResponseSubject) UnmarshalJSON(data []byte) (err error) { |
| 143 | + return apijson.UnmarshalRoot(data, r) |
| 144 | +} |
| 145 | + |
| 146 | +func (r identityGetAuthenticatedIdentityResponseSubjectJSON) RawJSON() string { |
| 147 | + return r.raw |
| 148 | +} |
| 149 | + |
| 150 | +// Principal is the principal of the subject |
| 151 | +type IdentityGetAuthenticatedIdentityResponseSubjectPrincipal string |
| 152 | + |
| 153 | +const ( |
| 154 | + IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalUnspecified IdentityGetAuthenticatedIdentityResponseSubjectPrincipal = "PRINCIPAL_UNSPECIFIED" |
| 155 | + IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalAccount IdentityGetAuthenticatedIdentityResponseSubjectPrincipal = "PRINCIPAL_ACCOUNT" |
| 156 | + IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalUser IdentityGetAuthenticatedIdentityResponseSubjectPrincipal = "PRINCIPAL_USER" |
| 157 | + IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalRunner IdentityGetAuthenticatedIdentityResponseSubjectPrincipal = "PRINCIPAL_RUNNER" |
| 158 | + IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalEnvironment IdentityGetAuthenticatedIdentityResponseSubjectPrincipal = "PRINCIPAL_ENVIRONMENT" |
| 159 | + IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalServiceAccount IdentityGetAuthenticatedIdentityResponseSubjectPrincipal = "PRINCIPAL_SERVICE_ACCOUNT" |
| 160 | +) |
| 161 | + |
| 162 | +func (r IdentityGetAuthenticatedIdentityResponseSubjectPrincipal) IsKnown() bool { |
| 163 | + switch r { |
| 164 | + case IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalUnspecified, IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalAccount, IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalUser, IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalRunner, IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalEnvironment, IdentityGetAuthenticatedIdentityResponseSubjectPrincipalPrincipalServiceAccount: |
| 165 | + return true |
| 166 | + } |
| 167 | + return false |
| 168 | +} |
| 169 | + |
| 170 | +type IdentityGetIDTokenResponse struct { |
| 171 | + Token string `json:"token"` |
| 172 | + JSON identityGetIDTokenResponseJSON `json:"-"` |
| 173 | +} |
| 174 | + |
| 175 | +// identityGetIDTokenResponseJSON contains the JSON metadata for the struct |
| 176 | +// [IdentityGetIDTokenResponse] |
| 177 | +type identityGetIDTokenResponseJSON struct { |
| 178 | + Token apijson.Field |
| 179 | + raw string |
| 180 | + ExtraFields map[string]apijson.Field |
| 181 | +} |
| 182 | + |
| 183 | +func (r *IdentityGetIDTokenResponse) UnmarshalJSON(data []byte) (err error) { |
| 184 | + return apijson.UnmarshalRoot(data, r) |
| 185 | +} |
| 186 | + |
| 187 | +func (r identityGetIDTokenResponseJSON) RawJSON() string { |
| 188 | + return r.raw |
| 189 | +} |
| 190 | + |
| 191 | +type IdentityExchangeTokenParams struct { |
| 192 | + // Define the version of the Connect protocol |
| 193 | + ConnectProtocolVersion param.Field[IdentityExchangeTokenParamsConnectProtocolVersion] `header:"Connect-Protocol-Version,required"` |
| 194 | + // exchange_token is the token to exchange |
| 195 | + ExchangeToken param.Field[string] `json:"exchangeToken"` |
| 196 | + // Define the timeout, in ms |
| 197 | + ConnectTimeoutMs param.Field[float64] `header:"Connect-Timeout-Ms"` |
| 198 | +} |
| 199 | + |
| 200 | +func (r IdentityExchangeTokenParams) MarshalJSON() (data []byte, err error) { |
| 201 | + return apijson.MarshalRoot(r) |
| 202 | +} |
| 203 | + |
| 204 | +// Define the version of the Connect protocol |
| 205 | +type IdentityExchangeTokenParamsConnectProtocolVersion float64 |
| 206 | + |
| 207 | +const ( |
| 208 | + IdentityExchangeTokenParamsConnectProtocolVersion1 IdentityExchangeTokenParamsConnectProtocolVersion = 1 |
| 209 | +) |
| 210 | + |
| 211 | +func (r IdentityExchangeTokenParamsConnectProtocolVersion) IsKnown() bool { |
| 212 | + switch r { |
| 213 | + case IdentityExchangeTokenParamsConnectProtocolVersion1: |
| 214 | + return true |
| 215 | + } |
| 216 | + return false |
| 217 | +} |
| 218 | + |
| 219 | +type IdentityGetAuthenticatedIdentityParams struct { |
| 220 | + Body interface{} `json:"body,required"` |
| 221 | + // Define the version of the Connect protocol |
| 222 | + ConnectProtocolVersion param.Field[IdentityGetAuthenticatedIdentityParamsConnectProtocolVersion] `header:"Connect-Protocol-Version,required"` |
| 223 | + // Define the timeout, in ms |
| 224 | + ConnectTimeoutMs param.Field[float64] `header:"Connect-Timeout-Ms"` |
| 225 | +} |
| 226 | + |
| 227 | +func (r IdentityGetAuthenticatedIdentityParams) MarshalJSON() (data []byte, err error) { |
| 228 | + return apijson.MarshalRoot(r.Body) |
| 229 | +} |
| 230 | + |
| 231 | +// Define the version of the Connect protocol |
| 232 | +type IdentityGetAuthenticatedIdentityParamsConnectProtocolVersion float64 |
| 233 | + |
| 234 | +const ( |
| 235 | + IdentityGetAuthenticatedIdentityParamsConnectProtocolVersion1 IdentityGetAuthenticatedIdentityParamsConnectProtocolVersion = 1 |
| 236 | +) |
| 237 | + |
| 238 | +func (r IdentityGetAuthenticatedIdentityParamsConnectProtocolVersion) IsKnown() bool { |
| 239 | + switch r { |
| 240 | + case IdentityGetAuthenticatedIdentityParamsConnectProtocolVersion1: |
| 241 | + return true |
| 242 | + } |
| 243 | + return false |
| 244 | +} |
| 245 | + |
| 246 | +type IdentityGetIDTokenParams struct { |
| 247 | + // Define the version of the Connect protocol |
| 248 | + ConnectProtocolVersion param.Field[IdentityGetIDTokenParamsConnectProtocolVersion] `header:"Connect-Protocol-Version,required"` |
| 249 | + Audience param.Field[[]string] `json:"audience"` |
| 250 | + // Define the timeout, in ms |
| 251 | + ConnectTimeoutMs param.Field[float64] `header:"Connect-Timeout-Ms"` |
| 252 | +} |
| 253 | + |
| 254 | +func (r IdentityGetIDTokenParams) MarshalJSON() (data []byte, err error) { |
| 255 | + return apijson.MarshalRoot(r) |
| 256 | +} |
| 257 | + |
| 258 | +// Define the version of the Connect protocol |
| 259 | +type IdentityGetIDTokenParamsConnectProtocolVersion float64 |
| 260 | + |
| 261 | +const ( |
| 262 | + IdentityGetIDTokenParamsConnectProtocolVersion1 IdentityGetIDTokenParamsConnectProtocolVersion = 1 |
| 263 | +) |
| 264 | + |
| 265 | +func (r IdentityGetIDTokenParamsConnectProtocolVersion) IsKnown() bool { |
| 266 | + switch r { |
| 267 | + case IdentityGetIDTokenParamsConnectProtocolVersion1: |
| 268 | + return true |
| 269 | + } |
| 270 | + return false |
| 271 | +} |
0 commit comments