diff --git a/internal/commands/build.go b/internal/commands/build.go index 5a4db87..04a5777 100644 --- a/internal/commands/build.go +++ b/internal/commands/build.go @@ -131,7 +131,7 @@ var Build = &cli.Command{ }, } -func doBuildCreate(ctx context.Context, hathora *sdk.SDK, buildTag, buildId, filePath string, hideUploadProgress bool) (*components.BuildV3, error) { +func doBuildCreate(ctx context.Context, hathora *sdk.HathoraCloud, buildTag, buildId, filePath string, hideUploadProgress bool) (*components.BuildV3, error) { file, err := archive.RequireTGZ(filePath) if err != nil { return nil, fmt.Errorf("no build file available for run: %w", err) @@ -305,7 +305,7 @@ var ( type BuildConfig struct { *GlobalConfig - SDK *sdk.SDK + SDK *sdk.HathoraCloud Output output.FormatWriter } diff --git a/internal/commands/deployment.go b/internal/commands/deployment.go index 25836c9..77276fb 100644 --- a/internal/commands/deployment.go +++ b/internal/commands/deployment.go @@ -366,7 +366,7 @@ var ( type DeploymentConfig struct { *GlobalConfig - SDK *sdk.SDK + SDK *sdk.HathoraCloud Output output.FormatWriter } diff --git a/internal/commands/log.go b/internal/commands/log.go index 4fb6ed9..ee72969 100644 --- a/internal/commands/log.go +++ b/internal/commands/log.go @@ -109,7 +109,7 @@ var ( type LogConfig struct { *GlobalConfig - SDK *sdk.SDK + SDK *sdk.HathoraCloud } var _ LoadableConfig = (*LogConfig)(nil) diff --git a/internal/mock/hathora.go b/internal/mock/hathora.go index 46fa2b5..8c360c3 100644 --- a/internal/mock/hathora.go +++ b/internal/mock/hathora.go @@ -14,7 +14,7 @@ import ( type HathoraIntegration struct { Endpoint string - SDK *sdk.SDK + SDK *sdk.HathoraCloud mock *mockHathora } diff --git a/internal/sdk/hathoracloud.go b/internal/sdk/hathoracloud.go index 0d4bd5c..79ffee9 100644 --- a/internal/sdk/hathoracloud.go +++ b/internal/sdk/hathoracloud.go @@ -4,11 +4,14 @@ package sdk import ( "context" + "fmt" "net/http" "time" "github.com/hathora/ci/internal/sdk/internal/globals" "github.com/hathora/ci/internal/sdk/internal/hooks" + "github.com/hathora/ci/internal/sdk/internal/utils" + "github.com/hathora/ci/internal/sdk/models/components" "github.com/hathora/ci/internal/sdk/retry" ) @@ -68,214 +71,214 @@ func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) { return ServerList[c.ServerIndex], nil } -// // HathoraCloud - Hathora Cloud API: Welcome to the Hathora Cloud API documentation! Learn how to use the Hathora Cloud APIs to build and scale your game servers globally. -// type HathoraCloud struct { -// // -// TokensV1 *TokensV1 -// RoomsV1 *RoomsV1 -// RoomsV2 *RoomsV2 -// // Deprecated. Use [ProcessesV3](https://hathora.dev/api#tag/ProcessesV3). -// ProcessesV1 *ProcessesV1 -// // Deprecated. Use [ProcessesV3](https://hathora.dev/api#tag/ProcessesV3). -// ProcessesV2 *ProcessesV2 -// // Operations to get data on active and stopped [processes](https://hathora.dev/docs/concepts/hathora-entities#process). -// ProcessesV3 *ProcessesV3 -// OrganizationsV1 *OrganizationsV1 -// // Operations to get metrics by [process](https://hathora.dev/docs/concepts/hathora-entities#process). We store 72 hours of metrics data. -// MetricsV1 *MetricsV1 -// // -// ManagementV1 *ManagementV1 -// LogsV1 *LogsV1 -// LobbiesV1 *LobbiesV1 -// LobbiesV2 *LobbiesV2 -// LobbiesV3 *LobbiesV3 -// // Operations to manage and view a [fleet](https://hathora.dev/docs/concepts/hathora-entities#fleet). -// FleetsV1 *FleetsV1 -// // Deprecated. Does not include latest Regions (missing Dallas region). Use [DiscoveryV2](https://hathora.dev/api#tag/DiscoveryV2). -// DiscoveryV1 *DiscoveryV1 -// // Service that allows clients to directly ping all Hathora regions to get latency information -// DiscoveryV2 *DiscoveryV2 -// DeploymentsV1 *DeploymentsV1 -// DeploymentsV2 *DeploymentsV2 -// // Operations that allow you configure and manage an application's [build](https://hathora.dev/docs/concepts/hathora-entities#build) at runtime. -// DeploymentsV3 *DeploymentsV3 -// BuildsV1 *BuildsV1 -// BuildsV2 *BuildsV2 -// // Operations that allow you create and manage your [builds](https://hathora.dev/docs/concepts/hathora-entities#build). -// BuildsV3 *BuildsV3 -// // -// BillingV1 *BillingV1 -// // Operations that allow you to generate a Hathora-signed [JSON web token (JWT)](https://jwt.io/) for [player authentication](https://hathora.dev/docs/lobbies-and-matchmaking/auth-service). -// AuthV1 *AuthV1 -// AppsV1 *AppsV1 -// // Operations that allow you manage your [applications](https://hathora.dev/docs/concepts/hathora-entities#application). -// AppsV2 *AppsV2 - -// sdkConfiguration sdkConfiguration -// } - -// type SDKOption func(*HathoraCloud) - -// // WithServerURL allows the overriding of the default server URL -// func WithServerURL(serverURL string) SDKOption { -// return func(sdk *HathoraCloud) { -// sdk.sdkConfiguration.ServerURL = serverURL -// } -// } - -// // WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters -// func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption { -// return func(sdk *HathoraCloud) { -// if params != nil { -// serverURL = utils.ReplaceParameters(serverURL, params) -// } - -// sdk.sdkConfiguration.ServerURL = serverURL -// } -// } - -// // WithServerIndex allows the overriding of the default server by index -// func WithServerIndex(serverIndex int) SDKOption { -// return func(sdk *HathoraCloud) { -// if serverIndex < 0 || serverIndex >= len(ServerList) { -// panic(fmt.Errorf("server index %d out of range", serverIndex)) -// } - -// sdk.sdkConfiguration.ServerIndex = serverIndex -// } -// } - -// // WithClient allows the overriding of the default HTTP client used by the SDK -// func WithClient(client HTTPClient) SDKOption { -// return func(sdk *HathoraCloud) { -// sdk.sdkConfiguration.Client = client -// } -// } - -// // WithSecurity configures the SDK to use the provided security details -// func WithSecurity(hathoraDevToken string) SDKOption { -// return func(sdk *HathoraCloud) { -// security := components.Security{HathoraDevToken: &hathoraDevToken} -// sdk.sdkConfiguration.Security = utils.AsSecuritySource(&security) -// } -// } - -// // WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication -// func WithSecuritySource(security func(context.Context) (components.Security, error)) SDKOption { -// return func(sdk *HathoraCloud) { -// sdk.sdkConfiguration.Security = func(ctx context.Context) (interface{}, error) { -// return security(ctx) -// } -// } -// } - -// // WithOrgID allows setting the OrgID parameter for all supported operations -// func WithOrgID(orgID string) SDKOption { -// return func(sdk *HathoraCloud) { -// sdk.sdkConfiguration.Globals.OrgID = &orgID -// } -// } - -// // WithAppID allows setting the AppID parameter for all supported operations -// func WithAppID(appID string) SDKOption { -// return func(sdk *HathoraCloud) { -// sdk.sdkConfiguration.Globals.AppID = &appID -// } -// } - -// func WithRetryConfig(retryConfig retry.Config) SDKOption { -// return func(sdk *HathoraCloud) { -// sdk.sdkConfiguration.RetryConfig = &retryConfig -// } -// } - -// // WithTimeout Optional request timeout applied to each operation -// func WithTimeout(timeout time.Duration) SDKOption { -// return func(sdk *HathoraCloud) { -// sdk.sdkConfiguration.Timeout = &timeout -// } -// } - -// // New creates a new instance of the SDK with the provided options -// func New(opts ...SDKOption) *HathoraCloud { -// sdk := &HathoraCloud{ -// sdkConfiguration: sdkConfiguration{ -// Language: "go", -// OpenAPIDocVersion: "0.0.1", -// SDKVersion: "0.2.1", -// GenVersion: "2.480.1", -// UserAgent: "speakeasy-sdk/go 0.2.1 2.480.1 0.0.1 hathoracloud", -// Globals: globals.Globals{}, -// Hooks: hooks.New(), -// }, -// } -// for _, opt := range opts { -// opt(sdk) -// } +// HathoraCloud - Hathora Cloud API: Welcome to the Hathora Cloud API documentation! Learn how to use the Hathora Cloud APIs to build and scale your game servers globally. +type HathoraCloud struct { + // + TokensV1 *TokensV1 + RoomsV1 *RoomsV1 + RoomsV2 *RoomsV2 + // Deprecated. Use [ProcessesV3](https://hathora.dev/api#tag/ProcessesV3). + ProcessesV1 *ProcessesV1 + // Deprecated. Use [ProcessesV3](https://hathora.dev/api#tag/ProcessesV3). + ProcessesV2 *ProcessesV2 + // Operations to get data on active and stopped [processes](https://hathora.dev/docs/concepts/hathora-entities#process). + ProcessesV3 *ProcessesV3 + OrganizationsV1 *OrganizationsV1 + // Operations to get metrics by [process](https://hathora.dev/docs/concepts/hathora-entities#process). We store 72 hours of metrics data. + MetricsV1 *MetricsV1 + // + ManagementV1 *ManagementV1 + LogsV1 *LogsV1 + LobbiesV1 *LobbiesV1 + LobbiesV2 *LobbiesV2 + LobbiesV3 *LobbiesV3 + // Operations to manage and view a [fleet](https://hathora.dev/docs/concepts/hathora-entities#fleet). + FleetsV1 *FleetsV1 + // Deprecated. Does not include latest Regions (missing Dallas region). Use [DiscoveryV2](https://hathora.dev/api#tag/DiscoveryV2). + DiscoveryV1 *DiscoveryV1 + // Service that allows clients to directly ping all Hathora regions to get latency information + DiscoveryV2 *DiscoveryV2 + DeploymentsV1 *DeploymentsV1 + DeploymentsV2 *DeploymentsV2 + // Operations that allow you configure and manage an application's [build](https://hathora.dev/docs/concepts/hathora-entities#build) at runtime. + DeploymentsV3 *DeploymentsV3 + BuildsV1 *BuildsV1 + BuildsV2 *BuildsV2 + // Operations that allow you create and manage your [builds](https://hathora.dev/docs/concepts/hathora-entities#build). + BuildsV3 *BuildsV3 + // + BillingV1 *BillingV1 + // Operations that allow you to generate a Hathora-signed [JSON web token (JWT)](https://jwt.io/) for [player authentication](https://hathora.dev/docs/lobbies-and-matchmaking/auth-service). + AuthV1 *AuthV1 + AppsV1 *AppsV1 + // Operations that allow you manage your [applications](https://hathora.dev/docs/concepts/hathora-entities#application). + AppsV2 *AppsV2 + + sdkConfiguration sdkConfiguration +} + +type SDKOption func(*HathoraCloud) + +// WithServerURL allows the overriding of the default server URL +func WithServerURL(serverURL string) SDKOption { + return func(sdk *HathoraCloud) { + sdk.sdkConfiguration.ServerURL = serverURL + } +} + +// WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters +func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption { + return func(sdk *HathoraCloud) { + if params != nil { + serverURL = utils.ReplaceParameters(serverURL, params) + } + + sdk.sdkConfiguration.ServerURL = serverURL + } +} + +// WithServerIndex allows the overriding of the default server by index +func WithServerIndex(serverIndex int) SDKOption { + return func(sdk *HathoraCloud) { + if serverIndex < 0 || serverIndex >= len(ServerList) { + panic(fmt.Errorf("server index %d out of range", serverIndex)) + } + + sdk.sdkConfiguration.ServerIndex = serverIndex + } +} + +// WithClient allows the overriding of the default HTTP client used by the SDK +func WithClient(client HTTPClient) SDKOption { + return func(sdk *HathoraCloud) { + sdk.sdkConfiguration.Client = client + } +} + +// WithSecurity configures the SDK to use the provided security details +func WithSecurity(hathoraDevToken string) SDKOption { + return func(sdk *HathoraCloud) { + security := components.Security{HathoraDevToken: &hathoraDevToken} + sdk.sdkConfiguration.Security = utils.AsSecuritySource(&security) + } +} + +// WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication +func WithSecuritySource(security func(context.Context) (components.Security, error)) SDKOption { + return func(sdk *HathoraCloud) { + sdk.sdkConfiguration.Security = func(ctx context.Context) (interface{}, error) { + return security(ctx) + } + } +} + +// WithOrgID allows setting the OrgID parameter for all supported operations +func WithOrgID(orgID string) SDKOption { + return func(sdk *HathoraCloud) { + sdk.sdkConfiguration.Globals.OrgID = &orgID + } +} + +// WithAppID allows setting the AppID parameter for all supported operations +func WithAppID(appID string) SDKOption { + return func(sdk *HathoraCloud) { + sdk.sdkConfiguration.Globals.AppID = &appID + } +} + +func WithRetryConfig(retryConfig retry.Config) SDKOption { + return func(sdk *HathoraCloud) { + sdk.sdkConfiguration.RetryConfig = &retryConfig + } +} + +// WithTimeout Optional request timeout applied to each operation +func WithTimeout(timeout time.Duration) SDKOption { + return func(sdk *HathoraCloud) { + sdk.sdkConfiguration.Timeout = &timeout + } +} + +// New creates a new instance of the SDK with the provided options +func New(opts ...SDKOption) *HathoraCloud { + sdk := &HathoraCloud{ + sdkConfiguration: sdkConfiguration{ + Language: "go", + OpenAPIDocVersion: "0.0.1", + SDKVersion: "0.2.1", + GenVersion: "2.480.1", + UserAgent: "speakeasy-sdk/go 0.2.1 2.480.1 0.0.1 hathoracloud", + Globals: globals.Globals{}, + Hooks: hooks.New(), + }, + } + for _, opt := range opts { + opt(sdk) + } -// // Use WithClient to override the default client if you would like to customize the timeout -// if sdk.sdkConfiguration.Client == nil { -// sdk.sdkConfiguration.Client = &http.Client{Timeout: 60 * time.Second} -// } + // Use WithClient to override the default client if you would like to customize the timeout + if sdk.sdkConfiguration.Client == nil { + sdk.sdkConfiguration.Client = &http.Client{Timeout: 60 * time.Second} + } -// currentServerURL, _ := sdk.sdkConfiguration.GetServerDetails() -// serverURL := currentServerURL -// serverURL, sdk.sdkConfiguration.Client = sdk.sdkConfiguration.Hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client) -// if serverURL != currentServerURL { -// sdk.sdkConfiguration.ServerURL = serverURL -// } + currentServerURL, _ := sdk.sdkConfiguration.GetServerDetails() + serverURL := currentServerURL + serverURL, sdk.sdkConfiguration.Client = sdk.sdkConfiguration.Hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client) + if serverURL != currentServerURL { + sdk.sdkConfiguration.ServerURL = serverURL + } -// sdk.TokensV1 = newTokensV1(sdk.sdkConfiguration) + sdk.TokensV1 = newTokensV1(sdk.sdkConfiguration) -// sdk.RoomsV1 = newRoomsV1(sdk.sdkConfiguration) + sdk.RoomsV1 = newRoomsV1(sdk.sdkConfiguration) -// sdk.RoomsV2 = newRoomsV2(sdk.sdkConfiguration) + sdk.RoomsV2 = newRoomsV2(sdk.sdkConfiguration) -// sdk.ProcessesV1 = newProcessesV1(sdk.sdkConfiguration) + sdk.ProcessesV1 = newProcessesV1(sdk.sdkConfiguration) -// sdk.ProcessesV2 = newProcessesV2(sdk.sdkConfiguration) + sdk.ProcessesV2 = newProcessesV2(sdk.sdkConfiguration) -// sdk.ProcessesV3 = newProcessesV3(sdk.sdkConfiguration) + sdk.ProcessesV3 = newProcessesV3(sdk.sdkConfiguration) -// sdk.OrganizationsV1 = newOrganizationsV1(sdk.sdkConfiguration) + sdk.OrganizationsV1 = newOrganizationsV1(sdk.sdkConfiguration) -// sdk.MetricsV1 = newMetricsV1(sdk.sdkConfiguration) + sdk.MetricsV1 = newMetricsV1(sdk.sdkConfiguration) -// sdk.ManagementV1 = newManagementV1(sdk.sdkConfiguration) + sdk.ManagementV1 = newManagementV1(sdk.sdkConfiguration) -// sdk.LogsV1 = newLogsV1(sdk.sdkConfiguration) + sdk.LogsV1 = newLogsV1(sdk.sdkConfiguration) -// sdk.LobbiesV1 = newLobbiesV1(sdk.sdkConfiguration) + sdk.LobbiesV1 = newLobbiesV1(sdk.sdkConfiguration) -// sdk.LobbiesV2 = newLobbiesV2(sdk.sdkConfiguration) + sdk.LobbiesV2 = newLobbiesV2(sdk.sdkConfiguration) -// sdk.LobbiesV3 = newLobbiesV3(sdk.sdkConfiguration) + sdk.LobbiesV3 = newLobbiesV3(sdk.sdkConfiguration) -// sdk.FleetsV1 = newFleetsV1(sdk.sdkConfiguration) + sdk.FleetsV1 = newFleetsV1(sdk.sdkConfiguration) -// sdk.DiscoveryV1 = newDiscoveryV1(sdk.sdkConfiguration) + sdk.DiscoveryV1 = newDiscoveryV1(sdk.sdkConfiguration) -// sdk.DiscoveryV2 = newDiscoveryV2(sdk.sdkConfiguration) + sdk.DiscoveryV2 = newDiscoveryV2(sdk.sdkConfiguration) -// sdk.DeploymentsV1 = newDeploymentsV1(sdk.sdkConfiguration) + sdk.DeploymentsV1 = newDeploymentsV1(sdk.sdkConfiguration) -// sdk.DeploymentsV2 = newDeploymentsV2(sdk.sdkConfiguration) + sdk.DeploymentsV2 = newDeploymentsV2(sdk.sdkConfiguration) -// sdk.DeploymentsV3 = newDeploymentsV3(sdk.sdkConfiguration) + sdk.DeploymentsV3 = newDeploymentsV3(sdk.sdkConfiguration) -// sdk.BuildsV1 = newBuildsV1(sdk.sdkConfiguration) + sdk.BuildsV1 = newBuildsV1(sdk.sdkConfiguration) -// sdk.BuildsV2 = newBuildsV2(sdk.sdkConfiguration) + sdk.BuildsV2 = newBuildsV2(sdk.sdkConfiguration) -// sdk.BuildsV3 = newBuildsV3(sdk.sdkConfiguration) + sdk.BuildsV3 = newBuildsV3(sdk.sdkConfiguration) -// sdk.BillingV1 = newBillingV1(sdk.sdkConfiguration) + sdk.BillingV1 = newBillingV1(sdk.sdkConfiguration) -// sdk.AuthV1 = newAuthV1(sdk.sdkConfiguration) + sdk.AuthV1 = newAuthV1(sdk.sdkConfiguration) -// sdk.AppsV1 = newAppsV1(sdk.sdkConfiguration) + sdk.AppsV1 = newAppsV1(sdk.sdkConfiguration) -// sdk.AppsV2 = newAppsV2(sdk.sdkConfiguration) + sdk.AppsV2 = newAppsV2(sdk.sdkConfiguration) -// return sdk -// } + return sdk +} diff --git a/internal/sdk/sdk.go b/internal/sdk/sdk.go deleted file mode 100644 index c28d6a6..0000000 --- a/internal/sdk/sdk.go +++ /dev/null @@ -1,266 +0,0 @@ -package sdk - -// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. - - -import ( - "context" - "fmt" - "net/http" - "time" - - "github.com/hathora/ci/internal/sdk/internal/globals" - "github.com/hathora/ci/internal/sdk/internal/hooks" - "github.com/hathora/ci/internal/sdk/internal/utils" - "github.com/hathora/ci/internal/sdk/models/components" - "github.com/hathora/ci/internal/sdk/retry" -) - -// // ServerList contains the list of servers available to the SDK -// var ServerList = []string{ -// "https://api.hathora.dev", -// "https:///", -// } - -// // HTTPClient provides an interface for suplying the SDK with a custom HTTP client -// type HTTPClient interface { -// Do(req *http.Request) (*http.Response, error) -// } - -// // String provides a helper function to return a pointer to a string -// func String(s string) *string { return &s } - -// // Bool provides a helper function to return a pointer to a bool -// func Bool(b bool) *bool { return &b } - -// // Int provides a helper function to return a pointer to an int -// func Int(i int) *int { return &i } - -// // Int64 provides a helper function to return a pointer to an int64 -// func Int64(i int64) *int64 { return &i } - -// // Float32 provides a helper function to return a pointer to a float32 -// func Float32(f float32) *float32 { return &f } - -// // Float64 provides a helper function to return a pointer to a float64 -// func Float64(f float64) *float64 { return &f } - -// type sdkConfiguration struct { -// Client HTTPClient -// Security func(context.Context) (interface{}, error) -// ServerURL string -// ServerIndex int -// Language string -// OpenAPIDocVersion string -// SDKVersion string -// GenVersion string -// UserAgent string -// Globals globals.Globals -// RetryConfig *retry.Config -// Hooks *hooks.Hooks -// Timeout *time.Duration -// } - -// func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) { -// if c.ServerURL != "" { -// return c.ServerURL, nil -// } - -// return ServerList[c.ServerIndex], nil -// } - -// SDK - Hathora Cloud API: Welcome to the Hathora Cloud API documentation! Learn how to use the Hathora Cloud APIs to build and scale your game servers globally. -type SDK struct { - // - TokensV1 *TokensV1 - RoomsV1 *RoomsV1 - RoomsV2 *RoomsV2 - // Deprecated. Use [ProcessesV2](https://hathora.dev/api#tag/ProcessesV2). - ProcessesV1 *ProcessesV1 - // Operations to get data on active and stopped [processes](https://hathora.dev/docs/concepts/hathora-entities#process). - ProcessesV2 *ProcessesV2 - ProcessesV3 *ProcessesV3 - OrganizationsV1 *OrganizationsV1 - // Operations to get metrics by [process](https://hathora.dev/docs/concepts/hathora-entities#process). We store 72 hours of metrics data. - MetricsV1 *MetricsV1 - // - ManagementV1 *ManagementV1 - LogsV1 *LogsV1 - LobbiesV1 *LobbiesV1 - LobbiesV2 *LobbiesV2 - LobbiesV3 *LobbiesV3 - // Deprecated. Does not include latest Regions (missing Dallas region). Use [DiscoveryV2](https://hathora.dev/api#tag/DiscoveryV2). - DiscoveryV1 *DiscoveryV1 - // Service that allows clients to directly ping all Hathora regions to get latency information - DiscoveryV2 *DiscoveryV2 - DeploymentsV1 *DeploymentsV1 - DeploymentsV2 *DeploymentsV2 - DeploymentsV3 *DeploymentsV3 - BuildsV1 *BuildsV1 - BuildsV2 *BuildsV2 - BuildsV3 *BuildsV3 - // - BillingV1 *BillingV1 - // Operations that allow you to generate a Hathora-signed [JSON web token (JWT)](https://jwt.io/) for [player authentication](https://hathora.dev/docs/lobbies-and-matchmaking/auth-service). - AuthV1 *AuthV1 - AppsV1 *AppsV1 - AppsV2 *AppsV2 - - sdkConfiguration sdkConfiguration -} - -type SDKOption func(*SDK) - -// WithServerURL allows the overriding of the default server URL -func WithServerURL(serverURL string) SDKOption { - return func(sdk *SDK) { - sdk.sdkConfiguration.ServerURL = serverURL - } -} - -// WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters -func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption { - return func(sdk *SDK) { - if params != nil { - serverURL = utils.ReplaceParameters(serverURL, params) - } - - sdk.sdkConfiguration.ServerURL = serverURL - } -} - -// WithServerIndex allows the overriding of the default server by index -func WithServerIndex(serverIndex int) SDKOption { - return func(sdk *SDK) { - if serverIndex < 0 || serverIndex >= len(ServerList) { - panic(fmt.Errorf("server index %d out of range", serverIndex)) - } - - sdk.sdkConfiguration.ServerIndex = serverIndex - } -} - -// WithClient allows the overriding of the default HTTP client used by the SDK -func WithClient(client HTTPClient) SDKOption { - return func(sdk *SDK) { - sdk.sdkConfiguration.Client = client - } -} - -// WithSecurity configures the SDK to use the provided security details -func WithSecurity(security components.Security) SDKOption { - return func(sdk *SDK) { - sdk.sdkConfiguration.Security = utils.AsSecuritySource(security) - } -} - -// WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication -func WithSecuritySource(security func(context.Context) (components.Security, error)) SDKOption { - return func(sdk *SDK) { - sdk.sdkConfiguration.Security = func(ctx context.Context) (interface{}, error) { - return security(ctx) - } - } -} - -// WithAppID allows setting the AppID parameter for all supported operations -func WithAppID(appID string) SDKOption { - return func(sdk *SDK) { - sdk.sdkConfiguration.Globals.AppID = &appID - } -} - -func WithRetryConfig(retryConfig retry.Config) SDKOption { - return func(sdk *SDK) { - sdk.sdkConfiguration.RetryConfig = &retryConfig - } -} - -// WithTimeout Optional request timeout applied to each operation -func WithTimeout(timeout time.Duration) SDKOption { - return func(sdk *SDK) { - sdk.sdkConfiguration.Timeout = &timeout - } -} - -// New creates a new instance of the SDK with the provided options -func New(opts ...SDKOption) *SDK { - sdk := &SDK{ - sdkConfiguration: sdkConfiguration{ - Language: "go", - OpenAPIDocVersion: "0.0.1", - SDKVersion: "0.4.2", - GenVersion: "2.380.2", - UserAgent: "speakeasy-sdk/go 0.4.2 2.380.2 0.0.1 github.com/hathora/ci/internal/sdk", - Globals: globals.Globals{}, - Hooks: hooks.New(), - }, - } - for _, opt := range opts { - opt(sdk) - } - - // Use WithClient to override the default client if you would like to customize the timeout - if sdk.sdkConfiguration.Client == nil { - sdk.sdkConfiguration.Client = &http.Client{Timeout: 60 * time.Second} - } - - currentServerURL, _ := sdk.sdkConfiguration.GetServerDetails() - serverURL := currentServerURL - serverURL, sdk.sdkConfiguration.Client = sdk.sdkConfiguration.Hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client) - if serverURL != currentServerURL { - sdk.sdkConfiguration.ServerURL = serverURL - } - - sdk.TokensV1 = newTokensV1(sdk.sdkConfiguration) - - sdk.RoomsV1 = newRoomsV1(sdk.sdkConfiguration) - - sdk.RoomsV2 = newRoomsV2(sdk.sdkConfiguration) - - sdk.ProcessesV1 = newProcessesV1(sdk.sdkConfiguration) - - sdk.ProcessesV2 = newProcessesV2(sdk.sdkConfiguration) - - sdk.ProcessesV3 = newProcessesV3(sdk.sdkConfiguration) - - sdk.OrganizationsV1 = newOrganizationsV1(sdk.sdkConfiguration) - - sdk.MetricsV1 = newMetricsV1(sdk.sdkConfiguration) - - sdk.ManagementV1 = newManagementV1(sdk.sdkConfiguration) - - sdk.LogsV1 = newLogsV1(sdk.sdkConfiguration) - - sdk.LobbiesV1 = newLobbiesV1(sdk.sdkConfiguration) - - sdk.LobbiesV2 = newLobbiesV2(sdk.sdkConfiguration) - - sdk.LobbiesV3 = newLobbiesV3(sdk.sdkConfiguration) - - sdk.DiscoveryV1 = newDiscoveryV1(sdk.sdkConfiguration) - - sdk.DiscoveryV2 = newDiscoveryV2(sdk.sdkConfiguration) - - sdk.DeploymentsV1 = newDeploymentsV1(sdk.sdkConfiguration) - - sdk.DeploymentsV2 = newDeploymentsV2(sdk.sdkConfiguration) - - sdk.DeploymentsV3 = newDeploymentsV3(sdk.sdkConfiguration) - - sdk.BuildsV1 = newBuildsV1(sdk.sdkConfiguration) - - sdk.BuildsV2 = newBuildsV2(sdk.sdkConfiguration) - - sdk.BuildsV3 = newBuildsV3(sdk.sdkConfiguration) - - sdk.BillingV1 = newBillingV1(sdk.sdkConfiguration) - - sdk.AuthV1 = newAuthV1(sdk.sdkConfiguration) - - sdk.AppsV1 = newAppsV1(sdk.sdkConfiguration) - - sdk.AppsV2 = newAppsV2(sdk.sdkConfiguration) - - return sdk -} diff --git a/internal/setup/sdk.go b/internal/setup/sdk.go index 16d6958..0e234e8 100644 --- a/internal/setup/sdk.go +++ b/internal/setup/sdk.go @@ -2,16 +2,11 @@ package setup import ( "github.com/hathora/ci/internal/sdk" - "github.com/hathora/ci/internal/sdk/models/components" ) -func SDK(token, baseURL string, loggingVerbosity int) *sdk.SDK { +func SDK(token, baseURL string, loggingVerbosity int) *sdk.HathoraCloud { return sdk.New( - sdk.WithSecurity( - components.Security{ - HathoraDevToken: sdk.String(token), - }, - ), + sdk.WithSecurity(token), sdk.WithServerURL(baseURL), sdk.WithClient(HTTPClient(loggingVerbosity)), )