Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 当id为空时,通过uuid填充 #16

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

1. 项目使用`golangci-lint`进行检测,提交 pr 之前请在本地执行 `make lint` 并通过。

2. 如非必要,尽可能谨慎新增配置文件,以免造成升级时产生意料之外的问题。
2. 如有新的服务商,则需要注意在对应readme也做好对应标注说明。

3. 如果domain_id或record_id为空,则可通过调用 public.GetID() 进行填充。
7 changes: 1 addition & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 1 addition & 24 deletions pkg/provider/amazon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/dnsla.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/godaddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -37,6 +39,7 @@ var (
Config *Configuration
Cache *bigcache.BigCache
CertCache *bigcache.BigCache
ID uuid.UUID = uuid.New()
)

type Account struct {
Expand Down Expand Up @@ -81,3 +84,8 @@ func InitCache() {
logger.Fatal("init cache failed: ", err)
}
}

// GetID 获取唯一ID
func GetID() string {
return strings.ReplaceAll(ID.String(), "-", "")
}
Loading