diff --git a/.github/workflows/release-charts.yml b/.github/workflows/release-charts.yml new file mode 100644 index 000000000..c5da02a2e --- /dev/null +++ b/.github/workflows/release-charts.yml @@ -0,0 +1,25 @@ +name: Release Charts + +on: + push: + branches: + - master + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.0.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/go.mod b/go.mod index 56540353f..77eea061d 100644 --- a/go.mod +++ b/go.mod @@ -46,6 +46,7 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect + github.com/miekg/dns v1.1.59 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect @@ -73,6 +74,7 @@ require ( go.uber.org/zap v1.27.0 // indirect golang.org/x/crypto v0.24.0 // indirect golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect + golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.20.0 // indirect golang.org/x/sync v0.7.0 // indirect diff --git a/go.sum b/go.sum index b6f905b4f..5b4ea2ebd 100644 --- a/go.sum +++ b/go.sum @@ -104,6 +104,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/miekg/dns v1.1.59 h1:C9EXc/UToRwKLhK5wKU/I4QVsBUc8kE6MkHBkeypWZs= +github.com/miekg/dns v1.1.59/go.mod h1:nZpewl5p6IvctfgrckopVx2OlSEHPRO/U4SYkRklrEk= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -205,6 +207,8 @@ golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJ golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= +golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= diff --git a/main.go b/main.go index a77e93dee..1fbd2d498 100644 --- a/main.go +++ b/main.go @@ -107,7 +107,7 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error { // sets a record in the DNS provider's console resp, err := namesilo.Call[namesilo.Response](apiKey, "dnsAddRecord", map[string]string{ - "domain": ch.ResolvedZone, + "domain": namesilo.GetDomainFromZone(ch.ResolvedZone), "rrtype": "TXT", "rrhost": strings.TrimSuffix(ch.ResolvedFQDN, "."+ch.ResolvedZone), "rrvalue": ch.Key, @@ -142,7 +142,7 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error { } // 1. fetch the TXT record id listResp, err := namesilo.Call[namesilo.DnsRecordListResponse](apiKey, "dnsListRecords", map[string]string{ - "domain": ch.ResolvedZone, + "domain": namesilo.GetDomainFromZone(ch.ResolvedZone), }) if err != nil { utils.Log("Error listing TXT records for %s, %s: %s", ch.ResolvedFQDN, ch.ResolvedZone, err.Error()) @@ -153,7 +153,7 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error { } targetRecordID := "" for _, r := range listResp.Reply.ResourceRecord { - if r.Host == ch.ResolvedFQDN && r.Type == "TXT" && r.Value == ch.Key { + if r.Host == namesilo.GetDomainFromZone(ch.ResolvedFQDN) && r.Type == "TXT" && r.Value == ch.Key { targetRecordID = r.ResourceID break } @@ -169,7 +169,7 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error { // 2. delete the TXT record deleteResp, err := namesilo.Call[namesilo.Response](apiKey, "dnsDeleteRecord", map[string]string{ - "domain": ch.ResolvedFQDN, + "domain": namesilo.GetDomainFromZone(ch.ResolvedZone), "rrid": targetRecordID, }) if err != nil { diff --git a/main_test.go b/main_test.go new file mode 100644 index 000000000..ffc017185 --- /dev/null +++ b/main_test.go @@ -0,0 +1,32 @@ +package main + +import ( + "os" + "testing" + + acmetest "github.com/cert-manager/cert-manager/test/acme" +) + +var ( + zone = os.Getenv("TEST_ZONE_NAME") +) + +func TestRunsSuite(t *testing.T) { + // The manifest path should contain a file named config.json that is a + // snippet of valid configuration that should be included on the + // ChallengeRequest passed as part of the test cases. + // + + // Uncomment the below fixture when implementing your custom DNS provider + fixture := acmetest.NewFixture(&customDNSProviderSolver{}, + acmetest.SetResolvedZone(zone), + acmetest.SetAllowAmbientCredentials(false), + acmetest.SetManifestPath("testdata/namesilo"), + acmetest.SetDNSServer("202.46.34.75:53"), + // acmetest.SetBinariesPath("_test/kubebuilder/bin"), + ) + //need to uncomment and RunConformance delete runBasic and runExtended once https://github.com/cert-manager/cert-manager/pull/4835 is merged + //fixture.RunConformance(t) + fixture.RunBasic(t) + fixture.RunExtended(t) +} diff --git a/namesilo/namesilo.go b/namesilo/namesilo.go index e67ae6e2c..ef9fcab67 100644 --- a/namesilo/namesilo.go +++ b/namesilo/namesilo.go @@ -75,3 +75,7 @@ func Call[Resp any](apiKey string, operation string, params map[string]string) ( } return resp, nil } + +func GetDomainFromZone(fqdn string) string { + return strings.TrimSuffix(fqdn, ".") +} diff --git a/testdata/namesilo/config.json b/testdata/namesilo/config.json index 0967ef424..b102cbef9 100644 --- a/testdata/namesilo/config.json +++ b/testdata/namesilo/config.json @@ -1 +1,6 @@ -{} +{ + "apiKey": { + "name": "namesilo-api-key", + "key": "namesilo-api-key" + } +} diff --git a/testdata/namesilo/namesilo-api-key.yaml b/testdata/namesilo/namesilo-api-key.yaml new file mode 100644 index 000000000..454d69387 --- /dev/null +++ b/testdata/namesilo/namesilo-api-key.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Secret +metadata: + name: namesilo-api-key +data: + namesilo-api-key: replace-with-base64-namesilo-api-key \ No newline at end of file diff --git a/utils/utils.go b/utils/utils.go index 9a62acb2b..05e99be4f 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -3,5 +3,5 @@ package utils import "fmt" func Log(format string, args ...any) { - fmt.Printf(format, args...) + fmt.Printf(format+"\n", args...) }