Skip to content

Commit

Permalink
feat(sdk): Change oAuth strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
flemzord committed Sep 23, 2024
1 parent f7d9e35 commit e0cb7a3
Show file tree
Hide file tree
Showing 34 changed files with 766 additions and 547 deletions.
8 changes: 6 additions & 2 deletions releases/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ info:
servers:
- url: http://localhost
description: local server
- url: https://{stack}.sandbox.formance.cloud
description: sandbox server

security:
- Authorization: []
#security:
# - Authorization: []
# - NoAuthorization: []
# - NoAuth: []

tags:
- name: ledger.v1
Expand Down
8 changes: 5 additions & 3 deletions releases/sdks/go/.speakeasy/gen.lock
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
lockVersion: 2.0.0
id: 7eac0a45-60a2-40bb-9e85-26bd77ec2a6d
id: 8cc5b996-ee96-49ac-9b4e-0cc5e3bfbe2f
management:
docChecksum: ce9e9a1abe285e9e111c5ad7edccbbf3
docChecksum: 7a767c56727b4554fc8223aecdd101e2
docVersion: v0.0.0
speakeasyVersion: 1.346.0
generationVersion: 2.379.3
releaseVersion: v0.0.0
configChecksum: 86fb0b4c762641bbbe6b4f59e9dd3989
configChecksum: f2202d55313914a857427cd0c614fbb1
features:
go:
additionalDependencies: 0.1.0
Expand All @@ -25,6 +25,7 @@ features:
intellisenseMarkdownSupport: 0.1.0
nameOverrides: 2.81.2
nullables: 0.1.0
oauth2ClientCredentials: 0.1.1
responseFormat: 0.1.2
retries: 2.83.0
sdkHooks: 0.1.0
Expand Down Expand Up @@ -1375,4 +1376,5 @@ generatedFiles:
- pkg/models/operations/options.go
- .gitattributes
- internal/hooks/hooks.go
- internal/hooks/clientcredentials.go
- CONTRIBUTING.md
217 changes: 109 additions & 108 deletions releases/sdks/go/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# github.com/formancehq/formance-sdk-go/v2

<div align="left">
<a href="https://speakeasyapi.dev/"><img src="https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454" /></a>
<a href="https://www.speakeasy.com/?utm_source=<no value>&utm_campaign=go"><img src="https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454" /></a>
<a href="https://opensource.org/licenses/MIT">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" style="width: 100px; height: 28px;" />
</a>
Expand All @@ -11,9 +11,9 @@
## 🏗 **Welcome to your new SDK!** 🏗

