huaweicloud

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 14 Imported by: 8

README

Huawei Cloud for libdns

Go Reference

This package implements the libdns interfaces for Huawei Cloud DNS, allowing you to manage DNS records.

Authenticating

To authenticate you need to supply your AccessKeyId and SecretAccessKey to the Provider.

Example

Here's a minimal example of how to get all your DNS records using this libdns provider

package main

import (
	"context"
	"fmt"

	"github.com/libdns/huaweicloud"
)

func main() {
	provider := huaweicloud.Provider{
		AccessKeyId: "<AccessKeyId form your huaweicloud console>",
		SecretAccessKey: "<SecretAccessKey form your huaweicloud console>",
	}

	records, err  := provider.GetRecords(context.TODO(), "example.com.")
	if err != nil {
		fmt.Println(err.Error())
	}

	for _, record := range records {
		fmt.Printf("%s %v %s %s\n", record.Name, record.TTL.Seconds(), record.Type, record.Value)
	}
}

For complete demo check _example/main.go

Documentation

Index

Constants

View Source
const (
	DateFormat           = "20060102T150405Z"
	SignAlgorithm        = "SDK-HMAC-SHA256"
	HeaderXDateTime      = "X-Sdk-Date"
	HeaderXHost          = "host"
	HeaderXAuthorization = "Authorization"
	HeaderXContentSha256 = "X-Sdk-Content-Sha256"
)

Variables

This section is empty.

Functions

func AuthHeaderValue added in v1.0.0

func AuthHeaderValue(signatureStr, accessKeyStr string, signedHeaders []string) string

AuthHeaderValue Get the finalized value for the "Authorization" header. The signature parameter is the output from SignStringToSign

func CanonicalHeaders added in v1.0.0

func CanonicalHeaders(request *http.Request, signerHeaders []string) string

CanonicalHeaders returns the canonical headers

func CanonicalQueryString added in v1.0.0

func CanonicalQueryString(request *http.Request) string

CanonicalQueryString returns the canonical query string

func CanonicalRequest added in v1.0.0

func CanonicalRequest(request *http.Request, signedHeaders []string) (string, error)

CanonicalRequest Build a CanonicalRequest from a regular request string

func CanonicalURI added in v1.0.0

func CanonicalURI(request *http.Request) string

CanonicalURI returns request uri

func HexEncodeSHA256Hash added in v1.0.0

func HexEncodeSHA256Hash(body []byte) (string, error)

HexEncodeSHA256Hash returns hexcode of sha256

func RequestPayload added in v1.0.0

func RequestPayload(request *http.Request) ([]byte, error)

RequestPayload returns the request body

func SignStringToSign added in v1.0.0

func SignStringToSign(stringToSign string, signingKey []byte) (string, error)

SignStringToSign Create the HWS Signature

func SignedHeaders added in v1.0.0

func SignedHeaders(r *http.Request) []string

SignedHeaders returns the headers that are signed

func StringToSign added in v1.0.0

func StringToSign(canonicalRequest string, t time.Time) (string, error)

StringToSign Create a "String to Sign"

Types

type Client added in v1.0.0

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

func NewClient added in v1.0.0

func NewClient(accessKeyId, secretAccessKey, region string) *Client

NewClient creates a new Huawei Cloud DNS client.

func (*Client) AppendRecord added in v1.0.0

func (c *Client) AppendRecord(ctx context.Context, zone string, record RecordSet) (*RecordSet, error)

func (*Client) DeleteRecord added in v1.0.0

func (c *Client) DeleteRecord(ctx context.Context, zone string, recordId string) (*RecordSet, error)

func (*Client) GetRecordId added in v1.0.0

func (c *Client) GetRecordId(ctx context.Context, zone, recName, recType string, recVal ...string) (string, error)

func (*Client) GetRecords added in v1.0.0

func (c *Client) GetRecords(ctx context.Context, zone string) ([]RecordSet, error)

func (*Client) UpdateRecord added in v1.0.0

func (c *Client) UpdateRecord(ctx context.Context, zone string, record RecordSet) (*RecordSet, error)

type ListRecordsResponse added in v1.0.0

type ListRecordsResponse struct {
	RecordSets []RecordSet `json:"recordsets,omitempty"`
}

type ListZonesResponse added in v1.0.0

type ListZonesResponse struct {
	Zones []Zone `json:"zones,omitempty"`
}

type Provider

type Provider struct {
	// AccessKeyId is required by the Huawei Cloud API for authentication.
	AccessKeyId string `json:"access_key_id,omitempty"`
	// SecretAccessKey is required by the Huawei Cloud API for authentication.
	SecretAccessKey string `json:"secret_access_key,omitempty"`
	// RegionId is optional and defaults to "cn-south-1".
	RegionId string `json:"region_id,omitempty"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with Huawei Cloud

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added. NOTE: This implementation is NOT atomic.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone. It returns the records that were deleted. NOTE: This implementation is NOT atomic.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records. NOTE: This implementation is NOT atomic.

type RecordSet added in v1.0.0

type RecordSet struct {
	// Record Set的ID
	Id string `json:"id,omitempty"`
	// Record Set的名称(FQDN形式)
	Name string `json:"name,omitempty"`
	// 记录类型。
	Type string `json:"type,omitempty"`
	// 解析记录在本地DNS服务器的缓存时间,缓存时间越长更新生效越慢,以秒为单位。
	Ttl int32 `json:"ttl,omitempty"`
	// 域名解析后的值。
	Records []string `json:"records,omitempty"`
}

type Signer added in v1.0.0

type Signer struct {
	Key    string
	Secret string
}

Signer Signature HWS meta

func (*Signer) Sign added in v1.0.0

func (s *Signer) Sign(request *http.Request) error

Sign SignRequest set Authorization header

type Zone added in v1.0.0

type Zone struct {
	// zone的ID,uuid形式的一个资源标识。
	Id string `json:"id,omitempty"`
	// zone名称。
	Name string `json:"name,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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