diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock
index b7694bd..2df6c00 100755
--- a/.speakeasy/gen.lock
+++ b/.speakeasy/gen.lock
@@ -1,19 +1,19 @@
lockVersion: 2.0.0
id: 4fc4737a-135f-4840-8e6d-42a2b2a2884b
management:
- docChecksum: 1adbad72708fe75ac7626a1e7e1dfc13
+ docChecksum: 75f7e089853056de07ee9bd3d0b1678d
docVersion: 1.0.0
- speakeasyVersion: 1.335.2
- generationVersion: 2.372.3
- releaseVersion: 0.7.0
- configChecksum: c299315b1cde1ca427dc047689fa60ff
+ speakeasyVersion: 1.340.0
+ generationVersion: 2.375.5
+ releaseVersion: 0.8.0
+ configChecksum: f7715aaf0773d3aaeefa9a127727517d
repoURL: https://github.com/unkeyed/unkey-go.git
installationURL: https://github.com/unkeyed/unkey-go
features:
go:
additionalDependencies: 0.1.0
constsAndDefaults: 0.1.4
- core: 3.4.15
+ core: 3.5.0
defaultEnabledRetries: 0.2.0
deprecations: 2.81.1
envVarSecurityUsage: 0.2.0
@@ -24,6 +24,7 @@ features:
ignores: 2.81.1
intellisenseMarkdownSupport: 0.1.0
nullables: 0.1.0
+ pagination: 2.82.1
responseFormat: 0.1.2
retries: 2.83.0
sdkHooks: 0.1.0
@@ -35,6 +36,7 @@ generatedFiles:
- ratelimits.go
- migrations.go
- permissions.go
+ - identities.go
- unkey.go
- go.mod
- models/sdkerrors/sdkerror.go
@@ -56,6 +58,8 @@ generatedFiles:
- internal/utils/utils.go
- /models/operations/createapi.go
- /models/operations/deleteapi.go
+ - /models/operations/createidentity.go
+ - /models/operations/deleteeidentity.go
- /models/operations/v1liveness.go
- /models/operations/getkey.go
- /models/operations/deletekey.go
@@ -84,6 +88,9 @@ generatedFiles:
- /models/operations/deleterole.go
- /models/operations/getrole.go
- /models/operations/listroles.go
+ - /models/operations/getidentity.go
+ - /models/operations/listidentities.go
+ - /models/operations/updateidentity.go
- /models/components/httpmetadata.go
- /models/components/key.go
- /models/components/v1keysverifykeyresponse.go
@@ -103,6 +110,13 @@ generatedFiles:
- docs/models/operations/deleteapirequestbody.md
- docs/models/operations/deleteapiresponsebody.md
- docs/models/operations/deleteapiresponse.md
+ - docs/models/operations/ratelimits.md
+ - docs/models/operations/createidentityrequestbody.md
+ - docs/models/operations/createidentityresponsebody.md
+ - docs/models/operations/createidentityresponse.md
+ - docs/models/operations/deleteeidentityrequestbody.md
+ - docs/models/operations/deleteeidentityresponsebody.md
+ - docs/models/operations/deleteeidentityresponse.md
- docs/models/operations/services.md
- docs/models/operations/v1livenessresponsebody.md
- docs/models/operations/v1livenessresponse.md
@@ -215,6 +229,19 @@ generatedFiles:
- docs/models/operations/getroleresponse.md
- docs/models/operations/listrolesresponsebody.md
- docs/models/operations/listrolesresponse.md
+ - docs/models/operations/getidentityrequest.md
+ - docs/models/operations/getidentityratelimits.md
+ - docs/models/operations/getidentityresponsebody.md
+ - docs/models/operations/getidentityresponse.md
+ - docs/models/operations/listidentitiesrequest.md
+ - docs/models/operations/listidentitiesratelimits.md
+ - docs/models/operations/identities.md
+ - docs/models/operations/listidentitiesresponsebody.md
+ - docs/models/operations/listidentitiesresponse.md
+ - docs/models/operations/updateidentityratelimits.md
+ - docs/models/operations/updateidentityrequestbody.md
+ - docs/models/operations/updateidentityresponsebody.md
+ - docs/models/operations/updateidentityresponse.md
- docs/models/components/httpmetadata.md
- docs/models/components/interval.md
- docs/models/components/refill.md
@@ -223,6 +250,7 @@ generatedFiles:
- docs/models/components/key.md
- docs/models/components/v1keysverifykeyresponseratelimit.md
- docs/models/components/code.md
+ - docs/models/components/identity.md
- docs/models/components/v1keysverifykeyresponse.md
- docs/models/components/authorization.md
- docs/models/components/v1keysverifykeyrequestratelimit.md
@@ -261,7 +289,9 @@ generatedFiles:
- docs/sdks/ratelimits/README.md
- docs/sdks/migrations/README.md
- docs/sdks/permissions/README.md
+ - docs/sdks/identities/README.md
- USAGE.md
- models/operations/options.go
- .gitattributes
- internal/hooks/hooks.go
+ - CONTRIBUTING.md
diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml
index 282129f..4c26642 100755
--- a/.speakeasy/gen.yaml
+++ b/.speakeasy/gen.yaml
@@ -12,7 +12,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: true
go:
- version: 0.7.0
+ version: 0.8.0
additionalDependencies: {}
allowUnknownFieldsInWeakUnions: false
clientServerStatusCodesAsErrors: true
diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock
index a5fa9c4..62d7942 100644
--- a/.speakeasy/workflow.lock
+++ b/.speakeasy/workflow.lock
@@ -1,9 +1,9 @@
-speakeasyVersion: 1.335.2
+speakeasyVersion: 1.340.0
sources:
openapi.json:
sourceNamespace: openapi-json
- sourceRevisionDigest: sha256:5754c6125ef1a2d0690dd2ba633bc841608de7594320804124517ded211f4f1a
- sourceBlobDigest: sha256:f0439adffd2a8e451bd3b624609ededd5e1b0eb06fc998eafa5e2ee5df6613d4
+ sourceRevisionDigest: sha256:8692dc0ff51ce0350cb69b2465bc3289d63a4986945e5574285cd187a05248c1
+ sourceBlobDigest: sha256:249aa19308afcc8b58771b1b2833cd720293edea20e33016faa4e23aef204656
tags:
- latest
- main
@@ -11,8 +11,8 @@ targets:
go:
source: openapi.json
sourceNamespace: openapi-json
- sourceRevisionDigest: sha256:5754c6125ef1a2d0690dd2ba633bc841608de7594320804124517ded211f4f1a
- sourceBlobDigest: sha256:f0439adffd2a8e451bd3b624609ededd5e1b0eb06fc998eafa5e2ee5df6613d4
+ sourceRevisionDigest: sha256:8692dc0ff51ce0350cb69b2465bc3289d63a4986945e5574285cd187a05248c1
+ sourceBlobDigest: sha256:249aa19308afcc8b58771b1b2833cd720293edea20e33016faa4e23aef204656
outLocation: /github/workspace/repo
workflow:
workflowVersion: 1.0.0
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..d585717
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,26 @@
+# Contributing to This Repository
+
+Thank you for your interest in contributing to this repository. Please note that this repository contains generated code. As such, we do not accept direct changes or pull requests. Instead, we encourage you to follow the guidelines below to report issues and suggest improvements.
+
+## How to Report Issues
+
+If you encounter any bugs or have suggestions for improvements, please open an issue on GitHub. When reporting an issue, please provide as much detail as possible to help us reproduce the problem. This includes:
+
+- A clear and descriptive title
+- Steps to reproduce the issue
+- Expected and actual behavior
+- Any relevant logs, screenshots, or error messages
+- Information about your environment (e.g., operating system, software versions)
+ - For example can be collected using the `npx envinfo` command from your terminal if you have Node.js installed
+
+## Issue Triage and Upstream Fixes
+
+We will review and triage issues as quickly as possible. Our goal is to address bugs and incorporate improvements in the upstream source code. Fixes will be included in the next generation of the generated code.
+
+## Contact
+
+If you have any questions or need further assistance, please feel free to reach out by opening an issue.
+
+Thank you for your understanding and cooperation!
+
+The Maintainers
diff --git a/README.md b/README.md
index 39a2df9..6a92b10 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,8 @@ func main() {
* [CreateAPI](docs/sdks/unkey/README.md#createapi)
* [DeleteAPI](docs/sdks/unkey/README.md#deleteapi)
+* [CreateIdentity](docs/sdks/unkey/README.md#createidentity)
+* [DeleteeIdentity](docs/sdks/unkey/README.md#deleteeidentity)
### [Liveness](docs/sdks/liveness/README.md)
@@ -102,6 +104,12 @@ func main() {
* [DeleteRole](docs/sdks/permissions/README.md#deleterole)
* [GetRole](docs/sdks/permissions/README.md#getrole)
* [ListRoles](docs/sdks/permissions/README.md#listroles)
+
+### [Identities](docs/sdks/identities/README.md)
+
+* [GetIdentity](docs/sdks/identities/README.md#getidentity)
+* [ListIdentities](docs/sdks/identities/README.md#listidentities)
+* [UpdateIdentity](docs/sdks/identities/README.md#updateidentity)
@@ -449,6 +457,58 @@ func main() {
```
+
+## Pagination
+
+Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
+returned response object will have a `Next` method that can be called to pull down the next group of results. If the
+return value of `Next` is `nil`, then there are no more pages to be fetched.
+
+Here's an example of one such pagination call:
+```go
+package main
+
+import (
+ "context"
+ unkeygo "github.com/unkeyed/unkey-go"
+ "github.com/unkeyed/unkey-go/models/operations"
+ "log"
+ "os"
+)
+
+func main() {
+ s := unkeygo.New(
+ unkeygo.WithSecurity(os.Getenv("BEARER_AUTH")),
+ )
+ request := operations.ListIdentitiesRequest{
+ Limit: unkeygo.Int64(100),
+ }
+ ctx := context.Background()
+ res, err := s.Identities.ListIdentities(ctx, request)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if res.Object != nil {
+ for {
+ // handle items
+
+ res, err = res.Next()
+
+ if err != nil {
+ // handle error
+ }
+
+ if res == nil {
+ break
+ }
+ }
+
+ }
+}
+
+```
+
+
# Development
diff --git a/RELEASES.md b/RELEASES.md
index 0b30be9..ef30d1d 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -128,4 +128,14 @@ Based on:
### Generated
- [go v0.7.0] .
### Releases
-- [Go v0.7.0] https://github.com/unkeyed/unkey-go/releases/tag/v0.7.0 - .
\ No newline at end of file
+- [Go v0.7.0] https://github.com/unkeyed/unkey-go/releases/tag/v0.7.0 - .
+
+## 2024-07-17 22:05:01
+### Changes
+Based on:
+- OpenAPI Doc
+- Speakeasy CLI 1.340.0 (2.375.5) https://github.com/speakeasy-api/speakeasy
+### Generated
+- [go v0.8.0] .
+### Releases
+- [Go v0.8.0] https://github.com/unkeyed/unkey-go/releases/tag/v0.8.0 - .
\ No newline at end of file
diff --git a/docs/models/components/identity.md b/docs/models/components/identity.md
new file mode 100644
index 0000000..c1328d4
--- /dev/null
+++ b/docs/models/components/identity.md
@@ -0,0 +1,12 @@
+# Identity
+
+The associated identity of this key.
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| ------------------ | ------------------ | ------------------ | ------------------ |
+| `ID` | *string* | :heavy_check_mark: | N/A |
+| `ExternalID` | *string* | :heavy_check_mark: | N/A |
+| `Meta` | map[string]*any* | :heavy_check_mark: | N/A |
\ No newline at end of file
diff --git a/docs/models/components/ratelimits.md b/docs/models/components/ratelimits.md
index a127e73..38f58bc 100644
--- a/docs/models/components/ratelimits.md
+++ b/docs/models/components/ratelimits.md
@@ -5,8 +5,7 @@
| Field | Type | Required | Description | Example |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
-| `Name` | *string* | :heavy_check_mark: | The name of the ratelimit | tokens |
+| `Name` | *string* | :heavy_check_mark: | The name of the ratelimit. | tokens |
| `Cost` | **int64* | :heavy_minus_sign: | Optionally override how expensive this operation is and how many tokens are deducted from the current limit. | |
-| `Identifier` | **string* | :heavy_minus_sign: | The identifier used for ratelimiting. If omitted, we use the key's id. | |
| `Limit` | **float64* | :heavy_minus_sign: | Optionally override the limit. | |
| `Duration` | **float64* | :heavy_minus_sign: | Optionally override the ratelimit window duration. | |
\ No newline at end of file
diff --git a/docs/models/components/v1keysverifykeyrequest.md b/docs/models/components/v1keysverifykeyrequest.md
index 72b945b..0491e5e 100644
--- a/docs/models/components/v1keysverifykeyrequest.md
+++ b/docs/models/components/v1keysverifykeyrequest.md
@@ -3,10 +3,10 @@
## Fields
-| Field | Type | Required | Description | Example |
-| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `APIID` | **string* | :heavy_minus_sign: | The id of the api where the key belongs to. This is optional for now but will be required soon.
The key will be verified against the api's configuration. If the key does not belong to the api, the verification will fail. | api_1234 |
-| `Key` | *string* | :heavy_check_mark: | The key to verify | sk_1234 |
-| `Authorization` | [*components.Authorization](../../models/components/authorization.md) | :heavy_minus_sign: | Perform RBAC checks | |
-| `Ratelimit` | [*components.V1KeysVerifyKeyRequestRatelimit](../../models/components/v1keysverifykeyrequestratelimit.md) | :heavy_minus_sign: | N/A | |
-| `Ratelimits` | [][components.Ratelimits](../../models/components/ratelimits.md) | :heavy_minus_sign: | N/A | |
\ No newline at end of file
+| Field | Type | Required | Description | Example |
+| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `APIID` | **string* | :heavy_minus_sign: | The id of the api where the key belongs to. This is optional for now but will be required soon.
The key will be verified against the api's configuration. If the key does not belong to the api, the verification will fail. | api_1234 |
+| `Key` | *string* | :heavy_check_mark: | The key to verify | sk_1234 |
+| `Authorization` | [*components.Authorization](../../models/components/authorization.md) | :heavy_minus_sign: | Perform RBAC checks | |
+| ~~`Ratelimit`~~ | [*components.V1KeysVerifyKeyRequestRatelimit](../../models/components/v1keysverifykeyrequestratelimit.md) | :heavy_minus_sign: | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.
Use 'ratelimits' with `[{ name: "default", cost: 2}]` | |
+| `Ratelimits` | [][components.Ratelimits](../../models/components/ratelimits.md) | :heavy_minus_sign: | You can check against multiple ratelimits when verifying a key. Let's say you are building an app that uses AI under the hood and you want to limit your customers to 500 requests per hour, but also ensure they use up less than 20k tokens per day.
[](https://www.unkey.com/docs/concepts/identities/ratelimits) | [
{
"name": "requests",
"limit": 500,
"duration": 3600000
},
{
"name": "tokens",
"limit": 20000,
"duration": 86400000
}
] |
\ No newline at end of file
diff --git a/docs/models/components/v1keysverifykeyrequestratelimit.md b/docs/models/components/v1keysverifykeyrequestratelimit.md
index 8cea3df..47dcc57 100644
--- a/docs/models/components/v1keysverifykeyrequestratelimit.md
+++ b/docs/models/components/v1keysverifykeyrequestratelimit.md
@@ -1,4 +1,8 @@
-# V1KeysVerifyKeyRequestRatelimit
+# ~~V1KeysVerifyKeyRequestRatelimit~~
+
+Use 'ratelimits' with `[{ name: "default", cost: 2}]`
+
+> :warning: **DEPRECATED**: This will be removed in a future release, please migrate away from it as soon as possible.
## Fields
diff --git a/docs/models/components/v1keysverifykeyresponse.md b/docs/models/components/v1keysverifykeyresponse.md
index 7f17490..5c2caa9 100644
--- a/docs/models/components/v1keysverifykeyresponse.md
+++ b/docs/models/components/v1keysverifykeyresponse.md
@@ -11,9 +11,10 @@
| `OwnerID` | **string* | :heavy_minus_sign: | The id of the tenant associated with this key. Use whatever reference you have in your system to identify the tenant. When verifying the key, we will send this field back to you, so you know who is accessing your API. | user_123 |
| `Meta` | map[string]*any* | :heavy_minus_sign: | Any additional metadata you want to store with the key | {
"roles": [
"admin",
"user"
],
"stripeCustomerId": "cus_1234"
} |
| `Expires` | **int64* | :heavy_minus_sign: | The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring. | 123 |
-| `Ratelimit` | [*components.V1KeysVerifyKeyResponseRatelimit](../../models/components/v1keysverifykeyresponseratelimit.md) | :heavy_minus_sign: | Multi ratelimits TODO: | {
"limit": 10,
"remaining": 9,
"reset": 3600000
} |
+| `Ratelimit` | [*components.V1KeysVerifyKeyResponseRatelimit](../../models/components/v1keysverifykeyresponseratelimit.md) | :heavy_minus_sign: | The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit. | {
"limit": 10,
"remaining": 9,
"reset": 3600000
} |
| `Remaining` | **int64* | :heavy_minus_sign: | The number of requests that can be made with this key before it becomes invalid. If this field is null or undefined, the key has no request limit. | 1000 |
| `Code` | [components.Code](../../models/components/code.md) | :heavy_check_mark: | A machine readable code why the key is not valid.
Possible values are:
- VALID: the key is valid and you should proceed
- NOT_FOUND: the key does not exist or has expired
- FORBIDDEN: the key is not allowed to access the api
- USAGE_EXCEEDED: the key has exceeded its request limit
- RATE_LIMITED: the key has been ratelimited
- UNAUTHORIZED: the key is not authorized
- DISABLED: the key is disabled
- INSUFFICIENT_PERMISSIONS: you do not have the required permissions to perform this action
- EXPIRED: The key was only valid for a certain time and has expired.
| |
| `Enabled` | **bool* | :heavy_minus_sign: | Sets the key to be enabled or disabled. Disabled keys will not verify. | |
| `Permissions` | []*string* | :heavy_minus_sign: | A list of all the permissions this key is connected to. | [
"dns.record.update",
"dns.record.delete"
] |
-| `Environment` | **string* | :heavy_minus_sign: | The environment of the key, this is what what you set when you crated the key | test |
\ No newline at end of file
+| `Environment` | **string* | :heavy_minus_sign: | The environment of the key, this is what what you set when you crated the key | test |
+| `Identity` | [*components.Identity](../../models/components/identity.md) | :heavy_minus_sign: | The associated identity of this key. | |
\ No newline at end of file
diff --git a/docs/models/components/v1keysverifykeyresponseratelimit.md b/docs/models/components/v1keysverifykeyresponseratelimit.md
index d9a2f00..e5fe2cd 100644
--- a/docs/models/components/v1keysverifykeyresponseratelimit.md
+++ b/docs/models/components/v1keysverifykeyresponseratelimit.md
@@ -1,6 +1,6 @@
# V1KeysVerifyKeyResponseRatelimit
-Multi ratelimits TODO:
+The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit.
## Fields
diff --git a/docs/models/operations/createidentityrequestbody.md b/docs/models/operations/createidentityrequestbody.md
new file mode 100644
index 0000000..18e9d4f
--- /dev/null
+++ b/docs/models/operations/createidentityrequestbody.md
@@ -0,0 +1,10 @@
+# CreateIdentityRequestBody
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `ExternalID` | *string* | :heavy_check_mark: | The id of this identity in your system.
This usually comes from your authentication provider and could be a userId, organisationId or even an email.
It does not matter what you use, as long as it uniquely identifies something in your application.
| user_123 |
+| `Meta` | map[string]*any* | :heavy_minus_sign: | Attach metadata to this identity that you need to have access to when verifying a key.
This will be returned as part of the `verifyKey` response.
| |
+| `Ratelimits` | [][operations.Ratelimits](../../models/operations/ratelimits.md) | :heavy_minus_sign: | Attach ratelimits to this identity.
When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits. | |
\ No newline at end of file
diff --git a/docs/models/operations/createidentityresponse.md b/docs/models/operations/createidentityresponse.md
new file mode 100644
index 0000000..b9284aa
--- /dev/null
+++ b/docs/models/operations/createidentityresponse.md
@@ -0,0 +1,9 @@
+# CreateIdentityResponse
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
+| `HTTPMeta` | [components.HTTPMetadata](../../models/components/httpmetadata.md) | :heavy_check_mark: | N/A |
+| `Object` | [*operations.CreateIdentityResponseBody](../../models/operations/createidentityresponsebody.md) | :heavy_minus_sign: | The configuration for an api |
\ No newline at end of file
diff --git a/docs/models/operations/createidentityresponsebody.md b/docs/models/operations/createidentityresponsebody.md
new file mode 100644
index 0000000..29c22f3
--- /dev/null
+++ b/docs/models/operations/createidentityresponsebody.md
@@ -0,0 +1,10 @@
+# CreateIdentityResponseBody
+
+The configuration for an api
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- |
+| `IdentityID` | *string* | :heavy_check_mark: | The id of the identity. Used internally, you do not need to store this. | id_123 |
\ No newline at end of file
diff --git a/docs/models/operations/createkeyrequestbody.md b/docs/models/operations/createkeyrequestbody.md
index e93b458..d88f007 100644
--- a/docs/models/operations/createkeyrequestbody.md
+++ b/docs/models/operations/createkeyrequestbody.md
@@ -9,7 +9,8 @@
| `Prefix` | **string* | :heavy_minus_sign: | To make it easier for your users to understand which product an api key belongs to, you can add prefix them.
For example Stripe famously prefixes their customer ids with cus_ or their api keys with sk_live_.
The underscore is automatically added if you are defining a prefix, for example: "prefix": "abc" will result in a key like abc_xxxxxxxxx
| |
| `Name` | **string* | :heavy_minus_sign: | The name for your Key. This is not customer facing. | my key |
| `ByteLength` | **int64* | :heavy_minus_sign: | The byte length used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle. The default is 16 bytes, or 2^^128 possible combinations. | |
-| `OwnerID` | **string* | :heavy_minus_sign: | Your user’s Id. This will provide a link between Unkey and your customer record.
When validating a key, we will return this back to you, so you can clearly identify your user from their api key. | team_123 |
+| ~~`OwnerID`~~ | **string* | :heavy_minus_sign: | : warning: ** DEPRECATED **: This will be removed in a future release, please migrate away from it as soon as possible.
Deprecated, use `externalId` | team_123 |
+| `ExternalID` | **string* | :heavy_minus_sign: | Your user's Id. This will provide a link between Unkey and your customer record.
When validating a key, we will return this back to you, so you can clearly identify your user from their api key. | team_123 |
| `Meta` | map[string]*any* | :heavy_minus_sign: | This is a place for dynamic meta data, anything that feels useful for you should go here | {
"billingTier": "PRO",
"trialEnds": "2023-06-16T17:16:37.161Z"
} |
| `Roles` | []*string* | :heavy_minus_sign: | A list of roles that this key should have. If the role does not exist, an error is thrown | [
"admin",
"finance"
] |
| `Permissions` | []*string* | :heavy_minus_sign: | A list of permissions that this key should have. If the permission does not exist, an error is thrown | [
"domains.create_record",
"say_hello"
] |
diff --git a/docs/models/operations/deleteeidentityrequestbody.md b/docs/models/operations/deleteeidentityrequestbody.md
new file mode 100644
index 0000000..3385e3b
--- /dev/null
+++ b/docs/models/operations/deleteeidentityrequestbody.md
@@ -0,0 +1,8 @@
+# DeleteeIdentityRequestBody
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| -------------------------------- | -------------------------------- | -------------------------------- | -------------------------------- | -------------------------------- |
+| `IdentityID` | *string* | :heavy_check_mark: | The id of the identity to delete | id_1234 |
\ No newline at end of file
diff --git a/docs/models/operations/deleteeidentityresponse.md b/docs/models/operations/deleteeidentityresponse.md
new file mode 100644
index 0000000..56b88dd
--- /dev/null
+++ b/docs/models/operations/deleteeidentityresponse.md
@@ -0,0 +1,9 @@
+# DeleteeIdentityResponse
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
+| `HTTPMeta` | [components.HTTPMetadata](../../models/components/httpmetadata.md) | :heavy_check_mark: | N/A |
+| `Object` | [*operations.DeleteeIdentityResponseBody](../../models/operations/deleteeidentityresponsebody.md) | :heavy_minus_sign: | The identity was successfully deleted, it may take up to 30s for this to take effect in all regions |
\ No newline at end of file
diff --git a/docs/models/operations/deleteeidentityresponsebody.md b/docs/models/operations/deleteeidentityresponsebody.md
new file mode 100644
index 0000000..85595ad
--- /dev/null
+++ b/docs/models/operations/deleteeidentityresponsebody.md
@@ -0,0 +1,9 @@
+# DeleteeIdentityResponseBody
+
+The identity was successfully deleted, it may take up to 30s for this to take effect in all regions
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| ----------- | ----------- | ----------- | ----------- |
\ No newline at end of file
diff --git a/docs/models/operations/getidentityratelimits.md b/docs/models/operations/getidentityratelimits.md
new file mode 100644
index 0000000..ea1e581
--- /dev/null
+++ b/docs/models/operations/getidentityratelimits.md
@@ -0,0 +1,10 @@
+# GetIdentityRatelimits
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
+| `Name` | *string* | :heavy_check_mark: | The name of this limit. You will need to use this again when verifying a key. | tokens |
+| `Limit` | *float64* | :heavy_check_mark: | How many requests may pass within a given window before requests are rejected. | 10 |
+| `Duration` | *float64* | :heavy_check_mark: | The duration for each ratelimit window in milliseconds. | 1000 |
\ No newline at end of file
diff --git a/docs/models/operations/getidentityrequest.md b/docs/models/operations/getidentityrequest.md
new file mode 100644
index 0000000..5a5184e
--- /dev/null
+++ b/docs/models/operations/getidentityrequest.md
@@ -0,0 +1,9 @@
+# GetIdentityRequest
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
+| `IdentityID` | **string* | :heavy_minus_sign: | N/A | id_1234 |
+| `ExternalID` | **string* | :heavy_minus_sign: | N/A | id_1234 |
\ No newline at end of file
diff --git a/docs/models/operations/getidentityresponse.md b/docs/models/operations/getidentityresponse.md
new file mode 100644
index 0000000..83ca0fa
--- /dev/null
+++ b/docs/models/operations/getidentityresponse.md
@@ -0,0 +1,9 @@
+# GetIdentityResponse
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
+| `HTTPMeta` | [components.HTTPMetadata](../../models/components/httpmetadata.md) | :heavy_check_mark: | N/A |
+| `Object` | [*operations.GetIdentityResponseBody](../../models/operations/getidentityresponsebody.md) | :heavy_minus_sign: | The configuration for an api |
\ No newline at end of file
diff --git a/docs/models/operations/getidentityresponsebody.md b/docs/models/operations/getidentityresponsebody.md
new file mode 100644
index 0000000..22d8e24
--- /dev/null
+++ b/docs/models/operations/getidentityresponsebody.md
@@ -0,0 +1,13 @@
+# GetIdentityResponseBody
+
+The configuration for an api
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
+| `ID` | *string* | :heavy_check_mark: | The id of this identity. Used to interact with unkey's API |
+| `ExternalID` | *string* | :heavy_check_mark: | The id in your system |
+| `Meta` | map[string]*any* | :heavy_check_mark: | The meta object defined for this identity. |
+| `Ratelimits` | [][operations.GetIdentityRatelimits](../../models/operations/getidentityratelimits.md) | :heavy_check_mark: | When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits. |
\ No newline at end of file
diff --git a/docs/models/operations/identities.md b/docs/models/operations/identities.md
new file mode 100644
index 0000000..64cd6fa
--- /dev/null
+++ b/docs/models/operations/identities.md
@@ -0,0 +1,10 @@
+# Identities
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
+| `ID` | *string* | :heavy_check_mark: | The id of this identity. Used to interact with unkey's API |
+| `ExternalID` | *string* | :heavy_check_mark: | The id in your system |
+| `Ratelimits` | [][operations.ListIdentitiesRatelimits](../../models/operations/listidentitiesratelimits.md) | :heavy_check_mark: | When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits. |
\ No newline at end of file
diff --git a/docs/models/operations/listidentitiesratelimits.md b/docs/models/operations/listidentitiesratelimits.md
new file mode 100644
index 0000000..9adfdbb
--- /dev/null
+++ b/docs/models/operations/listidentitiesratelimits.md
@@ -0,0 +1,10 @@
+# ListIdentitiesRatelimits
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
+| `Name` | *string* | :heavy_check_mark: | The name of this limit. You will need to use this again when verifying a key. | tokens |
+| `Limit` | *float64* | :heavy_check_mark: | How many requests may pass within a given window before requests are rejected. | 10 |
+| `Duration` | *float64* | :heavy_check_mark: | The duration for each ratelimit window in milliseconds. | 1000 |
\ No newline at end of file
diff --git a/docs/models/operations/listidentitiesrequest.md b/docs/models/operations/listidentitiesrequest.md
new file mode 100644
index 0000000..a376557
--- /dev/null
+++ b/docs/models/operations/listidentitiesrequest.md
@@ -0,0 +1,10 @@
+# ListIdentitiesRequest
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
+| `Environment` | **string* | :heavy_minus_sign: | N/A | |
+| `Limit` | **int64* | :heavy_minus_sign: | N/A | 100 |
+| `Cursor` | **string* | :heavy_minus_sign: | N/A | |
\ No newline at end of file
diff --git a/docs/models/operations/listidentitiesresponse.md b/docs/models/operations/listidentitiesresponse.md
new file mode 100644
index 0000000..2c35307
--- /dev/null
+++ b/docs/models/operations/listidentitiesresponse.md
@@ -0,0 +1,9 @@
+# ListIdentitiesResponse
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
+| `HTTPMeta` | [components.HTTPMetadata](../../models/components/httpmetadata.md) | :heavy_check_mark: | N/A |
+| `Object` | [*operations.ListIdentitiesResponseBody](../../models/operations/listidentitiesresponsebody.md) | :heavy_minus_sign: | A list of identities. |
\ No newline at end of file
diff --git a/docs/models/operations/listidentitiesresponsebody.md b/docs/models/operations/listidentitiesresponsebody.md
new file mode 100644
index 0000000..4c39f4b
--- /dev/null
+++ b/docs/models/operations/listidentitiesresponsebody.md
@@ -0,0 +1,12 @@
+# ListIdentitiesResponseBody
+
+A list of identities.
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
+| `Identities` | [][operations.Identities](../../models/operations/identities.md) | :heavy_check_mark: | A list of identities. | |
+| `Cursor` | **string* | :heavy_minus_sign: | The cursor to use for the next page of results, if no cursor is returned, there are no more results | eyJrZXkiOiJrZXlfMTIzNCJ9 |
+| `Total` | *int64* | :heavy_check_mark: | The total number of identities for this environment | |
\ No newline at end of file
diff --git a/docs/models/operations/ratelimits.md b/docs/models/operations/ratelimits.md
new file mode 100644
index 0000000..7ba2948
--- /dev/null
+++ b/docs/models/operations/ratelimits.md
@@ -0,0 +1,10 @@
+# Ratelimits
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
+| `Name` | *string* | :heavy_check_mark: | The name of this limit. You will need to use this again when verifying a key. | tokens |
+| `Limit` | *float64* | :heavy_check_mark: | How many requests may pass within a given window before requests are rejected. | 10 |
+| `Duration` | *float64* | :heavy_check_mark: | The duration for each ratelimit window in milliseconds. | 1000 |
\ No newline at end of file
diff --git a/docs/models/operations/updateidentityratelimits.md b/docs/models/operations/updateidentityratelimits.md
new file mode 100644
index 0000000..e4e95be
--- /dev/null
+++ b/docs/models/operations/updateidentityratelimits.md
@@ -0,0 +1,10 @@
+# UpdateIdentityRatelimits
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
+| `Name` | *string* | :heavy_check_mark: | The name of this limit. You will need to use this again when verifying a key. | tokens |
+| `Limit` | *float64* | :heavy_check_mark: | How many requests may pass within a given window before requests are rejected. | 10 |
+| `Duration` | *float64* | :heavy_check_mark: | The duration for each ratelimit window in milliseconds. | 1000 |
\ No newline at end of file
diff --git a/docs/models/operations/updateidentityrequestbody.md b/docs/models/operations/updateidentityrequestbody.md
new file mode 100644
index 0000000..ba934cb
--- /dev/null
+++ b/docs/models/operations/updateidentityrequestbody.md
@@ -0,0 +1,12 @@
+# UpdateIdentityRequestBody
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `IdentityID` | **string* | :heavy_minus_sign: | The id of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence. | id_1234 |
+| `ExternalID` | **string* | :heavy_minus_sign: | The externalId of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence. | user_1234 |
+| `Environment` | **string* | :heavy_minus_sign: | This is not yet used but here for future compatibility. | |
+| `Meta` | map[string]*any* | :heavy_minus_sign: | Attach metadata to this identity that you need to have access to when verifying a key.
Set to `{}` to clear.
This will be returned as part of the `verifyKey` response.
| |
+| `Ratelimits` | [][operations.UpdateIdentityRatelimits](../../models/operations/updateidentityratelimits.md) | :heavy_minus_sign: | Attach ratelimits to this identity.
This overwrites all existing ratelimits on this identity.
Setting an empty array will delete all existing ratelimits.
When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits. | |
\ No newline at end of file
diff --git a/docs/models/operations/updateidentityresponse.md b/docs/models/operations/updateidentityresponse.md
new file mode 100644
index 0000000..905cc39
--- /dev/null
+++ b/docs/models/operations/updateidentityresponse.md
@@ -0,0 +1,9 @@
+# UpdateIdentityResponse
+
+
+## Fields
+
+| Field | Type | Required | Description |
+| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |
+| `HTTPMeta` | [components.HTTPMetadata](../../models/components/httpmetadata.md) | :heavy_check_mark: | N/A |
+| `ResponseBodies` | [][operations.UpdateIdentityResponseBody](../../models/operations/updateidentityresponsebody.md) | :heavy_minus_sign: | The identity after the update. |
\ No newline at end of file
diff --git a/docs/models/operations/updateidentityresponsebody.md b/docs/models/operations/updateidentityresponsebody.md
new file mode 100644
index 0000000..4f5b979
--- /dev/null
+++ b/docs/models/operations/updateidentityresponsebody.md
@@ -0,0 +1,9 @@
+# UpdateIdentityResponseBody
+
+
+## Fields
+
+| Field | Type | Required | Description | Example |
+| ------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------- |
+| `ID` | *string* | :heavy_check_mark: | The id of the permission. This is used internally | perm_123 |
+| `Name` | *string* | :heavy_check_mark: | The name of the permission | dns.record.create |
\ No newline at end of file
diff --git a/docs/sdks/identities/README.md b/docs/sdks/identities/README.md
new file mode 100644
index 0000000..8be2b20
--- /dev/null
+++ b/docs/sdks/identities/README.md
@@ -0,0 +1,198 @@
+# Identities
+(*Identities*)
+
+### Available Operations
+
+* [GetIdentity](#getidentity)
+* [ListIdentities](#listidentities)
+* [UpdateIdentity](#updateidentity)
+
+## GetIdentity
+
+### Example Usage
+
+```go
+package main
+
+import(
+ "os"
+ unkeygo "github.com/unkeyed/unkey-go"
+ "github.com/unkeyed/unkey-go/models/operations"
+ "context"
+ "log"
+)
+
+func main() {
+ s := unkeygo.New(
+ unkeygo.WithSecurity(os.Getenv("BEARER_AUTH")),
+ )
+ request := operations.GetIdentityRequest{
+ IdentityID: unkeygo.String("id_1234"),
+ ExternalID: unkeygo.String("id_1234"),
+ }
+ ctx := context.Background()
+ res, err := s.Identities.GetIdentity(ctx, request)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if res.Object != nil {
+ // handle response
+ }
+}
+```
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
+| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
+| `request` | [operations.GetIdentityRequest](../../models/operations/getidentityrequest.md) | :heavy_check_mark: | The request object to use for the request. |
+| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
+
+
+### Response
+
+**[*operations.GetIdentityResponse](../../models/operations/getidentityresponse.md), error**
+| Error Object | Status Code | Content Type |
+| -------------------------------- | -------------------------------- | -------------------------------- |
+| sdkerrors.ErrBadRequest | 400 | application/json |
+| sdkerrors.ErrUnauthorized | 401 | application/json |
+| sdkerrors.ErrForbidden | 403 | application/json |
+| sdkerrors.ErrNotFound | 404 | application/json |
+| sdkerrors.ErrConflict | 409 | application/json |
+| sdkerrors.ErrTooManyRequests | 429 | application/json |
+| sdkerrors.ErrInternalServerError | 500 | application/json |
+| sdkerrors.SDKError | 4xx-5xx | */* |
+
+## ListIdentities
+
+### Example Usage
+
+```go
+package main
+
+import(
+ "os"
+ unkeygo "github.com/unkeyed/unkey-go"
+ "github.com/unkeyed/unkey-go/models/operations"
+ "context"
+ "log"
+)
+
+func main() {
+ s := unkeygo.New(
+ unkeygo.WithSecurity(os.Getenv("BEARER_AUTH")),
+ )
+ request := operations.ListIdentitiesRequest{
+ Limit: unkeygo.Int64(100),
+ }
+ ctx := context.Background()
+ res, err := s.Identities.ListIdentities(ctx, request)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if res.Object != nil {
+ for {
+ // handle items
+
+ res, err = res.Next()
+
+ if err != nil {
+ // handle error
+ }
+
+ if res == nil {
+ break
+ }
+ }
+
+ }
+}
+```
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ |
+| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
+| `request` | [operations.ListIdentitiesRequest](../../models/operations/listidentitiesrequest.md) | :heavy_check_mark: | The request object to use for the request. |
+| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
+
+
+### Response
+
+**[*operations.ListIdentitiesResponse](../../models/operations/listidentitiesresponse.md), error**
+| Error Object | Status Code | Content Type |
+| -------------------------------- | -------------------------------- | -------------------------------- |
+| sdkerrors.ErrBadRequest | 400 | application/json |
+| sdkerrors.ErrUnauthorized | 401 | application/json |
+| sdkerrors.ErrForbidden | 403 | application/json |
+| sdkerrors.ErrNotFound | 404 | application/json |
+| sdkerrors.ErrConflict | 409 | application/json |
+| sdkerrors.ErrTooManyRequests | 429 | application/json |
+| sdkerrors.ErrInternalServerError | 500 | application/json |
+| sdkerrors.SDKError | 4xx-5xx | */* |
+
+## UpdateIdentity
+
+### Example Usage
+
+```go
+package main
+
+import(
+ "os"
+ unkeygo "github.com/unkeyed/unkey-go"
+ "github.com/unkeyed/unkey-go/models/operations"
+ "context"
+ "log"
+)
+
+func main() {
+ s := unkeygo.New(
+ unkeygo.WithSecurity(os.Getenv("BEARER_AUTH")),
+ )
+ request := operations.UpdateIdentityRequestBody{
+ IdentityID: unkeygo.String("id_1234"),
+ ExternalID: unkeygo.String("user_1234"),
+ Ratelimits: []operations.UpdateIdentityRatelimits{
+ operations.UpdateIdentityRatelimits{
+ Name: "tokens",
+ Limit: 10,
+ Duration: 1000,
+ },
+ },
+ }
+ ctx := context.Background()
+ res, err := s.Identities.UpdateIdentity(ctx, request)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if res.ResponseBodies != nil {
+ // handle response
+ }
+}
+```
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
+| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
+| `request` | [operations.UpdateIdentityRequestBody](../../models/operations/updateidentityrequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
+| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
+
+
+### Response
+
+**[*operations.UpdateIdentityResponse](../../models/operations/updateidentityresponse.md), error**
+| Error Object | Status Code | Content Type |
+| -------------------------------- | -------------------------------- | -------------------------------- |
+| sdkerrors.ErrBadRequest | 400 | application/json |
+| sdkerrors.ErrUnauthorized | 401 | application/json |
+| sdkerrors.ErrForbidden | 403 | application/json |
+| sdkerrors.ErrNotFound | 404 | application/json |
+| sdkerrors.ErrConflict | 409 | application/json |
+| sdkerrors.ErrTooManyRequests | 429 | application/json |
+| sdkerrors.ErrInternalServerError | 500 | application/json |
+| sdkerrors.SDKError | 4xx-5xx | */* |
diff --git a/docs/sdks/keys/README.md b/docs/sdks/keys/README.md
index 1dfe43c..5154178 100644
--- a/docs/sdks/keys/README.md
+++ b/docs/sdks/keys/README.md
@@ -151,7 +151,7 @@ func main() {
request := operations.CreateKeyRequestBody{
APIID: "api_123",
Name: unkeygo.String("my key"),
- OwnerID: unkeygo.String("team_123"),
+ ExternalID: unkeygo.String("team_123"),
Meta: map[string]any{
"billingTier": "PRO",
"trialEnds": "2023-06-16T17:16:37.161Z",
@@ -233,8 +233,15 @@ func main() {
APIID: unkeygo.String("api_1234"),
Key: "sk_1234",
Ratelimits: []components.Ratelimits{
+ components.Ratelimits{
+ Name: "requests",
+ Limit: unkeygo.Float64(500),
+ Duration: unkeygo.Float64(3600000),
+ },
components.Ratelimits{
Name: "tokens",
+ Limit: unkeygo.Float64(20000),
+ Duration: unkeygo.Float64(86400000),
},
},
}
diff --git a/docs/sdks/unkey/README.md b/docs/sdks/unkey/README.md
index f64aa7c..14099b7 100644
--- a/docs/sdks/unkey/README.md
+++ b/docs/sdks/unkey/README.md
@@ -7,6 +7,8 @@
* [CreateAPI](#createapi)
* [DeleteAPI](#deleteapi)
+* [CreateIdentity](#createidentity)
+* [DeleteeIdentity](#deleteeidentity)
## CreateAPI
@@ -119,3 +121,122 @@ func main() {
| sdkerrors.ErrTooManyRequests | 429 | application/json |
| sdkerrors.ErrInternalServerError | 500 | application/json |
| sdkerrors.SDKError | 4xx-5xx | */* |
+
+## CreateIdentity
+
+### Example Usage
+
+```go
+package main
+
+import(
+ "os"
+ unkeygo "github.com/unkeyed/unkey-go"
+ "github.com/unkeyed/unkey-go/models/operations"
+ "context"
+ "log"
+)
+
+func main() {
+ s := unkeygo.New(
+ unkeygo.WithSecurity(os.Getenv("BEARER_AUTH")),
+ )
+ request := operations.CreateIdentityRequestBody{
+ ExternalID: "user_123",
+ Ratelimits: []operations.Ratelimits{
+ operations.Ratelimits{
+ Name: "tokens",
+ Limit: 10,
+ Duration: 1000,
+ },
+ },
+ }
+ ctx := context.Background()
+ res, err := s.CreateIdentity(ctx, request)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if res.Object != nil {
+ // handle response
+ }
+}
+```
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
+| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
+| `request` | [operations.CreateIdentityRequestBody](../../models/operations/createidentityrequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
+| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
+
+
+### Response
+
+**[*operations.CreateIdentityResponse](../../models/operations/createidentityresponse.md), error**
+| Error Object | Status Code | Content Type |
+| -------------------------------- | -------------------------------- | -------------------------------- |
+| sdkerrors.ErrBadRequest | 400 | application/json |
+| sdkerrors.ErrUnauthorized | 401 | application/json |
+| sdkerrors.ErrForbidden | 403 | application/json |
+| sdkerrors.ErrNotFound | 404 | application/json |
+| sdkerrors.ErrConflict | 409 | application/json |
+| sdkerrors.ErrTooManyRequests | 429 | application/json |
+| sdkerrors.ErrInternalServerError | 500 | application/json |
+| sdkerrors.SDKError | 4xx-5xx | */* |
+
+## DeleteeIdentity
+
+### Example Usage
+
+```go
+package main
+
+import(
+ "os"
+ unkeygo "github.com/unkeyed/unkey-go"
+ "github.com/unkeyed/unkey-go/models/operations"
+ "context"
+ "log"
+)
+
+func main() {
+ s := unkeygo.New(
+ unkeygo.WithSecurity(os.Getenv("BEARER_AUTH")),
+ )
+ request := operations.DeleteeIdentityRequestBody{
+ IdentityID: "id_1234",
+ }
+ ctx := context.Background()
+ res, err := s.DeleteeIdentity(ctx, request)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if res.Object != nil {
+ // handle response
+ }
+}
+```
+
+### Parameters
+
+| Parameter | Type | Required | Description |
+| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
+| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy_check_mark: | The context to use for the request. |
+| `request` | [operations.DeleteeIdentityRequestBody](../../models/operations/deleteeidentityrequestbody.md) | :heavy_check_mark: | The request object to use for the request. |
+| `opts` | [][operations.Option](../../models/operations/option.md) | :heavy_minus_sign: | The options for this request. |
+
+
+### Response
+
+**[*operations.DeleteeIdentityResponse](../../models/operations/deleteeidentityresponse.md), error**
+| Error Object | Status Code | Content Type |
+| -------------------------------- | -------------------------------- | -------------------------------- |
+| sdkerrors.ErrBadRequest | 400 | application/json |
+| sdkerrors.ErrUnauthorized | 401 | application/json |
+| sdkerrors.ErrForbidden | 403 | application/json |
+| sdkerrors.ErrNotFound | 404 | application/json |
+| sdkerrors.ErrConflict | 409 | application/json |
+| sdkerrors.ErrTooManyRequests | 429 | application/json |
+| sdkerrors.ErrInternalServerError | 500 | application/json |
+| sdkerrors.SDKError | 4xx-5xx | */* |
diff --git a/go.mod b/go.mod
index ee5e9bf..501f995 100644
--- a/go.mod
+++ b/go.mod
@@ -5,4 +5,5 @@ go 1.20
require (
github.com/cenkalti/backoff/v4 v4.2.0
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05
+ github.com/spyzhov/ajson v0.8.0
)
diff --git a/go.sum b/go.sum
index f955779..1f07f51 100644
--- a/go.sum
+++ b/go.sum
@@ -2,3 +2,5 @@ github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+M
github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 h1:S92OBrGuLLZsyM5ybUzgc/mPjIYk2AZqufieooe98uw=
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ=
+github.com/spyzhov/ajson v0.8.0 h1:sFXyMbi4Y/BKjrsfkUZHSjA2JM1184enheSjjoT/zCc=
+github.com/spyzhov/ajson v0.8.0/go.mod h1:63V+CGM6f1Bu/p4nLIN8885ojBdt88TbLoSFzyqMuVA=
diff --git a/identities.go b/identities.go
new file mode 100644
index 0000000..f7d7691
--- /dev/null
+++ b/identities.go
@@ -0,0 +1,871 @@
+// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
+
+package unkeygo
+
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "github.com/cenkalti/backoff/v4"
+ "github.com/spyzhov/ajson"
+ "github.com/unkeyed/unkey-go/internal/hooks"
+ "github.com/unkeyed/unkey-go/internal/utils"
+ "github.com/unkeyed/unkey-go/models/components"
+ "github.com/unkeyed/unkey-go/models/operations"
+ "github.com/unkeyed/unkey-go/models/sdkerrors"
+ "github.com/unkeyed/unkey-go/retry"
+ "io"
+ "net/http"
+ "net/url"
+ "strconv"
+)
+
+type Identities struct {
+ sdkConfiguration sdkConfiguration
+}
+
+func newIdentities(sdkConfig sdkConfiguration) *Identities {
+ return &Identities{
+ sdkConfiguration: sdkConfig,
+ }
+}
+
+func (s *Identities) GetIdentity(ctx context.Context, request operations.GetIdentityRequest, opts ...operations.Option) (*operations.GetIdentityResponse, error) {
+ hookCtx := hooks.HookContext{
+ Context: ctx,
+ OperationID: "getIdentity",
+ OAuth2Scopes: []string{},
+ SecuritySource: s.sdkConfiguration.Security,
+ }
+
+ o := operations.Options{}
+ supportedOptions := []string{
+ operations.SupportedOptionRetries,
+ operations.SupportedOptionTimeout,
+ }
+
+ for _, opt := range opts {
+ if err := opt(&o, supportedOptions...); err != nil {
+ return nil, fmt.Errorf("error applying option: %w", err)
+ }
+ }
+
+ baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
+ opURL, err := url.JoinPath(baseURL, "/v1/identities.getIdentity")
+ if err != nil {
+ return nil, fmt.Errorf("error generating URL: %w", err)
+ }
+
+ timeout := o.Timeout
+ if timeout == nil {
+ timeout = s.sdkConfiguration.Timeout
+ }
+
+ if timeout != nil {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, *timeout)
+ defer cancel()
+ }
+
+ req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil)
+ if err != nil {
+ return nil, fmt.Errorf("error creating request: %w", err)
+ }
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
+
+ if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
+ return nil, fmt.Errorf("error populating query params: %w", err)
+ }
+
+ if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
+ return nil, err
+ }
+
+ globalRetryConfig := s.sdkConfiguration.RetryConfig
+ retryConfig := o.Retries
+ if retryConfig == nil {
+ if globalRetryConfig != nil {
+ retryConfig = globalRetryConfig
+ } else {
+ retryConfig = &retry.Config{
+ Strategy: "backoff", Backoff: &retry.BackoffStrategy{
+ InitialInterval: 50,
+ MaxInterval: 1000,
+ Exponent: 1.5,
+ MaxElapsedTime: 30000,
+ },
+ RetryConnectionErrors: true,
+ }
+ }
+ }
+
+ var httpRes *http.Response
+ if retryConfig != nil {
+ httpRes, err = utils.Retry(ctx, utils.Retries{
+ Config: retryConfig,
+ StatusCodes: []string{
+ "5XX",
+ },
+ }, func() (*http.Response, error) {
+ if req.Body != nil {
+ copyBody, err := req.GetBody()
+ if err != nil {
+ return nil, err
+ }
+ req.Body = copyBody
+ }
+
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, backoff.Permanent(err)
+ }
+
+ httpRes, err := s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ }
+ return httpRes, err
+ })
+
+ if err != nil {
+ return nil, err
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ } else {
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, err
+ }
+
+ httpRes, err = s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ return nil, err
+ } else if utils.MatchStatusCodes([]string{"400", "401", "403", "404", "409", "429", "4XX", "500", "5XX"}, httpRes.StatusCode) {
+ _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
+ if err != nil {
+ return nil, err
+ } else if _httpRes != nil {
+ httpRes = _httpRes
+ }
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ res := &operations.GetIdentityResponse{
+ HTTPMeta: components.HTTPMetadata{
+ Request: req,
+ Response: httpRes,
+ },
+ }
+
+ rawBody, err := io.ReadAll(httpRes.Body)
+ if err != nil {
+ return nil, fmt.Errorf("error reading response body: %w", err)
+ }
+ httpRes.Body.Close()
+ httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
+
+ switch {
+ case httpRes.StatusCode == 200:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out operations.GetIdentityResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ res.Object = &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 400:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrBadRequest
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 401:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrUnauthorized
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 403:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrForbidden
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 404:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrNotFound
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 409:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrConflict
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 429:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrTooManyRequests
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 500:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrInternalServerError
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
+ fallthrough
+ case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
+ return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
+ default:
+ return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
+ }
+
+ return res, nil
+
+}
+
+func (s *Identities) ListIdentities(ctx context.Context, request operations.ListIdentitiesRequest, opts ...operations.Option) (*operations.ListIdentitiesResponse, error) {
+ hookCtx := hooks.HookContext{
+ Context: ctx,
+ OperationID: "listIdentities",
+ OAuth2Scopes: []string{},
+ SecuritySource: s.sdkConfiguration.Security,
+ }
+
+ o := operations.Options{}
+ supportedOptions := []string{
+ operations.SupportedOptionRetries,
+ operations.SupportedOptionTimeout,
+ }
+
+ for _, opt := range opts {
+ if err := opt(&o, supportedOptions...); err != nil {
+ return nil, fmt.Errorf("error applying option: %w", err)
+ }
+ }
+
+ baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
+ opURL, err := url.JoinPath(baseURL, "/v1/identities.listIdentities")
+ if err != nil {
+ return nil, fmt.Errorf("error generating URL: %w", err)
+ }
+
+ timeout := o.Timeout
+ if timeout == nil {
+ timeout = s.sdkConfiguration.Timeout
+ }
+
+ if timeout != nil {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, *timeout)
+ defer cancel()
+ }
+
+ req, err := http.NewRequestWithContext(ctx, "GET", opURL, nil)
+ if err != nil {
+ return nil, fmt.Errorf("error creating request: %w", err)
+ }
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
+
+ if err := utils.PopulateQueryParams(ctx, req, request, nil); err != nil {
+ return nil, fmt.Errorf("error populating query params: %w", err)
+ }
+
+ if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
+ return nil, err
+ }
+
+ globalRetryConfig := s.sdkConfiguration.RetryConfig
+ retryConfig := o.Retries
+ if retryConfig == nil {
+ if globalRetryConfig != nil {
+ retryConfig = globalRetryConfig
+ } else {
+ retryConfig = &retry.Config{
+ Strategy: "backoff", Backoff: &retry.BackoffStrategy{
+ InitialInterval: 50,
+ MaxInterval: 1000,
+ Exponent: 1.5,
+ MaxElapsedTime: 30000,
+ },
+ RetryConnectionErrors: true,
+ }
+ }
+ }
+
+ var httpRes *http.Response
+ if retryConfig != nil {
+ httpRes, err = utils.Retry(ctx, utils.Retries{
+ Config: retryConfig,
+ StatusCodes: []string{
+ "5XX",
+ },
+ }, func() (*http.Response, error) {
+ if req.Body != nil {
+ copyBody, err := req.GetBody()
+ if err != nil {
+ return nil, err
+ }
+ req.Body = copyBody
+ }
+
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, backoff.Permanent(err)
+ }
+
+ httpRes, err := s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ }
+ return httpRes, err
+ })
+
+ if err != nil {
+ return nil, err
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ } else {
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, err
+ }
+
+ httpRes, err = s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ return nil, err
+ } else if utils.MatchStatusCodes([]string{"400", "401", "403", "404", "409", "429", "4XX", "500", "5XX"}, httpRes.StatusCode) {
+ _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
+ if err != nil {
+ return nil, err
+ } else if _httpRes != nil {
+ httpRes = _httpRes
+ }
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ res := &operations.ListIdentitiesResponse{
+ HTTPMeta: components.HTTPMetadata{
+ Request: req,
+ Response: httpRes,
+ },
+ }
+
+ rawBody, err := io.ReadAll(httpRes.Body)
+ if err != nil {
+ return nil, fmt.Errorf("error reading response body: %w", err)
+ }
+ httpRes.Body.Close()
+ httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
+ res.Next =
+ func() (*operations.ListIdentitiesResponse, error) {
+ b, err := ajson.Unmarshal(rawBody)
+ if err != nil {
+ return nil, err
+ }
+ nC, err := ajson.Eval(b, "$.cursor")
+ if err != nil {
+ return nil, err
+ }
+ var nCVal string
+
+ if nC.IsNumeric() {
+ numVal, err := nC.GetNumeric()
+ if err != nil {
+ return nil, err
+ }
+ // GetNumeric returns as float64 so convert to the appropriate type.
+ nCVal = strconv.FormatFloat(numVal, 'f', 0, 64)
+ } else {
+ val, err := nC.Value()
+ if err != nil {
+ return nil, err
+ }
+ if val == nil {
+ return nil, nil
+ }
+ nCVal = val.(string)
+ }
+
+ return s.ListIdentities(
+ ctx,
+ operations.ListIdentitiesRequest{
+ Environment: request.Environment,
+ Limit: request.Limit,
+ Cursor: &nCVal,
+ },
+ opts...,
+ )
+ }
+
+ switch {
+ case httpRes.StatusCode == 200:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out operations.ListIdentitiesResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ res.Object = &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 400:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrBadRequest
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 401:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrUnauthorized
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 403:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrForbidden
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 404:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrNotFound
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 409:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrConflict
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 429:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrTooManyRequests
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 500:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrInternalServerError
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
+ fallthrough
+ case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
+ return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
+ default:
+ return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
+ }
+
+ return res, nil
+
+}
+
+func (s *Identities) UpdateIdentity(ctx context.Context, request operations.UpdateIdentityRequestBody, opts ...operations.Option) (*operations.UpdateIdentityResponse, error) {
+ hookCtx := hooks.HookContext{
+ Context: ctx,
+ OperationID: "updateIdentity",
+ OAuth2Scopes: []string{},
+ SecuritySource: s.sdkConfiguration.Security,
+ }
+
+ o := operations.Options{}
+ supportedOptions := []string{
+ operations.SupportedOptionRetries,
+ operations.SupportedOptionTimeout,
+ }
+
+ for _, opt := range opts {
+ if err := opt(&o, supportedOptions...); err != nil {
+ return nil, fmt.Errorf("error applying option: %w", err)
+ }
+ }
+
+ baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
+ opURL, err := url.JoinPath(baseURL, "/v1/identities.updateIdentity")
+ if err != nil {
+ return nil, fmt.Errorf("error generating URL: %w", err)
+ }
+
+ bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`)
+ if err != nil {
+ return nil, err
+ }
+
+ timeout := o.Timeout
+ if timeout == nil {
+ timeout = s.sdkConfiguration.Timeout
+ }
+
+ if timeout != nil {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, *timeout)
+ defer cancel()
+ }
+
+ req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader)
+ if err != nil {
+ return nil, fmt.Errorf("error creating request: %w", err)
+ }
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
+ req.Header.Set("Content-Type", reqContentType)
+
+ if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
+ return nil, err
+ }
+
+ globalRetryConfig := s.sdkConfiguration.RetryConfig
+ retryConfig := o.Retries
+ if retryConfig == nil {
+ if globalRetryConfig != nil {
+ retryConfig = globalRetryConfig
+ } else {
+ retryConfig = &retry.Config{
+ Strategy: "backoff", Backoff: &retry.BackoffStrategy{
+ InitialInterval: 50,
+ MaxInterval: 1000,
+ Exponent: 1.5,
+ MaxElapsedTime: 30000,
+ },
+ RetryConnectionErrors: true,
+ }
+ }
+ }
+
+ var httpRes *http.Response
+ if retryConfig != nil {
+ httpRes, err = utils.Retry(ctx, utils.Retries{
+ Config: retryConfig,
+ StatusCodes: []string{
+ "5XX",
+ },
+ }, func() (*http.Response, error) {
+ if req.Body != nil {
+ copyBody, err := req.GetBody()
+ if err != nil {
+ return nil, err
+ }
+ req.Body = copyBody
+ }
+
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, backoff.Permanent(err)
+ }
+
+ httpRes, err := s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ }
+ return httpRes, err
+ })
+
+ if err != nil {
+ return nil, err
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ } else {
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, err
+ }
+
+ httpRes, err = s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ return nil, err
+ } else if utils.MatchStatusCodes([]string{"400", "401", "403", "404", "409", "429", "4XX", "500", "5XX"}, httpRes.StatusCode) {
+ _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
+ if err != nil {
+ return nil, err
+ } else if _httpRes != nil {
+ httpRes = _httpRes
+ }
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ res := &operations.UpdateIdentityResponse{
+ HTTPMeta: components.HTTPMetadata{
+ Request: req,
+ Response: httpRes,
+ },
+ }
+
+ rawBody, err := io.ReadAll(httpRes.Body)
+ if err != nil {
+ return nil, fmt.Errorf("error reading response body: %w", err)
+ }
+ httpRes.Body.Close()
+ httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
+
+ switch {
+ case httpRes.StatusCode == 200:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out []operations.UpdateIdentityResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ res.ResponseBodies = out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 400:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrBadRequest
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 401:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrUnauthorized
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 403:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrForbidden
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 404:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrNotFound
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 409:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrConflict
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 429:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrTooManyRequests
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 500:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrInternalServerError
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
+ fallthrough
+ case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
+ return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
+ default:
+ return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
+ }
+
+ return res, nil
+
+}
diff --git a/models/components/v1keysverifykeyrequest.go b/models/components/v1keysverifykeyrequest.go
index 7a33485..3502f98 100644
--- a/models/components/v1keysverifykeyrequest.go
+++ b/models/components/v1keysverifykeyrequest.go
@@ -19,6 +19,9 @@ func (o *Authorization) GetPermissions() *PermissionQuery {
return o.Permissions
}
+// V1KeysVerifyKeyRequestRatelimit - Use 'ratelimits' with `[{ name: "default", cost: 2}]`
+//
+// Deprecated type: This will be removed in a future release, please migrate away from it as soon as possible.
type V1KeysVerifyKeyRequestRatelimit struct {
// Override how many tokens are deducted during the ratelimit operation.
Cost *int64 `default:"1" json:"cost"`
@@ -43,12 +46,10 @@ func (o *V1KeysVerifyKeyRequestRatelimit) GetCost() *int64 {
}
type Ratelimits struct {
- // The name of the ratelimit
+ // The name of the ratelimit.
Name string `json:"name"`
// Optionally override how expensive this operation is and how many tokens are deducted from the current limit.
Cost *int64 `default:"1" json:"cost"`
- // The identifier used for ratelimiting. If omitted, we use the key's id.
- Identifier *string `default:"key id" json:"identifier"`
// Optionally override the limit.
Limit *float64 `json:"limit,omitempty"`
// Optionally override the ratelimit window duration.
@@ -80,13 +81,6 @@ func (o *Ratelimits) GetCost() *int64 {
return o.Cost
}
-func (o *Ratelimits) GetIdentifier() *string {
- if o == nil {
- return nil
- }
- return o.Identifier
-}
-
func (o *Ratelimits) GetLimit() *float64 {
if o == nil {
return nil
@@ -108,9 +102,14 @@ type V1KeysVerifyKeyRequest struct {
// The key to verify
Key string `json:"key"`
// Perform RBAC checks
- Authorization *Authorization `json:"authorization,omitempty"`
- Ratelimit *V1KeysVerifyKeyRequestRatelimit `json:"ratelimit,omitempty"`
- Ratelimits []Ratelimits `json:"ratelimits,omitempty"`
+ Authorization *Authorization `json:"authorization,omitempty"`
+ // Use 'ratelimits' with `[{ name: "default", cost: 2}]`
+ //
+ // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
+ Ratelimit *V1KeysVerifyKeyRequestRatelimit `json:"ratelimit,omitempty"`
+ // You can check against multiple ratelimits when verifying a key. Let's say you are building an app that uses AI under the hood and you want to limit your customers to 500 requests per hour, but also ensure they use up less than 20k tokens per day.
+ //
+ Ratelimits []Ratelimits `json:"ratelimits,omitempty"`
}
func (o *V1KeysVerifyKeyRequest) GetAPIID() *string {
diff --git a/models/components/v1keysverifykeyresponse.go b/models/components/v1keysverifykeyresponse.go
index 9357d84..4d1197a 100644
--- a/models/components/v1keysverifykeyresponse.go
+++ b/models/components/v1keysverifykeyresponse.go
@@ -7,7 +7,7 @@ import (
"fmt"
)
-// V1KeysVerifyKeyResponseRatelimit - Multi ratelimits TODO:
+// V1KeysVerifyKeyResponseRatelimit - The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit.
type V1KeysVerifyKeyResponseRatelimit struct {
// Maximum number of requests that can be made inside a window
Limit int64 `json:"limit"`
@@ -96,6 +96,34 @@ func (e *Code) UnmarshalJSON(data []byte) error {
}
}
+// Identity - The associated identity of this key.
+type Identity struct {
+ ID string `json:"id"`
+ ExternalID string `json:"externalId"`
+ Meta map[string]any `json:"meta"`
+}
+
+func (o *Identity) GetID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ID
+}
+
+func (o *Identity) GetExternalID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ExternalID
+}
+
+func (o *Identity) GetMeta() map[string]any {
+ if o == nil {
+ return map[string]any{}
+ }
+ return o.Meta
+}
+
type V1KeysVerifyKeyResponse struct {
// The id of the key
KeyID *string `json:"keyId,omitempty"`
@@ -110,7 +138,7 @@ type V1KeysVerifyKeyResponse struct {
Meta map[string]any `json:"meta,omitempty"`
// The unix timestamp in milliseconds when the key will expire. If this field is null or undefined, the key is not expiring.
Expires *int64 `json:"expires,omitempty"`
- // Multi ratelimits TODO:
+ // The ratelimit configuration for this key. If this field is null or undefined, the key has no ratelimit.
Ratelimit *V1KeysVerifyKeyResponseRatelimit `json:"ratelimit,omitempty"`
// The number of requests that can be made with this key before it becomes invalid. If this field is null or undefined, the key has no request limit.
Remaining *int64 `json:"remaining,omitempty"`
@@ -133,6 +161,8 @@ type V1KeysVerifyKeyResponse struct {
Permissions []string `json:"permissions,omitempty"`
// The environment of the key, this is what what you set when you crated the key
Environment *string `json:"environment,omitempty"`
+ // The associated identity of this key.
+ Identity *Identity `json:"identity,omitempty"`
}
func (o *V1KeysVerifyKeyResponse) GetKeyID() *string {
@@ -218,3 +248,10 @@ func (o *V1KeysVerifyKeyResponse) GetEnvironment() *string {
}
return o.Environment
}
+
+func (o *V1KeysVerifyKeyResponse) GetIdentity() *Identity {
+ if o == nil {
+ return nil
+ }
+ return o.Identity
+}
diff --git a/models/operations/createidentity.go b/models/operations/createidentity.go
new file mode 100644
index 0000000..d89e1f8
--- /dev/null
+++ b/models/operations/createidentity.go
@@ -0,0 +1,109 @@
+// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
+
+package operations
+
+import (
+ "github.com/unkeyed/unkey-go/models/components"
+)
+
+type Ratelimits struct {
+ // The name of this limit. You will need to use this again when verifying a key.
+ Name string `json:"name"`
+ // How many requests may pass within a given window before requests are rejected.
+ Limit float64 `json:"limit"`
+ // The duration for each ratelimit window in milliseconds.
+ Duration float64 `json:"duration"`
+}
+
+func (o *Ratelimits) GetName() string {
+ if o == nil {
+ return ""
+ }
+ return o.Name
+}
+
+func (o *Ratelimits) GetLimit() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Limit
+}
+
+func (o *Ratelimits) GetDuration() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Duration
+}
+
+type CreateIdentityRequestBody struct {
+ // The id of this identity in your system.
+ //
+ // This usually comes from your authentication provider and could be a userId, organisationId or even an email.
+ // It does not matter what you use, as long as it uniquely identifies something in your application.
+ //
+ ExternalID string `json:"externalId"`
+ // Attach metadata to this identity that you need to have access to when verifying a key.
+ //
+ // This will be returned as part of the `verifyKey` response.
+ //
+ Meta map[string]any `json:"meta,omitempty"`
+ // Attach ratelimits to this identity.
+ //
+ // When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits.
+ Ratelimits []Ratelimits `json:"ratelimits,omitempty"`
+}
+
+func (o *CreateIdentityRequestBody) GetExternalID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ExternalID
+}
+
+func (o *CreateIdentityRequestBody) GetMeta() map[string]any {
+ if o == nil {
+ return nil
+ }
+ return o.Meta
+}
+
+func (o *CreateIdentityRequestBody) GetRatelimits() []Ratelimits {
+ if o == nil {
+ return nil
+ }
+ return o.Ratelimits
+}
+
+// CreateIdentityResponseBody - The configuration for an api
+type CreateIdentityResponseBody struct {
+ // The id of the identity. Used internally, you do not need to store this.
+ IdentityID string `json:"identityId"`
+}
+
+func (o *CreateIdentityResponseBody) GetIdentityID() string {
+ if o == nil {
+ return ""
+ }
+ return o.IdentityID
+}
+
+type CreateIdentityResponse struct {
+ HTTPMeta components.HTTPMetadata `json:"-"`
+ // The configuration for an api
+ Object *CreateIdentityResponseBody
+}
+
+func (o *CreateIdentityResponse) GetHTTPMeta() components.HTTPMetadata {
+ if o == nil {
+ return components.HTTPMetadata{}
+ }
+ return o.HTTPMeta
+}
+
+func (o *CreateIdentityResponse) GetObject() *CreateIdentityResponseBody {
+ if o == nil {
+ return nil
+ }
+ return o.Object
+}
diff --git a/models/operations/createkey.go b/models/operations/createkey.go
index 8117b68..f7e7f96 100644
--- a/models/operations/createkey.go
+++ b/models/operations/createkey.go
@@ -178,9 +178,13 @@ type CreateKeyRequestBody struct {
Name *string `json:"name,omitempty"`
// The byte length used to generate your key determines its entropy as well as its length. Higher is better, but keys become longer and more annoying to handle. The default is 16 bytes, or 2^^128 possible combinations.
ByteLength *int64 `default:"16" json:"byteLength"`
- // Your user’s Id. This will provide a link between Unkey and your customer record.
- // When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
+ // Deprecated, use `externalId`
+ //
+ // Deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
OwnerID *string `json:"ownerId,omitempty"`
+ // Your user's Id. This will provide a link between Unkey and your customer record.
+ // When validating a key, we will return this back to you, so you can clearly identify your user from their api key.
+ ExternalID *string `json:"externalId,omitempty"`
// This is a place for dynamic meta data, anything that feels useful for you should go here
Meta map[string]any `json:"meta,omitempty"`
// A list of roles that this key should have. If the role does not exist, an error is thrown
@@ -255,6 +259,13 @@ func (o *CreateKeyRequestBody) GetOwnerID() *string {
return o.OwnerID
}
+func (o *CreateKeyRequestBody) GetExternalID() *string {
+ if o == nil {
+ return nil
+ }
+ return o.ExternalID
+}
+
func (o *CreateKeyRequestBody) GetMeta() map[string]any {
if o == nil {
return nil
diff --git a/models/operations/deleteeidentity.go b/models/operations/deleteeidentity.go
new file mode 100644
index 0000000..88bf579
--- /dev/null
+++ b/models/operations/deleteeidentity.go
@@ -0,0 +1,43 @@
+// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
+
+package operations
+
+import (
+ "github.com/unkeyed/unkey-go/models/components"
+)
+
+type DeleteeIdentityRequestBody struct {
+ // The id of the identity to delete
+ IdentityID string `json:"identityId"`
+}
+
+func (o *DeleteeIdentityRequestBody) GetIdentityID() string {
+ if o == nil {
+ return ""
+ }
+ return o.IdentityID
+}
+
+// DeleteeIdentityResponseBody - The identity was successfully deleted, it may take up to 30s for this to take effect in all regions
+type DeleteeIdentityResponseBody struct {
+}
+
+type DeleteeIdentityResponse struct {
+ HTTPMeta components.HTTPMetadata `json:"-"`
+ // The identity was successfully deleted, it may take up to 30s for this to take effect in all regions
+ Object *DeleteeIdentityResponseBody
+}
+
+func (o *DeleteeIdentityResponse) GetHTTPMeta() components.HTTPMetadata {
+ if o == nil {
+ return components.HTTPMetadata{}
+ }
+ return o.HTTPMeta
+}
+
+func (o *DeleteeIdentityResponse) GetObject() *DeleteeIdentityResponseBody {
+ if o == nil {
+ return nil
+ }
+ return o.Object
+}
diff --git a/models/operations/getidentity.go b/models/operations/getidentity.go
new file mode 100644
index 0000000..6b90152
--- /dev/null
+++ b/models/operations/getidentity.go
@@ -0,0 +1,116 @@
+// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
+
+package operations
+
+import (
+ "github.com/unkeyed/unkey-go/models/components"
+)
+
+type GetIdentityRequest struct {
+ IdentityID *string `queryParam:"style=form,explode=true,name=identityId"`
+ ExternalID *string `queryParam:"style=form,explode=true,name=externalId"`
+}
+
+func (o *GetIdentityRequest) GetIdentityID() *string {
+ if o == nil {
+ return nil
+ }
+ return o.IdentityID
+}
+
+func (o *GetIdentityRequest) GetExternalID() *string {
+ if o == nil {
+ return nil
+ }
+ return o.ExternalID
+}
+
+type GetIdentityRatelimits struct {
+ // The name of this limit. You will need to use this again when verifying a key.
+ Name string `json:"name"`
+ // How many requests may pass within a given window before requests are rejected.
+ Limit float64 `json:"limit"`
+ // The duration for each ratelimit window in milliseconds.
+ Duration float64 `json:"duration"`
+}
+
+func (o *GetIdentityRatelimits) GetName() string {
+ if o == nil {
+ return ""
+ }
+ return o.Name
+}
+
+func (o *GetIdentityRatelimits) GetLimit() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Limit
+}
+
+func (o *GetIdentityRatelimits) GetDuration() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Duration
+}
+
+// GetIdentityResponseBody - The configuration for an api
+type GetIdentityResponseBody struct {
+ // The id of this identity. Used to interact with unkey's API
+ ID string `json:"id"`
+ // The id in your system
+ ExternalID string `json:"externalId"`
+ // The meta object defined for this identity.
+ Meta map[string]any `json:"meta"`
+ // When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits.
+ Ratelimits []GetIdentityRatelimits `json:"ratelimits"`
+}
+
+func (o *GetIdentityResponseBody) GetID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ID
+}
+
+func (o *GetIdentityResponseBody) GetExternalID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ExternalID
+}
+
+func (o *GetIdentityResponseBody) GetMeta() map[string]any {
+ if o == nil {
+ return map[string]any{}
+ }
+ return o.Meta
+}
+
+func (o *GetIdentityResponseBody) GetRatelimits() []GetIdentityRatelimits {
+ if o == nil {
+ return []GetIdentityRatelimits{}
+ }
+ return o.Ratelimits
+}
+
+type GetIdentityResponse struct {
+ HTTPMeta components.HTTPMetadata `json:"-"`
+ // The configuration for an api
+ Object *GetIdentityResponseBody
+}
+
+func (o *GetIdentityResponse) GetHTTPMeta() components.HTTPMetadata {
+ if o == nil {
+ return components.HTTPMetadata{}
+ }
+ return o.HTTPMeta
+}
+
+func (o *GetIdentityResponse) GetObject() *GetIdentityResponseBody {
+ if o == nil {
+ return nil
+ }
+ return o.Object
+}
diff --git a/models/operations/listidentities.go b/models/operations/listidentities.go
new file mode 100644
index 0000000..e9c4fe6
--- /dev/null
+++ b/models/operations/listidentities.go
@@ -0,0 +1,159 @@
+// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
+
+package operations
+
+import (
+ "github.com/unkeyed/unkey-go/internal/utils"
+ "github.com/unkeyed/unkey-go/models/components"
+)
+
+type ListIdentitiesRequest struct {
+ Environment *string `default:"default" queryParam:"style=form,explode=true,name=environment"`
+ Limit *int64 `default:"100" queryParam:"style=form,explode=true,name=limit"`
+ Cursor *string `queryParam:"style=form,explode=true,name=cursor"`
+}
+
+func (l ListIdentitiesRequest) MarshalJSON() ([]byte, error) {
+ return utils.MarshalJSON(l, "", false)
+}
+
+func (l *ListIdentitiesRequest) UnmarshalJSON(data []byte) error {
+ if err := utils.UnmarshalJSON(data, &l, "", false, false); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (o *ListIdentitiesRequest) GetEnvironment() *string {
+ if o == nil {
+ return nil
+ }
+ return o.Environment
+}
+
+func (o *ListIdentitiesRequest) GetLimit() *int64 {
+ if o == nil {
+ return nil
+ }
+ return o.Limit
+}
+
+func (o *ListIdentitiesRequest) GetCursor() *string {
+ if o == nil {
+ return nil
+ }
+ return o.Cursor
+}
+
+type ListIdentitiesRatelimits struct {
+ // The name of this limit. You will need to use this again when verifying a key.
+ Name string `json:"name"`
+ // How many requests may pass within a given window before requests are rejected.
+ Limit float64 `json:"limit"`
+ // The duration for each ratelimit window in milliseconds.
+ Duration float64 `json:"duration"`
+}
+
+func (o *ListIdentitiesRatelimits) GetName() string {
+ if o == nil {
+ return ""
+ }
+ return o.Name
+}
+
+func (o *ListIdentitiesRatelimits) GetLimit() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Limit
+}
+
+func (o *ListIdentitiesRatelimits) GetDuration() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Duration
+}
+
+type Identities struct {
+ // The id of this identity. Used to interact with unkey's API
+ ID string `json:"id"`
+ // The id in your system
+ ExternalID string `json:"externalId"`
+ // When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits.
+ Ratelimits []ListIdentitiesRatelimits `json:"ratelimits"`
+}
+
+func (o *Identities) GetID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ID
+}
+
+func (o *Identities) GetExternalID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ExternalID
+}
+
+func (o *Identities) GetRatelimits() []ListIdentitiesRatelimits {
+ if o == nil {
+ return []ListIdentitiesRatelimits{}
+ }
+ return o.Ratelimits
+}
+
+// ListIdentitiesResponseBody - A list of identities.
+type ListIdentitiesResponseBody struct {
+ // A list of identities.
+ Identities []Identities `json:"identities"`
+ // The cursor to use for the next page of results, if no cursor is returned, there are no more results
+ Cursor *string `json:"cursor,omitempty"`
+ // The total number of identities for this environment
+ Total int64 `json:"total"`
+}
+
+func (o *ListIdentitiesResponseBody) GetIdentities() []Identities {
+ if o == nil {
+ return []Identities{}
+ }
+ return o.Identities
+}
+
+func (o *ListIdentitiesResponseBody) GetCursor() *string {
+ if o == nil {
+ return nil
+ }
+ return o.Cursor
+}
+
+func (o *ListIdentitiesResponseBody) GetTotal() int64 {
+ if o == nil {
+ return 0
+ }
+ return o.Total
+}
+
+type ListIdentitiesResponse struct {
+ HTTPMeta components.HTTPMetadata `json:"-"`
+ // A list of identities.
+ Object *ListIdentitiesResponseBody
+
+ Next func() (*ListIdentitiesResponse, error)
+}
+
+func (o *ListIdentitiesResponse) GetHTTPMeta() components.HTTPMetadata {
+ if o == nil {
+ return components.HTTPMetadata{}
+ }
+ return o.HTTPMeta
+}
+
+func (o *ListIdentitiesResponse) GetObject() *ListIdentitiesResponseBody {
+ if o == nil {
+ return nil
+ }
+ return o.Object
+}
diff --git a/models/operations/updateidentity.go b/models/operations/updateidentity.go
new file mode 100644
index 0000000..5be11be
--- /dev/null
+++ b/models/operations/updateidentity.go
@@ -0,0 +1,148 @@
+// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
+
+package operations
+
+import (
+ "github.com/unkeyed/unkey-go/internal/utils"
+ "github.com/unkeyed/unkey-go/models/components"
+)
+
+type UpdateIdentityRatelimits struct {
+ // The name of this limit. You will need to use this again when verifying a key.
+ Name string `json:"name"`
+ // How many requests may pass within a given window before requests are rejected.
+ Limit float64 `json:"limit"`
+ // The duration for each ratelimit window in milliseconds.
+ Duration float64 `json:"duration"`
+}
+
+func (o *UpdateIdentityRatelimits) GetName() string {
+ if o == nil {
+ return ""
+ }
+ return o.Name
+}
+
+func (o *UpdateIdentityRatelimits) GetLimit() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Limit
+}
+
+func (o *UpdateIdentityRatelimits) GetDuration() float64 {
+ if o == nil {
+ return 0.0
+ }
+ return o.Duration
+}
+
+type UpdateIdentityRequestBody struct {
+ // The id of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence.
+ IdentityID *string `json:"identityId,omitempty"`
+ // The externalId of the identity to update, use either `identityId` or `externalId`, if both are provided, `identityId` takes precedence.
+ ExternalID *string `json:"externalId,omitempty"`
+ // This is not yet used but here for future compatibility.
+ Environment *string `default:"default" json:"environment"`
+ // Attach metadata to this identity that you need to have access to when verifying a key.
+ //
+ // Set to `{}` to clear.
+ //
+ // This will be returned as part of the `verifyKey` response.
+ //
+ Meta map[string]any `json:"meta,omitempty"`
+ // Attach ratelimits to this identity.
+ //
+ // This overwrites all existing ratelimits on this identity.
+ // Setting an empty array will delete all existing ratelimits.
+ //
+ // When verifying keys, you can specify which limits you want to use and all keys attached to this identity, will share the limits.
+ Ratelimits []UpdateIdentityRatelimits `json:"ratelimits,omitempty"`
+}
+
+func (u UpdateIdentityRequestBody) MarshalJSON() ([]byte, error) {
+ return utils.MarshalJSON(u, "", false)
+}
+
+func (u *UpdateIdentityRequestBody) UnmarshalJSON(data []byte) error {
+ if err := utils.UnmarshalJSON(data, &u, "", false, false); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (o *UpdateIdentityRequestBody) GetIdentityID() *string {
+ if o == nil {
+ return nil
+ }
+ return o.IdentityID
+}
+
+func (o *UpdateIdentityRequestBody) GetExternalID() *string {
+ if o == nil {
+ return nil
+ }
+ return o.ExternalID
+}
+
+func (o *UpdateIdentityRequestBody) GetEnvironment() *string {
+ if o == nil {
+ return nil
+ }
+ return o.Environment
+}
+
+func (o *UpdateIdentityRequestBody) GetMeta() map[string]any {
+ if o == nil {
+ return nil
+ }
+ return o.Meta
+}
+
+func (o *UpdateIdentityRequestBody) GetRatelimits() []UpdateIdentityRatelimits {
+ if o == nil {
+ return nil
+ }
+ return o.Ratelimits
+}
+
+type UpdateIdentityResponseBody struct {
+ // The id of the permission. This is used internally
+ ID string `json:"id"`
+ // The name of the permission
+ Name string `json:"name"`
+}
+
+func (o *UpdateIdentityResponseBody) GetID() string {
+ if o == nil {
+ return ""
+ }
+ return o.ID
+}
+
+func (o *UpdateIdentityResponseBody) GetName() string {
+ if o == nil {
+ return ""
+ }
+ return o.Name
+}
+
+type UpdateIdentityResponse struct {
+ HTTPMeta components.HTTPMetadata `json:"-"`
+ // The identity after the update.
+ ResponseBodies []UpdateIdentityResponseBody
+}
+
+func (o *UpdateIdentityResponse) GetHTTPMeta() components.HTTPMetadata {
+ if o == nil {
+ return components.HTTPMetadata{}
+ }
+ return o.HTTPMeta
+}
+
+func (o *UpdateIdentityResponse) GetResponseBodies() []UpdateIdentityResponseBody {
+ if o == nil {
+ return nil
+ }
+ return o.ResponseBodies
+}
diff --git a/unkey.go b/unkey.go
index 4fe693e..a8d4447 100644
--- a/unkey.go
+++ b/unkey.go
@@ -78,6 +78,7 @@ type Unkey struct {
Ratelimits *Ratelimits
Migrations *Migrations
Permissions *Permissions
+ Identities *Identities
sdkConfiguration sdkConfiguration
}
@@ -156,9 +157,9 @@ func New(opts ...SDKOption) *Unkey {
sdkConfiguration: sdkConfiguration{
Language: "go",
OpenAPIDocVersion: "1.0.0",
- SDKVersion: "0.7.0",
- GenVersion: "2.372.3",
- UserAgent: "speakeasy-sdk/go 0.7.0 2.372.3 1.0.0 github.com/unkeyed/unkey-go",
+ SDKVersion: "0.8.0",
+ GenVersion: "2.375.5",
+ UserAgent: "speakeasy-sdk/go 0.8.0 2.375.5 1.0.0 github.com/unkeyed/unkey-go",
Hooks: hooks.New(),
},
}
@@ -190,6 +191,8 @@ func New(opts ...SDKOption) *Unkey {
sdk.Permissions = newPermissions(sdk.sdkConfiguration)
+ sdk.Identities = newIdentities(sdk.sdkConfiguration)
+
return sdk
}
@@ -728,3 +731,539 @@ func (s *Unkey) DeleteAPI(ctx context.Context, request operations.DeleteAPIReque
return res, nil
}
+
+func (s *Unkey) CreateIdentity(ctx context.Context, request operations.CreateIdentityRequestBody, opts ...operations.Option) (*operations.CreateIdentityResponse, error) {
+ hookCtx := hooks.HookContext{
+ Context: ctx,
+ OperationID: "createIdentity",
+ OAuth2Scopes: []string{},
+ SecuritySource: s.sdkConfiguration.Security,
+ }
+
+ o := operations.Options{}
+ supportedOptions := []string{
+ operations.SupportedOptionRetries,
+ operations.SupportedOptionTimeout,
+ }
+
+ for _, opt := range opts {
+ if err := opt(&o, supportedOptions...); err != nil {
+ return nil, fmt.Errorf("error applying option: %w", err)
+ }
+ }
+
+ baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
+ opURL, err := url.JoinPath(baseURL, "/v1/identities.createIdentity")
+ if err != nil {
+ return nil, fmt.Errorf("error generating URL: %w", err)
+ }
+
+ bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`)
+ if err != nil {
+ return nil, err
+ }
+
+ timeout := o.Timeout
+ if timeout == nil {
+ timeout = s.sdkConfiguration.Timeout
+ }
+
+ if timeout != nil {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, *timeout)
+ defer cancel()
+ }
+
+ req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader)
+ if err != nil {
+ return nil, fmt.Errorf("error creating request: %w", err)
+ }
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
+ req.Header.Set("Content-Type", reqContentType)
+
+ if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
+ return nil, err
+ }
+
+ globalRetryConfig := s.sdkConfiguration.RetryConfig
+ retryConfig := o.Retries
+ if retryConfig == nil {
+ if globalRetryConfig != nil {
+ retryConfig = globalRetryConfig
+ } else {
+ retryConfig = &retry.Config{
+ Strategy: "backoff", Backoff: &retry.BackoffStrategy{
+ InitialInterval: 50,
+ MaxInterval: 1000,
+ Exponent: 1.5,
+ MaxElapsedTime: 30000,
+ },
+ RetryConnectionErrors: true,
+ }
+ }
+ }
+
+ var httpRes *http.Response
+ if retryConfig != nil {
+ httpRes, err = utils.Retry(ctx, utils.Retries{
+ Config: retryConfig,
+ StatusCodes: []string{
+ "5XX",
+ },
+ }, func() (*http.Response, error) {
+ if req.Body != nil {
+ copyBody, err := req.GetBody()
+ if err != nil {
+ return nil, err
+ }
+ req.Body = copyBody
+ }
+
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, backoff.Permanent(err)
+ }
+
+ httpRes, err := s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ }
+ return httpRes, err
+ })
+
+ if err != nil {
+ return nil, err
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ } else {
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, err
+ }
+
+ httpRes, err = s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ return nil, err
+ } else if utils.MatchStatusCodes([]string{"400", "401", "403", "404", "409", "429", "4XX", "500", "5XX"}, httpRes.StatusCode) {
+ _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
+ if err != nil {
+ return nil, err
+ } else if _httpRes != nil {
+ httpRes = _httpRes
+ }
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ res := &operations.CreateIdentityResponse{
+ HTTPMeta: components.HTTPMetadata{
+ Request: req,
+ Response: httpRes,
+ },
+ }
+
+ rawBody, err := io.ReadAll(httpRes.Body)
+ if err != nil {
+ return nil, fmt.Errorf("error reading response body: %w", err)
+ }
+ httpRes.Body.Close()
+ httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
+
+ switch {
+ case httpRes.StatusCode == 200:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out operations.CreateIdentityResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ res.Object = &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 400:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrBadRequest
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 401:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrUnauthorized
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 403:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrForbidden
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 404:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrNotFound
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 409:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrConflict
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 429:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrTooManyRequests
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 500:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrInternalServerError
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
+ fallthrough
+ case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
+ return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
+ default:
+ return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
+ }
+
+ return res, nil
+
+}
+
+func (s *Unkey) DeleteeIdentity(ctx context.Context, request operations.DeleteeIdentityRequestBody, opts ...operations.Option) (*operations.DeleteeIdentityResponse, error) {
+ hookCtx := hooks.HookContext{
+ Context: ctx,
+ OperationID: "deleteeIdentity",
+ OAuth2Scopes: []string{},
+ SecuritySource: s.sdkConfiguration.Security,
+ }
+
+ o := operations.Options{}
+ supportedOptions := []string{
+ operations.SupportedOptionRetries,
+ operations.SupportedOptionTimeout,
+ }
+
+ for _, opt := range opts {
+ if err := opt(&o, supportedOptions...); err != nil {
+ return nil, fmt.Errorf("error applying option: %w", err)
+ }
+ }
+
+ baseURL := utils.ReplaceParameters(s.sdkConfiguration.GetServerDetails())
+ opURL, err := url.JoinPath(baseURL, "/v1/identities.deleteIdentity")
+ if err != nil {
+ return nil, fmt.Errorf("error generating URL: %w", err)
+ }
+
+ bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, false, false, "Request", "json", `request:"mediaType=application/json"`)
+ if err != nil {
+ return nil, err
+ }
+
+ timeout := o.Timeout
+ if timeout == nil {
+ timeout = s.sdkConfiguration.Timeout
+ }
+
+ if timeout != nil {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, *timeout)
+ defer cancel()
+ }
+
+ req, err := http.NewRequestWithContext(ctx, "POST", opURL, bodyReader)
+ if err != nil {
+ return nil, fmt.Errorf("error creating request: %w", err)
+ }
+ req.Header.Set("Accept", "application/json")
+ req.Header.Set("User-Agent", s.sdkConfiguration.UserAgent)
+ req.Header.Set("Content-Type", reqContentType)
+
+ if err := utils.PopulateSecurity(ctx, req, s.sdkConfiguration.Security); err != nil {
+ return nil, err
+ }
+
+ globalRetryConfig := s.sdkConfiguration.RetryConfig
+ retryConfig := o.Retries
+ if retryConfig == nil {
+ if globalRetryConfig != nil {
+ retryConfig = globalRetryConfig
+ } else {
+ retryConfig = &retry.Config{
+ Strategy: "backoff", Backoff: &retry.BackoffStrategy{
+ InitialInterval: 50,
+ MaxInterval: 1000,
+ Exponent: 1.5,
+ MaxElapsedTime: 30000,
+ },
+ RetryConnectionErrors: true,
+ }
+ }
+ }
+
+ var httpRes *http.Response
+ if retryConfig != nil {
+ httpRes, err = utils.Retry(ctx, utils.Retries{
+ Config: retryConfig,
+ StatusCodes: []string{
+ "5XX",
+ },
+ }, func() (*http.Response, error) {
+ if req.Body != nil {
+ copyBody, err := req.GetBody()
+ if err != nil {
+ return nil, err
+ }
+ req.Body = copyBody
+ }
+
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, backoff.Permanent(err)
+ }
+
+ httpRes, err := s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ }
+ return httpRes, err
+ })
+
+ if err != nil {
+ return nil, err
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ } else {
+ req, err = s.sdkConfiguration.Hooks.BeforeRequest(hooks.BeforeRequestContext{HookContext: hookCtx}, req)
+ if err != nil {
+ return nil, err
+ }
+
+ httpRes, err = s.sdkConfiguration.Client.Do(req)
+ if err != nil || httpRes == nil {
+ if err != nil {
+ err = fmt.Errorf("error sending request: %w", err)
+ } else {
+ err = fmt.Errorf("error sending request: no response")
+ }
+
+ _, err = s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, nil, err)
+ return nil, err
+ } else if utils.MatchStatusCodes([]string{"400", "401", "403", "404", "409", "429", "4XX", "500", "5XX"}, httpRes.StatusCode) {
+ _httpRes, err := s.sdkConfiguration.Hooks.AfterError(hooks.AfterErrorContext{HookContext: hookCtx}, httpRes, nil)
+ if err != nil {
+ return nil, err
+ } else if _httpRes != nil {
+ httpRes = _httpRes
+ }
+ } else {
+ httpRes, err = s.sdkConfiguration.Hooks.AfterSuccess(hooks.AfterSuccessContext{HookContext: hookCtx}, httpRes)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ res := &operations.DeleteeIdentityResponse{
+ HTTPMeta: components.HTTPMetadata{
+ Request: req,
+ Response: httpRes,
+ },
+ }
+
+ rawBody, err := io.ReadAll(httpRes.Body)
+ if err != nil {
+ return nil, fmt.Errorf("error reading response body: %w", err)
+ }
+ httpRes.Body.Close()
+ httpRes.Body = io.NopCloser(bytes.NewBuffer(rawBody))
+
+ switch {
+ case httpRes.StatusCode == 200:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out operations.DeleteeIdentityResponseBody
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ res.Object = &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 400:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrBadRequest
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 401:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrUnauthorized
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 403:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrForbidden
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 404:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrNotFound
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 409:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrConflict
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 429:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrTooManyRequests
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode == 500:
+ switch {
+ case utils.MatchContentType(httpRes.Header.Get("Content-Type"), `application/json`):
+ var out sdkerrors.ErrInternalServerError
+ if err := utils.UnmarshalJsonFromResponseBody(bytes.NewBuffer(rawBody), &out, ""); err != nil {
+ return nil, err
+ }
+
+ return nil, &out
+ default:
+ return nil, sdkerrors.NewSDKError(fmt.Sprintf("unknown content-type received: %s", httpRes.Header.Get("Content-Type")), httpRes.StatusCode, string(rawBody), httpRes)
+ }
+ case httpRes.StatusCode >= 400 && httpRes.StatusCode < 500:
+ fallthrough
+ case httpRes.StatusCode >= 500 && httpRes.StatusCode < 600:
+ return nil, sdkerrors.NewSDKError("API error occurred", httpRes.StatusCode, string(rawBody), httpRes)
+ default:
+ return nil, sdkerrors.NewSDKError("unknown status code returned", httpRes.StatusCode, string(rawBody), httpRes)
+ }
+
+ return res, nil
+
+}