webaccel

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 10

README

webaccel-api-go

Go Reference Tests Go Report Card

ウェブアクセラレータAPI をGo言語から扱うためのライブラリ

Overview

従来はiaas-api-go(libsacloud v2)で提供していたAPIライブラリを独立したリポジトリとして切り出したものです。

⚠ webaccel-api-goは現在開発中です。

webaccel-api-goを利用したクライアントコードの例
package example

import (
	"context"
	"log"

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

func Example() {
	// デフォルトではusacloudプロファイルや環境変数が利用される。
	// パラメータを指定することで上書きしたり無効化したりできる
	client := &webaccel.Client{
		//Profile:           "default",
		//AccessToken:       "token",
		//AccessTokenSecret: "secret",
		//DisableProfile:    false,
		//DisableEnv:        false,
	}
	op := webaccel.NewOp(client)

	// サイト一覧
	found, err := op.List(context.Background())
	if err != nil {
		panic(err)
	}
	log.Println(found)

	// 全キャッシュ削除
	deleteAllCacheRequest := &webaccel.DeleteAllCacheRequest{
		Domain: "example.com",
	}
	if err := op.DeleteAllCache(context.Background(), deleteAllCacheRequest); err != nil {
		panic(err)
	}

	// URLごとにキャッシュ削除
	deleteCacheRequest := &webaccel.DeleteCacheRequest{
		URL: []string{
			"https://example.com/url1",
			"https://example.com/url2",
		},
	}
	if _, err := op.DeleteCache(context.Background(), deleteCacheRequest); err != nil {
		panic(err)
	}
}

Installation

Use go get.

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

Then import the webaccel package into your own code.

import "github.com/sacloud/webaccel-api-go"

License

webaccel-api-go Copyright 2022 The webaccel-api-go authors.

This project is published under Apache 2.0 License.

Documentation

Index

Constants

View Source
const (
	OriginTypesWebServer     = "0" // ウェブサーバ
	OriginTypesObjectStorage = "1" // オブジェクトストレージ
)

OriginType

View Source
const (
	RequestProtocolsHttpAndHttps    = "0" // http/https
	RequestProtocolsHttpsOnly       = "1" // httpsのみ
	RequestProtocolsRedirectToHttps = "2" // httpsに」リダイレクト
)

RequestProtocol

View Source
const (
	OriginProtocolsHttp  = "http"
	OriginProtocolsHttps = "https"
)

OriginProtocol

View Source
const (
	VarySupportDisabled = "0" // 無効
	VarySupportEnabled  = "1" // 有効
)

VarySupport

View Source
const (
	DocIndexDisabled = "0" // 無効
	DocIndexEnabled  = "1" // 有効
)

DocIndex

View Source
const DefaultAPIRootURL = "https://secure.sakura.ad.jp/cloud/zone/is1a/api/webaccel/1.0/"

DefaultAPIRootURL デフォルトのAPIルートURL

Variables

View Source
var UserAgent = fmt.Sprintf(
	"webaccel-api-go/v%s (%s/%s; +https://github.com/sacloud/webaccel-api-go) %s",
	Version,
	runtime.GOOS,
	runtime.GOARCH,
	client.DefaultUserAgent,
)

UserAgent APIリクエスト時のユーザーエージェント

View Source
var (
	// Version app version
	Version = "1.1.0"
)

Functions

This section is empty.

Types

type API

type API interface {
	List(ctx context.Context) (*ListSitesResult, error)
	Read(ctx context.Context, id string) (*Site, error)
	Update(ctx context.Context, id string, param *UpdateSiteRequest) (*Site, error)
	ReadCertificate(ctx context.Context, id string) (*Certificates, error)
	CreateCertificate(ctx context.Context, id string, param *CreateOrUpdateCertificateRequest) (*Certificates, error)
	UpdateCertificate(ctx context.Context, id string, param *CreateOrUpdateCertificateRequest) (*Certificates, error)
	DeleteCertificate(ctx context.Context, id string) error
	DeleteAllCache(ctx context.Context, param *DeleteAllCacheRequest) error
	DeleteCache(ctx context.Context, param *DeleteCacheRequest) ([]*DeleteCacheResult, error)
	MonthlyUsage(ctx context.Context, targetYM string) (*MonthlyUsageResults, error)
}

API is interface for operate WebAccel resource

func NewOp

func NewOp(caller APICaller) API

NewOp creates new Op instance

type APICaller

type APICaller interface {
	Do(ctx context.Context, method, uri string, body interface{}) ([]byte, error)
	RootURL() string
}

type APIError

type APIError interface {
	// errorインターフェースを内包
	error

	// ResponseCode エラー発生時のレスポンスコード
	ResponseCode() int

	// Code エラーコード
	Code() string

	// Message エラー発生時のメッセージ
	Message() string

	// Serial エラー追跡用シリアルコード
	Serial() string

	// OriginalError エラー(オリジナル)
	OriginalError() *APIErrorResponse
}

APIError APIコール時のエラー情報

func NewAPIError

func NewAPIError(requestMethod string, requestURL *url.URL, responseCode int, err *APIErrorResponse) APIError

NewAPIError APIコール時のエラー情報

type APIErrorResponse

type APIErrorResponse struct {
	IsFatal      bool   `json:"is_fatal,omitempty"`   // IsFatal
	Serial       string `json:"serial,omitempty"`     // Serial
	Status       string `json:"status,omitempty"`     // Status
	ErrorCode    string `json:"error_code,omitempty"` // ErrorCode
	ErrorMessage string `json:"error_msg,omitempty"`  // ErrorMessage
}

APIErrorResponse APIエラー型

type CORSRule added in v1.1.0

type CORSRule struct {
	AllowsAnyOrigin bool     // trueの場合全オリジンを許可
	AllowedOrigins  []string `validate:"omitempty,max=4"`
}

CORSRule .

type Certificates

type Certificates struct {
	Current *CurrentCertificate
	Old     []*OldCertificate
}

Certificates 証明書

type Client

type Client struct {
	// Profile usacloud互換プロファイル名
	Profile string

	// APIRootURL APIのリクエスト先URLプレフィックス、省略可能
	APIRootURL string

	// AccessToken APIキー:トークン
	// Optionsでの指定より優先される
	AccessToken string
	// AccessTokenSecret APIキー:シークレット
	// Optionsでの指定より優先される
	AccessTokenSecret string

	// Options HTTPクライアント関連オプション
	Options *client.Options

	// DisableProfile usacloud互換プロファイルからの設定読み取りを無効化
	DisableProfile bool

	// DisableEnv 環境変数からの設定読み取りを無効化
	DisableEnv bool
	// contains filtered or unexported fields
}

Client APIクライアント

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, uri string, body interface{}) ([]byte, error)

