Skip to content

Commit

Permalink
add namesilo provider
Browse files Browse the repository at this point in the history
  • Loading branch information
usual2970 committed Sep 10, 2024
1 parent b8cff68 commit 7ad8cdf
Show file tree
Hide file tree
Showing 15 changed files with 801 additions and 40 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/nrdcg/namesilo v0.2.1 // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
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/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -290,6 +291,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nrdcg/namesilo v0.2.1 h1:kLjCjsufdW/IlC+iSfAqj0iQGgKjlbUUeDJio5Y6eMg=
github.com/nrdcg/namesilo v0.2.1/go.mod h1:lwMvfQTyYq+BbjJd30ylEG4GPSS6PII0Tia4rRpRiyw=
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b h1:FfH+VrHHk6Lxt9HdVS0PXzSXFyS2NbZKXv33FYPol0A=
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b/go.mod h1:AC62GU6hc0BrNm+9RK9VSiwa/EUe1bkIeFORAMcHvJU=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
Expand Down
3 changes: 3 additions & 0 deletions internal/applicant/applicant.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
configTypeTencent = "tencent"
configTypeAliyun = "aliyun"
configTypeCloudflare = "cloudflare"
configTypeNamesilo = "namesilo"
)

type Certificate struct {
Expand Down Expand Up @@ -70,6 +71,8 @@ func Get(record *models.Record) (Applicant, error) {
return NewAliyun(option), nil
case configTypeCloudflare:
return NewCloudflare(option), nil
case configTypeNamesilo:
return NewNamesilo(option), nil
default:
return nil, errors.New("unknown config type")
}
Expand Down
34 changes: 34 additions & 0 deletions internal/applicant/namesilo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package applicant

import (
"certimate/internal/domain"
"encoding/json"
"os"

namesiloProvider "github.com/go-acme/lego/v4/providers/dns/namesilo"
)

type namesilo struct {
option *ApplyOption
}

func NewNamesilo(option *ApplyOption) Applicant {
return &namesilo{
option: option,
}
}

func (a *namesilo) Apply() (*Certificate, error) {

access := &domain.NameSiloAccess{}
json.Unmarshal([]byte(a.option.Access), access)

os.Setenv("NAMESILO_API_KEY", access.ApiKey)

dnsProvider, err := namesiloProvider.NewDNSProvider()
if err != nil {
return nil, err
}

return apply(a.option, dnsProvider)
}
4 changes: 4 additions & 0 deletions internal/domain/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ type QiniuAccess struct {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
}

type NameSiloAccess struct {
ApiKey string `json:"apiKey"`
}
Loading

0 comments on commit 7ad8cdf

Please sign in to comment.