diff --git a/.golangci.toml b/.golangci.toml index 93a11605..8930971a 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -193,3 +193,6 @@ [[issues.exclude-rules]] path = "providers/dns/dns_providers.go" text = "Function name: NewDNSChallengeProviderByName," + [[issues.exclude-rules]] + path = "providers/dns/sakuracloud/client.go" + text = "mu is a global variable" diff --git a/docs/content/dns/zz_gen_sakuracloud.md b/docs/content/dns/zz_gen_sakuracloud.md index ecc15fc1..628294d8 100644 --- a/docs/content/dns/zz_gen_sakuracloud.md +++ b/docs/content/dns/zz_gen_sakuracloud.md @@ -63,7 +63,7 @@ More information [here]({{< ref "dns#configuration-and-credentials" >}}). ## More information - [API documentation](https://developer.sakura.ad.jp/cloud/api/1.1/) -- [Go client](https://github.com/sacloud/libsacloud) +- [Go client](https://github.com/sacloud/iaas-api-go) diff --git a/go.mod b/go.mod index 82825d96..6cfd4557 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/mattn/go-isatty v0.0.14 github.com/miekg/dns v1.1.47 github.com/mimuret/golang-iij-dpf v0.7.1 - github.com/mitchellh/mapstructure v1.4.1 + github.com/mitchellh/mapstructure v1.5.0 github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04 github.com/nrdcg/auroradns v1.1.0 github.com/nrdcg/desec v0.6.0 @@ -45,17 +45,18 @@ require ( github.com/ovh/go-ovh v1.1.0 github.com/pquerna/otp v1.3.0 github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2 - github.com/sacloud/libsacloud v1.36.2 + github.com/sacloud/api-client-go v0.2.0 + github.com/sacloud/iaas-api-go v1.2.1 github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f github.com/softlayer/softlayer-go v1.0.3 - github.com/stretchr/testify v1.7.5 + github.com/stretchr/testify v1.8.0 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.287 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.287 github.com/transip/gotransip/v6 v6.6.1 github.com/urfave/cli/v2 v2.3.0 github.com/vinyldns/go-vinyldns v0.9.16 github.com/vultr/govultr/v2 v2.16.0 - golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e + golang.org/x/crypto v0.0.0-20220214200702-86341886e292 golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 @@ -73,6 +74,7 @@ require ( github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect + github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -80,6 +82,7 @@ require ( github.com/dimchansky/utfbom v1.1.1 // indirect github.com/fatih/structs v1.1.0 // indirect github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect + github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/go-errors/errors v1.0.1 // indirect github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 // indirect github.com/gofrs/uuid v3.2.0+incompatible // indirect @@ -104,6 +107,8 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/sacloud/go-http v0.1.1 // indirect + github.com/sacloud/packages-go v0.0.3 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect github.com/smartystreets/assertions v1.0.1 // indirect @@ -112,7 +117,7 @@ require ( github.com/spf13/cast v1.3.1 // indirect github.com/stretchr/objx v0.4.0 // indirect go.opencensus.io v0.22.3 // indirect - go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277 // indirect + go.uber.org/ratelimit v0.2.0 // indirect golang.org/x/mod v0.4.2 // indirect golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect golang.org/x/text v0.3.7 // indirect diff --git a/go.sum b/go.sum index 217b42ed..24d5a0aa 100644 --- a/go.sum +++ b/go.sum @@ -63,6 +63,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183 h1:dkj8/dxOQ4L1XpwCzRLqukvUBbxuNdz3FeyvHFnRjmo= github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183/go.mod h1:pUKYbK5JQ+1Dfxk80P0qxGqe5dkxDoabbZS7zOcouyA= +github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 h1:MzBOUgng9orim59UnfUTLRjMpd09C5uEVQ6RPGeCaVI= +github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= @@ -122,8 +124,9 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTg github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= +github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= +github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= @@ -138,6 +141,10 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-playground/validator/v10 v10.10.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 h1:JVrqSeQfdhYRFk24TvhTZWU0q8lfCojxZQFi3Ou7+uY= github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48/go.mod h1:dZGr0i9PLlaaTD4H/hoZIDjQ+r6xq8mgbRzHZf7f2J8= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -230,6 +237,7 @@ github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ= github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= @@ -248,6 +256,7 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df h1:MZf03xP9WdakyXhOWuAD5uPK3wHh96wCsqe3hCMKh8E= @@ -285,6 +294,9 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -295,6 +307,7 @@ github.com/labbsr0x/goh v1.0.1 h1:97aBJkDjpyBZGPbQuOK5/gHcSFbcr5aRsq3RSRJFpPk= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/linode/linodego v0.31.1 h1:dBtjKo7J9UhNFhTOclEXb12RRyQDaRBxISdONVuU+DA= github.com/linode/linodego v0.31.1/go.mod h1:BR0gVkCJffEdIGJSl6bHR80Ty+Uvg/2jkjmrWaFectM= github.com/liquidweb/go-lwApi v0.0.0-20190605172801-52a4864d2738/go.mod h1:0sYF9rMXb0vlG+4SzdiGMXHheCZxjguMq+Zb4S2BfBs= @@ -321,10 +334,8 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-tty v0.0.0-20180219170247-931426f7535a/go.mod h1:XPvLUNfbS4fJH25nqRHfWLMa1ONC8Amw+mIA639KxkE= github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -337,14 +348,13 @@ github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= -github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 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= @@ -356,7 +366,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04 h1:o6uBwrhM5C8Ll3MAAxrQxRHEu7FkapwTuI2WmL1rw4g= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nrdcg/auroradns v1.1.0 h1:KekGh8kmf2MNwqZVVYo/fw/ZONt8QMEmbMFOeljteWo= github.com/nrdcg/auroradns v1.1.0/go.mod h1:O7tViUZbAcnykVnrGkXzIJTHoQCHcgalgAe6X1mzHfk= @@ -397,6 +406,7 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -428,11 +438,20 @@ github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2 h1:dq90+d51/hQR github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/sacloud/libsacloud v1.36.2 h1:aosI7clbQ9IU0Hj+3rpk3SKJop5nLPpLThnWCivPqjI= -github.com/sacloud/libsacloud v1.36.2/go.mod h1:P7YAOVmnIn3DKHqCZcUKYUXmSwGBm3yS7IBEjKVSrjg= +github.com/sacloud/api-client-go v0.2.0 h1:mRApZCTSvWoJq1CVPiPud67BotjwUX0z0Y+ife3o/W8= +github.com/sacloud/api-client-go v0.2.0/go.mod h1:N/TaASjFqlvOEHCu0p2QBlmve0+4vASuQTinm8tsPVk= +github.com/sacloud/go-http v0.1.1 h1:yAQnZ/F2lCWuVxjkWAeU0M+kCNgBDu7Y8wrIKn97axs= +github.com/sacloud/go-http v0.1.1/go.mod h1:7HxUqATJaTUHYuqv93bhbTDCgqzxtxa9Zm/VvVtBUeU= +github.com/sacloud/iaas-api-go v1.2.1 h1:QuIWelF6KSQLPeDJy4HMNbQND7XQlZyjyRnc8lGiG1I= +github.com/sacloud/iaas-api-go v1.2.1/go.mod h1:+ScynU5gBwq+rA7qw6EppIQwRhXSMkGoRkZlFIj5v+g= +github.com/sacloud/packages-go v0.0.3 h1:MtUVkZyAwvr3drjjTj4PKssRrm3hRGWPdEj+skIHbUA= +github.com/sacloud/packages-go v0.0.3/go.mod h1:Eny1qnbKr9n/5yfXDiwOC+0YMiBhK1HBYGjjmxes+CI= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f h1:WSnaD0/cvbKJgSTYbjAPf4RJXVvNNDAwVm+W8wEmnGE= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -442,7 +461,6 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= @@ -480,10 +498,12 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q= github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.287 h1:ohsyW4WffPdd2JLPio2Sd0qGr93hzkawAt9vWdCFLgY= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.287/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= @@ -492,8 +512,6 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.287/go.mod github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/transip/gotransip/v6 v6.6.1 h1:nsCU1ErZS5G0FeOpgGXc4FsWvBff9GPswSMggsC4564= github.com/transip/gotransip/v6 v6.6.1/go.mod h1:pQZ36hWWRahCUXkFWlx9Hs711gLd8J4qdgLdRzmtY+g= -github.com/uber-go/atomic v1.3.2 h1:Azu9lPBWRNKzYXSIwRfgRuDuS0YKsK4NFhiQv98gkxo= -github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= @@ -516,13 +534,13 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3 h1:8sGtKOrtQqkN1bp2AtX+misvLIlOmsEsNd+9NIcPEm8= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277 h1:d9qaMM+ODpCq+9We41//fu/sHsTnXcrqd1en3x+GKy4= -go.uber.org/ratelimit v0.0.0-20180316092928-c15da0234277/go.mod h1:2X8KaoNd1J0lZV+PxJk/5+DGbO/tpwLR1m++a7FnB/Y= +go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA= +go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -537,8 +555,9 @@ golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= +golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -622,7 +641,6 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -671,11 +689,14 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU= golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -794,8 +815,9 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0= diff --git a/providers/dns/sakuracloud/client.go b/providers/dns/sakuracloud/client.go index 1f557c8f..c6df7f53 100644 --- a/providers/dns/sakuracloud/client.go +++ b/providers/dns/sakuracloud/client.go @@ -1,67 +1,79 @@ package sakuracloud import ( - "errors" + "context" "fmt" - "net/http" "strings" + "sync" "github.com/go-acme/lego/v4/challenge/dns01" - "github.com/sacloud/libsacloud/api" - "github.com/sacloud/libsacloud/sacloud" + "github.com/sacloud/iaas-api-go" + "github.com/sacloud/iaas-api-go/search" ) -const sacloudAPILockKey = "lego/dns/sacloud" +// This mutex is required for concurrent updates. +// see: https://github.com/go-acme/lego/pull/850 +var mu sync.Mutex func (d *DNSProvider) addTXTRecord(fqdn, domain, value string, ttl int) error { - sacloud.LockByKey(sacloudAPILockKey) - defer sacloud.UnlockByKey(sacloudAPILockKey) + mu.Lock() + defer mu.Unlock() zone, err := d.getHostedZone(domain) if err != nil { - return fmt.Errorf("sakuracloud: %w", err) + return fmt.Errorf("%w", err) } name := extractRecordName(fqdn, zone.Name) - zone.AddRecord(zone.CreateNewRecord(name, "TXT", value, ttl)) - _, err = d.client.Update(zone.ID, zone) + records := append(zone.Records, &iaas.DNSRecord{ + Name: name, + Type: "TXT", + RData: value, + TTL: ttl, + }) + _, err = d.client.UpdateSettings(context.Background(), zone.ID, &iaas.DNSUpdateSettingsRequest{ + Records: records, + SettingsHash: zone.SettingsHash, + }) if err != nil { - return fmt.Errorf("sakuracloud: API call failed: %w", err) + return fmt.Errorf("API call failed: %w", err) } return nil } -func (d *DNSProvider) cleanupTXTRecord(fqdn, domain string) error { - sacloud.LockByKey(sacloudAPILockKey) - defer sacloud.UnlockByKey(sacloudAPILockKey) +func (d *DNSProvider) cleanupTXTRecord(fqdn, domain, value string) error { + mu.Lock() + defer mu.Unlock() zone, err := d.getHostedZone(domain) if err != nil { - return fmt.Errorf("sakuracloud: %w", err) + return err } - records := findTxtRecords(fqdn, zone) + recordName := extractRecordName(fqdn, zone.Name) - for _, record := range records { - var updRecords []sacloud.DNSRecordSet - for _, r := range zone.Settings.DNS.ResourceRecordSets { - if !(r.Name == record.Name && r.Type == record.Type && r.RData == record.RData) { - updRecords = append(updRecords, r) - } + var updRecords iaas.DNSRecords + for _, r := range zone.Records { + if !(r.Name == recordName && r.Type == "TXT" && r.RData == value) { + updRecords = append(updRecords, r) } - zone.Settings.DNS.ResourceRecordSets = updRecords } - _, err = d.client.Update(zone.ID, zone) - if err != nil { - return fmt.Errorf("sakuracloud: API call failed: %w", err) + settings := &iaas.DNSUpdateSettingsRequest{ + Records: updRecords, + SettingsHash: zone.SettingsHash, } + _, err = d.client.UpdateSettings(context.Background(), zone.ID, settings) + if err != nil { + return fmt.Errorf("API call failed: %w", err) + } + return nil } -func (d *DNSProvider) getHostedZone(domain string) (*sacloud.DNS, error) { +func (d *DNSProvider) getHostedZone(domain string) (*iaas.DNS, error) { authZone, err := dns01.FindZoneByFqdn(dns01.ToFqdn(domain)) if err != nil { return nil, err @@ -69,37 +81,30 @@ func (d *DNSProvider) getHostedZone(domain string) (*sacloud.DNS, error) { zoneName := dns01.UnFqdn(authZone) - res, err := d.client.Reset().WithNameLike(zoneName).Find() + conditions := &iaas.FindCondition{ + Filter: search.Filter{ + search.Key("Name"): search.ExactMatch(zoneName), + }, + } + + res, err := d.client.Find(context.Background(), conditions) if err != nil { - var notFound api.Error - if errors.As(err, ¬Found) && notFound.ResponseCode() == http.StatusNotFound { + if iaas.IsNotFoundError(err) { return nil, fmt.Errorf("zone %s not found on SakuraCloud DNS: %w", zoneName, err) } return nil, fmt.Errorf("API call failed: %w", err) } - for _, zone := range res.CommonServiceDNSItems { + for _, zone := range res.DNS { if zone.Name == zoneName { - return &zone, nil + return zone, nil } } return nil, fmt.Errorf("zone %s not found", zoneName) } -func findTxtRecords(fqdn string, zone *sacloud.DNS) []sacloud.DNSRecordSet { - recordName := extractRecordName(fqdn, zone.Name) - - var res []sacloud.DNSRecordSet - for _, record := range zone.Settings.DNS.ResourceRecordSets { - if record.Name == recordName && record.Type == "TXT" { - res = append(res, record) - } - } - return res -} - func extractRecordName(fqdn, zone string) string { name := dns01.UnFqdn(fqdn) if idx := strings.Index(name, "."+zone); idx != -1 { diff --git a/providers/dns/sakuracloud/client_test.go b/providers/dns/sakuracloud/client_test.go index 26a1b82b..831024ea 100644 --- a/providers/dns/sakuracloud/client_test.go +++ b/providers/dns/sakuracloud/client_test.go @@ -1,90 +1,61 @@ package sakuracloud import ( - "encoding/json" + "context" "fmt" - "net/http" - "net/http/httptest" "sync" "testing" - "github.com/sacloud/libsacloud/api" - "github.com/sacloud/libsacloud/sacloud" + client "github.com/sacloud/api-client-go" + "github.com/sacloud/iaas-api-go" + "github.com/sacloud/iaas-api-go/helper/api" "github.com/stretchr/testify/require" ) -type simpleResponse struct { - *sacloud.DNS `json:"CommonServiceItem,omitempty"` -} - -type apiQuery struct { - Filter struct { - Name string `json:"Name"` - ProviderClass string `json:"Provider.Class"` - } `json:"Filter"` -} - -func setupTest(t *testing.T, handler http.HandlerFunc) { +func setupTest(t *testing.T) { t.Helper() - mux := http.NewServeMux() - server := httptest.NewServer(mux) - t.Cleanup(server.Close) + t.Setenv("SAKURACLOUD_FAKE_MODE", "1") - mux.HandleFunc("/is1a/api/cloud/1.1/commonserviceitem/", handler) - - backup := api.SakuraCloudAPIRoot - t.Cleanup(func() { - api.SakuraCloudAPIRoot = backup - }) - api.SakuraCloudAPIRoot = server.URL + createDummyZone(t, fakeCaller()) } -func TestDNSProvider_addTXTRecord(t *testing.T) { - searchResp := &api.SearchDNSResponse{} +func fakeCaller() iaas.APICaller { + return api.NewCallerWithOptions(&api.CallerOptions{ + Options: &client.Options{ + AccessToken: "dummy", + AccessTokenSecret: "dummy", + }, + FakeMode: true, + }) +} - handler := func(rw http.ResponseWriter, req *http.Request) { - switch req.Method { - case http.MethodGet: - if len(searchResp.CommonServiceDNSItems) == 0 { - q := &apiQuery{} - if err := json.Unmarshal([]byte(req.URL.RawQuery), q); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } +func createDummyZone(t *testing.T, caller iaas.APICaller) { + t.Helper() - fakeZone := sacloud.CreateNewDNS(q.Filter.Name) - fakeZone.ID = 123456789012 - searchResp = &api.SearchDNSResponse{CommonServiceDNSItems: []sacloud.DNS{*fakeZone}} - } + ctx := context.Background() - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - case http.MethodPut: // Update - resp := &simpleResponse{} - if err := json.NewDecoder(req.Body).Decode(resp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } + dnsOp := iaas.NewDNSOp(caller) - var items []sacloud.DNS - for _, v := range searchResp.CommonServiceDNSItems { - if resp.Name == v.Name { - items = append(items, *resp.DNS) - } else { - items = append(items, v) - } - } - searchResp.CommonServiceDNSItems = items + // cleanup + zones, err := dnsOp.Find(ctx, &iaas.FindCondition{}) + require.NoError(t, err) - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - default: - http.Error(rw, "OOPS", http.StatusServiceUnavailable) + for _, zone := range zones.DNS { + if zone.Name == "example.com" { + err = dnsOp.Delete(ctx, zone.ID) + require.NoError(t, err) + break } } - setupTest(t, handler) + // create dummy zone + _, err = iaas.NewDNSOp(caller).Create(context.Background(), &iaas.DNSCreateRequest{Name: "example.com"}) + require.NoError(t, err) +} + +func TestDNSProvider_addAndCleanupRecords(t *testing.T) { + setupTest(t) config := NewDefaultConfig() config.Token = "token1" @@ -93,125 +64,31 @@ func TestDNSProvider_addTXTRecord(t *testing.T) { p, err := NewDNSProviderConfig(config) require.NoError(t, err) - err = p.addTXTRecord("test.example.com", "example.com", "dummyValue", 10) - require.NoError(t, err) + t.Run("addTXTRecord", func(t *testing.T) { + err = p.addTXTRecord("test.example.com", "example.com", "dummyValue", 10) + require.NoError(t, err) - updZone, err := p.getHostedZone("example.com") - require.NoError(t, err) - require.NotNil(t, updZone) + updZone, e := p.getHostedZone("example.com") + require.NoError(t, e) + require.NotNil(t, updZone) - require.Len(t, updZone.Settings.DNS.ResourceRecordSets, 1) + require.Len(t, updZone.Records, 1) + }) + + t.Run("cleanupTXTRecord", func(t *testing.T) { + err = p.cleanupTXTRecord("test.example.com", "example.com", "dummyValue") + require.NoError(t, err) + + updZone, e := p.getHostedZone("example.com") + require.NoError(t, e) + require.NotNil(t, updZone) + + require.Len(t, updZone.Records, 0) + }) } -func TestDNSProvider_cleanupTXTRecord(t *testing.T) { - searchResp := &api.SearchDNSResponse{} - - handler := func(rw http.ResponseWriter, req *http.Request) { - switch req.Method { - case http.MethodGet: - if len(searchResp.CommonServiceDNSItems) == 0 { - q := &apiQuery{} - if err := json.Unmarshal([]byte(req.URL.RawQuery), q); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - - fakeZone := sacloud.CreateNewDNS(q.Filter.Name) - fakeZone.ID = 123456789012 - fakeZone.CreateNewRecord("test", "TXT", "dummyValue", 10) - searchResp = &api.SearchDNSResponse{CommonServiceDNSItems: []sacloud.DNS{*fakeZone}} - } - - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - case http.MethodPut: // Update - resp := &simpleResponse{} - if err := json.NewDecoder(req.Body).Decode(resp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - - var items []sacloud.DNS - for _, v := range searchResp.CommonServiceDNSItems { - if resp.Name == v.Name { - items = append(items, *resp.DNS) - } else { - items = append(items, v) - } - } - searchResp.CommonServiceDNSItems = items - - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - default: - http.Error(rw, "OOPS", http.StatusServiceUnavailable) - } - } - - setupTest(t, handler) - - config := NewDefaultConfig() - config.Token = "token2" - config.Secret = "secret2" - - p, err := NewDNSProviderConfig(config) - require.NoError(t, err) - - err = p.cleanupTXTRecord("test.example.com", "example.com") - require.NoError(t, err) - - updZone, err := p.getHostedZone("example.com") - require.NoError(t, err) - require.NotNil(t, updZone) - - require.Len(t, updZone.Settings.DNS.ResourceRecordSets, 0) -} - -func TestDNSProvider_addTXTRecord_concurrent(t *testing.T) { - searchResp := &api.SearchDNSResponse{} - - handler := func(rw http.ResponseWriter, req *http.Request) { - switch req.Method { - case http.MethodGet: - if len(searchResp.CommonServiceDNSItems) == 0 { - q := &apiQuery{} - if err := json.Unmarshal([]byte(req.URL.RawQuery), q); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - - fakeZone := sacloud.CreateNewDNS(q.Filter.Name) - fakeZone.ID = 123456789012 - searchResp = &api.SearchDNSResponse{CommonServiceDNSItems: []sacloud.DNS{*fakeZone}} - } - - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - case http.MethodPut: // Update - resp := &simpleResponse{} - if err := json.NewDecoder(req.Body).Decode(resp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - - var items []sacloud.DNS - for _, v := range searchResp.CommonServiceDNSItems { - if resp.Name == v.Name { - items = append(items, *resp.DNS) - } else { - items = append(items, v) - } - } - searchResp.CommonServiceDNSItems = items - - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - default: - http.Error(rw, "OOPS", http.StatusServiceUnavailable) - } - } - - setupTest(t, handler) +func TestDNSProvider_concurrentAddAndCleanupRecords(t *testing.T) { + setupTest(t) dummyRecordCount := 10 @@ -228,101 +105,44 @@ func TestDNSProvider_addTXTRecord_concurrent(t *testing.T) { } var wg sync.WaitGroup - wg.Add(len(providers)) - for i, p := range providers { - go func(fqdn string, client *DNSProvider) { - err := client.addTXTRecord(fqdn, "example.com", "dummyValue", 10) - require.NoError(t, err) - wg.Done() - }(fmt.Sprintf("test%d.example.com", i), p) - } + t.Run("addTXTRecord", func(t *testing.T) { + wg.Add(len(providers)) - wg.Wait() - - updZone, err := providers[0].getHostedZone("example.com") - require.NoError(t, err) - require.NotNil(t, updZone) - - require.Len(t, updZone.Settings.DNS.ResourceRecordSets, dummyRecordCount) -} - -func TestDNSProvider_cleanupTXTRecord_concurrent(t *testing.T) { - dummyRecordCount := 10 - - baseFakeZone := sacloud.CreateNewDNS("example.com") - baseFakeZone.ID = 123456789012 - for i := 0; i < dummyRecordCount; i++ { - baseFakeZone.AddRecord(baseFakeZone.CreateNewRecord(fmt.Sprintf("test%d", i), "TXT", "dummyValue", 10)) - } - - searchResp := &api.SearchDNSResponse{CommonServiceDNSItems: []sacloud.DNS{*baseFakeZone}} - - handler := func(rw http.ResponseWriter, req *http.Request) { - switch req.Method { - case http.MethodGet: - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - case http.MethodPut: // Update - resp := &simpleResponse{} - if err := json.NewDecoder(req.Body).Decode(resp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - - var items []sacloud.DNS - for _, v := range searchResp.CommonServiceDNSItems { - if resp.Name == v.Name { - items = append(items, *resp.DNS) - } else { - items = append(items, v) - } - } - searchResp.CommonServiceDNSItems = items - - if err := json.NewEncoder(rw).Encode(searchResp); err != nil { - http.Error(rw, err.Error(), http.StatusServiceUnavailable) - } - default: - http.Error(rw, "OOPS", http.StatusServiceUnavailable) + for i, p := range providers { + go func(j int, client *DNSProvider) { + err := client.addTXTRecord(fmt.Sprintf("test%d.example.com", j), "example.com", "dummyValue", 10) + require.NoError(t, err) + wg.Done() + }(i, p) } - } - setupTest(t, handler) + wg.Wait() - fakeZone := sacloud.CreateNewDNS("example.com") - fakeZone.ID = 123456789012 - for i := 0; i < dummyRecordCount; i++ { - fakeZone.AddRecord(fakeZone.CreateNewRecord(fmt.Sprintf("test%d", i), "TXT", "dummyValue", 10)) - } - - var providers []*DNSProvider - for i := 0; i < dummyRecordCount; i++ { - config := NewDefaultConfig() - config.Token = "token4" - config.Secret = "secret4" - - p, err := NewDNSProviderConfig(config) + updZone, err := providers[0].getHostedZone("example.com") require.NoError(t, err) - providers = append(providers, p) - } + require.NotNil(t, updZone) - var wg sync.WaitGroup - wg.Add(len(providers)) + require.Len(t, updZone.Records, dummyRecordCount) + }) - for i, p := range providers { - go func(fqdn string, client *DNSProvider) { - err := client.cleanupTXTRecord(fqdn, "example.com") - require.NoError(t, err) - wg.Done() - }(fmt.Sprintf("test%d.example.com", i), p) - } + t.Run("cleanupTXTRecord", func(t *testing.T) { + wg.Add(len(providers)) - wg.Wait() + for i, p := range providers { + go func(i int, client *DNSProvider) { + err := client.cleanupTXTRecord(fmt.Sprintf("test%d.example.com", i), "example.com", "dummyValue") + require.NoError(t, err) + wg.Done() + }(i, p) + } - updZone, err := providers[0].getHostedZone("example.com") - require.NoError(t, err) - require.NotNil(t, updZone) + wg.Wait() - require.Len(t, updZone.Settings.DNS.ResourceRecordSets, 0) + updZone, err := providers[0].getHostedZone("example.com") + require.NoError(t, err) + require.NotNil(t, updZone) + + require.Len(t, updZone.Records, 0) + }) } diff --git a/providers/dns/sakuracloud/sakuracloud.go b/providers/dns/sakuracloud/sakuracloud.go index 45f18afe..2cb523ce 100644 --- a/providers/dns/sakuracloud/sakuracloud.go +++ b/providers/dns/sakuracloud/sakuracloud.go @@ -9,7 +9,9 @@ import ( "github.com/go-acme/lego/v4/challenge/dns01" "github.com/go-acme/lego/v4/platform/config/env" - "github.com/sacloud/libsacloud/api" + client "github.com/sacloud/api-client-go" + "github.com/sacloud/iaas-api-go" + "github.com/sacloud/iaas-api-go/helper/api" ) // Environment variables names. @@ -50,7 +52,7 @@ func NewDefaultConfig() *Config { // DNSProvider implements the challenge.Provider interface. type DNSProvider struct { config *Config - client *api.DNSAPI + client iaas.DNSAPI } // NewDNSProvider returns a DNSProvider instance configured for SakuraCloud. @@ -83,15 +85,22 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { return nil, errors.New("sakuracloud: AccessSecret is missing") } - apiClient := api.NewClient(config.Token, config.Secret, "is1a") - if config.HTTPClient == nil { - apiClient.HTTPClient = http.DefaultClient - } else { - apiClient.HTTPClient = config.HTTPClient + defaultOption, err := api.DefaultOption() + if err != nil { + return nil, fmt.Errorf("sakuracloud: %w", err) + } + + options := &api.CallerOptions{ + Options: &client.Options{ + AccessToken: config.Token, + AccessTokenSecret: config.Secret, + HttpClient: config.HTTPClient, + UserAgent: fmt.Sprintf("go-acme/lego %s", iaas.DefaultUserAgent), + }, } return &DNSProvider{ - client: apiClient.GetDNSAPI(), + client: iaas.NewDNSOp(api.NewCallerWithOptions(api.MergeOptions(defaultOption, options))), config: config, }, nil } @@ -99,13 +108,25 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { // Present creates a TXT record to fulfill the dns-01 challenge. func (d *DNSProvider) Present(domain, token, keyAuth string) error { fqdn, value := dns01.GetRecord(domain, keyAuth) - return d.addTXTRecord(fqdn, domain, value, d.config.TTL) + + err := d.addTXTRecord(fqdn, domain, value, d.config.TTL) + if err != nil { + return fmt.Errorf("sakuracloud: %w", err) + } + + return nil } // CleanUp removes the TXT record matching the specified parameters. func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { - fqdn, _ := dns01.GetRecord(domain, keyAuth) - return d.cleanupTXTRecord(fqdn, domain) + fqdn, value := dns01.GetRecord(domain, keyAuth) + + err := d.cleanupTXTRecord(fqdn, domain, value) + if err != nil { + return fmt.Errorf("sakuracloud: %w", err) + } + + return nil } // Timeout returns the timeout and interval to use when checking for DNS propagation. diff --git a/providers/dns/sakuracloud/sakuracloud.toml b/providers/dns/sakuracloud/sakuracloud.toml index 8ee1e2c7..c6a2eeb9 100644 --- a/providers/dns/sakuracloud/sakuracloud.toml +++ b/providers/dns/sakuracloud/sakuracloud.toml @@ -22,4 +22,4 @@ lego --email you@example.com --dns sakuracloud --domains my.example.org run [Links] API = "https://developer.sakura.ad.jp/cloud/api/1.1/" - GoClient = "https://github.com/sacloud/libsacloud" + GoClient = "https://github.com/sacloud/iaas-api-go"