Skip to content

Latest commit

 

History

History
431 lines (326 loc) · 23.3 KB

File metadata and controls

431 lines (326 loc) · 23.3 KB

Images

Overview

Custom machine images for instances.

Available Operations

List

List all images owned by the authenticated user.

Example Usage

package main

import(
	"context"
	sfc "github.com/sfcompute/sfc-go"
	"github.com/sfcompute/sfc-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := sfc.New(
        sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

    res, err := s.Images.List(ctx, operations.ListImagesRequest{
        Workspace: "wksp_k3R-nX9vLm7Qp2Yw5Jd8F",
        ID: []string{
            "image_k3R-nX9vLm7Qp2Yw5Jd8F",
        },
        StartingAfter: sfc.Pointer("imagec_gqXR7s0Kj5mHvE2wNpLc4Q"),
        EndingBefore: sfc.Pointer("imagec_gqXR7s0Kj5mHvE2wNpLc4Q"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.ListImagesResponse != 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 ✔️ The context to use for the request.
request operations.ListImagesRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.ListImagesResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestError 400 application/json
apierrors.UnauthorizedError 401 application/json
apierrors.InternalServerError 500 application/json
apierrors.APIError 4XX, 5XX */*

StartUpload

Create an image and start a multipart upload.

Example Usage

package main

import(
	"context"
	sfc "github.com/sfcompute/sfc-go"
	"github.com/sfcompute/sfc-go/optionalnullable"
	"github.com/sfcompute/sfc-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := sfc.New(
        sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

    res, err := s.Images.StartUpload(ctx, components.StartUploadRequest{
        Name: optionalnullable.From(sfc.Pointer("my-resource-name")),
        Workspace: "wksp_k3R-nX9vLm7Qp2Yw5Jd8F",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.ImageUploadResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.StartUploadRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CreateImageResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestError 400 application/json
apierrors.UnauthorizedError 401 application/json
apierrors.ConflictError 409 application/json
apierrors.InternalServerError 500 application/json
apierrors.APIError 4XX, 5XX */*

Fetch

Retrieve an image by ID. Returns both user-owned and public images.

Example Usage

package main

import(
	"context"
	sfc "github.com/sfcompute/sfc-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := sfc.New(
        sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

    res, err := s.Images.Fetch(ctx, "image_k3R-nX9vLm7Qp2Yw5Jd8F")
    if err != nil {
        log.Fatal(err)
    }
    if res.ImageListEntry != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
id string ✔️ Image ID or resource path image_k3R-nX9vLm7Qp2Yw5Jd8F
opts []operations.Option The options for this request.

Response

*operations.FetchImageResponse, error

Errors

Error Type Status Code Content Type
apierrors.UnauthorizedError 401 application/json
apierrors.NotFoundError 404 application/json
apierrors.InternalServerError 500 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Delete an image.

Example Usage

package main

import(
	"context"
	sfc "github.com/sfcompute/sfc-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := sfc.New(
        sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

    res, err := s.Images.Delete(ctx, "image_k3R-nX9vLm7Qp2Yw5Jd8F")
    if err != nil {
        log.Fatal(err)
    }
    if res.DeleteImageResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
id string ✔️ Image ID, name, or resource path image_k3R-nX9vLm7Qp2Yw5Jd8F
opts []operations.Option The options for this request.

Response

*operations.DeleteImageResponse, error

Errors

Error Type Status Code Content Type
apierrors.UnauthorizedError 401 application/json
apierrors.NotFoundError 404 application/json
apierrors.ConflictError 409 application/json
apierrors.InternalServerError 500 application/json
apierrors.APIError 4XX, 5XX */*

CompleteUpload

Finalize a multipart image upload.

Example Usage

package main

import(
	"context"
	sfc "github.com/sfcompute/sfc-go"
	"github.com/sfcompute/sfc-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := sfc.New(
        sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

    res, err := s.Images.CompleteUpload(ctx, "image_k3R-nX9vLm7Qp2Yw5Jd8F", components.CompleteUploadRequest{
        Sha256: "<value>",
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.ImageUploadResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
id string ✔️ Image ID, name, or resource path image_k3R-nX9vLm7Qp2Yw5Jd8F
body components.CompleteUploadRequest ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.CompleteImageUploadResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestError 400 application/json
apierrors.UnauthorizedError 401 application/json
apierrors.NotFoundError 404 application/json
apierrors.InternalServerError 500 application/json
apierrors.APIError 4XX, 5XX */*

Download

Get a presigned URL to download an image.

Example Usage

package main

import(
	"context"
	sfc "github.com/sfcompute/sfc-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := sfc.New(
        sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

    res, err := s.Images.Download(ctx, "image_k3R-nX9vLm7Qp2Yw5Jd8F")
    if err != nil {
        log.Fatal(err)
    }
    if res.ImageDownloadResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
id string ✔️ Image ID, name, or resource path image_k3R-nX9vLm7Qp2Yw5Jd8F
opts []operations.Option The options for this request.

Response

*operations.DownloadImageResponse, error

Errors

Error Type Status Code Content Type
apierrors.UnauthorizedError 401 application/json
apierrors.NotFoundError 404 application/json
apierrors.ConflictError 409 application/json
apierrors.InternalServerError 500 application/json
apierrors.APIError 4XX, 5XX */*

UploadPart

Get a presigned URL to upload one part of a multipart image upload.

Example Usage

package main

import(
	"context"
	sfc "github.com/sfcompute/sfc-go"
	"github.com/sfcompute/sfc-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := sfc.New(
        sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
    )

    res, err := s.Images.UploadPart(ctx, "image_k3R-nX9vLm7Qp2Yw5Jd8F", components.UploadPartRequest{
        PartID: 797058,
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.UploadPartResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
id string ✔️ Image ID, name, or resource path image_k3R-nX9vLm7Qp2Yw5Jd8F
body components.UploadPartRequest ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.CreateImageUploadPartURLResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestError 400 application/json
apierrors.UnauthorizedError 401 application/json
apierrors.NotFoundError 404 application/json
apierrors.InternalServerError 500 application/json
apierrors.APIError 4XX, 5XX */*