Do APIコール実施

func (*Client) RootURL

func (c *Client) RootURL() string

type CreateOrUpdateCertificateRequest

type CreateOrUpdateCertificateRequest struct {
	CertificateChain string
	Key              string
}

CreateOrUpdateCertificateRequest .

type CurrentCertificate

type CurrentCertificate struct {
	ID                string
	SiteID            string
	CertificateChain  string
	Key               string
	CreatedAt         time.Time
	UpdatedAt         time.Time
	SerialNumber      string
	NotBefore         int64
	NotAfter          int64
	Issuer            *Issuer
	Subject           *Subject
	DNSNames          []string
	SHA256Fingerprint string
}

CurrentCertificate 現在有効な証明書

type DeleteAllCacheRequest

type DeleteAllCacheRequest struct {
	Domain string
}

DeleteAllCacheRequest .

type DeleteCacheRequest

type DeleteCacheRequest struct {
	URL []string
}

DeleteCacheRequest .

type DeleteCacheResult

type DeleteCacheResult struct {
	URL    string
	Status int
	Result string
}

DeleteCacheResult .

type Issuer

type Issuer struct {
	Country            string
	Organization       string
	OrganizationalUnit string
	CommonName         string
}

Issuer .

type ListSitesResult

type ListSitesResult struct {
	Total int `json:",omitempty"` // Total count of target resources
	From  int `json:",omitempty"` // Current page number
	Count int `json:",omitempty"` // Count of current page

	Sites []*Site `json:",omitempty"`
}

ListSitesResult .

type MonthlyUsage added in v1.1.0

type MonthlyUsage struct {
	SiteID             json.Number
	Domain             string
	ASCIIDomain        string
	Subdomain          string
	AccessCount        int64
	BytesSent          int64
	CacheMissBytesSent int64
	CacheHitRatio      float64
	BytesCacheHitRatio float64
	Price              int64
}

type MonthlyUsageResults added in v1.1.0

type MonthlyUsageResults struct {
	Year          int
	Month         int
	MonthlyUsages []*MonthlyUsage
}

MonthlyUsageResults 月別使用量

type OldCertificate

type OldCertificate struct {
	ID                string
	SiteID            string
	CertificateChain  string
	Key               string
	CreatedAt         time.Time
	UpdatedAt         time.Time
	SerialNumber      string
	NotBefore         int64
	NotAfter          int64
	Issuer            *Issuer
	Subject           *Subject
	DNSNames          []string
	SHA256Fingerprint string
}

OldCertificate .

type Op

type Op struct {
	Client APICaller
}

Op implements WebAccelAPI interface

func (*Op) CreateCertificate

func (o *Op) CreateCertificate(ctx context.Context, id string, param *CreateOrUpdateCertificateRequest) (*Certificates, error)

CreateCertificate サイトに証明書を登録

func (*Op) DeleteAllCache

func (o *Op) DeleteAllCache(ctx context.Context, param *DeleteAllCacheRequest) error

DeleteAllCache 全キャッシュ削除

func (*Op) DeleteCache

func (o *Op) DeleteCache(ctx context.Context, param *DeleteCacheRequest) ([]*DeleteCacheResult, error)

DeleteCache URLごとにキャッシュ削除

