Skip to content

Commit

Permalink
feat(api): api update (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jan 27, 2025
1 parent 41770b7 commit 65af2e1
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 191 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func main() {
client := nirvana.NewClient(
option.WithAuthToken("My Auth Token"), // defaults to os.LookupEnv("NIRVANA_LABS_AUTH_TOKEN")
)
operation, err := client.Compute.VMs.New(context.TODO(), vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
operation, err := client.Compute.VMs.New(context.TODO(), vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -193,8 +193,8 @@ When the API returns a non-success status code, we return an error with type
To handle errors, we recommend that you use the `errors.As` pattern:

```go
_, err := client.Compute.VMs.New(context.TODO(), vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
_, err := client.Compute.VMs.New(context.TODO(), vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -239,8 +239,8 @@ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
client.Compute.VMs.New(
ctx,
vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -294,8 +294,8 @@ client := nirvana.NewClient(
// Override per-request:
client.Compute.VMs.New(
context.TODO(),
vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down
40 changes: 20 additions & 20 deletions api.md

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"net/http"
"os"

"github.com/nirvana-labs/nirvana-go/compute"
"github.com/nirvana-labs/nirvana-go/internal/requestconfig"
"github.com/nirvana-labs/nirvana-go/networking"
"github.com/nirvana-labs/nirvana-go/operations"
"github.com/nirvana-labs/nirvana-go/option"
)
Expand All @@ -18,8 +20,8 @@ import (
type Client struct {
Options []option.RequestOption
Operations *operations.OperationService
Compute *ComputeService
Networking *NetworkingService
Compute *compute.ComputeService
Networking *networking.NetworkingService
}

// NewClient generates a new client with the default option read from the
Expand All @@ -36,8 +38,8 @@ func NewClient(opts ...option.RequestOption) (r *Client) {
r = &Client{Options: opts}

r.Operations = operations.NewOperationService(opts...)
r.Compute = NewComputeService(opts...)
r.Networking = NewNetworkingService(opts...)
r.Compute = compute.NewComputeService(opts...)
r.Networking = networking.NewNetworkingService(opts...)

return
}
Expand Down
32 changes: 16 additions & 16 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestUserAgentHeader(t *testing.T) {
},
}),
)
client.Compute.VMs.New(context.Background(), vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
client.Compute.VMs.New(context.Background(), vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -81,8 +81,8 @@ func TestRetryAfter(t *testing.T) {
},
}),
)
res, err := client.Compute.VMs.New(context.Background(), vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
res, err := client.Compute.VMs.New(context.Background(), vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -134,8 +134,8 @@ func TestDeleteRetryCountHeader(t *testing.T) {
}),
option.WithHeaderDel("X-Stainless-Retry-Count"),
)
res, err := client.Compute.VMs.New(context.Background(), vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
res, err := client.Compute.VMs.New(context.Background(), vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -182,8 +182,8 @@ func TestOverwriteRetryCountHeader(t *testing.T) {
}),
option.WithHeader("X-Stainless-Retry-Count", "42"),
)
res, err := client.Compute.VMs.New(context.Background(), vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
res, err := client.Compute.VMs.New(context.Background(), vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -229,8 +229,8 @@ func TestRetryAfterMs(t *testing.T) {
},
}),
)
res, err := client.Compute.VMs.New(context.Background(), vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
res, err := client.Compute.VMs.New(context.Background(), vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -270,8 +270,8 @@ func TestContextCancel(t *testing.T) {
)
cancelCtx, cancel := context.WithCancel(context.Background())
cancel()
res, err := client.Compute.VMs.New(cancelCtx, vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
res, err := client.Compute.VMs.New(cancelCtx, vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -308,8 +308,8 @@ func TestContextCancelDelay(t *testing.T) {
)
cancelCtx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond)
defer cancel()
res, err := client.Compute.VMs.New(cancelCtx, vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
res, err := client.Compute.VMs.New(cancelCtx, vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down Expand Up @@ -352,8 +352,8 @@ func TestContextDeadline(t *testing.T) {
},
}),
)
res, err := client.Compute.VMs.New(deadlineCtx, vms.ComputeVMNewParams{
BootVolume: nirvana.F(vms.ComputeVMNewParamsBootVolume{
res, err := client.Compute.VMs.New(deadlineCtx, vms.VMNewParams{
BootVolume: nirvana.F(vms.VMNewParamsBootVolume{
Size: nirvana.F(int64(100)),
}),
CPU: nirvana.F(vms.CPUParam{
Expand Down
79 changes: 79 additions & 0 deletions compute/aliases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package compute

import (
"github.com/nirvana-labs/nirvana-go/internal/apierror"
"github.com/nirvana-labs/nirvana-go/shared"
)

type Error = apierror.Error

// This is an alias to an internal type.
type RegionName = shared.RegionName

// This is an alias to an internal value.
const RegionNameAmsterdam = shared.RegionNameAmsterdam

// This is an alias to an internal value.
const RegionNameChicago = shared.RegionNameChicago

// This is an alias to an internal value.
const RegionNameFrankfurt = shared.RegionNameFrankfurt

// This is an alias to an internal value.
const RegionNameHongkong = shared.RegionNameHongkong

// This is an alias to an internal value.
const RegionNameLondon = shared.RegionNameLondon

// This is an alias to an internal value.
const RegionNameMumbai = shared.RegionNameMumbai

// This is an alias to an internal value.
const RegionNameSaopaulo = shared.RegionNameSaopaulo

// This is an alias to an internal value.
const RegionNameSeattle = shared.RegionNameSeattle

// This is an alias to an internal value.
const RegionNameSiliconvalley = shared.RegionNameSiliconvalley

// This is an alias to an internal value.
const RegionNameSingapore = shared.RegionNameSingapore

// This is an alias to an internal value.
const RegionNameStockholm = shared.RegionNameStockholm

// This is an alias to an internal value.
const RegionNameSydney = shared.RegionNameSydney

// This is an alias to an internal value.
const RegionNameTokyo = shared.RegionNameTokyo

// This is an alias to an internal value.
const RegionNameWashingtondc = shared.RegionNameWashingtondc

// This is an alias to an internal type.
type ResourceStatus = shared.ResourceStatus

// This is an alias to an internal value.
const ResourceStatusPending = shared.ResourceStatusPending

// This is an alias to an internal value.
const ResourceStatusCreating = shared.ResourceStatusCreating

// This is an alias to an internal value.
const ResourceStatusUpdating = shared.ResourceStatusUpdating

// This is an alias to an internal value.
const ResourceStatusReady = shared.ResourceStatusReady

// This is an alias to an internal value.
const ResourceStatusDeleting = shared.ResourceStatusDeleting

// This is an alias to an internal value.
const ResourceStatusDeleted = shared.ResourceStatusDeleted

// This is an alias to an internal value.
const ResourceStatusFailed = shared.ResourceStatusFailed
10 changes: 5 additions & 5 deletions compute.go → compute/compute.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package nirvana
package compute

import (
"github.com/nirvana-labs/nirvana-go/option"
Expand All @@ -14,8 +14,8 @@ import (
// the [NewComputeService] method instead.
type ComputeService struct {
Options []option.RequestOption
VMs *ComputeVMService
Volumes *ComputeVolumeService
VMs *VMService

Check failure on line 17 in compute/compute.go

View workflow job for this annotation

GitHub Actions / lint

undefined: VMService

Check failure on line 17 in compute/compute.go

View workflow job for this annotation

GitHub Actions / test

undefined: VMService
Volumes *VolumeService

Check failure on line 18 in compute/compute.go

View workflow job for this annotation

GitHub Actions / lint

undefined: VolumeService

Check failure on line 18 in compute/compute.go

View workflow job for this annotation

GitHub Actions / test

undefined: VolumeService
}

// NewComputeService generates a new service that applies the given options to each
Expand All @@ -24,7 +24,7 @@ type ComputeService struct {
func NewComputeService(opts ...option.RequestOption) (r *ComputeService) {
r = &ComputeService{}
r.Options = opts
r.VMs = NewComputeVMService(opts...)
r.Volumes = NewComputeVolumeService(opts...)
r.VMs = NewVMService(opts...)

Check failure on line 27 in compute/compute.go

View workflow job for this annotation

GitHub Actions / lint

undefined: NewVMService

Check failure on line 27 in compute/compute.go

View workflow job for this annotation

GitHub Actions / test

undefined: NewVMService
r.Volumes = NewVolumeService(opts...)

Check failure on line 28 in compute/compute.go

View workflow job for this annotation

GitHub Actions / lint

undefined: NewVolumeService

Check failure on line 28 in compute/compute.go

View workflow job for this annotation

GitHub Actions / test

undefined: NewVolumeService
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ import (
"github.com/nirvana-labs/nirvana-go/shared"
)

// NetworkingFirewallRuleService contains methods and other services that help with
// FirewallRuleService contains methods and other services that help with
// interacting with the Nirvana Labs API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewNetworkingFirewallRuleService] method instead.
type NetworkingFirewallRuleService struct {
// the [NewFirewallRuleService] method instead.
type FirewallRuleService struct {
Options []option.RequestOption
}

// NewNetworkingFirewallRuleService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewNetworkingFirewallRuleService(opts ...option.RequestOption) (r *NetworkingFirewallRuleService) {
r = &NetworkingFirewallRuleService{}
// NewFirewallRuleService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewFirewallRuleService(opts ...option.RequestOption) (r *FirewallRuleService) {
r = &FirewallRuleService{}
r.Options = opts
return
}

// Create a firewall rule
func (r *NetworkingFirewallRuleService) New(ctx context.Context, vpcID string, body NetworkingFirewallRuleNewParams, opts ...option.RequestOption) (res *operations.Operation, err error) {
func (r *FirewallRuleService) New(ctx context.Context, vpcID string, body FirewallRuleNewParams, opts ...option.RequestOption) (res *operations.Operation, err error) {
opts = append(r.Options[:], opts...)
if vpcID == "" {
err = errors.New("missing required vpc_id parameter")
Expand All @@ -48,7 +48,7 @@ func (r *NetworkingFirewallRuleService) New(ctx context.Context, vpcID string, b
}

// Update a firewall rule
func (r *NetworkingFirewallRuleService) Update(ctx context.Context, vpcID string, firewallRuleID string, body NetworkingFirewallRuleUpdateParams, opts ...option.RequestOption) (res *operations.Operation, err error) {
func (r *FirewallRuleService) Update(ctx context.Context, vpcID string, firewallRuleID string, body FirewallRuleUpdateParams, opts ...option.RequestOption) (res *operations.Operation, err error) {
opts = append(r.Options[:], opts...)
if vpcID == "" {
err = errors.New("missing required vpc_id parameter")
Expand All @@ -64,7 +64,7 @@ func (r *NetworkingFirewallRuleService) Update(ctx context.Context, vpcID string
}

// List all firewall rules
func (r *NetworkingFirewallRuleService) List(ctx context.Context, vpcID string, opts ...option.RequestOption) (res *FirewallRuleList, err error) {
func (r *FirewallRuleService) List(ctx context.Context, vpcID string, opts ...option.RequestOption) (res *FirewallRuleList, err error) {
opts = append(r.Options[:], opts...)
if vpcID == "" {
err = errors.New("missing required vpc_id parameter")
Expand All @@ -76,7 +76,7 @@ func (r *NetworkingFirewallRuleService) List(ctx context.Context, vpcID string,
}

// Delete a firewall rule
func (r *NetworkingFirewallRuleService) Delete(ctx context.Context, vpcID string, firewallRuleID string, opts ...option.RequestOption) (res *operations.Operation, err error) {
func (r *FirewallRuleService) Delete(ctx context.Context, vpcID string, firewallRuleID string, opts ...option.RequestOption) (res *operations.Operation, err error) {
opts = append(r.Options[:], opts...)
if vpcID == "" {
err = errors.New("missing required vpc_id parameter")
Expand All @@ -92,7 +92,7 @@ func (r *NetworkingFirewallRuleService) Delete(ctx context.Context, vpcID string
}

// Get details about a firewall rule
func (r *NetworkingFirewallRuleService) Get(ctx context.Context, vpcID string, firewallRuleID string, opts ...option.RequestOption) (res *FirewallRule, err error) {
func (r *FirewallRuleService) Get(ctx context.Context, vpcID string, firewallRuleID string, opts ...option.RequestOption) (res *FirewallRule, err error) {
opts = append(r.Options[:], opts...)
if vpcID == "" {
err = errors.New("missing required vpc_id parameter")
Expand Down Expand Up @@ -201,7 +201,7 @@ func (r firewallRuleListJSON) RawJSON() string {
return r.raw
}

type NetworkingFirewallRuleNewParams struct {
type FirewallRuleNewParams struct {
// Firewall rule endpoint.
Destination param.Field[FirewallRuleEndpointParam] `json:"destination,required"`
Name param.Field[string] `json:"name,required"`
Expand All @@ -211,35 +211,35 @@ type NetworkingFirewallRuleNewParams struct {
Source param.Field[FirewallRuleEndpointParam] `json:"source,required"`
}

func (r NetworkingFirewallRuleNewParams) MarshalJSON() (data []byte, err error) {
func (r FirewallRuleNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type NetworkingFirewallRuleUpdateParams struct {
type FirewallRuleUpdateParams struct {
// Firewall rule endpoint.
Destination param.Field[FirewallRuleEndpointParam] `json:"destination,required"`
Name param.Field[string] `json:"name,required"`
// Supported protocols.
Protocol param.Field[NetworkingFirewallRuleUpdateParamsProtocol] `json:"protocol,required"`
Protocol param.Field[FirewallRuleUpdateParamsProtocol] `json:"protocol,required"`
// Firewall rule endpoint.
Source param.Field[FirewallRuleEndpointParam] `json:"source,required"`
}

func (r NetworkingFirewallRuleUpdateParams) MarshalJSON() (data []byte, err error) {
func (r FirewallRuleUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// Supported protocols.
type NetworkingFirewallRuleUpdateParamsProtocol string
type FirewallRuleUpdateParamsProtocol string

const (
NetworkingFirewallRuleUpdateParamsProtocolTcp NetworkingFirewallRuleUpdateParamsProtocol = "tcp"
NetworkingFirewallRuleUpdateParamsProtocolUdp NetworkingFirewallRuleUpdateParamsProtocol = "udp"
FirewallRuleUpdateParamsProtocolTcp FirewallRuleUpdateParamsProtocol = "tcp"
FirewallRuleUpdateParamsProtocolUdp FirewallRuleUpdateParamsProtocol = "udp"
)

func (r NetworkingFirewallRuleUpdateParamsProtocol) IsKnown() bool {
func (r FirewallRuleUpdateParamsProtocol) IsKnown() bool {
switch r {
case NetworkingFirewallRuleUpdateParamsProtocolTcp, NetworkingFirewallRuleUpdateParamsProtocolUdp:
case FirewallRuleUpdateParamsProtocolTcp, FirewallRuleUpdateParamsProtocolUdp:
return true
}
return false
Expand Down
Loading

0 comments on commit 65af2e1

Please sign in to comment.