qiniu

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package qiniu implements certificate upload and exact-domain certificate deployment for Qiniu CDN products.

The certificate API and domain API use different hosts and authentication schemes. Keeping the request construction here makes it possible to sign the same bytes that are ultimately sent to the domain API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError added in v0.6.4

type APIError struct {
	// Operation identifies the failed Qiniu API operation.
	Operation string
	// StatusCode is the provider HTTP status code, or zero before a response exists.
	StatusCode int
	// ProviderRequestID is Qiniu's request identifier when the response included one.
	ProviderRequestID string
	// Retryable reports whether retrying the operation may succeed without configuration changes.
	Retryable bool
	// Message is a sanitized provider or local failure description.
	Message string
	// Cause retains the underlying transport or parsing error.
	Cause error
}

APIError carries enough provider context for a later caller to decide whether to retry.

func (*APIError) Error added in v0.6.4

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) Unwrap added in v0.6.4

func (e *APIError) Unwrap() error

Unwrap exposes the underlying cause for errors.Is and errors.As.

type CertificateUploadResult added in v0.6.4

type CertificateUploadResult struct {
	// CertificateID is Qiniu's certID and is required by the domain binding API.
	CertificateID string
	// ProviderRequestID is Qiniu's request identifier for the upload operation.
	ProviderRequestID string
}

CertificateUploadResult contains the certificate identity returned by Qiniu.

type HTTPClient added in v0.6.4

type HTTPClient interface {
	// Do sends one HTTP request and returns its response.
	Do(*http.Request) (*http.Response, error)
}

HTTPClient is the subset of http.Client used by Provider. It allows unit tests to inject an httptest client without global state.

type Options added in v0.6.4

type Options struct {
	// HTTPClient sends signed API requests. A timeout-enabled default is used when nil.
	HTTPClient HTTPClient
	// APIBaseURL overrides the Qiniu domain API host. It is intended for tests.
	APIBaseURL string
	// FusionBaseURL overrides the Qiniu certificate API host. It is intended for tests.
	FusionBaseURL string
}

Options configures a Provider instance.

type Product added in v0.6.4

type Product string

Product identifies the Qiniu domain product that owns a custom domain.

const (
	// ProductCDN identifies a Qiniu CDN custom domain.
	ProductCDN Product = "cdn"
	// ProductDCDN identifies a Qiniu DCDN custom domain.
	ProductDCDN Product = "dcdn"
)

type Provider

type Provider struct {
	// AccessKey is retained for compatibility with existing callers. Do not log it.
	AccessKey string
	// AccessSecret is retained for compatibility with existing callers. Do not log it.
	AccessSecret string
	// contains filtered or unexported fields
}

Provider owns the Qiniu credentials and HTTP transport used for certificate operations.

func New

func New(accessKey, accessSecret string) *Provider

New creates a Provider using Qiniu production API endpoints.

func NewWithOptions added in v0.6.4

func NewWithOptions(accessKey, accessSecret string, options *Options) *Provider

NewWithOptions creates a Provider with an injectable HTTP transport and API endpoints.

func (*Provider) BindCertificate added in v0.6.4

func (p *Provider) BindCertificate(ctx context.Context, product Product, certID, domain string) (*TargetDeploymentResult, error)

BindCertificate validates one exact Qiniu domain, binds an existing certID, and reads it back.

func (*Provider) DeployCertificate added in v0.6.4

DeployCertificate 为明确的七牛 CDN 或 DCDN 业务部署精确域名证书。

func (*Provider) DeployTargetCertificate added in v0.6.4

func (p *Provider) DeployTargetCertificate(ctx context.Context, product Product, name, domain, cert, key string) (*TargetDeploymentResult, error)

DeployTargetCertificate validates one exact Qiniu domain, uploads a certificate, binds it, and reads it back.

func (*Provider) TestConnection

func (p *Provider) TestConnection() (bool, error)

TestConnection tests QBox credentials against the Qiniu certificate API.

func (*Provider) TestConnectionWithContext added in v0.6.4

func (p *Provider) TestConnectionWithContext(ctx context.Context) (bool, error)

TestConnectionWithContext tests QBox credentials while respecting caller cancellation.

func (*Provider) UploadCertificate

func (p *Provider) UploadCertificate(name, domain, cert, key string) error

UploadCertificate uploads a certificate for the legacy ProviderHandler interface. Call UploadCertificateWithContext when the caller needs Qiniu's certID.

func (*Provider) UploadCertificateWithContext added in v0.6.4

func (p *Provider) UploadCertificateWithContext(ctx context.Context, name, domain, cert, key string) (*CertificateUploadResult, error)

UploadCertificateWithContext uploads a PEM certificate with QBox authentication and retains certID.

type TargetDeploymentResult added in v0.6.4

type TargetDeploymentResult struct {
	// CertificateID is the Qiniu certID bound to the custom domain.
	CertificateID string
	// Domain is the exact custom domain that was verified and updated.
	Domain string
	// Product is the Qiniu product validated before the update.
	Product Product
	// UploadRequestID identifies the certificate upload request when this method uploaded a certificate.
	UploadRequestID string
	// ProviderRequestID identifies the domain update request.
	ProviderRequestID string
}

TargetDeploymentResult describes one exact-domain certificate deployment at the Qiniu API layer.

Jump to

Keyboard shortcuts

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