Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): api update #41

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 19
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nirvana-labs%2Fnirvana-6aab21baffe1788ef3489dedfb817e9425a87edc3955e0b9cf720cca4302d7a3.yml
configured_endpoints: 20
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nirvana-labs%2Fnirvana-2b25d79eca57a37c23952533aa8514885103b3c8af056890c68291262b0c5d5c.yml
5 changes: 5 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Params Types:
Response Types:

- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#CPU">CPU</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OsImage">OsImage</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#Ram">Ram</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#VM">VM</a>
- <a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#VMList">VMList</a>
Expand All @@ -32,6 +33,10 @@ Methods:

## OsImages

Methods:

- <code title="get /vms/os_images">client.VMs.OsImages.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OsImageService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) ([]<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms">vms</a>.<a href="https://pkg.go.dev/github.com/nirvana-labs/nirvana-go/vms#OsImage">OsImage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

# VPCs

Response Types:
Expand Down
12 changes: 12 additions & 0 deletions vms/osimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
package vms

import (
"context"
"net/http"

"github.com/nirvana-labs/nirvana-go/internal/requestconfig"
"github.com/nirvana-labs/nirvana-go/option"
)

Expand All @@ -24,3 +28,11 @@ func NewOsImageService(opts ...option.RequestOption) (r *OsImageService) {
r.Options = opts
return
}

// List all OS Images
func (r *OsImageService) List(ctx context.Context, opts ...option.RequestOption) (res *[]OsImage, err error) {
opts = append(r.Options[:], opts...)
path := "vms/os_images"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
36 changes: 36 additions & 0 deletions vms/osimage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package vms_test

import (
"context"
"errors"
"os"
"testing"

"github.com/nirvana-labs/nirvana-go"
"github.com/nirvana-labs/nirvana-go/internal/testutil"
"github.com/nirvana-labs/nirvana-go/option"
)

func TestOsImageList(t *testing.T) {
baseURL := "http://localhost:4010"
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
baseURL = envURL
}
if !testutil.CheckTestServer(t, baseURL) {
return
}
client := nirvana.NewClient(
option.WithBaseURL(baseURL),
option.WithAuthToken("My Auth Token"),
)
_, err := client.VMs.OsImages.List(context.TODO())
if err != nil {
var apierr *nirvana.Error
if errors.As(err, &apierr) {
t.Log(string(apierr.DumpRequest(true)))
}
t.Fatalf("err should be nil: %s", err.Error())
}
}
24 changes: 24 additions & 0 deletions vms/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@ func (r CPUParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type OsImage struct {
CreatedAt string `json:"created_at,required"`
DisplayName string `json:"display_name,required"`
Name string `json:"name,required"`
JSON osImageJSON `json:"-"`
}

// osImageJSON contains the JSON metadata for the struct [OsImage]
type osImageJSON struct {
CreatedAt apijson.Field
DisplayName apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *OsImage) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r osImageJSON) RawJSON() string {
return r.raw
}

// RAM details.
type Ram struct {
// RAM size
Expand Down