It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:
- [ ] 🛠 Make your SDK feel handcrafted by [customizing it](https://www.speakeasyapi.dev/docs/customize-sdks)
- [ ] 🛠 Make your SDK feel handcrafted by [customizing it](https://www.speakeasy.com/docs/customize-sdks)
- [ ] ♻️ Refine your SDK quickly by iterating locally with the [Speakeasy CLI](https://github.com/speakeasy-api/speakeasy)
- [ ] 🎁 Publish your SDK to package managers by [configuring automatic publishing](https://www.speakeasyapi.dev/docs/productionize-sdks/publish-sdks)
- [ ] 🎁 Publish your SDK to package managers by [configuring automatic publishing](https://www.speakeasy.com/docs/advanced-setup/publish-sdks)
- [ ] ✨ When ready to productionize, delete this section from the README

<!-- Start SDK Installation [installation] -->
Expand Down Expand Up @@ -43,7 +43,7 @@ import (
func main() {
s := v2.New(
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

Expand Down Expand Up @@ -274,6 +274,98 @@ func main() {
* [TestConfig](docs/sdks/formancewebhooksv1/README.md#testconfig) - Test one config
<!-- End Available Resources and Operations [operations] -->

<!-- Start Retries [retries] -->
## Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a `retry.Config` object to the call by using the `WithRetries` option:
```go
package main

import (
"context"
"github.com/formancehq/formance-sdk-go/v2"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/shared"
"github.com/formancehq/formance-sdk-go/v2/pkg/retry"
"log"
"os"
"pkg/models/operations"
)

func main() {
s := v2.New(
v2.WithSecurity(shared.Security{
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

ctx := context.Background()
res, err := s.GetVersions(ctx, operations.WithRetries(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}))
if err != nil {
log.Fatal(err)
}
if res.GetVersionsResponse != nil {
// handle response
}
}

```

If you'd like to override the default retry strategy for all operations that support retries, you can use the `WithRetryConfig` option at SDK initialization:
```go
package main

import (
"context"
"github.com/formancehq/formance-sdk-go/v2"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/shared"
"github.com/formancehq/formance-sdk-go/v2/pkg/retry"
"log"
"os"
)

func main() {
s := v2.New(
v2.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
v2.WithSecurity(shared.Security{
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

ctx := context.Background()
res, err := s.GetVersions(ctx)
if err != nil {
log.Fatal(err)
}
if res.GetVersionsResponse != nil {
// handle response
}
}

```
<!-- End Retries [retries] -->

<!-- Start Error Handling [errors] -->
## Error Handling

Expand Down Expand Up @@ -304,7 +396,7 @@ import (
func main() {
s := v2.New(
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)
request := operations.CreateTransactionsRequest{
Expand Down Expand Up @@ -374,7 +466,7 @@ func main() {
s := v2.New(
v2.WithServerIndex(0),
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

Expand Down Expand Up @@ -409,7 +501,7 @@ func main() {
s := v2.New(
v2.WithServerURL("http://localhost"),
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

Expand Down Expand Up @@ -460,13 +552,14 @@ This can be a convenient way to configure timeouts, cookies, proxies, custom hea

### Per-Client Security Schemes

This SDK supports the following security scheme globally:
This SDK supports the following security schemes globally:

| Name | Type | Scheme |
| --------------- | --------------- | --------------- |
| `Authorization` | oauth2 | OAuth2 token |
| Name | Type | Scheme |
| -------------- | -------------- | -------------- |
| `ClientID` | oauth2 | OAuth2 token |
| `ClientSecret` | oauth2 | OAuth2 token |

You can configure it using the `WithSecurity` option when initializing the SDK client instance. For example:
You can set the security parameters through the `WithSecurity` option when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
```go
package main

Expand All @@ -481,7 +574,7 @@ import (
func main() {
s := v2.New(
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

Expand All @@ -504,98 +597,6 @@ func main() {

<!-- End Special Types [types] -->

<!-- Start Retries [retries] -->
## Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a `retry.Config` object to the call by using the `WithRetries` option:
```go
package main

import (
"context"
"github.com/formancehq/formance-sdk-go/v2"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/shared"
"github.com/formancehq/formance-sdk-go/v2/pkg/retry"
"log"
"os"
"pkg/models/operations"
)

func main() {
s := v2.New(
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
}),
)

ctx := context.Background()
res, err := s.GetVersions(ctx, operations.WithRetries(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}))
if err != nil {
log.Fatal(err)
}
if res.GetVersionsResponse != nil {
// handle response
}
}

```

If you'd like to override the default retry strategy for all operations that support retries, you can use the `WithRetryConfig` option at SDK initialization:
```go
package main

import (
"context"
"github.com/formancehq/formance-sdk-go/v2"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/shared"
"github.com/formancehq/formance-sdk-go/v2/pkg/retry"
"log"
"os"
)

func main() {
s := v2.New(
v2.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
}),
)

ctx := context.Background()
res, err := s.GetVersions(ctx)
if err != nil {
log.Fatal(err)
}
if res.GetVersionsResponse != nil {
// handle response
}
}

```
<!-- End Retries [retries] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->

# Development
Expand All @@ -608,7 +609,7 @@ looking for the latest version.

## Contributions

While we value open-source contributions to this SDK, this library is generated programmatically.
Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

### SDK Created by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks)
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=<no value>&utm_campaign=go)
2 changes: 1 addition & 1 deletion releases/sdks/go/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func main() {
s := v2.New(
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

Expand Down
8 changes: 5 additions & 3 deletions releases/sdks/go/docs/pkg/models/shared/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

## Fields

| Field | Type | Required | Description |
| ------------------ | ------------------ | ------------------ | ------------------ |
| `Authorization` | *string* | :heavy_check_mark: | N/A |
| Field | Type | Required | Description | Example |
| ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
| `ClientID` | **string* | :heavy_minus_sign: | N/A | |
| `ClientSecret` | **string* | :heavy_minus_sign: | N/A | |
| `TokenURL` | **string* | :heavy_minus_sign: | N/A | |
2 changes: 1 addition & 1 deletion releases/sdks/go/docs/sdks/formance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import(
func main() {
s := v2.New(
v2.WithSecurity(shared.Security{
Authorization: os.Getenv("AUTHORIZATION"),
ClientID: v2.String(os.Getenv("CLIENT_ID")),
}),
)

Expand Down
Loading

0 comments on commit e0cb7a3

Please sign in to comment.