func (*Op) DeleteCertificate

func (o *Op) DeleteCertificate(ctx context.Context, id string) error

DeleteCertificate サイトの証明書を削除

func (*Op) List

func (o *Op) List(ctx context.Context) (*ListSitesResult, error)

List サイト一覧

NOTE: 各サイトのCORSRulesはnullになる点に注意

func (*Op) MonthlyUsage added in v1.1.0

func (o *Op) MonthlyUsage(ctx context.Context, targetYM string) (*MonthlyUsageResults, error)

MonthlyUsage クラウドアカウントに登録されている全サイトの月別使用量を取得する。

targetフィールドの値は「yyyymm」形式で対象年月を指定する。 (例: 2021年02月の場合は、「202102」と指定。) 指定がない場合は、今月の月別使用量を取得する。

func (*Op) Read

func (o *Op) Read(ctx context.Context, id string) (*Site, error)

Read サイト詳細

func (*Op) ReadCertificate

func (o *Op) ReadCertificate(ctx context.Context, id string) (*Certificates, error)

ReadCertificate サイト証明書の参照

func (*Op) Update added in v1.1.0

func (o *Op) Update(ctx context.Context, id string, param *UpdateSiteRequest) (*Site, error)

Update サイト更新

func (*Op) UpdateCertificate

func (o *Op) UpdateCertificate(ctx context.Context, id string, param *CreateOrUpdateCertificateRequest) (*Certificates, error)

UpdateCertificate サイトの証明書を更新

type Site

type Site struct {
	ID   string
	Name string

	DomainType      string `validate:"oneof=own_domain subdomain"`
	Domain          string
	Subdomain       string
	ASCIIDomain     string
	RequestProtocol string // 0:http/https, 1:httpsのみ, 2:httpsにリダイレクト
	DefaultCacheTTL int    `validate:"min=-1,max=604800"` // -1:無効, 0 ~ 604800 の範囲内の数値: デフォルトのキャッシュ期間(秒)
	VarySupport     string // 0:無効, 1:有効

	OriginType     string // 0:ウェブサーバ, 1:オブジェクトストレージ
	Origin         string
	OriginProtocol string
	HostHeader     string

	// オブジェクトストレージをオリジンにする場合
	BucketName string
	S3Endpoint string
	S3Region   string
	DocIndex   string // 0:無効, 1:有効

	// CORSRules ルール一覧、設定されている場合単一要素を持つ配列となる
	// NOTE: List()だと空、Read()でのみ参照可能
	CORSRules         []*CORSRule
	OnetimeURLSecrets []string

	Status             string `validate:"oneof=enabled disabled"`
	HasCertificate     bool
	HasOldCertificate  bool
	GibSentInLastWeek  int64
	CertValidNotBefore int64
	CertValidNotAfter  int64
	CreatedAt          time.Time
}

Site サイト

type Subject

type Subject struct {
	Country            string
	Organization       string
	OrganizationalUnit string
	Locality           string
	Province           string
	StreetAddress      string
	PostalCode         string
	SerialNumber       string
	CommonName         string
}

Subject .

type UpdateSiteRequest added in v1.1.0

type UpdateSiteRequest struct {
	// 「オリジン種別」に関係なく設定できる共通項目
	Name            string `json:",omitempty"`
	OriginType      string `json:",omitempty" validate:"omitempty,oneof=0 1"`   // 0:ウェブサーバ, 1:オブジェクトストレージ
	RequestProtocol string `json:",omitempty" validate:"omitempty,oneof=0 1 2"` // 0:http/https, 1:httpsのみ, 2:httpsにリダイレクト
	OriginProtocol  string `json:",omitempty" validate:"omitempty,oneof=http https"`
	DefaultCacheTTL int    `json:",omitempty" validate:"omitempty,min=-1,max=604800"` // -1:無効, 0 ~ 604800 の範囲内の数値: デフォルトのキャッシュ期間(秒)
	VarySupport     string `json:",omitempty" validate:"omitempty,oneof=0 1"`         // 0:無効, 1:有効

	// CORSRules ルール一覧、設定されている場合単一要素を持つ配列となる
	CORSRules         []*CORSRule `json:",omitempty"`
	OnetimeURLSecrets []string    `json:",omitempty"`

	// 「オリジン種別」が「ウェブサーバ」の場合に設定可能な項目
	Origin     string `json:",omitempty"`
	HostHeader string `json:",omitempty"`

	// 「オリジン種別」が「オブジェクトストレージ」の場合に設定可能な項目
	BucketName      string `json:",omitempty"`
	S3Endpoint      string `json:",omitempty"`
	S3Region        string `json:",omitempty"`
	DocIndex        string `json:",omitempty" validate:"omitempty,oneof=0 1"` // 0:無効, 1:有効
	AccessKeyID     string `json:",omitempty"`
	SecretAccessKey string `json:",omitempty"`
}

UpdateSiteRequest サイト更新リクエスト

Jump to

Keyboard shortcuts

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