api

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Algorithm           = "JDCLOUD2-HMAC-SHA256"
	SigningTerm         = "jdcloud2_request"
	TimeFormat          = "20060102T150405Z"
	HeaderAuthorization = "Authorization"
	HeaderXJdcloudDate  = "X-Jdcloud-Date"
	HeaderXJdcloudNonce = "X-Jdcloud-Nonce"
	HeaderXJdcloudToken = "X-Jdcloud-Security-Token"
)
View Source
const DefaultSigningRegion = "jdcloud-api"
View Source
const (
	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func DecodeError

func DecodeError(statusCode int, body []byte) error

func ErrorCode

func ErrorCode(err error) int

func NewHTTPClient

func NewHTTPClient() *http.Client

func NewTransport

func NewTransport() *http.Transport

func NewUUIDv4

func NewUUIDv4() (string, error)

NewUUIDv4 returns a random UUIDv4 in canonical 8-4-4-4-12 form.

func ResolveHost

func ResolveHost(service string) string

ResolveHost returns the service endpoint host used by J1 actions.

func ResolveSigningRegion

func ResolveSigningRegion(region string) string

ResolveSigningRegion returns the region that participates in signature derivation. Global IAM calls fall back to the literal "jdcloud-api".

Types

type APIError

type APIError struct {
	HTTPStatus int
	Code       int
	Status     string
	Message    string
	RequestID  string
	Service    string
	Action     string
}

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) IsAuthFailure

func (e *APIError) IsAuthFailure() bool

type APIErrorBody

type APIErrorBody struct {
	Status  string `json:"status"`
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*APIErrorBody) UnmarshalJSON

func (b *APIErrorBody) UnmarshalJSON(data []byte) error

type Bucket

type Bucket struct {
	Name string `json:"name"`
}

type Client

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

func NewClient

func NewClient(credential auth.Credential, opts ...Option) *Client

func (*Client) DoJSON

func (c *Client) DoJSON(ctx context.Context, req Request, out any) error

type DescribeInstancesResponse

type DescribeInstancesResponse struct {
	RequestID string        `json:"requestId"`
	Error     *APIErrorBody `json:"error,omitempty"`
	Result    struct {
		Instances  []Instance `json:"instances"`
		TotalCount int        `json:"totalCount"`
	} `json:"result"`
}

type DescribeSubUserResponse

type DescribeSubUserResponse struct {
	RequestID string        `json:"requestId"`
	Error     *APIErrorBody `json:"error,omitempty"`
	Result    struct {
		SubUser SubUser `json:"subUser"`
	} `json:"result"`
}

type DescribeSubUsersResponse

type DescribeSubUsersResponse struct {
	RequestID string        `json:"requestId"`
	Error     *APIErrorBody `json:"error,omitempty"`
	Result    struct {
		SubUsers []SubUser `json:"subUsers"`
		Total    int       `json:"total"`
	} `json:"result"`
}

type Instance

type Instance struct {
	InstanceID       string `json:"instanceId"`
	Hostname         string `json:"hostname"`
	Status           string `json:"status"`
	OSType           string `json:"osType"`
	PrivateIPAddress string `json:"privateIpAddress"`
	ElasticIPAddress string `json:"elasticIpAddress"`
}

type ListBucketsResponse

type ListBucketsResponse struct {
	RequestID string        `json:"requestId"`
	Error     *APIErrorBody `json:"error,omitempty"`
	Result    struct {
		Buckets []Bucket `json:"buckets"`
	} `json:"result"`
}

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(rawURL string) Option

func WithClock

func WithClock(now func() time.Time) Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithNonceFunc

func WithNonceFunc(fn func() string) Option

func WithRetryPolicy

func WithRetryPolicy(policy RetryPolicy) Option

type Request

type Request struct {
	Service    string
	Region     string
	Method     string
	Version    string
	Path       string
	Query      url.Values
	Body       []byte
	Headers    http.Header
	Idempotent bool
}

type RetryPolicy

type RetryPolicy struct {
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
	Sleep       func(context.Context, time.Duration) error
}

func DefaultRetryPolicy

func DefaultRetryPolicy() RetryPolicy

func (RetryPolicy) Do

func (p RetryPolicy) Do(ctx context.Context, idempotent bool, fn func() (*http.Response, error)) (*http.Response, error)

type SignInput

type SignInput struct {
	Method       string
	Host         string
	Path         string
	Query        url.Values
	Body         []byte
	ContentType  string
	Service      string
	Region       string
	AccessKey    string
	SecretKey    string
	SessionToken string
	Nonce        string
	Timestamp    time.Time
	Headers      http.Header
}

type Signature

type Signature struct {
	Authorization    string
	SignedHeaders    string
	CredentialScope  string
	CanonicalRequest string
	StringToSign     string
	XJdcloudDate     string
	XJdcloudNonce    string
	BodyDigest       string
}

func Sign

func Sign(input SignInput) (Signature, error)

type SubUser

type SubUser struct {
	Pin        string `json:"pin"`
	Name       string `json:"name"`
	Account    string `json:"account"`
	CreateTime string `json:"createTime"`
}

Jump to

Keyboard shortcuts

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