From 80e6e8fe5316cc1a3fd7c04c095c677e0a2d6d13 Mon Sep 17 00:00:00 2001 From: eryajf Date: Mon, 9 Sep 2024 22:14:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dlint=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 +-- README.md | 14 +++++++--- go.mod | 10 +++---- go.sum | 18 +++++++++++++ pkg/provider/amazon.go | 60 ++++++++++++++++++++---------------------- 5 files changed, 64 insertions(+), 42 deletions(-) diff --git a/Dockerfile b/Dockerfile index fcb4c46..312b5dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM registry.cn-hangzhou.aliyuncs.com/eryajf/golang:1.22.2-alpine3.19 AS build WORKDIR /app -ENV GOPROXY https://goproxy.io +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 \ @@ -16,7 +16,7 @@ FROM registry.cn-hangzhou.aliyuncs.com/eryajf/alpine:3.19 WORKDIR /app -LABEL maintainer eryajf +LABEL maintainer="eryajf" COPY --from=builder /app/config.example.yaml config.yaml COPY --from=builder /app/cloud_dns_exporter . diff --git a/README.md b/README.md index ee8a703..8179245 100644 --- a/README.md +++ b/README.md @@ -42,18 +42,24 @@ ## 快速体验 -本项目提供了docker-compose.yml配置文件用于快速体验。在启动前,请先在docker-compose.yml中配置好你的DNS服务商的AK/SK相关信息,并确保你的docker-compose的版本不低于[2.23.0](https://github.com/compose-spec/compose-spec/pull/429)。然后在docker-compose.yml所在目录下执行以下命令: +本项目提供了 `docker-compose.yml` 配置文件用于快速体验。在启动前,请先在 `docker-compose.yml` 中配置好你的DNS服务商的`AK/SK` 相关信息,并确保你的 `docker-compose` 的版本不低于[2.23.0](https://github.com/compose-spec/compose-spec/pull/429)。 + +然后在`docker-compose.yml`所在目录下执行以下命令: ```bash docker-compose up -d ``` + > 不懂docker-compose的用户,可以参考: [docker-compose官方教程](https://docs.docker.com/compose/reference/) 或 [中文教程](https://www.runoob.com/docker/docker-compose.html) -docker-compose.yml中定义了三个容器,分别是cloud_dns_exporter(用于获取域名和解析/证书信息),grafana(用于展示域名和解析/证书信息),prometheus(用于持久化存储域名和解析/证书信息) +`docker-compose.yml` 中定义了三个容器,分别是: +- `cloud_dns_exporter`: 用于获取域名和解析/证书信息 +- `grafana`: 用于展示域名和解析/证书信息 +- `prometheus`: 用于持久化存储域名和解析/证书信息 -使用docker-compose.yml启动后,通过http://localhost:3000访问Grafana的WebUI,使用默认的用户名和密码admin/admin登录。 +使用`docker-compose.yml`启动后,通过 http://localhost:3000 访问 `Grafana`,使用默认的用户名和密码`admin/admin`登录。 -Grafana中添加Prometheus类型的数据源,地址为http://prometheus:9090,然后保存。再导入Grafana Dashboard 21798,数据源选择刚才添加的prometheus数据源,即可看到UI展示效果。 +`Grafana` 中添加 `Prometheus` 类型的数据源,地址为 `http://prometheus:9090`,然后保存。再导入`Grafana Dashboard 21798`,数据源选择刚才添加的 `prometheus` 数据源,即可看到 `UI` 展示效果。 ## 一些注意 diff --git a/go.mod b/go.mod index e0533e2..ede7f07 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,10 @@ require ( github.com/alibabacloud-go/tea v1.2.2 github.com/allegro/bigcache/v3 v3.1.0 github.com/alyx/go-daddy v0.0.0-20240819232932-c2e4d209da9b + github.com/aws/aws-sdk-go-v2 v1.30.5 + github.com/aws/aws-sdk-go-v2/credentials v1.17.32 + github.com/aws/aws-sdk-go-v2/service/route53 v1.43.2 + github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.6 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 @@ -30,12 +34,8 @@ require ( github.com/alibabacloud-go/tea-utils/v2 v2.0.6 // indirect github.com/alibabacloud-go/tea-xml v1.1.3 // indirect github.com/aliyun/credentials-go v1.3.1 // indirect - github.com/aws/aws-sdk-go-v2 v1.30.5 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.17.32 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect - github.com/aws/aws-sdk-go-v2/service/route53 v1.43.2 // indirect - github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.6 // indirect github.com/aws/smithy-go v1.20.4 // indirect github.com/clbanning/mxj/v2 v2.5.5 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -68,7 +68,7 @@ require ( github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect - golang.org/x/net v0.28.0 // indirect + golang.org/x/net v0.28.0 golang.org/x/sys v0.23.0 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 8436998..9153175 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,20 @@ github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3b github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I= github.com/alyx/go-daddy v0.0.0-20240819232932-c2e4d209da9b h1:ITwV8o+xmGVD6IbBvjIlOoAsxX7me0ounq5UwzwdQlk= github.com/alyx/go-daddy v0.0.0-20240819232932-c2e4d209da9b/go.mod h1:JEEXFFpdZOowtBJN6+kUCQ+okHa4UfZtMBfWVRf71EM= +github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= +github.com/aws/aws-sdk-go-v2 v1.30.5/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0= +github.com/aws/aws-sdk-go-v2/credentials v1.17.32 h1:7Cxhp/BnT2RcGy4VisJ9miUPecY+lyE9I8JvcZofn9I= +github.com/aws/aws-sdk-go-v2/credentials v1.17.32/go.mod h1:P5/QMF3/DCHbXGEGkdbilXHsyTBX5D3HSwcrSc9p20I= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 h1:pI7Bzt0BJtYA0N/JEC6B8fJ4RBrEMi1LBrkMdFYNSnQ= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17/go.mod h1:Dh5zzJYMtxfIjYW+/evjQ8uj2OyR/ve2KROHGHlSFqE= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 h1:Mqr/V5gvrhA2gvgnF42Zh5iMiQNcOYthFYwCyrnuWlc= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17/go.mod h1:aLJpZlCmjE+V+KtN1q1uyZkfnUWpQGpbsn89XPKyzfU= +github.com/aws/aws-sdk-go-v2/service/route53 v1.43.2 h1:957e1/SwXIfPi/0OUJkH9YnPZRe9G6Kisd/xUhF7AUE= +github.com/aws/aws-sdk-go-v2/service/route53 v1.43.2/go.mod h1:343vcjcyOTuHTBBgUrOxPM36/jE96qLZnGL447ldrB0= +github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.6 h1:bZhgkE20ADw0wrPvUtU3oYq8wa/Zv1FdwnNEWircjsM= +github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.6/go.mod h1:JEql2FZJWlG7D+eJhKUTa0prZ+XVrCgQxIU4y0Up+So= +github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4= +github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -69,6 +83,10 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= diff --git a/pkg/provider/amazon.go b/pkg/provider/amazon.go index e774bad..b00823e 100644 --- a/pkg/provider/amazon.go +++ b/pkg/provider/amazon.go @@ -3,19 +3,19 @@ package provider import ( "encoding/json" "fmt" + "strings" + "sync" + "time" + "github.com/alibabacloud-go/tea/tea" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/route53" "github.com/aws/aws-sdk-go-v2/service/route53/types" "github.com/aws/aws-sdk-go-v2/service/route53domains" - domainTypes "github.com/aws/aws-sdk-go-v2/service/route53domains/types" "github.com/eryajf/cloud_dns_exporter/public" "github.com/golang-module/carbon/v2" "golang.org/x/net/context" - "strings" - "sync" - "time" ) type AmazonDNS struct { @@ -78,7 +78,7 @@ func (a *AmazonDNS) ListDomains() ([]Domain, error) { CloudProvider: a.account.CloudProvider, CloudName: a.account.CloudName, DomainID: strings.TrimPrefix(tea.StringValue(domain.Id), "/hostedzone/"), - DomainName: fmt.Sprintf(domainName), + DomainName: domainName, DomainRemark: tea.StringValue(nil), DomainStatus: "enable", CreatedDate: domainCreateAndExpiryDate.CreatedDate, @@ -140,7 +140,7 @@ func (a *AmazonDNS) ListRecords() ([]Record, error) { CloudName: a.account.CloudName, DomainName: domain, RecordID: tea.StringValue(record.SetIdentifier), - RecordType: fmt.Sprintf("%s", record.Type), + RecordType: string(record.Type), RecordWeight: fmt.Sprintf("%d", record.Weight), RecordStatus: oneStatus("enable"), RecordRemark: tea.StringValue(nil), @@ -184,9 +184,7 @@ func (a *AmazonDNS) getDomainList() (rst []types.HostedZone, err error) { if err != nil { return nil, err } - for _, zone := range output.HostedZones { - rst = append(rst, zone) - } + rst = append(rst, output.HostedZones...) if output.NextMarker == nil { break } @@ -224,28 +222,28 @@ 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_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 获取域名创建时间、过期时间, 通过域名详情获取