diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 63a71e0..f7df010 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,4 +6,6 @@ 1. 项目使用`golangci-lint`进行检测,提交 pr 之前请在本地执行 `make lint` 并通过。 -2. 如非必要,尽可能谨慎新增配置文件,以免造成升级时产生意料之外的问题。 \ No newline at end of file +2. 如有新的服务商,则需要注意在对应readme也做好对应标注说明。 + +3. 如果domain_id或record_id为空,则可通过调用 public.GetID() 进行填充。 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 312b5dc..0e9974b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,8 @@ -FROM registry.cn-hangzhou.aliyuncs.com/eryajf/golang:1.22.2-alpine3.19 AS builder +FROM registry.cn-hangzhou.aliyuncs.com/eryajf/golang:1.22.2-alpine3.19-eryajf AS builder WORKDIR /app - ENV GOPROXY="https://goproxy.io" -RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \ - && apk upgrade && apk add --no-cache --virtual .build-deps \ - ca-certificates gcc g++ curl upx git make - ADD . . RUN make build-linux && upx -9 cloud_dns_exporter diff --git a/go.mod b/go.mod index ede7f07..88b6da0 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/charmbracelet/log v0.2.2 github.com/go-resty/resty/v2 v2.14.0 github.com/golang-module/carbon/v2 v2.3.12 + github.com/google/uuid v1.6.0 github.com/prometheus/client_golang v1.16.0 github.com/robfig/cron/v3 v3.0.1 github.com/spf13/cobra v1.8.1 diff --git a/go.sum b/go.sum index 9153175..0615453 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/pkg/provider/amazon.go b/pkg/provider/amazon.go index b00823e..7e6c623 100644 --- a/pkg/provider/amazon.go +++ b/pkg/provider/amazon.go @@ -139,7 +139,7 @@ func (a *AmazonDNS) ListRecords() ([]Record, error) { CloudProvider: a.account.CloudProvider, CloudName: a.account.CloudName, DomainName: domain, - RecordID: tea.StringValue(record.SetIdentifier), + RecordID: public.GetID(), RecordType: string(record.Type), RecordWeight: fmt.Sprintf("%d", record.Weight), RecordStatus: oneStatus("enable"), @@ -222,29 +222,6 @@ func (a *AmazonDNS) getRecordList(domainId string) (rst []types.ResourceRecordSe return } -// // https://docs.aws.amazon.com/Route53/latest/APIReference/API_domains_ListDomains.html -// // getDomainNameList 获取域名列表 -// func (a *AmazonDNS) getDomainNameList() (rst []domainTypes.DomainSummary, err error) { -// client := NewAwsDomainClient(a.account.SecretID, a.account.SecretKey) -// var Marker *string -// for { -// output, err := client.ListDomains(context.Background(), &route53domains.ListDomainsInput{ -// Marker: Marker, -// }) -// if err != nil { -// return nil, err -// } -// for _, domain := range output.Domains { -// rst = append(rst, domain) -// } -// if output.NextPageMarker == nil { -// break -// } -// Marker = output.NextPageMarker -// } -// return -// } - // 域名详情接口 https://docs.aws.amazon.com/Route53/latest/APIReference/API_domains_GetDomainDetail.html // getDomainCreateAndExpiryDate 获取域名创建时间、过期时间, 通过域名详情获取 func (a *AmazonDNS) getDomainCreateAndExpiryDate(domainName string) (d Domain) { diff --git a/pkg/provider/dnsla.go b/pkg/provider/dnsla.go index 875aed1..9d3c707 100644 --- a/pkg/provider/dnsla.go +++ b/pkg/provider/dnsla.go @@ -124,7 +124,7 @@ func (d *DNSLaDNS) ListRecords() ([]Record, error) { CloudProvider: d.account.CloudProvider, CloudName: d.account.CloudName, DomainName: domain, - RecordID: v.Data, + RecordID: public.GetID(), RecordType: getRecordType(v.Type), RecordName: v.DisplayHost, RecordValue: v.Data, diff --git a/pkg/provider/godaddy.go b/pkg/provider/godaddy.go index 5417d1e..35df812 100644 --- a/pkg/provider/godaddy.go +++ b/pkg/provider/godaddy.go @@ -125,7 +125,7 @@ func (g *GodaddyDNS) ListRecords() ([]Record, error) { CloudProvider: g.account.CloudProvider, CloudName: g.account.CloudName, DomainName: domain, - RecordID: v.Data, + RecordID: public.GetID(), RecordType: v.Type, RecordName: v.Name, RecordValue: v.Data, diff --git a/public/public.go b/public/public.go index 4fe9cd5..651976a 100644 --- a/public/public.go +++ b/public/public.go @@ -3,11 +3,13 @@ package public import ( "context" "os" + "strings" "sync" "time" "github.com/allegro/bigcache/v3" "github.com/eryajf/cloud_dns_exporter/public/logger" + "github.com/google/uuid" "gopkg.in/yaml.v2" ) @@ -37,6 +39,7 @@ var ( Config *Configuration Cache *bigcache.BigCache CertCache *bigcache.BigCache + ID uuid.UUID = uuid.New() ) type Account struct { @@ -81,3 +84,8 @@ func InitCache() { logger.Fatal("init cache failed: ", err) } } + +// GetID 获取唯一ID +func GetID() string { + return strings.ReplaceAll(ID.String(), "-", "") +}