cloudhsm

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

cloudhsm-api-go

Go Reference Tests Go Report Card

さくらのクラウド「クラウドHSM」APIのGoクライアントライブラリ

概要

このライブラリは、さくらのクラウド「クラウドHSM」APIをGo言語から利用するためのクライアントです。 OpenAPI仕様から自動生成された型安全なAPIクライアントと、それをラップして使い勝手を向上させたクライアントを提供します。

[!WARNING] v1.0に達するまでは互換性のない形で変更される可能性がありますのでご注意ください。

インストール

go get github.com/sacloud/cloudhsm-api-go

使い方

事前準備

SDKを利用開始するにはさくらのクラウド「クラウドHSM」自体を利用開始する必要があります。執筆時点ではさくらのクラウドの利用申請とは別途クラウドHSMの利用申請も必要です。申請手順の詳細に関してはクラウドHSMマニュアルをご参照ください。

認証情報

APIを実行するには認証が必要です。インタラクティブな環境の場合おすすめは usacloud を使って設定ファイルを作成することです。たとえば

usacloud config create --name is1a

にて作成したプロファイル is1a があるとすると、SDKとしては、

import (
    cloudhsm "github.com/sacloud/cloudhsm-api-go"
    client "github.com/sacloud/api-client-go"
)

func main() {
    client, err := cloudhsm.NewClient(client.WithProfile("is1a"))

    // 以下略
}

のようにして読み込むことができます。

一方でCI環境のようにファイルに書き出すのが適切ではない場合、環境変数経由で

import (
    "os"

    cloudhsm "github.com/sacloud/cloudhsm-api-go"
    client "github.com/sacloud/api-client-go"
)

func main() {
    client, err := cloudhsm.NewClient(client.WithApiKeys(
        os.Getenv("SAKURACLOUD_ACCESS_TOKEN"),
        os.Getenv("SAKURACLOUD_ACCESS_TOKEN_SECRET"),
    ))

    // 以下略
}

のように指定できます。

SDK
package main

import (
    "context"

    cloudhsm "github.com/sacloud/cloudhsm-api-go"
)

func main() {
    ctx := context.Background()
    client, err := cloudhsm.NewClient()
    if err != nil {
        // エラーハンドリング
    }

    // 例: ライセンス一覧取得
    licenses, err := cloudhsm.NewLicenseOp(client).List(ctx)
    if err != nil {
        // エラーハンドリング
    }
}

APIの詳細はGoDocapis/v1/配下の型定義を参照してください。

OpenAPI仕様について

openapi/openapi.jsonKMS/SecretManager/CloudHSM APIからダウンロードしたものを一部加工しています。

開発

ビルドやテストはMakefile経由で実行できます。

make
make test

ライセンス

Copyright (C) 2022-2025 The sacloud/cloudhsm-api-go Authors. このプロジェクトはApache 2.0 Licenseの下で公開されています。

Documentation

Index

Constants

View Source
const (
	// DefaultAPIRootURL デフォルトのAPIルートURL
	DefaultAPIRootURL = "https://secure.sakura.ad.jp/cloud/zone/is1b/api/cloud/1.1/"
)
View Source
const Version = "0.2.0"

Variables

View Source
var (
	// UserAgent APIリクエスト時のユーザーエージェント
	UserAgent = fmt.Sprintf(
		"cloudhsm-api-go/%s (%s/%s; +https://github.com/sacloud/cloudhsm-api-go) %s",
		Version,
		runtime.GOOS,
		runtime.GOARCH,
		client.DefaultUserAgent,
	)

	RequestCustomizers = []saht.RequestCustomizer{
		func(req *http.Request) error {
			req.Header.Set("X-Sakura-Bigint-As-Int", "1")
			return nil
		},
	}
)

Functions

func NewClient

func NewClient(params ...client.ClientParam) (*v1.Client, error)

func NewClientWithApiUrl

func NewClientWithApiUrl(apiUrl string, params ...client.ClientParam) (*v1.Client, error)

func NewClientWithApiUrlAndClient

func NewClientWithApiUrlAndClient(apiUrl string, apiClient *http.Client, params ...client.ClientParam) (*v1.Client, error)

func WithZone added in v0.2.0

func WithZone(z string) client.ClientParam

Types

type ClientAPI

type ClientAPI interface {
	List(ctx context.Context) ([]v1.CloudHSMClient, error)
	Create(ctx context.Context, request CloudHSMClientCreateParams) (*v1.CloudHSMClient, error)
	Read(ctx context.Context, id string) (*v1.CloudHSMClient, error)
	Update(ctx context.Context, id string, params CloudHSMClientUpdateParams) (*v1.CloudHSMClient, error)
	Delete(ctx context.Context, id string) error
}

func NewClientOp

func NewClientOp(client *v1.Client, hsm *v1.CloudHSM) (ClientAPI, error)

type ClientOp

type ClientOp struct {
	// contains filtered or unexported fields
}

func (*ClientOp) Create

func (*ClientOp) Delete

func (op *ClientOp) Delete(ctx context.Context, id string) error

func (*ClientOp) List

func (op *ClientOp) List(ctx context.Context) ([]v1.CloudHSMClient, error)

func (*ClientOp) Read

func (op *ClientOp) Read(ctx context.Context, id string) (*v1.CloudHSMClient, error)

func (*ClientOp) Update

type CloudHSMAPI

type CloudHSMAPI interface {
	List(ctx context.Context) ([]v1.CloudHSM, error)
	Create(ctx context.Context, request CloudHSMCreateParams) (*v1.CreateCloudHSM, error)
	Read(ctx context.Context, id string) (*v1.CloudHSM, error)
	Update(ctx context.Context, id string, params CloudHSMUpdateParams) (*v1.CloudHSM, error)
	Delete(ctx context.Context, id string) error
}

func NewCloudHSMOp

func NewCloudHSMOp(client *v1.Client) CloudHSMAPI

type CloudHSMClientCreateParams

type CloudHSMClientCreateParams struct {
	Name        string
	Certificate string
}

type CloudHSMClientUpdateParams

type CloudHSMClientUpdateParams struct {
	Name string
}

type CloudHSMCreateParams

type CloudHSMCreateParams struct {
	Name               string
	Description        *string
	Tags               []string
	Ipv4NetworkAddress string
	Ipv4PrefixLength   int
}

type CloudHSMOp

type CloudHSMOp struct {
	// contains filtered or unexported fields
}

func (*CloudHSMOp) Create

func (*CloudHSMOp) Delete

func (op *CloudHSMOp) Delete(ctx context.Context, id string) error

func (*CloudHSMOp) List

func (op *CloudHSMOp) List(ctx context.Context) ([]v1.CloudHSM, error)

func (*CloudHSMOp) Read

func (op *CloudHSMOp) Read(ctx context.Context, id string) (*v1.CloudHSM, error)

func (*CloudHSMOp) Update

type CloudHSMPeerCreateParams

type CloudHSMPeerCreateParams struct {
	RouterID  string
	SecretKey string
}

type CloudHSMSoftwareLicenseCreateParams

type CloudHSMSoftwareLicenseCreateParams struct {
	Name        string
	Description *string
	Tags        []string
}

type CloudHSMSoftwareLicenseUpdateParams

type CloudHSMSoftwareLicenseUpdateParams struct {
	Name        string
	Description string
	Tags        []string
}

type CloudHSMUpdateParams

type CloudHSMUpdateParams struct {
	Name               string
	Description        *string
	Tags               []string
	Ipv4NetworkAddress string
	Ipv4PrefixLength   int
}

type EmptySecuritySource

type EmptySecuritySource struct{}

func (EmptySecuritySource) BasicAuth

func (this EmptySecuritySource) BasicAuth(ctx context.Context, operationName v1.OperationName) (v1.BasicAuth, error)

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewAPIError

func NewAPIError(method string, code int, err error) *Error

func NewError

func NewError(msg string, err error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type LicenseOp

type LicenseOp struct {
	// contains filtered or unexported fields
}

func (*LicenseOp) Delete

func (op *LicenseOp) Delete(ctx context.Context, id string) error

func (*LicenseOp) List

func (*LicenseOp) Read

type PeerAPI

type PeerAPI interface {
	List(ctx context.Context) ([]v1.CloudHSMPeer, error)
	Create(ctx context.Context, request CloudHSMPeerCreateParams) error
	Delete(ctx context.Context, id string) error
}

func NewPeerOp

func NewPeerOp(client *v1.Client, hsm *v1.CloudHSM) (PeerAPI, error)

type PeerOp

type PeerOp struct {
	// contains filtered or unexported fields
}

func (*PeerOp) Create

func (*PeerOp) Delete

func (op *PeerOp) Delete(ctx context.Context, id string) error

func (*PeerOp) List

func (op *PeerOp) List(ctx context.Context) ([]v1.CloudHSMPeer, error)

Directories

Path Synopsis
apis
v1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL