diff --git a/.editorconfig b/.editorconfig index 38906a2..de01420 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,3 +5,10 @@ end_of_line = lf insert_final_newline = true charset = utf-8 trim_trailing_whitespace = true +indent_size = 2 +indent_style = space +tab_width = 2 + +[*.go] +indent_size = 4 +tab_width = 4 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..8617c18 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,48 @@ +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + strategy: + matrix: + target: + - arch: amd64 + os: linux + - arch: arm + os: linux + - arch: arm64 + os: linux + - arch: riscv64 + os: linux + - arch: wasm + os: wasip1 + ext: .wasm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Build + env: + CGO_ENABLED: 0 + GOOS: ${{ matrix.target.os }} + GOARCH: ${{ matrix.target.arch }} + run: go build -v -o fritzbox-cloudflare-dyndns${{ matrix.target.ext }} . + + - name: Tar up + run: tar -cJf "fritzbox-cloudflare-dyndns-${{ matrix.target.arch }}.tar.xz" fritzbox-cloudflare-dyndns${{ matrix.target.ext }} + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.1.3 + with: + name: fritzbox-cloudflare-dyndns-${{ matrix.target.arch }} + path: fritzbox-cloudflare-dyndns-${{ matrix.target.arch }}.tar.xz diff --git a/.gitignore b/.gitignore index a9ad188..eb7f945 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .env -.idea/ +/fritzbox-cloudflare-dyndns diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/fritzbox-cloudflare-dyndns.iml b/.idea/fritzbox-cloudflare-dyndns.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/fritzbox-cloudflare-dyndns.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7a7e7e6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d9f838a..0801236 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM golang:1.20-alpine as server_build +FROM golang:1.21-alpine as server_build + +WORKDIR /appbuild # Add build deps RUN apk add --update gcc g++ git @@ -7,34 +9,26 @@ COPY go.mod go.sum /appbuild/ COPY ./ /appbuild -RUN set -ex \ - && go version \ - && cd /appbuild \ - && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -mod=vendor -o server +RUN CGO_ENABLED=0 GOOS=linux go build -o fritzbox-cloudflare-dyndns # Build deployable server -FROM alpine:latest - -ENV FRITZBOX_ENDPOINT_URL ${FRITZBOX_ENDPOINT_URL:-http://fritz.box:49000} \ - FRITZBOX_ENDPOINT_TIMEOUT ${FRITZBOX_ENDPOINT_TIMEOUT:-30s} \ - DYNDNS_SERVER_BIND ${DYNDNS_SERVER_BIND:-:8080} \ - DYNDNS_SERVER_USERNAME ${DYNDNS_SERVER_USERNAME} \ - DYNDNS_SERVER_PASSWORD ${DYNDNS_SERVER_PASSWORD} \ - CLOUDFLARE_API_EMAIL "" \ - CLOUDFLARE_API_KEY "" \ - CLOUDFLARE_ZONES_IPV4 "" \ - CLOUDFLARE_ZONES_IPV6 "" \ - CLOUDFLARE_LOCAL_ADDRESS_IPV6 "" +FROM gcr.io/distroless/cc-debian12:debug + +ENV FRITZBOX_ENDPOINT_URL=${FRITZBOX_ENDPOINT_URL:-http://fritz.box:49000} \ + FRITZBOX_ENDPOINT_TIMEOUT=${FRITZBOX_ENDPOINT_TIMEOUT:-30s} \ + DYNDNS_SERVER_BIND=${DYNDNS_SERVER_BIND:-:8080} \ + DYNDNS_SERVER_USERNAME=${DYNDNS_SERVER_USERNAME} \ + DYNDNS_SERVER_PASSWORD=${DYNDNS_SERVER_PASSWORD} \ + CLOUDFLARE_API_EMAIL="" \ + CLOUDFLARE_API_KEY="" \ + CLOUDFLARE_ZONES_IPV4="" \ + CLOUDFLARE_ZONES_IPV6="" \ + CLOUDFLARE_LOCAL_ADDRESS_IPV6="" WORKDIR /app -RUN set -ex \ - && apk add --update --no-cache ca-certificates tzdata \ - && update-ca-certificates \ - && rm -rf /var/cache/apk/* - -COPY --from=server_build /appbuild/server /app/server +COPY --from=server_build /appbuild/fritzbox-cloudflare-dyndns /app/fritzbox-cloudflare-dyndns EXPOSE 8080 -CMD ["./server"] +CMD ["./fritzbox-cloudflare-dyndns"] diff --git a/go.mod b/go.mod index 00d7ab1..dff5e64 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,21 @@ -module github.com/adrianrudnik/fritzbox-cloudflare-dyndns +module github.com/cromefire/fritzbox-cloudflare-dyndns -go 1.19 +go 1.21 require ( - github.com/cloudflare/cloudflare-go v0.61.0 + github.com/cloudflare/cloudflare-go v0.79.0 github.com/joho/godotenv v1.5.1 - github.com/sirupsen/logrus v1.9.0 - golang.org/x/net v0.7.0 + golang.org/x/net v0.17.0 gopkg.in/xmlpath.v2 v2.0.0-20150820204837-860cbeca3ebc ) require ( + github.com/goccy/go-json v0.10.2 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-retryablehttp v0.7.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/kr/pretty v0.3.1 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect - golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect + golang.org/x/time v0.3.0 // indirect ) diff --git a/go.sum b/go.sum index 351a6b2..9817de4 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,14 @@ github.com/cloudflare/cloudflare-go v0.61.0 h1:h39WkNSA3CIMktE8rleiEwaJSc7bYCNCpzLAzCp//Kc= github.com/cloudflare/cloudflare-go v0.61.0/go.mod h1:9XgyMNcw8L8JhTKjasJNxx3vE7YM36g+GfNoIKxYPpI= +github.com/cloudflare/cloudflare-go v0.79.0 h1:ErwCYDjFCYppDJlDJ/5WhsSmzegAUe2+K9qgFyQDg3M= +github.com/cloudflare/cloudflare-go v0.79.0/go.mod h1:gkHQf9xEubaQPEuerBuoinR9P8bf8a05Lq0X6WKy1Oc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= @@ -15,6 +19,8 @@ github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrj github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0= github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= +github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA= +github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -30,19 +36,30 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 h1:M73Iuj3xbbb9Uk1DYhzydthsj6oOd6l9bpuFcNoUvTs= golang.org/x/time v0.0.0-20220224211638-0e9765cccd65/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/main.go b/main.go index 66e06fc..6ad31f5 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,12 @@ package main import ( - "github.com/adrianrudnik/fritzbox-cloudflare-dyndns/pkg/avm" - "github.com/adrianrudnik/fritzbox-cloudflare-dyndns/pkg/cloudflare" - "github.com/adrianrudnik/fritzbox-cloudflare-dyndns/pkg/dyndns" + "github.com/cromefire/fritzbox-cloudflare-dyndns/pkg/avm" + "github.com/cromefire/fritzbox-cloudflare-dyndns/pkg/cloudflare" + "github.com/cromefire/fritzbox-cloudflare-dyndns/pkg/dyndns" + "github.com/cromefire/fritzbox-cloudflare-dyndns/pkg/logging" "github.com/joho/godotenv" - log "github.com/sirupsen/logrus" + "log/slog" "net" "net/http" "net/url" @@ -29,10 +30,10 @@ func main() { if ipv6LocalAddress != "" { localIp = net.ParseIP(ipv6LocalAddress) if localIp == nil { - log.Error("Failed to parse IP from DEVICE_LOCAL_ADDRESS_IPV6, exiting") + slog.Error("Failed to parse IP from DEVICE_LOCAL_ADDRESS_IPV6, exiting") return } - log.Info("Using the IPv6 Prefix to construct the IPv6 Address") + slog.Info("Using the IPv6 Prefix to construct the IPv6 Address") } startPollServer(updater.In, &localIp) @@ -45,7 +46,7 @@ func main() { <-shutdown - log.Info("Shutdown detected") + slog.Info("Shutdown detected") } func newFritzBox() *avm.FritzBox { @@ -58,12 +59,13 @@ func newFritzBox() *avm.FritzBox { v, err := url.ParseRequestURI(endpointUrl) if err != nil { - log.WithError(err).Panic("Failed to parse env FRITZBOX_ENDPOINT_URL") + slog.Error("Failed to parse env FRITZBOX_ENDPOINT_URL", logging.ErrorAttr(err)) + panic(err) } fb.Url = strings.TrimRight(v.String(), "/") } else { - log.Info("Env FRITZBOX_ENDPOINT_URL not found, disabling FritzBox polling") + slog.Info("Env FRITZBOX_ENDPOINT_URL not found, disabling FritzBox polling") return nil } @@ -74,7 +76,7 @@ func newFritzBox() *avm.FritzBox { v, err := time.ParseDuration(endpointTimeout) if err != nil { - log.WithError(err).Warn("Failed to parse FRITZBOX_ENDPOINT_TIMEOUT, using defaults") + slog.Warn("Failed to parse FRITZBOX_ENDPOINT_TIMEOUT, using defaults", logging.ErrorAttr(err)) } else { fb.Timeout = v } @@ -84,7 +86,7 @@ func newFritzBox() *avm.FritzBox { } func newUpdater() *cloudflare.Updater { - u := cloudflare.NewUpdater() + u := cloudflare.NewUpdater(slog.Default()) token := os.Getenv("CLOUDFLARE_API_TOKEN") email := os.Getenv("CLOUDFLARE_API_EMAIL") @@ -92,10 +94,10 @@ func newUpdater() *cloudflare.Updater { if token == "" { if email == "" || key == "" { - log.Info("Env CLOUDFLARE_API_TOKEN not found, disabling CloudFlare updates") + slog.Info("Env CLOUDFLARE_API_TOKEN not found, disabling CloudFlare updates") return u } else { - log.Warn("Using deprecated credentials via the API key") + slog.Warn("Using deprecated credentials via the API key") } } @@ -103,7 +105,7 @@ func newUpdater() *cloudflare.Updater { ipv6Zone := os.Getenv("CLOUDFLARE_ZONES_IPV6") if ipv4Zone == "" && ipv6Zone == "" { - log.Warn("Env CLOUDFLARE_ZONES_IPV4 and CLOUDFLARE_ZONES_IPV6 not found, disabling CloudFlare updates") + slog.Warn("Env CLOUDFLARE_ZONES_IPV4 and CLOUDFLARE_ZONES_IPV6 not found, disabling CloudFlare updates") return u } @@ -124,7 +126,7 @@ func newUpdater() *cloudflare.Updater { } if err != nil { - log.WithError(err).Error("Failed to init Cloudflare updater, disabling CloudFlare updates") + slog.Error("Failed to init Cloudflare updater, disabling CloudFlare updates") return u } @@ -135,22 +137,24 @@ func startPushServer(out chan<- *net.IP, localIp *net.IP) { bind := os.Getenv("DYNDNS_SERVER_BIND") if bind == "" { - log.Info("Env DYNDNS_SERVER_BIND not found, disabling DynDns server") + slog.Info("Env DYNDNS_SERVER_BIND not found, disabling DynDns server") return } - server := dyndns.NewServer(out, localIp) + server := dyndns.NewServer(out, localIp, slog.Default()) server.Username = os.Getenv("DYNDNS_SERVER_USERNAME") server.Password = os.Getenv("DYNDNS_SERVER_PASSWORD") s := &http.Server{ - Addr: bind, + Addr: bind, + ErrorLog: slog.NewLogLogger(slog.Default().Handler(), slog.LevelInfo), } http.HandleFunc("/ip", server.Handler) go func() { - log.Fatal(s.ListenAndServe()) + err := s.ListenAndServe() + slog.Error("Server stopped", logging.ErrorAttr(err)) }() } @@ -166,13 +170,13 @@ func startPollServer(out chan<- *net.IP, localIp *net.IP) { v, err := time.ParseDuration(interval) if err != nil { - log.WithError(err).Warn("Failed to parse FRITZBOX_ENDPOINT_INTERVAL, using defaults") + slog.Warn("Failed to parse FRITZBOX_ENDPOINT_INTERVAL, using defaults", logging.ErrorAttr(err)) ticker = time.NewTicker(300 * time.Second) } else { ticker = time.NewTicker(v) } } else { - log.Info("Env FRITZBOX_ENDPOINT_INTERVAL not found, disabling polling") + slog.Info("Env FRITZBOX_ENDPOINT_INTERVAL not found, disabling polling") return } @@ -181,15 +185,15 @@ func startPollServer(out chan<- *net.IP, localIp *net.IP) { lastV6 := net.IP{} poll := func() { - log.Debug("Polling WAN IPs from router") + slog.Debug("Polling WAN IPs from router") ipv4, err := fritzbox.GetWanIpv4() if err != nil { - log.WithError(err).Warn("Failed to poll WAN IPv4 from router") + slog.Warn("Failed to poll WAN IPv4 from router", logging.ErrorAttr(err)) } else { if !lastV4.Equal(ipv4) { - log.WithField("ipv4", ipv4).Info("New WAN IPv4 found") + slog.Info("New WAN IPv4 found", slog.Any("ipv4", ipv4)) out <- &ipv4 lastV4 = ipv4 } @@ -200,10 +204,10 @@ func startPollServer(out chan<- *net.IP, localIp *net.IP) { ipv6, err := fritzbox.GetwanIpv6() if err != nil { - log.WithError(err).Warn("Failed to poll WAN IPv6 from router") + slog.Warn("Failed to poll WAN IPv6 from router", logging.ErrorAttr(err)) } else { if !lastV6.Equal(ipv6) { - log.WithField("ipv6", ipv6).Info("New WAN IPv6 found") + slog.Info("New WAN IPv6 found", slog.Any("ipv6", ipv6)) out <- &ipv6 lastV6 = ipv6 } @@ -212,7 +216,7 @@ func startPollServer(out chan<- *net.IP, localIp *net.IP) { prefix, err := fritzbox.GetIpv6Prefix() if err != nil { - log.WithError(err).Warn("Failed to poll IPv6 Prefix from router") + slog.Warn("Failed to poll IPv6 Prefix from router", logging.ErrorAttr(err)) } else { if !lastV6.Equal(prefix.IP) { @@ -234,7 +238,7 @@ func startPollServer(out chan<- *net.IP, localIp *net.IP) { constructedIp[i] = b } - log.WithField("prefix", prefix).WithField("ipv6", constructedIp).Info("New IPv6 Prefix found") + slog.Info("New IPv6 Prefix found", slog.Any("prefix", prefix), slog.Any("ipv6", constructedIp)) out <- &constructedIp lastV6 = prefix.IP diff --git a/pkg/cloudflare/updater.go b/pkg/cloudflare/updater.go index fa9fdae..127be11 100644 --- a/pkg/cloudflare/updater.go +++ b/pkg/cloudflare/updater.go @@ -4,8 +4,9 @@ import ( "context" "fmt" cf "github.com/cloudflare/cloudflare-go" - log "github.com/sirupsen/logrus" + "github.com/cromefire/fritzbox-cloudflare-dyndns/pkg/logging" "golang.org/x/net/publicsuffix" + "log/slog" "net" "strings" "time" @@ -25,14 +26,16 @@ type Updater struct { isInit bool api *cf.API + log *slog.Logger In chan *net.IP } -func NewUpdater() *Updater { +func NewUpdater(log *slog.Logger) *Updater { return &Updater{ isInit: false, In: make(chan *net.IP, 10), + log: log.With(slog.String("module", "cloudflare")), } } @@ -131,7 +134,7 @@ func (u *Updater) spawnWorker() { for { select { case ip := <-u.In: - log.WithField("ip", ip).Info("Received update request") + u.log.Info("Received update request", slog.Any("ip", ip)) for _, action := range u.actions { // Skip IPv6 action mismatching IP version @@ -145,7 +148,7 @@ func (u *Updater) spawnWorker() { } // Create detailed sub-logger for this action - alog := log.WithField("domain", fmt.Sprintf("%s/IPv%d", action.DnsRecord, action.IpVersion)) + alog := u.log.With(slog.String("domain", fmt.Sprintf("%s/IPv%d", action.DnsRecord, action.IpVersion))) // Decide record type on ip version var recordType string @@ -167,7 +170,7 @@ func (u *Updater) spawnWorker() { }) if err != nil { - alog.WithError(err).Error("Action failed, could not research DNS records") + alog.Error("Action failed, could not research DNS records", logging.ErrorAttr(err)) continue } @@ -187,18 +190,18 @@ func (u *Updater) spawnWorker() { }) if err != nil { - alog.WithError(err).Error("Action failed, could not create DNS record") + alog.Error("Action failed, could not create DNS record", logging.ErrorAttr(err)) continue } } // Update existing records for _, record := range records { - alog.WithField("record-id", record.ID).Info("Updating DNS record") + alog.Info("Updating DNS record", slog.Any("record-id", record.ID)) // Ensure we submit all required fields even if they did not change,otherwise // cloudflare-go might revert them to default values. - err := u.api.UpdateDNSRecord(ctx, rc, cf.UpdateDNSRecordParams{ + _, err := u.api.UpdateDNSRecord(ctx, rc, cf.UpdateDNSRecordParams{ ID: record.ID, Content: ip.String(), TTL: record.TTL, @@ -206,7 +209,7 @@ func (u *Updater) spawnWorker() { }) if err != nil { - alog.WithError(err).Error("Action failed, could not update DNS record") + alog.Error("Action failed, could not update DNS record", logging.ErrorAttr(err)) continue } } diff --git a/pkg/dyndns/server.go b/pkg/dyndns/server.go index 56cce97..0b2d7e6 100644 --- a/pkg/dyndns/server.go +++ b/pkg/dyndns/server.go @@ -1,13 +1,14 @@ package dyndns import ( - log "github.com/sirupsen/logrus" + "github.com/cromefire/fritzbox-cloudflare-dyndns/pkg/logging" + "log/slog" "net" "net/http" ) type Server struct { - log *log.Entry + log *slog.Logger out chan<- *net.IP localIp *net.IP @@ -15,9 +16,9 @@ type Server struct { Password string } -func NewServer(out chan<- *net.IP, localIp *net.IP) *Server { +func NewServer(out chan<- *net.IP, localIp *net.IP, log *slog.Logger) *Server { return &Server{ - log: log.WithField("module", "dyndns"), + log: log.With(slog.String("module", "dyndns")), out: out, localIp: localIp, } @@ -29,8 +30,9 @@ func NewServer(out chan<- *net.IP, localIp *net.IP) *Server { // // Expected parameters can be // -// "ipaddr" IPv4 address -// "ip6addr" IPv6 address +// "v4" IPv4 address +// "v6" IPv6 address +// "prefix" IPv6 prefix // // see https://service.avm.de/help/de/FRITZ-Box-Fon-WLAN-7490/016/hilfe_dyndns func (s *Server) Handler(w http.ResponseWriter, r *http.Request) { @@ -51,7 +53,7 @@ func (s *Server) Handler(w http.ResponseWriter, r *http.Request) { // Parse IPv4 ipv4 := net.ParseIP(params.Get("v4")) if ipv4 != nil && ipv4.To4() != nil { - s.log.WithField("ipv4", ipv4).Info("Forwarding update request for IPv4") + s.log.Info("Forwarding update request for IPv4", slog.Any("ipv4", ipv4)) s.out <- &ipv4 } @@ -59,14 +61,14 @@ func (s *Server) Handler(w http.ResponseWriter, r *http.Request) { // Parse IPv6 ipv6 := net.ParseIP(params.Get("v6")) if ipv6 != nil && ipv6.To4() == nil { - s.log.WithField("ipv6", ipv6).Info("Forwarding update request for IPv6") + s.log.Info("Forwarding update request for IPv6", slog.Any("ipv6", ipv6)) s.out <- &ipv6 } } else { // Parse Prefix _, prefix, err := net.ParseCIDR(params.Get("prefix")) if err != nil { - s.log.WithError(err).Warn("Failed to parse prefix") + s.log.Warn("Failed to parse prefix", slog.Any("prefix", prefix), logging.ErrorAttr(err)) } else { constructedIp := make(net.IP, net.IPv6len) @@ -87,7 +89,7 @@ func (s *Server) Handler(w http.ResponseWriter, r *http.Request) { constructedIp[i] = b } - s.log.WithField("prefix", prefix).WithField("ipv6", constructedIp).Info("Forwarding update request for IPv6") + s.log.Info("Forwarding update request for IPv6", slog.Any("prefix", prefix), slog.Any("ipv6", constructedIp)) s.out <- &constructedIp } } diff --git a/pkg/logging/constants.go b/pkg/logging/constants.go new file mode 100644 index 0000000..0466223 --- /dev/null +++ b/pkg/logging/constants.go @@ -0,0 +1,3 @@ +package logging + +const ErrorKey = "error" diff --git a/pkg/logging/helpers.go b/pkg/logging/helpers.go new file mode 100644 index 0000000..20c4c0a --- /dev/null +++ b/pkg/logging/helpers.go @@ -0,0 +1,7 @@ +package logging + +import "log/slog" + +func ErrorAttr(value error) slog.Attr { + return slog.Any(ErrorKey, value) +} diff --git a/vendor/github.com/cloudflare/cloudflare-go/.gitignore b/vendor/github.com/cloudflare/cloudflare-go/.gitignore deleted file mode 100644 index 5acd306..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.idea -.vscode/ -cmd/flarectl/dist/ -cmd/flarectl/flarectl -cmd/flarectl/flarectl.exe diff --git a/vendor/github.com/cloudflare/cloudflare-go/.golintci.yaml b/vendor/github.com/cloudflare/cloudflare-go/.golintci.yaml deleted file mode 100644 index c885d96..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/.golintci.yaml +++ /dev/null @@ -1,38 +0,0 @@ -run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 1m - - # exit code when at least one issue was found, default is 1 - issues-exit-code: 1 - - # include test files or not, default is true - tests: true - - # default is true. Enables skipping of directories: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - skip-dirs-use-default: true - - modules-download-mode: readonly - -linters: - enable: - - bodyclose # ensure HTTP response bodies are successfully closed. - - contextcheck # check we are passing context an inherited context. - - gofmt # checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification. - - errname # checks that sentinel errors are prefixed with the `Err`` and error types are suffixed with the `Error``. - - errorlint # used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - - godot # check if comments end in a period. - - misspell # finds commonly misspelled English words in comments. - - nilerr # checks that there is no simultaneous return of nil error and an invalid value. - - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes. - - unparam # reports unused function parameters. - - whitespace # detection of leading and trailing whitespace. - - gosec # inspects source code for security problems. - - bidichk # checks for dangerous unicode character sequences. - - exportloopref # prevent scope issues with pointers in loops. - - goconst # use constants where values are repeated. - - reassign # checks that package variables are not reassigned. - - goimports # checks import grouping and code formatting. - -output: - format: colored-line-number diff --git a/vendor/github.com/cloudflare/cloudflare-go/.semgrep.yml b/vendor/github.com/cloudflare/cloudflare-go/.semgrep.yml deleted file mode 100644 index 000f8a2..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/.semgrep.yml +++ /dev/null @@ -1,35 +0,0 @@ -rules: - - id: rfc-5737-ip-address - languages: - - go - message: Where a real IPv4 address isn't needed, use IPv4 addresses from RFC5737. - paths: - include: - - '*.go' - patterns: - - pattern-regex: '\d+\.\d+\.\d+\.\d+' - - pattern-not-regex: '10\.\d+\.\d+.\d+' - - pattern-not-regex: '192\.168\.\d+.\d+' - - pattern-not-regex: '192\.0\.2\.\d+' # 192.0.2.0/24 (TEST-NET-1, rfc5737) - - pattern-not-regex: '198\.51\.100\.\d+' # 198.51.100.0/24 (TEST-NET-2, rfc5737) - - pattern-not-regex: '203\.0\.113\.\d+' # 203.0.113.0/24 (TEST-NET-3, rfc5737) - severity: WARNING - - id: rfc-3849-ip-address - languages: - - generic - message: Where a real IPv6 address isn't needed, use IPv6 addresses from RFC3849. - paths: - include: - - '*.go' - patterns: - - pattern-regex: '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))' - severity: WARNING - - - id: calling-errors-wrap - languages: [go] - message: 'Do not call `errors.Wrap`. Use `fmt.Errorf(".. : %w", err)` instead.' - patterns: - - pattern-either: - - pattern: | - errors.Wrap(...) - severity: WARNING diff --git a/vendor/github.com/cloudflare/cloudflare-go/.semgrepignore b/vendor/github.com/cloudflare/cloudflare-go/.semgrepignore deleted file mode 100644 index e12718f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/.semgrepignore +++ /dev/null @@ -1,22 +0,0 @@ -# Based on the default .semgrepignore documented here: - -# https://semgrep.dev/docs/ignoring-files-folders-code/#understanding-semgrep-defaults - -# but not ignoring '\*\_test.go'. - -# Ignore git items - -.gitignore -.git/ -:include .gitignore - -.semgrep -.semgrep_logs/ - -.github/ -.vscode/ -.changelog/ -CHANGELOG.md -go.mod -go.sum -README.md diff --git a/vendor/github.com/cloudflare/cloudflare-go/CHANGELOG.md b/vendor/github.com/cloudflare/cloudflare-go/CHANGELOG.md deleted file mode 100644 index 284b44c..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/CHANGELOG.md +++ /dev/null @@ -1,386 +0,0 @@ -## 0.62.0 (Unreleased) - -## 0.61.0 (15th February, 2023) - -ENHANCEMENTS: - -* cloudflare: make it clearer when we hit a server error and to retry later ([#1207](https://github.com/cloudflare/cloudflare-go/issues/1207)) -* devices_policy: Add new exclude_office_ips field to policy ([#1205](https://github.com/cloudflare/cloudflare-go/issues/1205)) -* dlp_profile: Use int rather than uint for allowed_match_count field ([#1200](https://github.com/cloudflare/cloudflare-go/issues/1200)) - -BUG FIXES: - -* dns: always send `tags` to allow clearing ([#1196](https://github.com/cloudflare/cloudflare-go/issues/1196)) -* stream: renamed `RequiredSignedURLs` to `RequireSignedURLs` ([#1202](https://github.com/cloudflare/cloudflare-go/issues/1202)) - -DEPENDENCIES: - -* deps: bumps github.com/urfave/cli/v2 from 2.24.2 to 2.24.3 ([#1199](https://github.com/cloudflare/cloudflare-go/issues/1199)) - -## 0.60.0 (1st February, 2023) - -BREAKING CHANGES: - -* queues: UpdateQueue has been updated to match the API and now correctly updates a Queue's name ([#1188](https://github.com/cloudflare/cloudflare-go/issues/1188)) - -ENHANCEMENTS: - -* dlp_profile: Add new allowed_match_count field to profiles ([#1193](https://github.com/cloudflare/cloudflare-go/issues/1193)) -* dns: allow sending empty strings to remove comments ([#1195](https://github.com/cloudflare/cloudflare-go/issues/1195)) -* magic_transit_ipsec_tunnel: makes customer endpoint an optional field for ipsec tunnel creation ([#1185](https://github.com/cloudflare/cloudflare-go/issues/1185)) -* rulesets: add support for `score_per_period` and `score_response_header_name` ([#1183](https://github.com/cloudflare/cloudflare-go/issues/1183)) - -DEPENDENCIES: - -* deps: bumps dependabot/fetch-metadata from 1.3.5 to 1.3.6 ([#1184](https://github.com/cloudflare/cloudflare-go/issues/1184)) -* deps: bumps github.com/urfave/cli/v2 from 2.23.7 to 2.24.1 ([#1180](https://github.com/cloudflare/cloudflare-go/issues/1180)) -* deps: bumps github.com/urfave/cli/v2 from 2.24.1 to 2.24.2 ([#1191](https://github.com/cloudflare/cloudflare-go/issues/1191)) -* deps: bumps goreleaser/goreleaser-action from 4.1.0 to 4.2.0 ([#1192](https://github.com/cloudflare/cloudflare-go/issues/1192)) - -## 0.59.0 (January 18th, 2023) - -BREAKING CHANGES: - -* dns: remove these read-only fields from `UpdateDNSRecordParams`: `CreatedOn`, `ModifiedOn`, `Meta`, `ZoneID`, `ZoneName`, `Proxiable`, and `Locked` ([#1170](https://github.com/cloudflare/cloudflare-go/issues/1170)) -* dns: the fields `CreatedOn` and `ModifiedOn` are removed from `ListDNSRecordsParams` ([#1173](https://github.com/cloudflare/cloudflare-go/issues/1173)) - -NOTES: - -* dns: remove additional lookup from `Update` operations when `Name` or `Type` was omitted ([#1170](https://github.com/cloudflare/cloudflare-go/issues/1170)) - -ENHANCEMENTS: - -* access_organization: add user_seat_expiration_inactive_time field ([#1159](https://github.com/cloudflare/cloudflare-go/issues/1159)) -* dns: `GetDNSRecord`, `UpdateDNSRecord` and `DeleteDNSRecord` now return the new, dedicated error `ErrMissingDNSRecordID` when an empty DNS record ID is given. ([#1174](https://github.com/cloudflare/cloudflare-go/issues/1174)) -* dns: the URL parameter `tag-match` for listing DNS records is now supported as the field `TagMatch` in `ListDNSRecordsParams` ([#1173](https://github.com/cloudflare/cloudflare-go/issues/1173)) -* dns: update default `per_page` attribute to 100 records ([#1171](https://github.com/cloudflare/cloudflare-go/issues/1171)) -* teams_rules: adds support for Egress Policies ([#1142](https://github.com/cloudflare/cloudflare-go/issues/1142)) -* workers: Add support for compatibility_date and compatibility_flags when upoading a worker script ([#1177](https://github.com/cloudflare/cloudflare-go/issues/1177)) -* workers: script upload now supports Queues bindings ([#1176](https://github.com/cloudflare/cloudflare-go/issues/1176)) - -BUG FIXES: - -* dns: don't send "priority" for list operations as it isn't supported and is only used for internal filtering ([#1167](https://github.com/cloudflare/cloudflare-go/issues/1167)) -* dns: the field `Tags` in `ListDNSRecordsParams` was not correctly serialized into URL queries ([#1173](https://github.com/cloudflare/cloudflare-go/issues/1173)) -* managednetworks: Update should be PUT ([#1172](https://github.com/cloudflare/cloudflare-go/issues/1172)) - -## 0.58.1 (January 5th, 2023) - -ENHANCEMENTS: - -* cloudflare: automatically redact sensitive values from HTTP interactions ([#1164](https://github.com/cloudflare/cloudflare-go/issues/1164)) - -## 0.58.0 (January 4th, 2023) - -BREAKING CHANGES: - -* dns: `DNSRecord` has been renamed to `GetDNSRecord` ([#1151](https://github.com/cloudflare/cloudflare-go/issues/1151)) -* dns: `DNSRecords` has been renamed to `ListDNSRecords` ([#1151](https://github.com/cloudflare/cloudflare-go/issues/1151)) -* dns: method signatures have been updated to align with the upcoming client conventions ([#1151](https://github.com/cloudflare/cloudflare-go/issues/1151)) -* origin_ca: renamed to `CreateOriginCertificate` to `CreateOriginCACertificate` ([#1161](https://github.com/cloudflare/cloudflare-go/issues/1161)) -* origin_ca: renamed to `OriginCARootCertificate` to `GetOriginCARootCertificate` ([#1161](https://github.com/cloudflare/cloudflare-go/issues/1161)) -* origin_ca: renamed to `OriginCertificate` to `GetOriginCACertificate` ([#1161](https://github.com/cloudflare/cloudflare-go/issues/1161)) -* origin_ca: renamed to `OriginCertificates` to `ListOriginCACertificates` ([#1161](https://github.com/cloudflare/cloudflare-go/issues/1161)) -* origin_ca: renamed to `RevokeOriginCertificate` to `RevokeOriginCACertificate` ([#1161](https://github.com/cloudflare/cloudflare-go/issues/1161)) - -ENHANCEMENTS: - -* dns: add support for tags and comments ([#1151](https://github.com/cloudflare/cloudflare-go/issues/1151)) -* mtls_certificate: add support for managing mTLS certificates and assocations ([#1150](https://github.com/cloudflare/cloudflare-go/issues/1150)) -* origin_ca: add support for using API keys, API tokens or API User service keys for interacting with Origin CA endpoints ([#1161](https://github.com/cloudflare/cloudflare-go/issues/1161)) -* workers: Add support for workers logpush enablement on script upload ([#1160](https://github.com/cloudflare/cloudflare-go/issues/1160)) - -BUG FIXES: - -* email_routing_destination: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) -* email_routing_rules: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) -* filter: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) -* firewall_rules: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) -* lockdown: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) -* queue: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) -* teams_list: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) -* workers_kv: use empty reponse struct on each page call ([#1156](https://github.com/cloudflare/cloudflare-go/issues/1156)) - -DEPENDENCIES: - -* deps: bumps github.com/hashicorp/go-retryablehttp from 0.7.1 to 0.7.2 ([#1162](https://github.com/cloudflare/cloudflare-go/issues/1162)) - -## 0.57.1 (December 23rd, 2022) - -ENHANCEMENTS: - -* tiered_cache: Add support for Tiered Caching interactions for setting Smart and Generic topologies ([#1149](https://github.com/cloudflare/cloudflare-go/issues/1149)) - -BUG FIXES: - -* workers: correctly set `body` value for non-ES module uploads ([#1155](https://github.com/cloudflare/cloudflare-go/issues/1155)) - -## 0.57.0 (December 22nd, 2022) - -BREAKING CHANGES: - -* workers: API operations now target account level resources instead of older zone level resources (these are a 1:1 now) ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers: method signatures have been updated to align with the upcoming client conventions ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers_bindings: method signatures have been updated to align with the upcoming client conventions ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers_cron_triggers: method signatures have been updated to align with the upcoming client conventions ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers_kv: method signatures have been updated to align with the upcoming client conventions ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers_routes: method signatures have been updated to align with the upcoming client conventions ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers_secrets: method signatures have been updated to align with the upcoming client conventions ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers_tails: method signatures have been updated to align with the upcoming client conventions ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) - -NOTES: - -* workers: all worker methods have been split into product ownership(-ish) files ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) -* workers: all worker methods now require an explicit `ResourceContainer` for endpoints instead of relying on the globally defined `api.AccountID` ([#1137](https://github.com/cloudflare/cloudflare-go/issues/1137)) - -ENHANCEMENTS: - -* managed_networks: add CRUD functionality for managednetworks ([#1148](https://github.com/cloudflare/cloudflare-go/issues/1148)) - -DEPENDENCIES: - -* deps: bumps goreleaser/goreleaser-action from 3.2.0 to 4.1.0 ([#1146](https://github.com/cloudflare/cloudflare-go/issues/1146)) - -## 0.56.0 (December 5th, 2022) - -BREAKING CHANGES: - -* pages: Changed the type of EnvVars in PagesProjectDeploymentConfigEnvironment & PagesProjectDeployment in order to properly support secrets. ([#1136](https://github.com/cloudflare/cloudflare-go/issues/1136)) - -NOTES: - -* pages: removed the v1 logs endpoint for Pages deployments. Please switch to v2: https://developers.cloudflare.com/api/operations/pages-deployment-get-deployment-logs ([#1135](https://github.com/cloudflare/cloudflare-go/issues/1135)) - -ENHANCEMENTS: - -* cache_rules: add ignore option to query string struct ([#1140](https://github.com/cloudflare/cloudflare-go/issues/1140)) -* pages: Updates bindings and other Functions related propreties. Service bindings, secrets, fail open/close and usage model are all now supported. ([#1136](https://github.com/cloudflare/cloudflare-go/issues/1136)) -* workers: Support for Workers Analytics Engine bindings ([#1133](https://github.com/cloudflare/cloudflare-go/issues/1133)) - -DEPENDENCIES: - -* deps: bumps github.com/urfave/cli/v2 from 2.23.5 to 2.23.6 ([#1139](https://github.com/cloudflare/cloudflare-go/issues/1139)) - -## 0.55.0 (November 23th, 2022) - -BREAKING CHANGES: - -* workers_kv: `CreateWorkersKVNamespace` has been updated to match the experimental client method signatures (https://github.com/cloudflare/cloudflare-go/blob/master/docs/experimental.md). ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `DeleteWorkersKVBulk` has been renamed to `DeleteWorkersKVEntries`. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `DeleteWorkersKVNamespace` has been updated to match the experimental client method signatures (https://github.com/cloudflare/cloudflare-go/blob/master/docs/experimental.md). ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `DeleteWorkersKV` has been renamed to `DeleteWorkersKVEntry`. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `ListWorkersKVNamespaces` has been updated to match the experimental client method signatures (https://github.com/cloudflare/cloudflare-go/blob/master/docs/experimental.md). ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `ListWorkersKVsWithOptions` has been removed. Use `ListWorkersKVKeys` instead and pass in the options. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `ListWorkersKVs` has been renamed to `ListWorkersKVKeys`. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `ReadWorkersKV` has been renamed to `GetWorkersKV`. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `UpdateWorkersKVNamespace` has been updated to match the experimental client method signatures (https://github.com/cloudflare/cloudflare-go/blob/master/docs/experimental.md). ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `WriteWorkersKVBulk` has been renamed to `WriteWorkersKVEntries`. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) -* workers_kv: `WriteWorkersKV` has been renamed to `WriteWorkersKVEntry`. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) - -ENHANCEMENTS: - -* device_posture_rule: add input fields crowdstrike ([#1126](https://github.com/cloudflare/cloudflare-go/issues/1126)) -* queue: add support queue API ([#1131](https://github.com/cloudflare/cloudflare-go/issues/1131)) -* r2: Add support for listing R2 buckets ([#1063](https://github.com/cloudflare/cloudflare-go/issues/1063)) -* workers_domain: add support for workers domain API ([#1130](https://github.com/cloudflare/cloudflare-go/issues/1130)) -* workers_kv: `ListWorkersKVNamespaces` automatically paginates all results unless `PerPage` is defined. ([#1115](https://github.com/cloudflare/cloudflare-go/issues/1115)) - -DEPENDENCIES: - -* deps: bumps github.com/urfave/cli/v2 from 2.23.4 to 2.23.5 ([#1127](https://github.com/cloudflare/cloudflare-go/issues/1127)) - -## 0.54.0 (November 9th, 2022) - -ENHANCEMENTS: - -* access: add support for service token rotation ([#1120](https://github.com/cloudflare/cloudflare-go/issues/1120)) -* deps: fix import grouping, code formatting and enable goimports linter ([#1121](https://github.com/cloudflare/cloudflare-go/issues/1121)) - -DEPENDENCIES: - -* deps: bumps dependabot/fetch-metadata from 1.3.4 to 1.3.5 ([#1123](https://github.com/cloudflare/cloudflare-go/issues/1123)) -* deps: bumps github.com/urfave/cli/v2 from 2.20.3 to 2.23.0 ([#1122](https://github.com/cloudflare/cloudflare-go/issues/1122)) -* deps: bumps github.com/urfave/cli/v2 from 2.23.0 to 2.23.2 ([#1124](https://github.com/cloudflare/cloudflare-go/issues/1124)) -* deps: bumps github.com/urfave/cli/v2 from 2.23.2 to 2.23.4 ([#1125](https://github.com/cloudflare/cloudflare-go/issues/1125)) - -## 0.53.0 (October 26th, 2022) - -BREAKING CHANGES: - -* account_member: `CreateAccountMember` has been updated to accept a `CreateAccountMemberParams` struct instead of multiple parameters ([#1095](https://github.com/cloudflare/cloudflare-go/issues/1095)) -* teams_list: updated methods to match the experimental client format ([#1114](https://github.com/cloudflare/cloudflare-go/issues/1114)) - -ENHANCEMENTS: - -* account_member: add support for domain scoped roles ([#1095](https://github.com/cloudflare/cloudflare-go/issues/1095)) -* cloudflare: expose `Messages` from the `Response` object ([#1106](https://github.com/cloudflare/cloudflare-go/issues/1106)) -* dlp: Adds support for DLP resources ([#1111](https://github.com/cloudflare/cloudflare-go/issues/1111)) -* teams_list: `List` operations now automatically paginate ([#1114](https://github.com/cloudflare/cloudflare-go/issues/1114)) -* total_tls: adds support for TotalTLS ([#1105](https://github.com/cloudflare/cloudflare-go/issues/1105)) -* waiting_room: add support for waiting room rules ([#1102](https://github.com/cloudflare/cloudflare-go/issues/1102)) - -DEPENDENCIES: - -* deps: `ioutil` package is being deprecated in favor of `io` ([#1116](https://github.com/cloudflare/cloudflare-go/issues/1116)) -* deps: bumps github.com/stretchr/testify from 1.8.0 to 1.8.1 ([#1119](https://github.com/cloudflare/cloudflare-go/issues/1119)) -* deps: bumps github.com/urfave/cli/v2 from 2.19.2 to 2.20.2 ([#1108](https://github.com/cloudflare/cloudflare-go/issues/1108)) -* deps: bumps github.com/urfave/cli/v2 from 2.20.2 to 2.20.3 ([#1118](https://github.com/cloudflare/cloudflare-go/issues/1118)) -* deps: bumps goreleaser/goreleaser-action from 3.1.0 to 3.2.0 ([#1112](https://github.com/cloudflare/cloudflare-go/issues/1112)) -* deps: remove `github.com/pkg/errors` in favor of `errors` ([#1117](https://github.com/cloudflare/cloudflare-go/issues/1117)) - -## 0.52.0 (October 12th, 2022) - -ENHANCEMENTS: - -* access: add UI read-only field to organizations ([#1104](https://github.com/cloudflare/cloudflare-go/issues/1104)) -* devices_policy: Add support for additional device settings policies ([#1090](https://github.com/cloudflare/cloudflare-go/issues/1090)) -* rulesets: add support for `sensitivity_level` to override all rule sensitivity ([#1093](https://github.com/cloudflare/cloudflare-go/issues/1093)) - -DEPENDENCIES: - -* deps: bumps dependabot/fetch-metadata from 1.3.3 to 1.3.4 ([#1097](https://github.com/cloudflare/cloudflare-go/issues/1097)) -* deps: bumps github.com/urfave/cli/v2 from 2.16.3 to 2.17.1 ([#1094](https://github.com/cloudflare/cloudflare-go/issues/1094)) -* deps: bumps github.com/urfave/cli/v2 from 2.17.1 to 2.19.2 ([#1103](https://github.com/cloudflare/cloudflare-go/issues/1103)) - -## 0.51.0 (September 28th, 2022) - -BREAKING CHANGES: - -* load_balancing: update method signatures to match experimental conventions ([#1084](https://github.com/cloudflare/cloudflare-go/issues/1084)) - -ENHANCEMENTS: - -* device_posture_rule: add input fields for linux OS ([#1087](https://github.com/cloudflare/cloudflare-go/issues/1087)) -* load_balancing: support adaptive_routing and location_strategy ([#1091](https://github.com/cloudflare/cloudflare-go/issues/1091)) - -BUG FIXES: - -* user-agent-blocking-rules: add missing managed_challenge validation and removed the deprecated whitelist one ([#1089](https://github.com/cloudflare/cloudflare-go/issues/1089)) - -## 0.50.0 (September 14, 2022) - -ENHANCEMENTS: - -* auditlogs: add support for hide_user_logs filter parameter ([#1075](https://github.com/cloudflare/cloudflare-go/issues/1075)) - -BUG FIXES: - -* cloudflare: exiting closer to the source on context timeouts to improve error messaging and better defend from potential edge cases ([#1080](https://github.com/cloudflare/cloudflare-go/issues/1080)) -* origin certificate: Fix API auth type used ([#1082](https://github.com/cloudflare/cloudflare-go/issues/1082)) - -DEPENDENCIES: - -* deps: bumps github.com/urfave/cli/v2 from 2.11.2 to 2.14.0 ([#1077](https://github.com/cloudflare/cloudflare-go/issues/1077)) -* deps: bumps github.com/urfave/cli/v2 from 2.14.0 to 2.14.1 ([#1081](https://github.com/cloudflare/cloudflare-go/issues/1081)) -* deps: bumps github.com/urfave/cli/v2 from 2.14.1 to 2.15.0 ([#1085](https://github.com/cloudflare/cloudflare-go/issues/1085)) -* deps: bumps github.com/urfave/cli/v2 from 2.15.0 to 2.16.3 ([#1086](https://github.com/cloudflare/cloudflare-go/issues/1086)) - -## 0.49.0 (August 31st, 2022) - -ENHANCEMENTS: - -* access_service_token: add support for refreshing an existing token in place ([#1074](https://github.com/cloudflare/cloudflare-go/issues/1074)) -* api: addded context and headers to Raw method ([#1068](https://github.com/cloudflare/cloudflare-go/issues/1068)) -* api_shield: add GET/PUT for API Shield Configuration ([#1059](https://github.com/cloudflare/cloudflare-go/issues/1059)) -* pages_project: Add `kv_namespaces`, `durable_object_namespaces`, `r2_buckets`, and `d1_databases` bindings to deployment config ([#1065](https://github.com/cloudflare/cloudflare-go/issues/1065)) -* pages_project: Add `preview_deployment_setting`, `preview_branch_includes`, and `preview_branch_excludes` to source config ([#1065](https://github.com/cloudflare/cloudflare-go/issues/1065)) -* pages_project: Add `production_branch` field ([#1065](https://github.com/cloudflare/cloudflare-go/issues/1065)) -* teams_account: add support for `os_distro_name` and `os_distro_revision` ([#1073](https://github.com/cloudflare/cloudflare-go/issues/1073)) -* url_normalization_settings: Add APIs to get and update URL normalization settings ([#1071](https://github.com/cloudflare/cloudflare-go/issues/1071)) -* workers: Support for multipart encoding for DownloadWorker on a module-format Worker script ([#1040](https://github.com/cloudflare/cloudflare-go/issues/1040)) - -BUG FIXES: - -* cloudflare: fix nil dereference error in makeRequestWithAuthTypeAndHeaders ([#1072](https://github.com/cloudflare/cloudflare-go/issues/1072)) -* email_routing_rules: Fix response for email routing catch all rule. ([#1070](https://github.com/cloudflare/cloudflare-go/issues/1070)) -* email_routing_settings: change enable endpoint from `enabled` to `enable` ([#1060](https://github.com/cloudflare/cloudflare-go/issues/1060)) -* stream: Update pctComplete to string from int ([#1066](https://github.com/cloudflare/cloudflare-go/issues/1066)) - -DEPENDENCIES: - -* deps: bumps goreleaser/goreleaser-action from 3.0.0 to 3.1.0 ([#1067](https://github.com/cloudflare/cloudflare-go/issues/1067)) - -## 0.48.0 (August 22nd, 2022) - -ENHANCEMENTS: - -* errors: add some error type convenience functions for mocking and inspection ([#1047](https://github.com/cloudflare/cloudflare-go/issues/1047)) -* pages_project: Add compatibility date and compatibility_flags to pages deployment configs ([#1051](https://github.com/cloudflare/cloudflare-go/issues/1051)) -* teams_account: add support for `suppress_footer` ([#1053](https://github.com/cloudflare/cloudflare-go/issues/1053)) - -BUG FIXES: - -* r2: fix create bucket endpoint ([#1035](https://github.com/cloudflare/cloudflare-go/issues/1035)) -* tunnel_configuration: Remove unnecessary double-unmarshalling due to changes in the API ([#1046](https://github.com/cloudflare/cloudflare-go/issues/1046)) - -## 0.47.1 (August 18th, 2022) - -BUG FIXES: - -* zonelockdown: add `Priority` to `ZoneLockdownCreateParams` and `ZoneLockdownUpdateParams` ([#1052](https://github.com/cloudflare/cloudflare-go/issues/1052)) - -## 0.47.0 (August 17th, 2022) - -BREAKING CHANGES: - -* certificate_packs: deprecate "custom" configuration for ACM everywhere ([#1032](https://github.com/cloudflare/cloudflare-go/issues/1032)) - -ENHANCEMENTS: - -* cloudflare: make it clear when the rate limit retries have been exhausted ([#1043](https://github.com/cloudflare/cloudflare-go/issues/1043)) -* email_routing_destination: Adds support for the email routing destination API ([#1034](https://github.com/cloudflare/cloudflare-go/issues/1034)) -* email_routing_rules: Adds support for the email routing rules API ([#1034](https://github.com/cloudflare/cloudflare-go/issues/1034)) -* email_routing_settings: Adds support for the email routing settings API ([#1034](https://github.com/cloudflare/cloudflare-go/issues/1034)) -* filter: fix double endpoint calls & moving towards common method signature ([#1016](https://github.com/cloudflare/cloudflare-go/issues/1016)) -* firewall_rule: fix double endpoint calls & moving towards common method signature ([#1016](https://github.com/cloudflare/cloudflare-go/issues/1016)) -* lockdown: automatically paginate `List` results unless `Page` and `PerPage` are provided ([#1017](https://github.com/cloudflare/cloudflare-go/issues/1017)) -* r2: Add in support for creating and deleting R2 buckets ([#1028](https://github.com/cloudflare/cloudflare-go/issues/1028)) -* rulesets: add support for `http_config_settings` phase and supporting actions ([#1036](https://github.com/cloudflare/cloudflare-go/issues/1036)) -* workers-account-settings: Add in support for Workers account settings API ([#1027](https://github.com/cloudflare/cloudflare-go/issues/1027)) -* workers-subdomain: Add in support Workers Subdomain API ([#1031](https://github.com/cloudflare/cloudflare-go/issues/1031)) -* workers-tail: Add in support for Workers tail API ([#1026](https://github.com/cloudflare/cloudflare-go/issues/1026)) -* workers: Add support for attaching a worker to a domain ([#1014](https://github.com/cloudflare/cloudflare-go/issues/1014)) -* workers: Add support to upload module workers ([#1010](https://github.com/cloudflare/cloudflare-go/issues/1010)) - -BUG FIXES: - -* email_routing_destination: Update API reference URLs ([#1038](https://github.com/cloudflare/cloudflare-go/issues/1038)) -* email_routing_rules: Update API reference URLs ([#1038](https://github.com/cloudflare/cloudflare-go/issues/1038)) -* email_routing_settings: Update API reference URLs ([#1038](https://github.com/cloudflare/cloudflare-go/issues/1038)) -* tunnel_routes: Fix not removing route when it contains virtual network ([#1030](https://github.com/cloudflare/cloudflare-go/issues/1030)) -* workers_test: Fix incorrect test from PR #1014 ([#1048](https://github.com/cloudflare/cloudflare-go/issues/1048)) -* workers_test: Use application/json mime-type in headers ([#1049](https://github.com/cloudflare/cloudflare-go/issues/1049)) - -DEPENDENCIES: - -* deps: bumps golang.org/x/tools/gopls from 0.9.3 to 0.9.4 ([#1044](https://github.com/cloudflare/cloudflare-go/issues/1044)) -* deps: bumps github.com/golangci/golangci-lint from 1.47.3 to 1.48.0 ([#1020](https://github.com/cloudflare/cloudflare-go/issues/1020)) -* deps: bumps github.com/urfave/cli/v2 from 2.11.1 to 2.11.2 ([#1042](https://github.com/cloudflare/cloudflare-go/issues/1042)) -* deps: bumps golang.org/x/tools/gopls from 0.9.1 to 0.9.2 ([#1037](https://github.com/cloudflare/cloudflare-go/issues/1037)) -* deps: bumps golang.org/x/tools/gopls from 0.9.2 to 0.9.3 ([#1039](https://github.com/cloudflare/cloudflare-go/issues/1039)) - -## 0.46.0 (3rd August, 2022) - -NOTES: - -* docs: add release notes ([#1001](https://github.com/cloudflare/cloudflare-go/issues/1001)) - -ENHANCEMENTS: - -* filter: automatically paginate `List` results unless `Page` and `PerPage` are provided ([#1004](https://github.com/cloudflare/cloudflare-go/issues/1004)) -* firewall_rule: automatically paginate `List` results unless `Page` and `PerPage` are provided ([#1004](https://github.com/cloudflare/cloudflare-go/issues/1004)) -* rulesets: add support for `http_custom_errors` phase ([#998](https://github.com/cloudflare/cloudflare-go/issues/998)) -* rulesets: add support for `serve_error` action ([#998](https://github.com/cloudflare/cloudflare-go/issues/998)) - -BUG FIXES: - -* access_application: fix inability to set bool values to false ([#1006](https://github.com/cloudflare/cloudflare-go/issues/1006)) -* rulesets: fix sni action parameter ([#1002](https://github.com/cloudflare/cloudflare-go/issues/1002)) - -DEPENDENCIES: - -* provider: bumps github.com/golangci/golangci-lint from 1.47.1 to 1.47.2 ([#1005](https://github.com/cloudflare/cloudflare-go/issues/1005)) -* provider: bumps github.com/golangci/golangci-lint from 1.47.2 to 1.47.3 ([#1008](https://github.com/cloudflare/cloudflare-go/issues/1008)) -* provider: bumps github.com/urfave/cli/v2 from 2.11.0 to 2.11.1 ([#1003](https://github.com/cloudflare/cloudflare-go/issues/1003)) - -## 0.45.0 (July 20th, 2022) diff --git a/vendor/github.com/cloudflare/cloudflare-go/CODE_OF_CONDUCT.md b/vendor/github.com/cloudflare/cloudflare-go/CODE_OF_CONDUCT.md deleted file mode 100644 index bfbc69d..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,77 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, sex characteristics, gender identity and expression, -level of experience, education, socio-economic status, nationality, personal -appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at ggalow@cloudflare.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq - diff --git a/vendor/github.com/cloudflare/cloudflare-go/LICENSE b/vendor/github.com/cloudflare/cloudflare-go/LICENSE deleted file mode 100644 index 39e4ddc..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2015-2022, Cloudflare. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this -list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors -may be used to endorse or promote products derived from this software without -specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cloudflare/cloudflare-go/README.md b/vendor/github.com/cloudflare/cloudflare-go/README.md deleted file mode 100644 index 988d1a3..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/README.md +++ /dev/null @@ -1,126 +0,0 @@ -# cloudflare-go - -[![Go Reference](https://pkg.go.dev/badge/github.com/cloudflare/cloudflare-go.svg)](https://pkg.go.dev/github.com/cloudflare/cloudflare-go) -![Test](https://github.com/cloudflare/cloudflare-go/workflows/Test/badge.svg) -[![Go Report Card](https://goreportcard.com/badge/github.com/cloudflare/cloudflare-go?style=flat-square)](https://goreportcard.com/report/github.com/cloudflare/cloudflare-go) - -> **Note**: This library is under active development as we expand it to cover -> our (expanding!) API. Consider the public API of this package a little -> unstable as we work towards a v1.0. - -A Go library for interacting with -[Cloudflare's API v4](https://api.cloudflare.com/). This library allows you to: - -- Manage and automate changes to your DNS records within Cloudflare -- Manage and automate changes to your zones (domains) on Cloudflare, including - adding new zones to your account -- List and modify the status of WAF (Web Application Firewall) rules for your - zones -- Fetch Cloudflare's IP ranges for automating your firewall whitelisting - -A command-line client, [flarectl](cmd/flarectl), is also available as part of -this project. - -## Features - -The current feature list includes: - -- [x] Cache purging -- [x] Cloudflare IPs -- [x] Custom hostnames -- [x] DNS Firewall -- [x] DNS Records -- [x] Firewall (partial) -- [x] Gateway Locations -- [x] [Keyless SSL](https://blog.cloudflare.com/keyless-ssl-the-nitty-gritty-technical-details/) -- [x] [Load Balancing](https://blog.cloudflare.com/introducing-load-balancing-intelligent-failover-with-cloudflare/) -- [x] [Logpush Jobs](https://developers.cloudflare.com/logs/logpush/) -- [x] Magic Transit / Magic WAN -- [x] mTLS Certificate Store -- [x] Notifications -- [ ] Organization Administration -- [x] [Origin CA](https://blog.cloudflare.com/universal-ssl-encryption-all-the-way-to-the-origin-for-free/) -- [x] [Railgun](https://www.cloudflare.com/railgun/) administration -- [x] Rate Limiting -- [x] User Administration (partial) -- [x] Web Application Firewall (WAF) -- [x] Workers KV -- [x] Zone cache settings -- [x] Zone Lockdown and User-Agent Block rules -- [x] Zones -- [x] Managed Headers - -Pull Requests are welcome, but please open an issue (or comment in an existing -issue) to discuss any non-trivial changes before submitting code. - -## Installation - -You need a working Go environment. We officially support only currently supported Go versions according to [Go project's release policy](https://go.dev/doc/devel/release#policy). - -``` -go get github.com/cloudflare/cloudflare-go -``` - -## Getting Started - -```go -package main - -import ( - "context" - "fmt" - "log" - "os" - - "github.com/cloudflare/cloudflare-go" -) - -func main() { - // Construct a new API object using a global API key - api, err := cloudflare.New(os.Getenv("CLOUDFLARE_API_KEY"), os.Getenv("CLOUDFLARE_API_EMAIL")) - // alternatively, you can use a scoped API token - // api, err := cloudflare.NewWithAPIToken(os.Getenv("CLOUDFLARE_API_TOKEN")) - if err != nil { - log.Fatal(err) - } - - // Most API calls require a Context - ctx := context.Background() - - // Fetch user details on the account - u, err := api.UserDetails(ctx) - if err != nil { - log.Fatal(err) - } - // Print user details - fmt.Println(u) - - // Fetch the zone ID - id, err := api.ZoneIDByName("example.com") // Assuming example.com exists in your Cloudflare account already - if err != nil { - log.Fatal(err) - } - - // Fetch zone details - zone, err := api.ZoneDetails(ctx, id) - if err != nil { - log.Fatal(err) - } - // Print zone details - fmt.Println(zone) -} -``` - -Also refer to the -[API documentation](https://pkg.go.dev/github.com/cloudflare/cloudflare-go) for -how to use this package in-depth. - -## Experimental improvements - -This library is starting to ship with experimental improvements that are not yet -ready for production but will be introduced before the next major version. See -[experimental README](/docs/experimental.md) for full details. - -# License - -BSD licensed. See the [LICENSE](LICENSE) file for details. diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_application.go b/vendor/github.com/cloudflare/cloudflare-go/access_application.go deleted file mode 100644 index 9b5a6aa..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_application.go +++ /dev/null @@ -1,313 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AccessApplicationType represents the application type. -type AccessApplicationType string - -// These constants represent all valid application types. -const ( - SelfHosted AccessApplicationType = "self_hosted" - SSH AccessApplicationType = "ssh" - VNC AccessApplicationType = "vnc" - Biso AccessApplicationType = "biso" - AppLauncher AccessApplicationType = "app_launcher" - Warp AccessApplicationType = "warp" - Bookmark AccessApplicationType = "bookmark" - Saas AccessApplicationType = "saas" -) - -// AccessApplication represents an Access application. -type AccessApplication struct { - GatewayRules []AccessApplicationGatewayRule `json:"gateway_rules,omitempty"` - AllowedIdps []string `json:"allowed_idps,omitempty"` - CustomDenyMessage string `json:"custom_deny_message,omitempty"` - LogoURL string `json:"logo_url,omitempty"` - AUD string `json:"aud,omitempty"` - Domain string `json:"domain"` - Type AccessApplicationType `json:"type,omitempty"` - SessionDuration string `json:"session_duration,omitempty"` - SameSiteCookieAttribute string `json:"same_site_cookie_attribute,omitempty"` - CustomDenyURL string `json:"custom_deny_url,omitempty"` - Name string `json:"name"` - ID string `json:"id,omitempty"` - PrivateAddress string `json:"private_address"` - CorsHeaders *AccessApplicationCorsHeaders `json:"cors_headers,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - SaasApplication *SaasApplication `json:"saas_app,omitempty"` - AutoRedirectToIdentity *bool `json:"auto_redirect_to_identity,omitempty"` - SkipInterstitial *bool `json:"skip_interstitial,omitempty"` - AppLauncherVisible *bool `json:"app_launcher_visible,omitempty"` - EnableBindingCookie *bool `json:"enable_binding_cookie,omitempty"` - HttpOnlyCookieAttribute *bool `json:"http_only_cookie_attribute,omitempty"` - ServiceAuth401Redirect *bool `json:"service_auth_401_redirect,omitempty"` -} - -type AccessApplicationGatewayRule struct { - ID string `json:"id,omitempty"` -} - -// AccessApplicationCorsHeaders represents the CORS HTTP headers for an Access -// Application. -type AccessApplicationCorsHeaders struct { - AllowedMethods []string `json:"allowed_methods,omitempty"` - AllowedOrigins []string `json:"allowed_origins,omitempty"` - AllowedHeaders []string `json:"allowed_headers,omitempty"` - AllowAllMethods bool `json:"allow_all_methods,omitempty"` - AllowAllHeaders bool `json:"allow_all_headers,omitempty"` - AllowAllOrigins bool `json:"allow_all_origins,omitempty"` - AllowCredentials bool `json:"allow_credentials,omitempty"` - MaxAge int `json:"max_age,omitempty"` -} - -// AccessApplicationListResponse represents the response from the list -// access applications endpoint. -type AccessApplicationListResponse struct { - Result []AccessApplication `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessApplicationDetailResponse is the API response, containing a single -// access application. -type AccessApplicationDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessApplication `json:"result"` -} - -type SourceConfig struct { - Name string `json:"name,omitempty"` - NameByIDP map[string]string `json:"name_by_idp,omitempty"` -} - -type SAMLAttributeConfig struct { - Name string `json:"name,omitempty"` - NameFormat string `json:"name_format,omitempty"` - FriendlyName string `json:"friendly_name,omitempty"` - Required bool `json:"required,omitempty"` - Source SourceConfig `json:"source"` -} - -type SaasApplication struct { - AppID string `json:"app_id,omitempty"` - ConsumerServiceUrl string `json:"consumer_service_url,omitempty"` - SPEntityID string `json:"sp_entity_id,omitempty"` - PublicKey string `json:"public_key,omitempty"` - IDPEntityID string `json:"idp_entity_id,omitempty"` - NameIDFormat string `json:"name_id_format,omitempty"` - SSOEndpoint string `json:"sso_endpoint,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - CustomAttributes []SAMLAttributeConfig `json:"custom_attributes,omitempty"` -} - -// AccessApplications returns all applications within an account. -// -// API reference: https://api.cloudflare.com/#access-applications-list-access-applications -func (api *API) AccessApplications(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccessApplication, ResultInfo, error) { - return api.accessApplications(ctx, accountID, pageOpts, AccountRouteRoot) -} - -// ZoneLevelAccessApplications returns all applications within a zone. -// -// API reference: https://api.cloudflare.com/#zone-level-access-applications-list-access-applications -func (api *API) ZoneLevelAccessApplications(ctx context.Context, zoneID string, pageOpts PaginationOptions) ([]AccessApplication, ResultInfo, error) { - return api.accessApplications(ctx, zoneID, pageOpts, ZoneRouteRoot) -} - -func (api *API) accessApplications(ctx context.Context, id string, pageOpts PaginationOptions, routeRoot RouteRoot) ([]AccessApplication, ResultInfo, error) { - uri := buildURI(fmt.Sprintf("/%s/%s/access/apps", routeRoot, id), pageOpts) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessApplication{}, ResultInfo{}, err - } - - var accessApplicationListResponse AccessApplicationListResponse - err = json.Unmarshal(res, &accessApplicationListResponse) - if err != nil { - return []AccessApplication{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessApplicationListResponse.Result, accessApplicationListResponse.ResultInfo, nil -} - -// AccessApplication returns a single application based on the -// application ID. -// -// API reference: https://api.cloudflare.com/#access-applications-access-applications-details -func (api *API) AccessApplication(ctx context.Context, accountID, applicationID string) (AccessApplication, error) { - return api.accessApplication(ctx, accountID, applicationID, AccountRouteRoot) -} - -// ZoneLevelAccessApplication returns a single zone level application based on the -// application ID. -// -// API reference: https://api.cloudflare.com/#zone-level-access-applications-access-applications-details -func (api *API) ZoneLevelAccessApplication(ctx context.Context, zoneID, applicationID string) (AccessApplication, error) { - return api.accessApplication(ctx, zoneID, applicationID, ZoneRouteRoot) -} - -func (api *API) accessApplication(ctx context.Context, id, applicationID string, routeRoot RouteRoot) (AccessApplication, error) { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s", - routeRoot, - id, - applicationID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessApplication{}, err - } - - var accessApplicationDetailResponse AccessApplicationDetailResponse - err = json.Unmarshal(res, &accessApplicationDetailResponse) - if err != nil { - return AccessApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessApplicationDetailResponse.Result, nil -} - -// CreateAccessApplication creates a new access application. -// -// API reference: https://api.cloudflare.com/#access-applications-create-access-application -func (api *API) CreateAccessApplication(ctx context.Context, accountID string, accessApplication AccessApplication) (AccessApplication, error) { - return api.createAccessApplication(ctx, accountID, accessApplication, AccountRouteRoot) -} - -// CreateZoneLevelAccessApplication creates a new zone level access application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-applications-create-access-application -func (api *API) CreateZoneLevelAccessApplication(ctx context.Context, zoneID string, accessApplication AccessApplication) (AccessApplication, error) { - return api.createAccessApplication(ctx, zoneID, accessApplication, ZoneRouteRoot) -} - -func (api *API) createAccessApplication(ctx context.Context, id string, accessApplication AccessApplication, routeRoot RouteRoot) (AccessApplication, error) { - uri := fmt.Sprintf("/%s/%s/access/apps", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, accessApplication) - if err != nil { - return AccessApplication{}, err - } - - var accessApplicationDetailResponse AccessApplicationDetailResponse - err = json.Unmarshal(res, &accessApplicationDetailResponse) - if err != nil { - return AccessApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessApplicationDetailResponse.Result, nil -} - -// UpdateAccessApplication updates an existing access application. -// -// API reference: https://api.cloudflare.com/#access-applications-update-access-application -func (api *API) UpdateAccessApplication(ctx context.Context, accountID string, accessApplication AccessApplication) (AccessApplication, error) { - return api.updateAccessApplication(ctx, accountID, accessApplication, AccountRouteRoot) -} - -// UpdateZoneLevelAccessApplication updates an existing zone level access application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-applications-update-access-application -func (api *API) UpdateZoneLevelAccessApplication(ctx context.Context, zoneID string, accessApplication AccessApplication) (AccessApplication, error) { - return api.updateAccessApplication(ctx, zoneID, accessApplication, ZoneRouteRoot) -} - -func (api *API) updateAccessApplication(ctx context.Context, id string, accessApplication AccessApplication, routeRoot RouteRoot) (AccessApplication, error) { - if accessApplication.ID == "" { - return AccessApplication{}, fmt.Errorf("access application ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s", - routeRoot, - id, - accessApplication.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, accessApplication) - if err != nil { - return AccessApplication{}, err - } - - var accessApplicationDetailResponse AccessApplicationDetailResponse - err = json.Unmarshal(res, &accessApplicationDetailResponse) - if err != nil { - return AccessApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessApplicationDetailResponse.Result, nil -} - -// DeleteAccessApplication deletes an access application. -// -// API reference: https://api.cloudflare.com/#access-applications-delete-access-application -func (api *API) DeleteAccessApplication(ctx context.Context, accountID, applicationID string) error { - return api.deleteAccessApplication(ctx, accountID, applicationID, AccountRouteRoot) -} - -// DeleteZoneLevelAccessApplication deletes a zone level access application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-applications-delete-access-application -func (api *API) DeleteZoneLevelAccessApplication(ctx context.Context, zoneID, applicationID string) error { - return api.deleteAccessApplication(ctx, zoneID, applicationID, ZoneRouteRoot) -} - -func (api *API) deleteAccessApplication(ctx context.Context, id, applicationID string, routeRoot RouteRoot) error { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s", - routeRoot, - id, - applicationID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} - -// RevokeAccessApplicationTokens revokes tokens associated with an -// access application. -// -// API reference: https://api.cloudflare.com/#access-applications-revoke-access-tokens -func (api *API) RevokeAccessApplicationTokens(ctx context.Context, accountID, applicationID string) error { - return api.revokeAccessApplicationTokens(ctx, accountID, applicationID, AccountRouteRoot) -} - -// RevokeZoneLevelAccessApplicationTokens revokes tokens associated with a zone level -// access application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-applications-revoke-access-tokens -func (api *API) RevokeZoneLevelAccessApplicationTokens(ctx context.Context, zoneID, applicationID string) error { - return api.revokeAccessApplicationTokens(ctx, zoneID, applicationID, ZoneRouteRoot) -} - -func (api *API) revokeAccessApplicationTokens(ctx context.Context, id string, applicationID string, routeRoot RouteRoot) error { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s/revoke-tokens", - routeRoot, - id, - applicationID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_audit_log.go b/vendor/github.com/cloudflare/cloudflare-go/access_audit_log.go deleted file mode 100644 index 1627914..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_audit_log.go +++ /dev/null @@ -1,85 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "strconv" - "time" -) - -// AccessAuditLogRecord is the structure of a single Access Audit Log entry. -type AccessAuditLogRecord struct { - UserEmail string `json:"user_email"` - IPAddress string `json:"ip_address"` - AppUID string `json:"app_uid"` - AppDomain string `json:"app_domain"` - Action string `json:"action"` - Connection string `json:"connection"` - Allowed bool `json:"allowed"` - CreatedAt *time.Time `json:"created_at"` - RayID string `json:"ray_id"` -} - -// AccessAuditLogListResponse represents the response from the list -// access applications endpoint. -type AccessAuditLogListResponse struct { - Result []AccessAuditLogRecord `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessAuditLogFilterOptions provides the structure of available audit log -// filters. -type AccessAuditLogFilterOptions struct { - Direction string - Since *time.Time - Until *time.Time - Limit int -} - -// AccessAuditLogs retrieves all audit logs for the Access service. -// -// API reference: https://api.cloudflare.com/#access-requests-access-requests-audit -func (api *API) AccessAuditLogs(ctx context.Context, accountID string, opts AccessAuditLogFilterOptions) ([]AccessAuditLogRecord, error) { - uri := fmt.Sprintf("/accounts/%s/access/logs/access-requests?%s", accountID, opts.Encode()) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessAuditLogRecord{}, err - } - - var accessAuditLogListResponse AccessAuditLogListResponse - err = json.Unmarshal(res, &accessAuditLogListResponse) - if err != nil { - return []AccessAuditLogRecord{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessAuditLogListResponse.Result, nil -} - -// Encode is a custom method for encoding the filter options into a usable HTTP -// query parameter string. -func (a AccessAuditLogFilterOptions) Encode() string { - v := url.Values{} - - if a.Direction != "" { - v.Set("direction", a.Direction) - } - - if a.Limit > 0 { - v.Set("limit", strconv.Itoa(a.Limit)) - } - - if a.Since != nil { - v.Set("since", (*a.Since).Format(time.RFC3339)) - } - - if a.Until != nil { - v.Set("until", (*a.Until).Format(time.RFC3339)) - } - - return v.Encode() -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_bookmark.go b/vendor/github.com/cloudflare/cloudflare-go/access_bookmark.go deleted file mode 100644 index 6a335b6..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_bookmark.go +++ /dev/null @@ -1,205 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AccessBookmark represents an Access bookmark application. -type AccessBookmark struct { - ID string `json:"id,omitempty"` - Domain string `json:"domain"` - Name string `json:"name"` - LogoURL string `json:"logo_url,omitempty"` - AppLauncherVisible *bool `json:"app_launcher_visible,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -// AccessBookmarkListResponse represents the response from the list -// access bookmarks endpoint. -type AccessBookmarkListResponse struct { - Result []AccessBookmark `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessBookmarkDetailResponse is the API response, containing a single -// access bookmark. -type AccessBookmarkDetailResponse struct { - Response - Result AccessBookmark `json:"result"` -} - -// AccessBookmarks returns all bookmarks within an account. -// -// API reference: https://api.cloudflare.com/#access-bookmarks-list-access-bookmarks -func (api *API) AccessBookmarks(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccessBookmark, ResultInfo, error) { - return api.accessBookmarks(ctx, accountID, pageOpts, AccountRouteRoot) -} - -// ZoneLevelAccessBookmarks returns all bookmarks within a zone. -// -// API reference: https://api.cloudflare.com/#zone-level-access-bookmarks-list-access-bookmarks -func (api *API) ZoneLevelAccessBookmarks(ctx context.Context, zoneID string, pageOpts PaginationOptions) ([]AccessBookmark, ResultInfo, error) { - return api.accessBookmarks(ctx, zoneID, pageOpts, ZoneRouteRoot) -} - -func (api *API) accessBookmarks(ctx context.Context, id string, pageOpts PaginationOptions, routeRoot RouteRoot) ([]AccessBookmark, ResultInfo, error) { - uri := buildURI(fmt.Sprintf("/%s/%s/access/bookmarks", routeRoot, id), pageOpts) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessBookmark{}, ResultInfo{}, err - } - - var accessBookmarkListResponse AccessBookmarkListResponse - err = json.Unmarshal(res, &accessBookmarkListResponse) - if err != nil { - return []AccessBookmark{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessBookmarkListResponse.Result, accessBookmarkListResponse.ResultInfo, nil -} - -// AccessBookmark returns a single bookmark based on the -// bookmark ID. -// -// API reference: https://api.cloudflare.com/#access-bookmarks-access-bookmarks-details -func (api *API) AccessBookmark(ctx context.Context, accountID, bookmarkID string) (AccessBookmark, error) { - return api.accessBookmark(ctx, accountID, bookmarkID, AccountRouteRoot) -} - -// ZoneLevelAccessBookmark returns a single zone level bookmark based on the -// bookmark ID. -// -// API reference: https://api.cloudflare.com/#zone-level-access-bookmarks-access-bookmarks-details -func (api *API) ZoneLevelAccessBookmark(ctx context.Context, zoneID, bookmarkID string) (AccessBookmark, error) { - return api.accessBookmark(ctx, zoneID, bookmarkID, ZoneRouteRoot) -} - -func (api *API) accessBookmark(ctx context.Context, id, bookmarkID string, routeRoot RouteRoot) (AccessBookmark, error) { - uri := fmt.Sprintf( - "/%s/%s/access/bookmarks/%s", - routeRoot, - id, - bookmarkID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessBookmark{}, err - } - - var accessBookmarkDetailResponse AccessBookmarkDetailResponse - err = json.Unmarshal(res, &accessBookmarkDetailResponse) - if err != nil { - return AccessBookmark{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessBookmarkDetailResponse.Result, nil -} - -// CreateAccessBookmark creates a new access bookmark. -// -// API reference: https://api.cloudflare.com/#access-bookmarks-create-access-bookmark -func (api *API) CreateAccessBookmark(ctx context.Context, accountID string, accessBookmark AccessBookmark) (AccessBookmark, error) { - return api.createAccessBookmark(ctx, accountID, accessBookmark, AccountRouteRoot) -} - -// CreateZoneLevelAccessBookmark creates a new zone level access bookmark. -// -// API reference: https://api.cloudflare.com/#zone-level-access-bookmarks-create-access-bookmark -func (api *API) CreateZoneLevelAccessBookmark(ctx context.Context, zoneID string, accessBookmark AccessBookmark) (AccessBookmark, error) { - return api.createAccessBookmark(ctx, zoneID, accessBookmark, ZoneRouteRoot) -} - -func (api *API) createAccessBookmark(ctx context.Context, id string, accessBookmark AccessBookmark, routeRoot RouteRoot) (AccessBookmark, error) { - uri := fmt.Sprintf("/%s/%s/access/bookmarks", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, accessBookmark) - if err != nil { - return AccessBookmark{}, err - } - - var accessBookmarkDetailResponse AccessBookmarkDetailResponse - err = json.Unmarshal(res, &accessBookmarkDetailResponse) - if err != nil { - return AccessBookmark{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessBookmarkDetailResponse.Result, nil -} - -// UpdateAccessBookmark updates an existing access bookmark. -// -// API reference: https://api.cloudflare.com/#access-bookmarks-update-access-bookmark -func (api *API) UpdateAccessBookmark(ctx context.Context, accountID string, accessBookmark AccessBookmark) (AccessBookmark, error) { - return api.updateAccessBookmark(ctx, accountID, accessBookmark, AccountRouteRoot) -} - -// UpdateZoneLevelAccessBookmark updates an existing zone level access bookmark. -// -// API reference: https://api.cloudflare.com/#zone-level-access-bookmarks-update-access-bookmark -func (api *API) UpdateZoneLevelAccessBookmark(ctx context.Context, zoneID string, accessBookmark AccessBookmark) (AccessBookmark, error) { - return api.updateAccessBookmark(ctx, zoneID, accessBookmark, ZoneRouteRoot) -} - -func (api *API) updateAccessBookmark(ctx context.Context, id string, accessBookmark AccessBookmark, routeRoot RouteRoot) (AccessBookmark, error) { - if accessBookmark.ID == "" { - return AccessBookmark{}, fmt.Errorf("access bookmark ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/access/bookmarks/%s", - routeRoot, - id, - accessBookmark.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, accessBookmark) - if err != nil { - return AccessBookmark{}, err - } - - var accessBookmarkDetailResponse AccessBookmarkDetailResponse - err = json.Unmarshal(res, &accessBookmarkDetailResponse) - if err != nil { - return AccessBookmark{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessBookmarkDetailResponse.Result, nil -} - -// DeleteAccessBookmark deletes an access bookmark. -// -// API reference: https://api.cloudflare.com/#access-bookmarks-delete-access-bookmark -func (api *API) DeleteAccessBookmark(ctx context.Context, accountID, bookmarkID string) error { - return api.deleteAccessBookmark(ctx, accountID, bookmarkID, AccountRouteRoot) -} - -// DeleteZoneLevelAccessBookmark deletes a zone level access bookmark. -// -// API reference: https://api.cloudflare.com/#zone-level-access-bookmarks-delete-access-bookmark -func (api *API) DeleteZoneLevelAccessBookmark(ctx context.Context, zoneID, bookmarkID string) error { - return api.deleteAccessBookmark(ctx, zoneID, bookmarkID, ZoneRouteRoot) -} - -func (api *API) deleteAccessBookmark(ctx context.Context, id, bookmarkID string, routeRoot RouteRoot) error { - uri := fmt.Sprintf( - "/%s/%s/access/bookmarks/%s", - routeRoot, - id, - bookmarkID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_ca_certificate.go b/vendor/github.com/cloudflare/cloudflare-go/access_ca_certificate.go deleted file mode 100644 index 1845bdb..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_ca_certificate.go +++ /dev/null @@ -1,164 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// AccessCACertificate is the structure of the CA certificate used for -// short lived certificates. -type AccessCACertificate struct { - ID string `json:"id"` - Aud string `json:"aud"` - PublicKey string `json:"public_key"` -} - -// AccessCACertificateListResponse represents the response of all CA -// certificates within Access. -type AccessCACertificateListResponse struct { - Response - Result []AccessCACertificate `json:"result"` -} - -// AccessCACertificateResponse represents the response of a single CA -// certificate. -type AccessCACertificateResponse struct { - Response - Result AccessCACertificate `json:"result"` -} - -// AccessCACertificates returns all CA certificates within Access. -// -// API reference: https://api.cloudflare.com/#access-short-lived-certificates-list-short-lived-certificates -func (api *API) AccessCACertificates(ctx context.Context, accountID string) ([]AccessCACertificate, error) { - return api.accessCACertificates(ctx, accountID, AccountRouteRoot) -} - -// ZoneLevelAccessCACertificates returns all zone level CA certificates within Access. -// -// API reference: https://api.cloudflare.com/#zone-level-access-short-lived-certificates-list-short-lived-certificates -func (api *API) ZoneLevelAccessCACertificates(ctx context.Context, zoneID string) ([]AccessCACertificate, error) { - return api.accessCACertificates(ctx, zoneID, ZoneRouteRoot) -} - -func (api *API) accessCACertificates(ctx context.Context, id string, routeRoot RouteRoot) ([]AccessCACertificate, error) { - uri := fmt.Sprintf("/%s/%s/access/apps/ca", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessCACertificate{}, err - } - - var accessCAListResponse AccessCACertificateListResponse - err = json.Unmarshal(res, &accessCAListResponse) - if err != nil { - return []AccessCACertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessCAListResponse.Result, nil -} - -// AccessCACertificate returns a single CA certificate associated with an Access -// Application. -// -// API reference: https://api.cloudflare.com/#access-short-lived-certificates-short-lived-certificate-details -func (api *API) AccessCACertificate(ctx context.Context, accountID, applicationID string) (AccessCACertificate, error) { - return api.accessCACertificate(ctx, accountID, applicationID, AccountRouteRoot) -} - -// ZoneLevelAccessCACertificate returns a single zone level CA certificate associated with an Access -// Application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-short-lived-certificates-short-lived-certificate-details -func (api *API) ZoneLevelAccessCACertificate(ctx context.Context, zoneID, applicationID string) (AccessCACertificate, error) { - return api.accessCACertificate(ctx, zoneID, applicationID, ZoneRouteRoot) -} - -func (api *API) accessCACertificate(ctx context.Context, id, applicationID string, routeRoot RouteRoot) (AccessCACertificate, error) { - uri := fmt.Sprintf("/%s/%s/access/apps/%s/ca", routeRoot, id, applicationID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessCACertificate{}, err - } - - var accessCAResponse AccessCACertificateResponse - err = json.Unmarshal(res, &accessCAResponse) - if err != nil { - return AccessCACertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessCAResponse.Result, nil -} - -// CreateAccessCACertificate creates a new CA certificate for an Access -// Application. -// -// API reference: https://api.cloudflare.com/#access-short-lived-certificates-create-short-lived-certificate -func (api *API) CreateAccessCACertificate(ctx context.Context, accountID, applicationID string) (AccessCACertificate, error) { - return api.createAccessCACertificate(ctx, accountID, applicationID, AccountRouteRoot) -} - -// CreateZoneLevelAccessCACertificate creates a new zone level CA certificate for an Access -// Application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-short-lived-certificates-create-short-lived-certificate -func (api *API) CreateZoneLevelAccessCACertificate(ctx context.Context, zoneID string, applicationID string) (AccessCACertificate, error) { - return api.createAccessCACertificate(ctx, zoneID, applicationID, ZoneRouteRoot) -} - -func (api *API) createAccessCACertificate(ctx context.Context, id string, applicationID string, routeRoot RouteRoot) (AccessCACertificate, error) { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s/ca", - routeRoot, - id, - applicationID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return AccessCACertificate{}, err - } - - var accessCACertificate AccessCACertificateResponse - err = json.Unmarshal(res, &accessCACertificate) - if err != nil { - return AccessCACertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessCACertificate.Result, nil -} - -// DeleteAccessCACertificate deletes an Access CA certificate on a defined -// Access Application. -// -// API reference: https://api.cloudflare.com/#access-short-lived-certificates-delete-access-certificate -func (api *API) DeleteAccessCACertificate(ctx context.Context, accountID, applicationID string) error { - return api.deleteAccessCACertificate(ctx, accountID, applicationID, AccountRouteRoot) -} - -// DeleteZoneLevelAccessCACertificate deletes a zone level Access CA certificate on a defined -// Access Application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-short-lived-certificates-delete-access-certificate -func (api *API) DeleteZoneLevelAccessCACertificate(ctx context.Context, zoneID, applicationID string) error { - return api.deleteAccessCACertificate(ctx, zoneID, applicationID, ZoneRouteRoot) -} - -func (api *API) deleteAccessCACertificate(ctx context.Context, id string, applicationID string, routeRoot RouteRoot) error { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s/ca", - routeRoot, - id, - applicationID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_group.go b/vendor/github.com/cloudflare/cloudflare-go/access_group.go deleted file mode 100644 index 9527e57..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_group.go +++ /dev/null @@ -1,383 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AccessGroup defines a group for allowing or disallowing access to -// one or more Access applications. -type AccessGroup struct { - ID string `json:"id,omitempty"` - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - Name string `json:"name"` - - // The include group works like an OR logical operator. The user must - // satisfy one of the rules. - Include []interface{} `json:"include"` - - // The exclude group works like a NOT logical operator. The user must - // not satisfy all of the rules in exclude. - Exclude []interface{} `json:"exclude"` - - // The require group works like a AND logical operator. The user must - // satisfy all of the rules in require. - Require []interface{} `json:"require"` -} - -// AccessGroupEmail is used for managing access based on the email. -// For example, restrict access to users with the email addresses -// `test@example.com` or `someone@example.com`. -type AccessGroupEmail struct { - Email struct { - Email string `json:"email"` - } `json:"email"` -} - -// AccessGroupEmailDomain is used for managing access based on an email -// domain domain such as `example.com` instead of individual addresses. -type AccessGroupEmailDomain struct { - EmailDomain struct { - Domain string `json:"domain"` - } `json:"email_domain"` -} - -// AccessGroupIP is used for managing access based in the IP. It -// accepts individual IPs or CIDRs. -type AccessGroupIP struct { - IP struct { - IP string `json:"ip"` - } `json:"ip"` -} - -// AccessGroupGeo is used for managing access based on the country code. -type AccessGroupGeo struct { - Geo struct { - CountryCode string `json:"country_code"` - } `json:"geo"` -} - -// AccessGroupEveryone is used for managing access to everyone. -type AccessGroupEveryone struct { - Everyone struct{} `json:"everyone"` -} - -// AccessGroupServiceToken is used for managing access based on a specific -// service token. -type AccessGroupServiceToken struct { - ServiceToken struct { - ID string `json:"token_id"` - } `json:"service_token"` -} - -// AccessGroupAnyValidServiceToken is used for managing access for all valid -// service tokens (not restricted). -type AccessGroupAnyValidServiceToken struct { - AnyValidServiceToken struct{} `json:"any_valid_service_token"` -} - -// AccessGroupAccessGroup is used for managing access based on an -// access group. -type AccessGroupAccessGroup struct { - Group struct { - ID string `json:"id"` - } `json:"group"` -} - -// AccessGroupCertificate is used for managing access to based on a valid -// mTLS certificate being presented. -type AccessGroupCertificate struct { - Certificate struct{} `json:"certificate"` -} - -// AccessGroupCertificateCommonName is used for managing access based on a -// common name within a certificate. -type AccessGroupCertificateCommonName struct { - CommonName struct { - CommonName string `json:"common_name"` - } `json:"common_name"` -} - -// AccessGroupExternalEvaluation is used for passing user identity to an external url. -type AccessGroupExternalEvaluation struct { - ExternalEvaluation struct { - EvaluateURL string `json:"evaluate_url"` - KeysURL string `json:"keys_url"` - } `json:"external_evaluation"` -} - -// AccessGroupGSuite is used to configure access based on GSuite group. -type AccessGroupGSuite struct { - Gsuite struct { - Email string `json:"email"` - IdentityProviderID string `json:"identity_provider_id"` - } `json:"gsuite"` -} - -// AccessGroupGitHub is used to configure access based on a GitHub organisation. -type AccessGroupGitHub struct { - GitHubOrganization struct { - Name string `json:"name"` - Team string `json:"team,omitempty"` - IdentityProviderID string `json:"identity_provider_id"` - } `json:"github-organization"` -} - -// AccessGroupAzure is used to configure access based on a Azure group. -type AccessGroupAzure struct { - AzureAD struct { - ID string `json:"id"` - IdentityProviderID string `json:"identity_provider_id"` - } `json:"azureAD"` -} - -// AccessGroupOkta is used to configure access based on a Okta group. -type AccessGroupOkta struct { - Okta struct { - Name string `json:"name"` - IdentityProviderID string `json:"identity_provider_id"` - } `json:"okta"` -} - -// AccessGroupSAML is used to allow SAML users with a specific attribute -// configuration. -type AccessGroupSAML struct { - Saml struct { - AttributeName string `json:"attribute_name"` - AttributeValue string `json:"attribute_value"` - IdentityProviderID string `json:"identity_provider_id"` - } `json:"saml"` -} - -// AccessGroupAuthMethod is used for managing access by the "amr" -// (Authentication Methods References) identifier. For example, an -// application may want to require that users authenticate using a hardware -// key by setting the "auth_method" to "swk". A list of values are listed -// here: https://tools.ietf.org/html/rfc8176#section-2. Custom values are -// supported as well. -type AccessGroupAuthMethod struct { - AuthMethod struct { - AuthMethod string `json:"auth_method"` - } `json:"auth_method"` -} - -// AccessGroupLoginMethod restricts the application to specific IdP instances. -type AccessGroupLoginMethod struct { - LoginMethod struct { - ID string `json:"id"` - } `json:"login_method"` -} - -// AccessGroupDevicePosture restricts the application to specific devices. -type AccessGroupDevicePosture struct { - DevicePosture struct { - ID string `json:"integration_uid"` - } `json:"device_posture"` -} - -// AccessGroupListResponse represents the response from the list -// access group endpoint. -type AccessGroupListResponse struct { - Result []AccessGroup `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessGroupIPList restricts the application to specific teams_list of ips. -type AccessGroupIPList struct { - IPList struct { - ID string `json:"id"` - } `json:"ip_list"` -} - -// AccessGroupDetailResponse is the API response, containing a single -// access group. -type AccessGroupDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessGroup `json:"result"` -} - -// AccessGroups returns all access groups for an access application. -// -// API reference: https://api.cloudflare.com/#access-groups-list-access-groups -func (api *API) AccessGroups(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccessGroup, ResultInfo, error) { - return api.accessGroups(ctx, accountID, pageOpts, AccountRouteRoot) -} - -// ZoneLevelAccessGroups returns all zone level access groups for an access application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-groups-list-access-groups -func (api *API) ZoneLevelAccessGroups(ctx context.Context, zoneID string, pageOpts PaginationOptions) ([]AccessGroup, ResultInfo, error) { - return api.accessGroups(ctx, zoneID, pageOpts, ZoneRouteRoot) -} - -func (api *API) accessGroups(ctx context.Context, id string, pageOpts PaginationOptions, routeRoot RouteRoot) ([]AccessGroup, ResultInfo, error) { - uri := buildURI( - fmt.Sprintf( - "/%s/%s/access/groups", - routeRoot, - id, - ), - pageOpts, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessGroup{}, ResultInfo{}, err - } - - var accessGroupListResponse AccessGroupListResponse - err = json.Unmarshal(res, &accessGroupListResponse) - if err != nil { - return []AccessGroup{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessGroupListResponse.Result, accessGroupListResponse.ResultInfo, nil -} - -// AccessGroup returns a single group based on the group ID. -// -// API reference: https://api.cloudflare.com/#access-groups-access-group-details -func (api *API) AccessGroup(ctx context.Context, accountID, groupID string) (AccessGroup, error) { - return api.accessGroup(ctx, accountID, groupID, AccountRouteRoot) -} - -// ZoneLevelAccessGroup returns a single zone level group based on the group ID. -// -// API reference: https://api.cloudflare.com/#zone-level-access-groups-access-group-details -func (api *API) ZoneLevelAccessGroup(ctx context.Context, zoneID, groupID string) (AccessGroup, error) { - return api.accessGroup(ctx, zoneID, groupID, ZoneRouteRoot) -} - -func (api *API) accessGroup(ctx context.Context, id, groupID string, routeRoot RouteRoot) (AccessGroup, error) { - uri := fmt.Sprintf( - "/%s/%s/access/groups/%s", - routeRoot, - id, - groupID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessGroup{}, err - } - - var accessGroupDetailResponse AccessGroupDetailResponse - err = json.Unmarshal(res, &accessGroupDetailResponse) - if err != nil { - return AccessGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessGroupDetailResponse.Result, nil -} - -// CreateAccessGroup creates a new access group. -// -// API reference: https://api.cloudflare.com/#access-groups-create-access-group -func (api *API) CreateAccessGroup(ctx context.Context, accountID string, accessGroup AccessGroup) (AccessGroup, error) { - return api.createAccessGroup(ctx, accountID, accessGroup, AccountRouteRoot) -} - -// CreateZoneLevelAccessGroup creates a new zone level access group. -// -// API reference: https://api.cloudflare.com/#zone-level-access-groups-create-access-group -func (api *API) CreateZoneLevelAccessGroup(ctx context.Context, zoneID string, accessGroup AccessGroup) (AccessGroup, error) { - return api.createAccessGroup(ctx, zoneID, accessGroup, ZoneRouteRoot) -} - -func (api *API) createAccessGroup(ctx context.Context, id string, accessGroup AccessGroup, routeRoot RouteRoot) (AccessGroup, error) { - uri := fmt.Sprintf( - "/%s/%s/access/groups", - routeRoot, - id, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, accessGroup) - if err != nil { - return AccessGroup{}, err - } - - var accessGroupDetailResponse AccessGroupDetailResponse - err = json.Unmarshal(res, &accessGroupDetailResponse) - if err != nil { - return AccessGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessGroupDetailResponse.Result, nil -} - -// UpdateAccessGroup updates an existing access group. -// -// API reference: https://api.cloudflare.com/#access-groups-update-access-group -func (api *API) UpdateAccessGroup(ctx context.Context, accountID string, accessGroup AccessGroup) (AccessGroup, error) { - return api.updateAccessGroup(ctx, accountID, accessGroup, AccountRouteRoot) -} - -// UpdateZoneLevelAccessGroup updates an existing zone level access group. -// -// API reference: https://api.cloudflare.com/#zone-level-access-groups-update-access-group -func (api *API) UpdateZoneLevelAccessGroup(ctx context.Context, zoneID string, accessGroup AccessGroup) (AccessGroup, error) { - return api.updateAccessGroup(ctx, zoneID, accessGroup, ZoneRouteRoot) -} - -func (api *API) updateAccessGroup(ctx context.Context, id string, accessGroup AccessGroup, routeRoot RouteRoot) (AccessGroup, error) { - if accessGroup.ID == "" { - return AccessGroup{}, fmt.Errorf("access group ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/access/groups/%s", - routeRoot, - id, - accessGroup.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, accessGroup) - if err != nil { - return AccessGroup{}, err - } - - var accessGroupDetailResponse AccessGroupDetailResponse - err = json.Unmarshal(res, &accessGroupDetailResponse) - if err != nil { - return AccessGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessGroupDetailResponse.Result, nil -} - -// DeleteAccessGroup deletes an access group. -// -// API reference: https://api.cloudflare.com/#access-groups-delete-access-group -func (api *API) DeleteAccessGroup(ctx context.Context, accountID, groupID string) error { - return api.deleteAccessGroup(ctx, accountID, groupID, AccountRouteRoot) -} - -// DeleteZoneLevelAccessGroup deletes a zone level access group. -// -// API reference: https://api.cloudflare.com/#zone-level-access-groups-delete-access-group -func (api *API) DeleteZoneLevelAccessGroup(ctx context.Context, zoneID, groupID string) error { - return api.deleteAccessGroup(ctx, zoneID, groupID, ZoneRouteRoot) -} - -func (api *API) deleteAccessGroup(ctx context.Context, id string, groupID string, routeRoot RouteRoot) error { - uri := fmt.Sprintf( - "/%s/%s/access/groups/%s", - routeRoot, - id, - groupID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_identity_provider.go b/vendor/github.com/cloudflare/cloudflare-go/access_identity_provider.go deleted file mode 100644 index fb986b4..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_identity_provider.go +++ /dev/null @@ -1,235 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// AccessIdentityProvider is the structure of the provider object. -type AccessIdentityProvider struct { - ID string `json:"id,omitempty"` - Name string `json:"name"` - Type string `json:"type"` - Config AccessIdentityProviderConfiguration `json:"config"` -} - -// AccessIdentityProviderConfiguration is the combined structure of *all* -// identity provider configuration fields. This is done to simplify the use of -// Access products and their relationship to each other. -// -// API reference: https://developers.cloudflare.com/access/configuring-identity-providers/ -type AccessIdentityProviderConfiguration struct { - APIToken string `json:"api_token,omitempty"` - AppsDomain string `json:"apps_domain,omitempty"` - Attributes []string `json:"attributes,omitempty"` - AuthURL string `json:"auth_url,omitempty"` - CentrifyAccount string `json:"centrify_account,omitempty"` - CentrifyAppID string `json:"centrify_app_id,omitempty"` - CertsURL string `json:"certs_url,omitempty"` - ClientID string `json:"client_id,omitempty"` - ClientSecret string `json:"client_secret,omitempty"` - DirectoryID string `json:"directory_id,omitempty"` - EmailAttributeName string `json:"email_attribute_name,omitempty"` - IdpPublicCert string `json:"idp_public_cert,omitempty"` - IssuerURL string `json:"issuer_url,omitempty"` - OktaAccount string `json:"okta_account,omitempty"` - OneloginAccount string `json:"onelogin_account,omitempty"` - RedirectURL string `json:"redirect_url,omitempty"` - SignRequest bool `json:"sign_request,omitempty"` - SsoTargetURL string `json:"sso_target_url,omitempty"` - SupportGroups bool `json:"support_groups,omitempty"` - TokenURL string `json:"token_url,omitempty"` - PKCEEnabled *bool `json:"pkce_enabled,omitempty"` -} - -// AccessIdentityProvidersListResponse is the API response for multiple -// Access Identity Providers. -type AccessIdentityProvidersListResponse struct { - Response - Result []AccessIdentityProvider `json:"result"` -} - -// AccessIdentityProviderListResponse is the API response for a single -// Access Identity Provider. -type AccessIdentityProviderListResponse struct { - Response - Result AccessIdentityProvider `json:"result"` -} - -// AccessIdentityProviders returns all Access Identity Providers for an -// account. -// -// API reference: https://api.cloudflare.com/#access-identity-providers-list-access-identity-providers -func (api *API) AccessIdentityProviders(ctx context.Context, accountID string) ([]AccessIdentityProvider, error) { - return api.accessIdentityProviders(ctx, accountID, AccountRouteRoot) -} - -// ZoneLevelAccessIdentityProviders returns all Access Identity Providers for an -// account. -// -// API reference: https://api.cloudflare.com/#zone-level-access-identity-providers-list-access-identity-providers -func (api *API) ZoneLevelAccessIdentityProviders(ctx context.Context, zoneID string) ([]AccessIdentityProvider, error) { - return api.accessIdentityProviders(ctx, zoneID, ZoneRouteRoot) -} - -func (api *API) accessIdentityProviders(ctx context.Context, id string, routeRoot RouteRoot) ([]AccessIdentityProvider, error) { - uri := fmt.Sprintf("/%s/%s/access/identity_providers", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessIdentityProvider{}, err - } - - var accessIdentityProviderResponse AccessIdentityProvidersListResponse - err = json.Unmarshal(res, &accessIdentityProviderResponse) - if err != nil { - return []AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessIdentityProviderResponse.Result, nil -} - -// AccessIdentityProviderDetails returns a single Access Identity -// Provider for an account. -// -// API reference: https://api.cloudflare.com/#access-identity-providers-access-identity-providers-details -func (api *API) AccessIdentityProviderDetails(ctx context.Context, accountID, identityProviderID string) (AccessIdentityProvider, error) { - return api.accessIdentityProviderDetails(ctx, accountID, identityProviderID, AccountRouteRoot) -} - -// ZoneLevelAccessIdentityProviderDetails returns a single zone level Access Identity -// Provider for an account. -// -// API reference: https://api.cloudflare.com/#zone-level-access-identity-providers-access-identity-providers-details -func (api *API) ZoneLevelAccessIdentityProviderDetails(ctx context.Context, zoneID, identityProviderID string) (AccessIdentityProvider, error) { - return api.accessIdentityProviderDetails(ctx, zoneID, identityProviderID, ZoneRouteRoot) -} - -func (api *API) accessIdentityProviderDetails(ctx context.Context, id string, identityProviderID string, routeRoot RouteRoot) (AccessIdentityProvider, error) { - uri := fmt.Sprintf( - "/%s/%s/access/identity_providers/%s", - routeRoot, - id, - identityProviderID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessIdentityProvider{}, err - } - - var accessIdentityProviderResponse AccessIdentityProviderListResponse - err = json.Unmarshal(res, &accessIdentityProviderResponse) - if err != nil { - return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessIdentityProviderResponse.Result, nil -} - -// CreateAccessIdentityProvider creates a new Access Identity Provider. -// -// API reference: https://api.cloudflare.com/#access-identity-providers-create-access-identity-provider -func (api *API) CreateAccessIdentityProvider(ctx context.Context, accountID string, identityProviderConfiguration AccessIdentityProvider) (AccessIdentityProvider, error) { - return api.createAccessIdentityProvider(ctx, accountID, identityProviderConfiguration, AccountRouteRoot) -} - -// CreateZoneLevelAccessIdentityProvider creates a new zone level Access Identity Provider. -// -// API reference: https://api.cloudflare.com/#zone-level-access-identity-providers-create-access-identity-provider -func (api *API) CreateZoneLevelAccessIdentityProvider(ctx context.Context, zoneID string, identityProviderConfiguration AccessIdentityProvider) (AccessIdentityProvider, error) { - return api.createAccessIdentityProvider(ctx, zoneID, identityProviderConfiguration, ZoneRouteRoot) -} - -func (api *API) createAccessIdentityProvider(ctx context.Context, id string, identityProviderConfiguration AccessIdentityProvider, routeRoot RouteRoot) (AccessIdentityProvider, error) { - uri := fmt.Sprintf("/%s/%s/access/identity_providers", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, identityProviderConfiguration) - if err != nil { - return AccessIdentityProvider{}, err - } - - var accessIdentityProviderResponse AccessIdentityProviderListResponse - err = json.Unmarshal(res, &accessIdentityProviderResponse) - if err != nil { - return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessIdentityProviderResponse.Result, nil -} - -// UpdateAccessIdentityProvider updates an existing Access Identity -// Provider. -// -// API reference: https://api.cloudflare.com/#access-identity-providers-create-access-identity-provider -func (api *API) UpdateAccessIdentityProvider(ctx context.Context, accountID, identityProviderUUID string, identityProviderConfiguration AccessIdentityProvider) (AccessIdentityProvider, error) { - return api.updateAccessIdentityProvider(ctx, accountID, identityProviderUUID, identityProviderConfiguration, AccountRouteRoot) -} - -// UpdateZoneLevelAccessIdentityProvider updates an existing zone level Access Identity -// Provider. -// -// API reference: https://api.cloudflare.com/#zone-level-access-identity-providers-update-access-identity-provider -func (api *API) UpdateZoneLevelAccessIdentityProvider(ctx context.Context, zoneID, identityProviderUUID string, identityProviderConfiguration AccessIdentityProvider) (AccessIdentityProvider, error) { - return api.updateAccessIdentityProvider(ctx, zoneID, identityProviderUUID, identityProviderConfiguration, ZoneRouteRoot) -} - -func (api *API) updateAccessIdentityProvider(ctx context.Context, id string, identityProviderUUID string, identityProviderConfiguration AccessIdentityProvider, routeRoot RouteRoot) (AccessIdentityProvider, error) { - uri := fmt.Sprintf( - "/%s/%s/access/identity_providers/%s", - routeRoot, - id, - identityProviderUUID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, identityProviderConfiguration) - if err != nil { - return AccessIdentityProvider{}, err - } - - var accessIdentityProviderResponse AccessIdentityProviderListResponse - err = json.Unmarshal(res, &accessIdentityProviderResponse) - if err != nil { - return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessIdentityProviderResponse.Result, nil -} - -// DeleteAccessIdentityProvider deletes an Access Identity Provider. -// -// API reference: https://api.cloudflare.com/#access-identity-providers-create-access-identity-provider -func (api *API) DeleteAccessIdentityProvider(ctx context.Context, accountID, identityProviderUUID string) (AccessIdentityProvider, error) { - return api.deleteAccessIdentityProvider(ctx, accountID, identityProviderUUID, AccountRouteRoot) -} - -// DeleteZoneLevelAccessIdentityProvider deletes a zone level Access Identity Provider. -// -// API reference: https://api.cloudflare.com/#zone-level-access-identity-providers-delete-access-identity-provider -func (api *API) DeleteZoneLevelAccessIdentityProvider(ctx context.Context, zoneID, identityProviderUUID string) (AccessIdentityProvider, error) { - return api.deleteAccessIdentityProvider(ctx, zoneID, identityProviderUUID, ZoneRouteRoot) -} - -func (api *API) deleteAccessIdentityProvider(ctx context.Context, id string, identityProviderUUID string, routeRoot RouteRoot) (AccessIdentityProvider, error) { - uri := fmt.Sprintf( - "/%s/%s/access/identity_providers/%s", - routeRoot, - id, - identityProviderUUID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return AccessIdentityProvider{}, err - } - - var accessIdentityProviderResponse AccessIdentityProviderListResponse - err = json.Unmarshal(res, &accessIdentityProviderResponse) - if err != nil { - return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessIdentityProviderResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_keys.go b/vendor/github.com/cloudflare/cloudflare-go/access_keys.go deleted file mode 100644 index 2edca03..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_keys.go +++ /dev/null @@ -1,63 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type AccessKeysConfig struct { - KeyRotationIntervalDays int `json:"key_rotation_interval_days"` - LastKeyRotationAt time.Time `json:"last_key_rotation_at"` - DaysUntilNextRotation int `json:"days_until_next_rotation"` -} - -type AccessKeysConfigUpdateRequest struct { - KeyRotationIntervalDays int `json:"key_rotation_interval_days"` -} - -type accessKeysConfigResponse struct { - Response - Result AccessKeysConfig `json:"result"` -} - -// AccessKeysConfig returns the Access Keys Configuration for an account. -// -// API reference: https://api.cloudflare.com/#access-keys-configuration-get-access-keys-configuration -func (api *API) AccessKeysConfig(ctx context.Context, accountID string) (AccessKeysConfig, error) { - uri := fmt.Sprintf("/%s/%s/access/keys", AccountRouteRoot, accountID) - - return api.accessKeysRequest(ctx, http.MethodGet, uri, nil) -} - -// UpdateAccessKeysConfig updates the Access Keys Configuration for an account. -// -// API reference: https://api.cloudflare.com/#access-keys-configuration-update-access-keys-configuration -func (api *API) UpdateAccessKeysConfig(ctx context.Context, accountID string, request AccessKeysConfigUpdateRequest) (AccessKeysConfig, error) { - uri := fmt.Sprintf("/%s/%s/access/keys", AccountRouteRoot, accountID) - - return api.accessKeysRequest(ctx, http.MethodPut, uri, request) -} - -// RotateAccessKeys rotates the Access Keys for an account and returns the updated Access Keys Configuration -// -// API reference: https://api.cloudflare.com/#access-keys-configuration-rotate-access-keys -func (api *API) RotateAccessKeys(ctx context.Context, accountID string) (AccessKeysConfig, error) { - uri := fmt.Sprintf("/%s/%s/access/keys/rotate", AccountRouteRoot, accountID) - return api.accessKeysRequest(ctx, http.MethodPost, uri, nil) -} - -func (api *API) accessKeysRequest(ctx context.Context, method, uri string, params interface{}) (AccessKeysConfig, error) { - res, err := api.makeRequestContext(ctx, method, uri, params) - if err != nil { - return AccessKeysConfig{}, err - } - - var keysConfigResponse accessKeysConfigResponse - if err := json.Unmarshal(res, &keysConfigResponse); err != nil { - return AccessKeysConfig{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return keysConfigResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_mutual_tls_certificates.go b/vendor/github.com/cloudflare/cloudflare-go/access_mutual_tls_certificates.go deleted file mode 100644 index af1eef5..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_mutual_tls_certificates.go +++ /dev/null @@ -1,224 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AccessMutualTLSCertificate is the structure of a single Access Mutual TLS -// certificate. -type AccessMutualTLSCertificate struct { - ID string `json:"id,omitempty"` - CreatedAt time.Time `json:"created_at,omitempty"` - UpdatedAt time.Time `json:"updated_at,omitempty"` - ExpiresOn time.Time `json:"expires_on,omitempty"` - Name string `json:"name,omitempty"` - Fingerprint string `json:"fingerprint,omitempty"` - Certificate string `json:"certificate,omitempty"` - AssociatedHostnames []string `json:"associated_hostnames,omitempty"` -} - -// AccessMutualTLSCertificateListResponse is the API response for all Access -// Mutual TLS certificates. -type AccessMutualTLSCertificateListResponse struct { - Response - Result []AccessMutualTLSCertificate `json:"result"` -} - -// AccessMutualTLSCertificateDetailResponse is the API response for a single -// Access Mutual TLS certificate. -type AccessMutualTLSCertificateDetailResponse struct { - Response - Result AccessMutualTLSCertificate `json:"result"` -} - -// AccessMutualTLSCertificates returns all Access TLS certificates for the account -// level. -// -// API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-properties -func (api *API) AccessMutualTLSCertificates(ctx context.Context, accountID string) ([]AccessMutualTLSCertificate, error) { - return api.accessMutualTLSCertificates(ctx, accountID, AccountRouteRoot) -} - -// ZoneAccessMutualTLSCertificates returns all Access TLS certificates for the -// zone level. -// -// API reference: https://api.cloudflare.com/#zone-level-access-mutual-tls-authentication-properties -func (api *API) ZoneAccessMutualTLSCertificates(ctx context.Context, zoneID string) ([]AccessMutualTLSCertificate, error) { - return api.accessMutualTLSCertificates(ctx, zoneID, ZoneRouteRoot) -} - -func (api *API) accessMutualTLSCertificates(ctx context.Context, id string, routeRoot RouteRoot) ([]AccessMutualTLSCertificate, error) { - uri := fmt.Sprintf( - "/%s/%s/access/certificates", - routeRoot, - id, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessMutualTLSCertificate{}, err - } - - var accessMutualTLSCertificateListResponse AccessMutualTLSCertificateListResponse - err = json.Unmarshal(res, &accessMutualTLSCertificateListResponse) - if err != nil { - return []AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessMutualTLSCertificateListResponse.Result, nil -} - -// AccessMutualTLSCertificate returns a single account level Access Mutual TLS -// certificate. -// -// API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-access-certificate-details -func (api *API) AccessMutualTLSCertificate(ctx context.Context, accountID, certificateID string) (AccessMutualTLSCertificate, error) { - return api.accessMutualTLSCertificate(ctx, accountID, certificateID, AccountRouteRoot) -} - -// ZoneAccessMutualTLSCertificate returns a single zone level Access Mutual TLS -// certificate. -// -// API reference: https://api.cloudflare.com/#zone-level-access-mutual-tls-authentication-access-certificate-details -func (api *API) ZoneAccessMutualTLSCertificate(ctx context.Context, zoneID, certificateID string) (AccessMutualTLSCertificate, error) { - return api.accessMutualTLSCertificate(ctx, zoneID, certificateID, ZoneRouteRoot) -} - -func (api *API) accessMutualTLSCertificate(ctx context.Context, id, certificateID string, routeRoot RouteRoot) (AccessMutualTLSCertificate, error) { - uri := fmt.Sprintf( - "/%s/%s/access/certificates/%s", - routeRoot, - id, - certificateID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessMutualTLSCertificate{}, err - } - - var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse - err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) - if err != nil { - return AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessMutualTLSCertificateDetailResponse.Result, nil -} - -// CreateAccessMutualTLSCertificate creates an account level Access TLS Mutual -// certificate. -// -// API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-create-access-certificate -func (api *API) CreateAccessMutualTLSCertificate(ctx context.Context, accountID string, certificate AccessMutualTLSCertificate) (AccessMutualTLSCertificate, error) { - return api.createAccessMutualTLSCertificate(ctx, accountID, certificate, AccountRouteRoot) -} - -// CreateZoneAccessMutualTLSCertificate creates a zone level Access TLS Mutual -// certificate. -// -// API reference: https://api.cloudflare.com/#zone-level-access-mutual-tls-authentication-create-access-certificate -func (api *API) CreateZoneAccessMutualTLSCertificate(ctx context.Context, zoneID string, certificate AccessMutualTLSCertificate) (AccessMutualTLSCertificate, error) { - return api.createAccessMutualTLSCertificate(ctx, zoneID, certificate, ZoneRouteRoot) -} - -func (api *API) createAccessMutualTLSCertificate(ctx context.Context, id string, certificate AccessMutualTLSCertificate, routeRoot RouteRoot) (AccessMutualTLSCertificate, error) { - uri := fmt.Sprintf( - "/%s/%s/access/certificates", - routeRoot, - id, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, certificate) - if err != nil { - return AccessMutualTLSCertificate{}, err - } - - var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse - err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) - if err != nil { - return AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessMutualTLSCertificateDetailResponse.Result, nil -} - -// UpdateAccessMutualTLSCertificate updates an account level Access TLS Mutual -// certificate. -// -// API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-update-access-certificate -func (api *API) UpdateAccessMutualTLSCertificate(ctx context.Context, accountID, certificateID string, certificate AccessMutualTLSCertificate) (AccessMutualTLSCertificate, error) { - return api.updateAccessMutualTLSCertificate(ctx, accountID, certificateID, certificate, AccountRouteRoot) -} - -// UpdateZoneAccessMutualTLSCertificate updates a zone level Access TLS Mutual -// certificate. -// -// API reference: https://api.cloudflare.com/#zone-level-access-mutual-tls-authentication-update-access-certificate -func (api *API) UpdateZoneAccessMutualTLSCertificate(ctx context.Context, zoneID, certificateID string, certificate AccessMutualTLSCertificate) (AccessMutualTLSCertificate, error) { - return api.updateAccessMutualTLSCertificate(ctx, zoneID, certificateID, certificate, ZoneRouteRoot) -} - -func (api *API) updateAccessMutualTLSCertificate(ctx context.Context, id string, certificateID string, certificate AccessMutualTLSCertificate, routeRoot RouteRoot) (AccessMutualTLSCertificate, error) { - uri := fmt.Sprintf( - "/%s/%s/access/certificates/%s", - routeRoot, - id, - certificateID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, certificate) - if err != nil { - return AccessMutualTLSCertificate{}, err - } - - var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse - err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) - if err != nil { - return AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessMutualTLSCertificateDetailResponse.Result, nil -} - -// DeleteAccessMutualTLSCertificate destroys an account level Access Mutual -// TLS certificate. -// -// API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-update-access-certificate -func (api *API) DeleteAccessMutualTLSCertificate(ctx context.Context, accountID, certificateID string) error { - return api.deleteAccessMutualTLSCertificate(ctx, accountID, certificateID, AccountRouteRoot) -} - -// DeleteZoneAccessMutualTLSCertificate destroys a zone level Access Mutual TLS -// certificate. -// -// API reference: https://api.cloudflare.com/#zone-level-access-mutual-tls-authentication-update-access-certificate -func (api *API) DeleteZoneAccessMutualTLSCertificate(ctx context.Context, zoneID, certificateID string) error { - return api.deleteAccessMutualTLSCertificate(ctx, zoneID, certificateID, ZoneRouteRoot) -} - -func (api *API) deleteAccessMutualTLSCertificate(ctx context.Context, id, certificateID string, routeRoot RouteRoot) error { - uri := fmt.Sprintf( - "/%s/%s/access/certificates/%s", - routeRoot, - id, - certificateID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse - err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_organization.go b/vendor/github.com/cloudflare/cloudflare-go/access_organization.go deleted file mode 100644 index 35c9e9e..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_organization.go +++ /dev/null @@ -1,139 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AccessOrganization represents an Access organization. -type AccessOrganization struct { - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - Name string `json:"name"` - AuthDomain string `json:"auth_domain"` - LoginDesign AccessOrganizationLoginDesign `json:"login_design"` - IsUIReadOnly *bool `json:"is_ui_read_only,omitempty"` - UserSeatExpirationInactiveTime string `json:"user_seat_expiration_inactive_time,omitempty"` -} - -// AccessOrganizationLoginDesign represents the login design options. -type AccessOrganizationLoginDesign struct { - BackgroundColor string `json:"background_color"` - LogoPath string `json:"logo_path"` - TextColor string `json:"text_color"` - HeaderText string `json:"header_text"` - FooterText string `json:"footer_text"` -} - -// AccessOrganizationListResponse represents the response from the list -// access organization endpoint. -type AccessOrganizationListResponse struct { - Result AccessOrganization `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessOrganizationDetailResponse is the API response, containing a -// single access organization. -type AccessOrganizationDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessOrganization `json:"result"` -} - -// AccessOrganization returns the Access organisation details. -// -// API reference: https://api.cloudflare.com/#access-organizations-access-organization-details -func (api *API) AccessOrganization(ctx context.Context, accountID string) (AccessOrganization, ResultInfo, error) { - return api.accessOrganization(ctx, accountID, AccountRouteRoot) -} - -// ZoneLevelAccessOrganization returns the zone level Access organisation details. -// -// API reference: https://api.cloudflare.com/#zone-level-access-organizations-access-organization-details -func (api *API) ZoneLevelAccessOrganization(ctx context.Context, zoneID string) (AccessOrganization, ResultInfo, error) { - return api.accessOrganization(ctx, zoneID, ZoneRouteRoot) -} - -func (api *API) accessOrganization(ctx context.Context, id string, routeRoot RouteRoot) (AccessOrganization, ResultInfo, error) { - uri := fmt.Sprintf("/%s/%s/access/organizations", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessOrganization{}, ResultInfo{}, err - } - - var accessOrganizationListResponse AccessOrganizationListResponse - err = json.Unmarshal(res, &accessOrganizationListResponse) - if err != nil { - return AccessOrganization{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessOrganizationListResponse.Result, accessOrganizationListResponse.ResultInfo, nil -} - -// CreateAccessOrganization creates the Access organisation details. -// -// API reference: https://api.cloudflare.com/#access-organizations-create-access-organization -func (api *API) CreateAccessOrganization(ctx context.Context, accountID string, accessOrganization AccessOrganization) (AccessOrganization, error) { - return api.createAccessOrganization(ctx, accountID, accessOrganization, AccountRouteRoot) -} - -// CreateZoneLevelAccessOrganization creates the zone level Access organisation details. -// -// API reference: https://api.cloudflare.com/#zone-level-access-organizations-create-access-organization -func (api *API) CreateZoneLevelAccessOrganization(ctx context.Context, zoneID string, accessOrganization AccessOrganization) (AccessOrganization, error) { - return api.createAccessOrganization(ctx, zoneID, accessOrganization, ZoneRouteRoot) -} - -func (api *API) createAccessOrganization(ctx context.Context, id string, accessOrganization AccessOrganization, routeRoot RouteRoot) (AccessOrganization, error) { - uri := fmt.Sprintf("/%s/%s/access/organizations", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, accessOrganization) - if err != nil { - return AccessOrganization{}, err - } - - var accessOrganizationDetailResponse AccessOrganizationDetailResponse - err = json.Unmarshal(res, &accessOrganizationDetailResponse) - if err != nil { - return AccessOrganization{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessOrganizationDetailResponse.Result, nil -} - -// UpdateAccessOrganization updates the Access organisation details. -// -// API reference: https://api.cloudflare.com/#access-organizations-update-access-organization -func (api *API) UpdateAccessOrganization(ctx context.Context, accountID string, accessOrganization AccessOrganization) (AccessOrganization, error) { - return api.updateAccessOrganization(ctx, accountID, accessOrganization, AccountRouteRoot) -} - -// UpdateZoneLevelAccessOrganization updates the zone level Access organisation details. -// -// API reference: https://api.cloudflare.com/#zone-level-access-organizations-update-access-organization -func (api *API) UpdateZoneLevelAccessOrganization(ctx context.Context, zoneID string, accessOrganization AccessOrganization) (AccessOrganization, error) { - return api.updateAccessOrganization(ctx, zoneID, accessOrganization, ZoneRouteRoot) -} - -func (api *API) updateAccessOrganization(ctx context.Context, id string, accessOrganization AccessOrganization, routeRoot RouteRoot) (AccessOrganization, error) { - uri := fmt.Sprintf("/%s/%s/access/organizations", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, accessOrganization) - if err != nil { - return AccessOrganization{}, err - } - - var accessOrganizationDetailResponse AccessOrganizationDetailResponse - err = json.Unmarshal(res, &accessOrganizationDetailResponse) - if err != nil { - return AccessOrganization{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessOrganizationDetailResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_policy.go b/vendor/github.com/cloudflare/cloudflare-go/access_policy.go deleted file mode 100644 index abbbaf4..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_policy.go +++ /dev/null @@ -1,243 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type AccessApprovalGroup struct { - EmailListUuid string `json:"email_list_uuid,omitempty"` - EmailAddresses []string `json:"email_addresses,omitempty"` - ApprovalsNeeded int `json:"approvals_needed,omitempty"` -} - -// AccessPolicy defines a policy for allowing or disallowing access to -// one or more Access applications. -type AccessPolicy struct { - ID string `json:"id,omitempty"` - Precedence int `json:"precedence"` - Decision string `json:"decision"` - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - Name string `json:"name"` - - PurposeJustificationRequired *bool `json:"purpose_justification_required,omitempty"` - PurposeJustificationPrompt *string `json:"purpose_justification_prompt,omitempty"` - ApprovalRequired *bool `json:"approval_required,omitempty"` - ApprovalGroups []AccessApprovalGroup `json:"approval_groups"` - - // The include policy works like an OR logical operator. The user must - // satisfy one of the rules. - Include []interface{} `json:"include"` - - // The exclude policy works like a NOT logical operator. The user must - // not satisfy all of the rules in exclude. - Exclude []interface{} `json:"exclude"` - - // The require policy works like a AND logical operator. The user must - // satisfy all of the rules in require. - Require []interface{} `json:"require"` -} - -// AccessPolicyListResponse represents the response from the list -// access policies endpoint. -type AccessPolicyListResponse struct { - Result []AccessPolicy `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessPolicyDetailResponse is the API response, containing a single -// access policy. -type AccessPolicyDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessPolicy `json:"result"` -} - -// AccessPolicies returns all access policies for an access application. -// -// API reference: https://api.cloudflare.com/#access-policy-list-access-policies -func (api *API) AccessPolicies(ctx context.Context, accountID, applicationID string, pageOpts PaginationOptions) ([]AccessPolicy, ResultInfo, error) { - return api.accessPolicies(ctx, accountID, applicationID, pageOpts, AccountRouteRoot) -} - -// ZoneLevelAccessPolicies returns all zone level access policies for an access application. -// -// API reference: https://api.cloudflare.com/#zone-level-access-policy-list-access-policies -func (api *API) ZoneLevelAccessPolicies(ctx context.Context, zoneID, applicationID string, pageOpts PaginationOptions) ([]AccessPolicy, ResultInfo, error) { - return api.accessPolicies(ctx, zoneID, applicationID, pageOpts, ZoneRouteRoot) -} - -func (api *API) accessPolicies(ctx context.Context, id string, applicationID string, pageOpts PaginationOptions, routeRoot RouteRoot) ([]AccessPolicy, ResultInfo, error) { - uri := buildURI( - fmt.Sprintf( - "/%s/%s/access/apps/%s/policies", - routeRoot, - id, - applicationID, - ), - pageOpts, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessPolicy{}, ResultInfo{}, err - } - - var accessPolicyListResponse AccessPolicyListResponse - err = json.Unmarshal(res, &accessPolicyListResponse) - if err != nil { - return []AccessPolicy{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessPolicyListResponse.Result, accessPolicyListResponse.ResultInfo, nil -} - -// AccessPolicy returns a single policy based on the policy ID. -// -// API reference: https://api.cloudflare.com/#access-policy-access-policy-details -func (api *API) AccessPolicy(ctx context.Context, accountID, applicationID, policyID string) (AccessPolicy, error) { - return api.accessPolicy(ctx, accountID, applicationID, policyID, AccountRouteRoot) -} - -// ZoneLevelAccessPolicy returns a single zone level policy based on the policy ID. -// -// API reference: https://api.cloudflare.com/#zone-level-access-policy-access-policy-details -func (api *API) ZoneLevelAccessPolicy(ctx context.Context, zoneID, applicationID, policyID string) (AccessPolicy, error) { - return api.accessPolicy(ctx, zoneID, applicationID, policyID, ZoneRouteRoot) -} - -func (api *API) accessPolicy(ctx context.Context, id string, applicationID string, policyID string, routeRoot RouteRoot) (AccessPolicy, error) { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s/policies/%s", - routeRoot, - id, - applicationID, - policyID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccessPolicy{}, err - } - - var accessPolicyDetailResponse AccessPolicyDetailResponse - err = json.Unmarshal(res, &accessPolicyDetailResponse) - if err != nil { - return AccessPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessPolicyDetailResponse.Result, nil -} - -// CreateAccessPolicy creates a new access policy. -// -// API reference: https://api.cloudflare.com/#access-policy-create-access-policy -func (api *API) CreateAccessPolicy(ctx context.Context, accountID, applicationID string, accessPolicy AccessPolicy) (AccessPolicy, error) { - return api.createAccessPolicy(ctx, accountID, applicationID, accessPolicy, AccountRouteRoot) -} - -// CreateZoneLevelAccessPolicy creates a new zone level access policy. -// -// API reference: https://api.cloudflare.com/#zone-level-access-policy-create-access-policy -func (api *API) CreateZoneLevelAccessPolicy(ctx context.Context, zoneID, applicationID string, accessPolicy AccessPolicy) (AccessPolicy, error) { - return api.createAccessPolicy(ctx, zoneID, applicationID, accessPolicy, ZoneRouteRoot) -} - -func (api *API) createAccessPolicy(ctx context.Context, id, applicationID string, accessPolicy AccessPolicy, routeRoot RouteRoot) (AccessPolicy, error) { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s/policies", - routeRoot, - id, - applicationID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, accessPolicy) - if err != nil { - return AccessPolicy{}, err - } - - var accessPolicyDetailResponse AccessPolicyDetailResponse - err = json.Unmarshal(res, &accessPolicyDetailResponse) - if err != nil { - return AccessPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessPolicyDetailResponse.Result, nil -} - -// UpdateAccessPolicy updates an existing access policy. -// -// API reference: https://api.cloudflare.com/#access-policy-update-access-policy -func (api *API) UpdateAccessPolicy(ctx context.Context, accountID, applicationID string, accessPolicy AccessPolicy) (AccessPolicy, error) { - return api.updateAccessPolicy(ctx, accountID, applicationID, accessPolicy, AccountRouteRoot) -} - -// UpdateZoneLevelAccessPolicy updates an existing zone level access policy. -// -// API reference: https://api.cloudflare.com/#zone-level-access-policy-update-access-policy -func (api *API) UpdateZoneLevelAccessPolicy(ctx context.Context, zoneID, applicationID string, accessPolicy AccessPolicy) (AccessPolicy, error) { - return api.updateAccessPolicy(ctx, zoneID, applicationID, accessPolicy, ZoneRouteRoot) -} - -func (api *API) updateAccessPolicy(ctx context.Context, id, applicationID string, accessPolicy AccessPolicy, routeRoot RouteRoot) (AccessPolicy, error) { - if accessPolicy.ID == "" { - return AccessPolicy{}, fmt.Errorf("access policy ID cannot be empty") - } - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s/policies/%s", - routeRoot, - id, - applicationID, - accessPolicy.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, accessPolicy) - if err != nil { - return AccessPolicy{}, err - } - - var accessPolicyDetailResponse AccessPolicyDetailResponse - err = json.Unmarshal(res, &accessPolicyDetailResponse) - if err != nil { - return AccessPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessPolicyDetailResponse.Result, nil -} - -// DeleteAccessPolicy deletes an access policy. -// -// API reference: https://api.cloudflare.com/#access-policy-update-access-policy -func (api *API) DeleteAccessPolicy(ctx context.Context, accountID, applicationID, accessPolicyID string) error { - return api.deleteAccessPolicy(ctx, accountID, applicationID, accessPolicyID, AccountRouteRoot) -} - -// DeleteZoneLevelAccessPolicy deletes a zone level access policy. -// -// API reference: https://api.cloudflare.com/#zone-level-access-policy-delete-access-policy -func (api *API) DeleteZoneLevelAccessPolicy(ctx context.Context, zoneID, applicationID, accessPolicyID string) error { - return api.deleteAccessPolicy(ctx, zoneID, applicationID, accessPolicyID, ZoneRouteRoot) -} - -func (api *API) deleteAccessPolicy(ctx context.Context, id, applicationID, accessPolicyID string, routeRoot RouteRoot) error { - uri := fmt.Sprintf( - "/%s/%s/access/apps/%s/policies/%s", - routeRoot, - id, - applicationID, - accessPolicyID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_service_tokens.go b/vendor/github.com/cloudflare/cloudflare-go/access_service_tokens.go deleted file mode 100644 index d0f5314..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_service_tokens.go +++ /dev/null @@ -1,297 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AccessServiceToken represents an Access Service Token. -type AccessServiceToken struct { - ClientID string `json:"client_id"` - CreatedAt *time.Time `json:"created_at"` - ExpiresAt *time.Time `json:"expires_at"` - ID string `json:"id"` - Name string `json:"name"` - UpdatedAt *time.Time `json:"updated_at"` -} - -// AccessServiceTokenUpdateResponse represents the response from the API -// when a new Service Token is updated. This base struct is also used in the -// Create as they are very similar responses. -type AccessServiceTokenUpdateResponse struct { - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - ExpiresAt *time.Time `json:"expires_at"` - ID string `json:"id"` - Name string `json:"name"` - ClientID string `json:"client_id"` -} - -// AccessServiceTokenRefreshResponse represents the response from the API -// when an existing service token is refreshed to last longer. -type AccessServiceTokenRefreshResponse struct { - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - ExpiresAt *time.Time `json:"expires_at"` - ID string `json:"id"` - Name string `json:"name"` - ClientID string `json:"client_id"` -} - -// AccessServiceTokenCreateResponse is the same API response as the Update -// operation with the exception that the `ClientSecret` is present in a -// Create operation. -type AccessServiceTokenCreateResponse struct { - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - ExpiresAt *time.Time `json:"expires_at"` - ID string `json:"id"` - Name string `json:"name"` - ClientID string `json:"client_id"` - ClientSecret string `json:"client_secret"` -} - -// AccessServiceTokenRotateResponse is the same API response as the Create -// operation. -type AccessServiceTokenRotateResponse struct { - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - ExpiresAt *time.Time `json:"expires_at"` - ID string `json:"id"` - Name string `json:"name"` - ClientID string `json:"client_id"` - ClientSecret string `json:"client_secret"` -} - -// AccessServiceTokensListResponse represents the response from the list -// Access Service Tokens endpoint. -type AccessServiceTokensListResponse struct { - Result []AccessServiceToken `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessServiceTokensDetailResponse is the API response, containing a single -// Access Service Token. -type AccessServiceTokensDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessServiceToken `json:"result"` -} - -// AccessServiceTokensCreationDetailResponse is the API response, containing a -// single Access Service Token. -type AccessServiceTokensCreationDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessServiceTokenCreateResponse `json:"result"` -} - -// AccessServiceTokensUpdateDetailResponse is the API response, containing a -// single Access Service Token. -type AccessServiceTokensUpdateDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessServiceTokenUpdateResponse `json:"result"` -} - -// AccessServiceTokensRefreshDetailResponse is the API response, containing a -// single Access Service Token. -type AccessServiceTokensRefreshDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessServiceTokenRefreshResponse `json:"result"` -} - -// AccessServiceTokensRotateSecretDetailResponse is the API response, containing a -// single Access Service Token. -type AccessServiceTokensRotateSecretDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccessServiceTokenRotateResponse `json:"result"` -} - -// AccessServiceTokens returns all Access Service Tokens for an account. -// -// API reference: https://api.cloudflare.com/#access-service-tokens-list-access-service-tokens -func (api *API) AccessServiceTokens(ctx context.Context, accountID string) ([]AccessServiceToken, ResultInfo, error) { - return api.accessServiceTokens(ctx, accountID, AccountRouteRoot) -} - -// ZoneLevelAccessServiceTokens returns all Access Service Tokens for a zone. -// -// API reference: https://api.cloudflare.com/#zone-level-access-service-tokens-list-access-service-tokens -func (api *API) ZoneLevelAccessServiceTokens(ctx context.Context, zoneID string) ([]AccessServiceToken, ResultInfo, error) { - return api.accessServiceTokens(ctx, zoneID, ZoneRouteRoot) -} - -func (api *API) accessServiceTokens(ctx context.Context, id string, routeRoot RouteRoot) ([]AccessServiceToken, ResultInfo, error) { - uri := fmt.Sprintf("/%s/%s/access/service_tokens", routeRoot, id) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccessServiceToken{}, ResultInfo{}, err - } - - var accessServiceTokensListResponse AccessServiceTokensListResponse - err = json.Unmarshal(res, &accessServiceTokensListResponse) - if err != nil { - return []AccessServiceToken{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessServiceTokensListResponse.Result, accessServiceTokensListResponse.ResultInfo, nil -} - -// CreateAccessServiceToken creates a new Access Service Token for an account. -// -// API reference: https://api.cloudflare.com/#access-service-tokens-create-access-service-token -func (api *API) CreateAccessServiceToken(ctx context.Context, accountID, name string) (AccessServiceTokenCreateResponse, error) { - return api.createAccessServiceToken(ctx, accountID, name, AccountRouteRoot) -} - -// CreateZoneLevelAccessServiceToken creates a new Access Service Token for a zone. -// -// API reference: https://api.cloudflare.com/#zone-level-access-service-tokens-create-access-service-token -func (api *API) CreateZoneLevelAccessServiceToken(ctx context.Context, zoneID, name string) (AccessServiceTokenCreateResponse, error) { - return api.createAccessServiceToken(ctx, zoneID, name, ZoneRouteRoot) -} - -func (api *API) createAccessServiceToken(ctx context.Context, id, name string, routeRoot RouteRoot) (AccessServiceTokenCreateResponse, error) { - uri := fmt.Sprintf("/%s/%s/access/service_tokens", routeRoot, id) - marshalledName, _ := json.Marshal(struct { - Name string `json:"name"` - }{name}) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, marshalledName) - - if err != nil { - return AccessServiceTokenCreateResponse{}, err - } - - var accessServiceTokenCreation AccessServiceTokensCreationDetailResponse - err = json.Unmarshal(res, &accessServiceTokenCreation) - if err != nil { - return AccessServiceTokenCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessServiceTokenCreation.Result, nil -} - -// UpdateAccessServiceToken updates an existing Access Service Token for an -// account. -// -// API reference: https://api.cloudflare.com/#access-service-tokens-update-access-service-token -func (api *API) UpdateAccessServiceToken(ctx context.Context, accountID, uuid, name string) (AccessServiceTokenUpdateResponse, error) { - return api.updateAccessServiceToken(ctx, accountID, uuid, name, AccountRouteRoot) -} - -// UpdateZoneLevelAccessServiceToken updates an existing Access Service Token for a -// zone. -// -// API reference: https://api.cloudflare.com/#zone-level-access-service-tokens-update-access-service-token -func (api *API) UpdateZoneLevelAccessServiceToken(ctx context.Context, zoneID, uuid, name string) (AccessServiceTokenUpdateResponse, error) { - return api.updateAccessServiceToken(ctx, zoneID, uuid, name, ZoneRouteRoot) -} - -func (api *API) updateAccessServiceToken(ctx context.Context, id, uuid, name string, routeRoot RouteRoot) (AccessServiceTokenUpdateResponse, error) { - uri := fmt.Sprintf("/%s/%s/access/service_tokens/%s", routeRoot, id, uuid) - - marshalledName, _ := json.Marshal(struct { - Name string `json:"name"` - }{name}) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, marshalledName) - if err != nil { - return AccessServiceTokenUpdateResponse{}, err - } - - var accessServiceTokenUpdate AccessServiceTokensUpdateDetailResponse - err = json.Unmarshal(res, &accessServiceTokenUpdate) - if err != nil { - return AccessServiceTokenUpdateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessServiceTokenUpdate.Result, nil -} - -// DeleteAccessServiceToken removes an existing Access Service Token for an -// account. -// -// API reference: https://api.cloudflare.com/#access-service-tokens-delete-access-service-token -func (api *API) DeleteAccessServiceToken(ctx context.Context, accountID, uuid string) (AccessServiceTokenUpdateResponse, error) { - return api.deleteAccessServiceToken(ctx, accountID, uuid, AccountRouteRoot) -} - -// DeleteZoneLevelAccessServiceToken removes an existing Access Service Token for a -// zone. -// -// API reference: https://api.cloudflare.com/#zone-level-access-service-tokens-delete-access-service-token -func (api *API) DeleteZoneLevelAccessServiceToken(ctx context.Context, zoneID, uuid string) (AccessServiceTokenUpdateResponse, error) { - return api.deleteAccessServiceToken(ctx, zoneID, uuid, ZoneRouteRoot) -} - -func (api *API) deleteAccessServiceToken(ctx context.Context, id, uuid string, routeRoot RouteRoot) (AccessServiceTokenUpdateResponse, error) { - uri := fmt.Sprintf("/%s/%s/access/service_tokens/%s", routeRoot, id, uuid) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return AccessServiceTokenUpdateResponse{}, err - } - - var accessServiceTokenUpdate AccessServiceTokensUpdateDetailResponse - err = json.Unmarshal(res, &accessServiceTokenUpdate) - if err != nil { - return AccessServiceTokenUpdateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessServiceTokenUpdate.Result, nil -} - -// RefreshAccessServiceToken updates the expiry of an Access Service Token -// in place. -// -// API reference: https://api.cloudflare.com/#access-service-tokens-refresh-a-service-token -func (api *API) RefreshAccessServiceToken(ctx context.Context, rc *ResourceContainer, id string) (AccessServiceTokenRefreshResponse, error) { - uri := fmt.Sprintf("/%s/%s/access/service_tokens/%s/refresh", rc.Level, rc.Identifier, id) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return AccessServiceTokenRefreshResponse{}, err - } - - var accessServiceTokenRefresh AccessServiceTokensRefreshDetailResponse - err = json.Unmarshal(res, &accessServiceTokenRefresh) - if err != nil { - return AccessServiceTokenRefreshResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessServiceTokenRefresh.Result, nil -} - -// RotateAccessServiceToken rotates the client secret of an Access Service -// Token in place. -// API reference: https://api.cloudflare.com/#access-service-tokens-rotate-a-service-token -func (api *API) RotateAccessServiceToken(ctx context.Context, rc *ResourceContainer, id string) (AccessServiceTokenRotateResponse, error) { - uri := fmt.Sprintf("/%s/%s/access/service_tokens/%s/rotate", rc.Level, rc.Identifier, id) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return AccessServiceTokenRotateResponse{}, err - } - - var accessServiceTokenRotate AccessServiceTokensRotateSecretDetailResponse - err = json.Unmarshal(res, &accessServiceTokenRotate) - if err != nil { - return AccessServiceTokenRotateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accessServiceTokenRotate.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/access_user_tokens.go b/vendor/github.com/cloudflare/cloudflare-go/access_user_tokens.go deleted file mode 100644 index 81f73fa..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/access_user_tokens.go +++ /dev/null @@ -1,38 +0,0 @@ -package cloudflare - -import ( - "context" - "fmt" - "net/http" -) - -type AccessUserEmail struct { - Email string `json:"email"` -} - -// RevokeAccessUserTokens revokes any outstanding tokens issued for a specific user -// Access User. -// -// API reference: https://api.cloudflare.com/#access-organizations-revoke-all-access-tokens-for-a-user -func (api *API) RevokeAccessUserTokens(ctx context.Context, accountID string, accessUserEmail AccessUserEmail) error { - return api.revokeUserTokens(ctx, accountID, accessUserEmail, AccountRouteRoot) -} - -// RevokeZoneLevelAccessUserTokens revokes any outstanding tokens issued for a specific user -// Access User. -// -// API reference: https://api.cloudflare.com/#zone-level-access-organizations-revoke-all-access-tokens-for-a-user -func (api *API) RevokeZoneLevelAccessUserTokens(ctx context.Context, zoneID string, accessUserEmail AccessUserEmail) error { - return api.revokeUserTokens(ctx, zoneID, accessUserEmail, ZoneRouteRoot) -} - -func (api *API) revokeUserTokens(ctx context.Context, id string, accessUserEmail AccessUserEmail, routeRoot RouteRoot) error { - uri := fmt.Sprintf("/%s/%s/access/organizations/revoke_user", routeRoot, id) - - _, err := api.makeRequestContext(ctx, http.MethodPost, uri, accessUserEmail) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/account_members.go b/vendor/github.com/cloudflare/cloudflare-go/account_members.go deleted file mode 100644 index d197fda..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/account_members.go +++ /dev/null @@ -1,244 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -// AccountMember is the definition of a member of an account. -type AccountMember struct { - ID string `json:"id"` - Code string `json:"code"` - User AccountMemberUserDetails `json:"user"` - Status string `json:"status"` - Roles []AccountRole `json:"roles,omitempty"` - Policies []Policy `json:"policies,omitempty"` -} - -// AccountMemberUserDetails outlines all the personal information about -// a member. -type AccountMemberUserDetails struct { - ID string `json:"id"` - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - Email string `json:"email"` - TwoFactorAuthenticationEnabled bool `json:"two_factor_authentication_enabled"` -} - -// AccountMembersListResponse represents the response from the list -// account members endpoint. -type AccountMembersListResponse struct { - Result []AccountMember `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccountMemberDetailResponse is the API response, containing a single -// account member. -type AccountMemberDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccountMember `json:"result"` -} - -// AccountMemberInvitation represents the invitation for a new member to -// the account. -type AccountMemberInvitation struct { - Email string `json:"email"` - Roles []string `json:"roles,omitempty"` - Policies []Policy `json:"policies,omitempty"` - Status string `json:"status,omitempty"` -} - -const errMissingMemberRolesOrPolicies = "account member must be created with roles or policies (not both)" - -var ErrMissingMemberRolesOrPolicies = errors.New(errMissingMemberRolesOrPolicies) - -type CreateAccountMemberParams struct { - EmailAddress string - Roles []string - Policies []Policy - Status string -} - -// AccountMembers returns all members of an account. -// -// API reference: https://api.cloudflare.com/#accounts-list-accounts -func (api *API) AccountMembers(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccountMember, ResultInfo, error) { - if accountID == "" { - return []AccountMember{}, ResultInfo{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/members", accountID), pageOpts) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccountMember{}, ResultInfo{}, err - } - - var accountMemberListresponse AccountMembersListResponse - err = json.Unmarshal(res, &accountMemberListresponse) - if err != nil { - return []AccountMember{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accountMemberListresponse.Result, accountMemberListresponse.ResultInfo, nil -} - -// CreateAccountMemberWithStatus invites a new member to join an account, allowing setting the status. -// -// Refer to the API reference for valid statuses. -// -// Deprecated: Use `CreateAccountMember` with a `Status` field instead. -// -// API reference: https://api.cloudflare.com/#account-members-add-member -func (api *API) CreateAccountMemberWithStatus(ctx context.Context, accountID string, emailAddress string, roles []string, status string) (AccountMember, error) { - return api.CreateAccountMember(ctx, AccountIdentifier(accountID), CreateAccountMemberParams{ - EmailAddress: emailAddress, - Roles: roles, - Status: status, - }) -} - -// CreateAccountMember invites a new member to join an account with roles. -// The member will be placed into "pending" status and receive an email confirmation. -// NOTE: If you are currently enrolled in Domain Scoped Roles, your roles will -// be converted to policies upon member invitation. -// -// API reference: https://api.cloudflare.com/#account-members-add-member -func (api *API) CreateAccountMember(ctx context.Context, rc *ResourceContainer, params CreateAccountMemberParams) (AccountMember, error) { - if rc.Level != AccountRouteLevel { - return AccountMember{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if rc.Identifier == "" { - return AccountMember{}, ErrMissingAccountID - } - - invite := AccountMemberInvitation{ - Email: params.EmailAddress, - Status: params.Status, - } - - roles := []AccountRole{} - for i := 0; i < len(params.Roles); i++ { - roles = append(roles, AccountRole{ID: params.Roles[i]}) - } - err := validateRolesAndPolicies(roles, params.Policies) - if err != nil { - return AccountMember{}, err - } - - if params.Roles != nil { - invite.Roles = params.Roles - } else if params.Policies != nil { - invite.Policies = params.Policies - } - - uri := fmt.Sprintf("/accounts/%s/members", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, invite) - if err != nil { - return AccountMember{}, err - } - - var accountMemberListResponse AccountMemberDetailResponse - err = json.Unmarshal(res, &accountMemberListResponse) - if err != nil { - return AccountMember{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accountMemberListResponse.Result, nil -} - -// DeleteAccountMember removes a member from an account. -// -// API reference: https://api.cloudflare.com/#account-members-remove-member -func (api *API) DeleteAccountMember(ctx context.Context, accountID string, userID string) error { - if accountID == "" { - return ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/members/%s", accountID, userID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} - -// UpdateAccountMember modifies an existing account member. -// -// API reference: https://api.cloudflare.com/#account-members-update-member -func (api *API) UpdateAccountMember(ctx context.Context, accountID string, userID string, member AccountMember) (AccountMember, error) { - if accountID == "" { - return AccountMember{}, ErrMissingAccountID - } - - err := validateRolesAndPolicies(member.Roles, member.Policies) - if err != nil { - return AccountMember{}, err - } - - uri := fmt.Sprintf("/accounts/%s/members/%s", accountID, userID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, member) - if err != nil { - return AccountMember{}, err - } - - var accountMemberListResponse AccountMemberDetailResponse - err = json.Unmarshal(res, &accountMemberListResponse) - if err != nil { - return AccountMember{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accountMemberListResponse.Result, nil -} - -// AccountMember returns details of a single account member. -// -// API reference: https://api.cloudflare.com/#account-members-member-details -func (api *API) AccountMember(ctx context.Context, accountID string, memberID string) (AccountMember, error) { - if accountID == "" { - return AccountMember{}, ErrMissingAccountID - } - - uri := fmt.Sprintf( - "/accounts/%s/members/%s", - accountID, - memberID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccountMember{}, err - } - - var accountMemberResponse AccountMemberDetailResponse - err = json.Unmarshal(res, &accountMemberResponse) - if err != nil { - return AccountMember{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accountMemberResponse.Result, nil -} - -// validateRolesAndPolicies ensures either roles or policies are provided in -// CreateAccountMember requests, but not both. -func validateRolesAndPolicies(roles []AccountRole, policies []Policy) error { - hasRoles := len(roles) > 0 - hasPolicies := len(policies) > 0 - hasRolesOrPolicies := hasRoles || hasPolicies - hasRolesAndPolicies := hasRoles && hasPolicies - hasCorrectPermissions := hasRolesOrPolicies && !hasRolesAndPolicies - if !hasCorrectPermissions { - return ErrMissingMemberRolesOrPolicies - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/account_roles.go b/vendor/github.com/cloudflare/cloudflare-go/account_roles.go deleted file mode 100644 index 2f51b37..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/account_roles.go +++ /dev/null @@ -1,80 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// AccountRole defines the roles that a member can have attached. -type AccountRole struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Permissions map[string]AccountRolePermission `json:"permissions"` -} - -// AccountRolePermission is the shared structure for all permissions -// that can be assigned to a member. -type AccountRolePermission struct { - Read bool `json:"read"` - Edit bool `json:"edit"` -} - -// AccountRolesListResponse represents the list response from the -// account roles. -type AccountRolesListResponse struct { - Result []AccountRole `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccountRoleDetailResponse is the API response, containing a single -// account role. -type AccountRoleDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result AccountRole `json:"result"` -} - -// AccountRoles returns all roles of an account. -// -// API reference: https://api.cloudflare.com/#account-roles-list-roles -func (api *API) AccountRoles(ctx context.Context, accountID string) ([]AccountRole, error) { - uri := fmt.Sprintf("/accounts/%s/roles?per_page=50", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []AccountRole{}, err - } - - var accountRolesListResponse AccountRolesListResponse - err = json.Unmarshal(res, &accountRolesListResponse) - if err != nil { - return []AccountRole{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accountRolesListResponse.Result, nil -} - -// AccountRole returns the details of a single account role. -// -// API reference: https://api.cloudflare.com/#account-roles-role-details -func (api *API) AccountRole(ctx context.Context, accountID string, roleID string) (AccountRole, error) { - uri := fmt.Sprintf("/accounts/%s/roles/%s", accountID, roleID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AccountRole{}, err - } - - var accountRole AccountRoleDetailResponse - err = json.Unmarshal(res, &accountRole) - if err != nil { - return AccountRole{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accountRole.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/accounts.go b/vendor/github.com/cloudflare/cloudflare-go/accounts.go deleted file mode 100644 index 7cca6e7..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/accounts.go +++ /dev/null @@ -1,150 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AccountSettings outlines the available options for an account. -type AccountSettings struct { - EnforceTwoFactor bool `json:"enforce_twofactor"` -} - -// Account represents the root object that owns resources. -type Account struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` - CreatedOn time.Time `json:"created_on,omitempty"` - Settings *AccountSettings `json:"settings,omitempty"` -} - -// AccountResponse represents the response from the accounts endpoint for a -// single account ID. -type AccountResponse struct { - Result Account `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccountListResponse represents the response from the list accounts endpoint. -type AccountListResponse struct { - Result []Account `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccountDetailResponse is the API response, containing a single Account. -type AccountDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result Account `json:"result"` -} - -// AccountsListParams holds the filterable options for Accounts. -type AccountsListParams struct { - Name string `url:"name,omitempty"` - - PaginationOptions -} - -// Accounts returns all accounts the logged in user has access to. -// -// API reference: https://api.cloudflare.com/#accounts-list-accounts -func (api *API) Accounts(ctx context.Context, params AccountsListParams) ([]Account, ResultInfo, error) { - res, err := api.makeRequestContext(ctx, http.MethodGet, buildURI("/accounts", params), nil) - if err != nil { - return []Account{}, ResultInfo{}, err - } - - var accListResponse AccountListResponse - err = json.Unmarshal(res, &accListResponse) - if err != nil { - return []Account{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return accListResponse.Result, accListResponse.ResultInfo, nil -} - -// Account returns a single account based on the ID. -// -// API reference: https://api.cloudflare.com/#accounts-account-details -func (api *API) Account(ctx context.Context, accountID string) (Account, ResultInfo, error) { - uri := fmt.Sprintf("/accounts/%s", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Account{}, ResultInfo{}, err - } - - var accResponse AccountResponse - err = json.Unmarshal(res, &accResponse) - if err != nil { - return Account{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return accResponse.Result, accResponse.ResultInfo, nil -} - -// UpdateAccount allows management of an account using the account ID. -// -// API reference: https://api.cloudflare.com/#accounts-update-account -func (api *API) UpdateAccount(ctx context.Context, accountID string, account Account) (Account, error) { - uri := fmt.Sprintf("/accounts/%s", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, account) - if err != nil { - return Account{}, err - } - - var a AccountDetailResponse - err = json.Unmarshal(res, &a) - if err != nil { - return Account{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return a.Result, nil -} - -// CreateAccount creates a new account. Note: This requires the Tenant -// entitlement. -// -// API reference: https://developers.cloudflare.com/tenant/tutorial/provisioning-resources#creating-an-account -func (api *API) CreateAccount(ctx context.Context, account Account) (Account, error) { - uri := "/accounts" - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, account) - if err != nil { - return Account{}, err - } - - var a AccountDetailResponse - err = json.Unmarshal(res, &a) - if err != nil { - return Account{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return a.Result, nil -} - -// DeleteAccount removes an account. Note: This requires the Tenant -// entitlement. -// -// API reference: https://developers.cloudflare.com/tenant/tutorial/provisioning-resources#optional-deleting-accounts -func (api *API) DeleteAccount(ctx context.Context, accountID string) error { - if accountID == "" { - return ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s", accountID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/api_shield.go b/vendor/github.com/cloudflare/cloudflare-go/api_shield.go deleted file mode 100644 index 4071508..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/api_shield.go +++ /dev/null @@ -1,70 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// AuthIdCharacteristics a single option from -// configuration?properties=auth_id_characteristics. -type AuthIdCharacteristics struct { - Type string `json:"type"` - Name string `json:"name"` -} - -// APIShield is all the available options under -// configuration?properties=auth_id_characteristics. -type APIShield struct { - AuthIdCharacteristics []AuthIdCharacteristics `json:"auth_id_characteristics"` -} - -// APIShieldResponse represents the response from the api_gateway/configuration endpoint. -type APIShieldResponse struct { - Result APIShield `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -type UpdateAPIShieldParams struct { - AuthIdCharacteristics []AuthIdCharacteristics `json:"auth_id_characteristics"` -} - -// GetAPIShieldConfiguration gets a zone API shield configuration. -// -// API documentation: https://api.cloudflare.com/#api-shield-settings-retrieve-information-about-specific-configuration-properties -func (api *API) GetAPIShieldConfiguration(ctx context.Context, rc *ResourceContainer) (APIShield, ResultInfo, error) { - uri := fmt.Sprintf("/zones/%s/api_gateway/configuration?properties=auth_id_characteristics", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return APIShield{}, ResultInfo{}, err - } - var asResponse APIShieldResponse - err = json.Unmarshal(res, &asResponse) - if err != nil { - return APIShield{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return asResponse.Result, asResponse.ResultInfo, nil -} - -// UpdateAPIShieldConfiguration sets a zone API shield configuration. -// -// API documentation: https://api.cloudflare.com/#api-shield-settings-set-configuration-properties -func (api *API) UpdateAPIShieldConfiguration(ctx context.Context, rc *ResourceContainer, params UpdateAPIShieldParams) (Response, error) { - uri := fmt.Sprintf("/zones/%s/api_gateway/configuration", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return Response{}, err - } - var asResponse Response - err = json.Unmarshal(res, &asResponse) - if err != nil { - return Response{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return asResponse, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/api_token.go b/vendor/github.com/cloudflare/cloudflare-go/api_token.go deleted file mode 100644 index 41bd85d..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/api_token.go +++ /dev/null @@ -1,237 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// APIToken is the full API token. -type APIToken struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Status string `json:"status,omitempty"` - IssuedOn *time.Time `json:"issued_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - NotBefore *time.Time `json:"not_before,omitempty"` - ExpiresOn *time.Time `json:"expires_on,omitempty"` - Policies []APITokenPolicies `json:"policies,omitempty"` - Condition *APITokenCondition `json:"condition,omitempty"` - Value string `json:"value,omitempty"` -} - -// APITokenPermissionGroups is the permission groups associated with API tokens. -type APITokenPermissionGroups struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - Scopes []string `json:"scopes,omitempty"` -} - -// APITokenPolicies are policies attached to an API token. -type APITokenPolicies struct { - ID string `json:"id,omitempty"` - Effect string `json:"effect"` - Resources map[string]interface{} `json:"resources"` - PermissionGroups []APITokenPermissionGroups `json:"permission_groups"` -} - -// APITokenRequestIPCondition is the struct for adding an IP restriction to an -// API token. -type APITokenRequestIPCondition struct { - In []string `json:"in,omitempty"` - NotIn []string `json:"not_in,omitempty"` -} - -// APITokenCondition is the outer structure for request conditions (currently -// only IPs). -type APITokenCondition struct { - RequestIP *APITokenRequestIPCondition `json:"request.ip,omitempty"` -} - -// APITokenResponse is the API response for a single API token. -type APITokenResponse struct { - Response - Result APIToken `json:"result"` -} - -// APITokenListResponse is the API response for multiple API tokens. -type APITokenListResponse struct { - Response - Result []APIToken `json:"result"` -} - -// APITokenRollResponse is the API response when rolling the token. -type APITokenRollResponse struct { - Response - Result string `json:"result"` -} - -// APITokenVerifyResponse is the API response for verifying a token. -type APITokenVerifyResponse struct { - Response - Result APITokenVerifyBody `json:"result"` -} - -// APITokenPermissionGroupsResponse is the API response for the available -// permission groups. -type APITokenPermissionGroupsResponse struct { - Response - Result []APITokenPermissionGroups `json:"result"` -} - -// APITokenVerifyBody is the API body for verifying a token. -type APITokenVerifyBody struct { - ID string `json:"id"` - Status string `json:"status"` - NotBefore time.Time `json:"not_before"` - ExpiresOn time.Time `json:"expires_on"` -} - -// GetAPIToken returns a single API token based on the ID. -// -// API reference: https://api.cloudflare.com/#user-api-tokens-token-details -func (api *API) GetAPIToken(ctx context.Context, tokenID string) (APIToken, error) { - uri := fmt.Sprintf("/user/tokens/%s", tokenID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return APIToken{}, err - } - - var apiTokenResponse APITokenResponse - err = json.Unmarshal(res, &apiTokenResponse) - if err != nil { - return APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return apiTokenResponse.Result, nil -} - -// APITokens returns all available API tokens. -// -// API reference: https://api.cloudflare.com/#user-api-tokens-list-tokens -func (api *API) APITokens(ctx context.Context) ([]APIToken, error) { - res, err := api.makeRequestContext(ctx, http.MethodGet, "/user/tokens", nil) - if err != nil { - return []APIToken{}, err - } - - var apiTokenListResponse APITokenListResponse - err = json.Unmarshal(res, &apiTokenListResponse) - if err != nil { - return []APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return apiTokenListResponse.Result, nil -} - -// CreateAPIToken creates a new token. Returns the API token that has been -// generated. -// -// The token value itself is only shown once (post create) and will present as -// `Value` from this method. If you fail to capture it at this point, you will -// need to roll the token in order to get a new value. -// -// API reference: https://api.cloudflare.com/#user-api-tokens-create-token -func (api *API) CreateAPIToken(ctx context.Context, token APIToken) (APIToken, error) { - res, err := api.makeRequestContext(ctx, http.MethodPost, "/user/tokens", token) - if err != nil { - return APIToken{}, err - } - - var createTokenAPIResponse APITokenResponse - err = json.Unmarshal(res, &createTokenAPIResponse) - if err != nil { - return APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return createTokenAPIResponse.Result, nil -} - -// UpdateAPIToken updates an existing API token. -// -// API reference: https://api.cloudflare.com/#user-api-tokens-update-token -func (api *API) UpdateAPIToken(ctx context.Context, tokenID string, token APIToken) (APIToken, error) { - res, err := api.makeRequestContext(ctx, http.MethodPut, "/user/tokens/"+tokenID, token) - if err != nil { - return APIToken{}, err - } - - var updatedTokenResponse APITokenResponse - err = json.Unmarshal(res, &updatedTokenResponse) - if err != nil { - return APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return updatedTokenResponse.Result, nil -} - -// RollAPIToken rolls the credential associated with the token. -// -// API reference: https://api.cloudflare.com/#user-api-tokens-roll-token -func (api *API) RollAPIToken(ctx context.Context, tokenID string) (string, error) { - uri := fmt.Sprintf("/user/tokens/%s/value", tokenID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, nil) - if err != nil { - return "", err - } - - var apiTokenRollResponse APITokenRollResponse - err = json.Unmarshal(res, &apiTokenRollResponse) - if err != nil { - return "", fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return apiTokenRollResponse.Result, nil -} - -// VerifyAPIToken tests the validity of the token. -// -// API reference: https://api.cloudflare.com/#user-api-tokens-verify-token -func (api *API) VerifyAPIToken(ctx context.Context) (APITokenVerifyBody, error) { - res, err := api.makeRequestContext(ctx, http.MethodGet, "/user/tokens/verify", nil) - if err != nil { - return APITokenVerifyBody{}, err - } - - var apiTokenVerifyResponse APITokenVerifyResponse - err = json.Unmarshal(res, &apiTokenVerifyResponse) - if err != nil { - return APITokenVerifyBody{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return apiTokenVerifyResponse.Result, nil -} - -// DeleteAPIToken deletes a single API token. -// -// API reference: https://api.cloudflare.com/#user-api-tokens-delete-token -func (api *API) DeleteAPIToken(ctx context.Context, tokenID string) error { - _, err := api.makeRequestContext(ctx, http.MethodDelete, "/user/tokens/"+tokenID, nil) - if err != nil { - return err - } - - return nil -} - -// ListAPITokensPermissionGroups returns all available API token permission groups. -// -// API reference: https://api.cloudflare.com/#permission-groups-list-permission-groups -func (api *API) ListAPITokensPermissionGroups(ctx context.Context) ([]APITokenPermissionGroups, error) { - var r APITokenPermissionGroupsResponse - res, err := api.makeRequestContext(ctx, http.MethodGet, "/user/tokens/permission_groups", nil) - if err != nil { - return []APITokenPermissionGroups{}, err - } - - err = json.Unmarshal(res, &r) - if err != nil { - return []APITokenPermissionGroups{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/argo.go b/vendor/github.com/cloudflare/cloudflare-go/argo.go deleted file mode 100644 index c72922f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/argo.go +++ /dev/null @@ -1,120 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -var validSettingValues = []string{"on", "off"} - -// ArgoFeatureSetting is the structure of the API object for the -// argo smart routing and tiered caching settings. -type ArgoFeatureSetting struct { - Editable bool `json:"editable,omitempty"` - ID string `json:"id,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty"` - Value string `json:"value"` -} - -// ArgoDetailsResponse is the API response for the argo smart routing -// and tiered caching response. -type ArgoDetailsResponse struct { - Result ArgoFeatureSetting `json:"result"` - Response -} - -// ArgoSmartRouting returns the current settings for smart routing. -// -// API reference: https://api.cloudflare.com/#argo-smart-routing-get-argo-smart-routing-setting -func (api *API) ArgoSmartRouting(ctx context.Context, zoneID string) (ArgoFeatureSetting, error) { - uri := fmt.Sprintf("/zones/%s/argo/smart_routing", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ArgoFeatureSetting{}, err - } - - var argoDetailsResponse ArgoDetailsResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// UpdateArgoSmartRouting updates the setting for smart routing. -// -// API reference: https://api.cloudflare.com/#argo-smart-routing-patch-argo-smart-routing-setting -func (api *API) UpdateArgoSmartRouting(ctx context.Context, zoneID, settingValue string) (ArgoFeatureSetting, error) { - if !contains(validSettingValues, settingValue) { - return ArgoFeatureSetting{}, fmt.Errorf("invalid setting value '%s'. must be 'on' or 'off'", settingValue) - } - - uri := fmt.Sprintf("/zones/%s/argo/smart_routing", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, ArgoFeatureSetting{Value: settingValue}) - if err != nil { - return ArgoFeatureSetting{}, err - } - - var argoDetailsResponse ArgoDetailsResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// ArgoTieredCaching returns the current settings for tiered caching. -// -// API reference: TBA. -func (api *API) ArgoTieredCaching(ctx context.Context, zoneID string) (ArgoFeatureSetting, error) { - uri := fmt.Sprintf("/zones/%s/argo/tiered_caching", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ArgoFeatureSetting{}, err - } - - var argoDetailsResponse ArgoDetailsResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// UpdateArgoTieredCaching updates the setting for tiered caching. -// -// API reference: TBA. -func (api *API) UpdateArgoTieredCaching(ctx context.Context, zoneID, settingValue string) (ArgoFeatureSetting, error) { - if !contains(validSettingValues, settingValue) { - return ArgoFeatureSetting{}, fmt.Errorf("invalid setting value '%s'. must be 'on' or 'off'", settingValue) - } - - uri := fmt.Sprintf("/zones/%s/argo/tiered_caching", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, ArgoFeatureSetting{Value: settingValue}) - if err != nil { - return ArgoFeatureSetting{}, err - } - - var argoDetailsResponse ArgoDetailsResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -func contains(s []string, e string) bool { - for _, a := range s { - if a == e { - return true - } - } - return false -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/argo_tunnel.go b/vendor/github.com/cloudflare/cloudflare-go/argo_tunnel.go deleted file mode 100644 index 89f6ae8..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/argo_tunnel.go +++ /dev/null @@ -1,161 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// ArgoTunnel is the struct definition of a tunnel. -type ArgoTunnel struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Secret string `json:"tunnel_secret,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - DeletedAt *time.Time `json:"deleted_at,omitempty"` - Connections []ArgoTunnelConnection `json:"connections,omitempty"` -} - -// ArgoTunnelConnection represents the connections associated with a tunnel. -type ArgoTunnelConnection struct { - ColoName string `json:"colo_name"` - UUID string `json:"uuid"` - IsPendingReconnect bool `json:"is_pending_reconnect"` -} - -// ArgoTunnelsDetailResponse is used for representing the API response payload for -// multiple tunnels. -type ArgoTunnelsDetailResponse struct { - Result []ArgoTunnel `json:"result"` - Response -} - -// ArgoTunnelDetailResponse is used for representing the API response payload for -// a single tunnel. -type ArgoTunnelDetailResponse struct { - Result ArgoTunnel `json:"result"` - Response -} - -// ArgoTunnels lists all tunnels. -// -// API reference: https://api.cloudflare.com/#argo-tunnel-list-argo-tunnels -// -// Deprecated: Use `Tunnels` instead. -func (api *API) ArgoTunnels(ctx context.Context, accountID string) ([]ArgoTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel", accountID) - - res, err := api.makeRequestContextWithHeaders(ctx, http.MethodGet, uri, nil, argoV1Header()) - if err != nil { - return []ArgoTunnel{}, err - } - - var argoDetailsResponse ArgoTunnelsDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return []ArgoTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// ArgoTunnel returns a single Argo tunnel. -// -// API reference: https://api.cloudflare.com/#argo-tunnel-get-argo-tunnel -// -// Deprecated: Use `Tunnel` instead. -func (api *API) ArgoTunnel(ctx context.Context, accountID, tunnelUUID string) (ArgoTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s", accountID, tunnelUUID) - - res, err := api.makeRequestContextWithHeaders(ctx, http.MethodGet, uri, nil, argoV1Header()) - if err != nil { - return ArgoTunnel{}, err - } - - var argoDetailsResponse ArgoTunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return ArgoTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// CreateArgoTunnel creates a new tunnel for the account. -// -// API reference: https://api.cloudflare.com/#argo-tunnel-create-argo-tunnel -// -// Deprecated: Use `CreateTunnel` instead. -func (api *API) CreateArgoTunnel(ctx context.Context, accountID, name, secret string) (ArgoTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel", accountID) - - tunnel := ArgoTunnel{Name: name, Secret: secret} - - res, err := api.makeRequestContextWithHeaders(ctx, http.MethodPost, uri, tunnel, argoV1Header()) - if err != nil { - return ArgoTunnel{}, err - } - - var argoDetailsResponse ArgoTunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return ArgoTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return argoDetailsResponse.Result, nil -} - -// DeleteArgoTunnel removes a single Argo tunnel. -// -// API reference: https://api.cloudflare.com/#argo-tunnel-delete-argo-tunnel -// -// Deprecated: Use `DeleteTunnel` instead. -func (api *API) DeleteArgoTunnel(ctx context.Context, accountID, tunnelUUID string) error { - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s", accountID, tunnelUUID) - - res, err := api.makeRequestContextWithHeaders(ctx, http.MethodDelete, uri, nil, argoV1Header()) - if err != nil { - return err - } - - var argoDetailsResponse ArgoTunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// CleanupArgoTunnelConnections deletes any inactive connections on a tunnel. -// -// API reference: https://api.cloudflare.com/#argo-tunnel-clean-up-argo-tunnel-connections -// -// Deprecated: Use `CleanupTunnelConnections` instead. -func (api *API) CleanupArgoTunnelConnections(ctx context.Context, accountID, tunnelUUID string) error { - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s/connections", accountID, tunnelUUID) - - res, err := api.makeRequestContextWithHeaders(ctx, http.MethodDelete, uri, nil, argoV1Header()) - if err != nil { - return err - } - - var argoDetailsResponse ArgoTunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// The early implementation of Argo Tunnel endpoints didn't conform to the V4 -// API standard response structure. This has been remedied going forward however -// to support older clients this isn't yet the default. An explicit `Accept` -// header is used to get the V4 compatible version. -func argoV1Header() http.Header { - header := make(http.Header) - header.Set("Accept", "application/json;version=1") - - return header -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/auditlogs.go b/vendor/github.com/cloudflare/cloudflare-go/auditlogs.go deleted file mode 100644 index 34e76b0..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/auditlogs.go +++ /dev/null @@ -1,157 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "net/http" - "net/url" - "path" - "strconv" - "time" -) - -// AuditLogAction is a member of AuditLog, the action that was taken. -type AuditLogAction struct { - Result bool `json:"result"` - Type string `json:"type"` -} - -// AuditLogActor is a member of AuditLog, who performed the action. -type AuditLogActor struct { - Email string `json:"email"` - ID string `json:"id"` - IP string `json:"ip"` - Type string `json:"type"` -} - -// AuditLogOwner is a member of AuditLog, who owns this audit log. -type AuditLogOwner struct { - ID string `json:"id"` -} - -// AuditLogResource is a member of AuditLog, what was the action performed on. -type AuditLogResource struct { - ID string `json:"id"` - Type string `json:"type"` -} - -// AuditLog is an resource that represents an update in the cloudflare dash. -type AuditLog struct { - Action AuditLogAction `json:"action"` - Actor AuditLogActor `json:"actor"` - ID string `json:"id"` - Metadata map[string]interface{} `json:"metadata"` - NewValue string `json:"newValue"` - NewValueJSON map[string]interface{} `json:"newValueJson"` - OldValue string `json:"oldValue"` - OldValueJSON map[string]interface{} `json:"oldValueJson"` - Owner AuditLogOwner `json:"owner"` - Resource AuditLogResource `json:"resource"` - When time.Time `json:"when"` -} - -// AuditLogResponse is the response returned from the cloudflare v4 api. -type AuditLogResponse struct { - Response Response - Result []AuditLog `json:"result"` - ResultInfo `json:"result_info"` -} - -// AuditLogFilter is an object for filtering the audit log response from the api. -type AuditLogFilter struct { - ID string - ActorIP string - ActorEmail string - HideUserLogs bool - Direction string - ZoneName string - Since string - Before string - PerPage int - Page int -} - -// ToQuery turns an audit log filter in to an HTTP Query Param -// list, suitable for use in a url.URL.RawQuery. It will not include empty -// members of the struct in the query parameters. -func (a AuditLogFilter) ToQuery() url.Values { - v := url.Values{} - - if a.ID != "" { - v.Add("id", a.ID) - } - if a.ActorIP != "" { - v.Add("actor.ip", a.ActorIP) - } - if a.ActorEmail != "" { - v.Add("actor.email", a.ActorEmail) - } - if a.HideUserLogs { - v.Add("hide_user_logs", "true") - } - if a.ZoneName != "" { - v.Add("zone.name", a.ZoneName) - } - if a.Direction != "" { - v.Add("direction", a.Direction) - } - if a.Since != "" { - v.Add("since", a.Since) - } - if a.Before != "" { - v.Add("before", a.Before) - } - if a.PerPage > 0 { - v.Add("per_page", strconv.Itoa(a.PerPage)) - } - if a.Page > 0 { - v.Add("page", strconv.Itoa(a.Page)) - } - - return v -} - -// GetOrganizationAuditLogs will return the audit logs of a specific -// organization, based on the ID passed in. The audit logs can be -// filtered based on any argument in the AuditLogFilter. -// -// API Reference: https://api.cloudflare.com/#audit-logs-list-organization-audit-logs -func (api *API) GetOrganizationAuditLogs(ctx context.Context, organizationID string, a AuditLogFilter) (AuditLogResponse, error) { - uri := url.URL{ - Path: path.Join("/accounts", organizationID, "audit_logs"), - ForceQuery: true, - RawQuery: a.ToQuery().Encode(), - } - res, err := api.makeRequestContext(ctx, http.MethodGet, uri.String(), nil) - if err != nil { - return AuditLogResponse{}, err - } - return unmarshalReturn(res) -} - -// unmarshalReturn will unmarshal bytes and return an auditlogresponse. -func unmarshalReturn(res []byte) (AuditLogResponse, error) { - var auditResponse AuditLogResponse - err := json.Unmarshal(res, &auditResponse) - if err != nil { - return auditResponse, err - } - return auditResponse, nil -} - -// GetUserAuditLogs will return your user's audit logs. The audit logs can be -// filtered based on any argument in the AuditLogFilter. -// -// API Reference: https://api.cloudflare.com/#audit-logs-list-user-audit-logs -func (api *API) GetUserAuditLogs(ctx context.Context, a AuditLogFilter) (AuditLogResponse, error) { - uri := url.URL{ - Path: path.Join("/user", "audit_logs"), - ForceQuery: true, - RawQuery: a.ToQuery().Encode(), - } - res, err := api.makeRequestContext(ctx, http.MethodGet, uri.String(), nil) - if err != nil { - return AuditLogResponse{}, err - } - return unmarshalReturn(res) -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls.go b/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls.go deleted file mode 100644 index 2936f65..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls.go +++ /dev/null @@ -1,66 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// AuthenticatedOriginPulls represents global AuthenticatedOriginPulls (tls_client_auth) metadata. -type AuthenticatedOriginPulls struct { - ID string `json:"id"` - Value string `json:"value"` - Editable bool `json:"editable"` - ModifiedOn time.Time `json:"modified_on"` -} - -// AuthenticatedOriginPullsResponse represents the response from the global AuthenticatedOriginPulls (tls_client_auth) details endpoint. -type AuthenticatedOriginPullsResponse struct { - Response - Result AuthenticatedOriginPulls `json:"result"` -} - -// GetAuthenticatedOriginPullsStatus returns the configuration details for global AuthenticatedOriginPulls (tls_client_auth). -// -// API reference: https://api.cloudflare.com/#zone-settings-get-tls-client-auth-setting -func (api *API) GetAuthenticatedOriginPullsStatus(ctx context.Context, zoneID string) (AuthenticatedOriginPulls, error) { - uri := fmt.Sprintf("/zones/%s/settings/tls_client_auth", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AuthenticatedOriginPulls{}, err - } - var r AuthenticatedOriginPullsResponse - if err := json.Unmarshal(res, &r); err != nil { - return AuthenticatedOriginPulls{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// SetAuthenticatedOriginPullsStatus toggles whether global AuthenticatedOriginPulls is enabled for the zone. -// -// API reference: https://api.cloudflare.com/#zone-settings-change-tls-client-auth-setting -func (api *API) SetAuthenticatedOriginPullsStatus(ctx context.Context, zoneID string, enable bool) (AuthenticatedOriginPulls, error) { - uri := fmt.Sprintf("/zones/%s/settings/tls_client_auth", zoneID) - var val string - if enable { - val = "on" - } else { - val = "off" - } - params := struct { - Value string `json:"value"` - }{ - Value: val, - } - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) - if err != nil { - return AuthenticatedOriginPulls{}, err - } - var r AuthenticatedOriginPullsResponse - if err := json.Unmarshal(res, &r); err != nil { - return AuthenticatedOriginPulls{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls_per_hostname.go b/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls_per_hostname.go deleted file mode 100644 index 8a488c5..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls_per_hostname.go +++ /dev/null @@ -1,174 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// PerHostnameAuthenticatedOriginPullsCertificateDetails represents the metadata for a Per Hostname AuthenticatedOriginPulls certificate. -type PerHostnameAuthenticatedOriginPullsCertificateDetails struct { - ID string `json:"id"` - Certificate string `json:"certificate"` - Issuer string `json:"issuer"` - Signature string `json:"signature"` - SerialNumber string `json:"serial_number"` - ExpiresOn time.Time `json:"expires_on"` - Status string `json:"status"` - UploadedOn time.Time `json:"uploaded_on"` -} - -// PerHostnameAuthenticatedOriginPullsCertificateResponse represents the response from endpoints relating to creating and deleting a Per Hostname AuthenticatedOriginPulls certificate. -type PerHostnameAuthenticatedOriginPullsCertificateResponse struct { - Response - Result PerHostnameAuthenticatedOriginPullsCertificateDetails `json:"result"` -} - -// PerHostnameAuthenticatedOriginPullsDetails contains metadata about the Per Hostname AuthenticatedOriginPulls configuration on a hostname. -type PerHostnameAuthenticatedOriginPullsDetails struct { - Hostname string `json:"hostname"` - CertID string `json:"cert_id"` - Enabled bool `json:"enabled"` - Status string `json:"status"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - CertStatus string `json:"cert_status"` - Issuer string `json:"issuer"` - Signature string `json:"signature"` - SerialNumber string `json:"serial_number"` - Certificate string `json:"certificate"` - CertUploadedOn time.Time `json:"cert_uploaded_on"` - CertUpdatedAt time.Time `json:"cert_updated_at"` - ExpiresOn time.Time `json:"expires_on"` -} - -// PerHostnameAuthenticatedOriginPullsDetailsResponse represents Per Hostname AuthenticatedOriginPulls configuration metadata for a single hostname. -type PerHostnameAuthenticatedOriginPullsDetailsResponse struct { - Response - Result PerHostnameAuthenticatedOriginPullsDetails `json:"result"` -} - -// PerHostnamesAuthenticatedOriginPullsDetailsResponse represents Per Hostname AuthenticatedOriginPulls configuration metadata for multiple hostnames. -type PerHostnamesAuthenticatedOriginPullsDetailsResponse struct { - Response - Result []PerHostnameAuthenticatedOriginPullsDetails `json:"result"` -} - -// PerHostnameAuthenticatedOriginPullsCertificateParams represents the required data related to the client certificate being uploaded to be used in Per Hostname AuthenticatedOriginPulls. -type PerHostnameAuthenticatedOriginPullsCertificateParams struct { - Certificate string `json:"certificate"` - PrivateKey string `json:"private_key"` -} - -// PerHostnameAuthenticatedOriginPullsConfig represents the config state for Per Hostname AuthenticatedOriginPulls applied on a hostname. -type PerHostnameAuthenticatedOriginPullsConfig struct { - Hostname string `json:"hostname"` - CertID string `json:"cert_id"` - Enabled bool `json:"enabled"` -} - -// PerHostnameAuthenticatedOriginPullsConfigParams represents the expected config param format for Per Hostname AuthenticatedOriginPulls applied on a hostname. -type PerHostnameAuthenticatedOriginPullsConfigParams struct { - Config []PerHostnameAuthenticatedOriginPullsConfig `json:"config"` -} - -// ListPerHostnameAuthenticatedOriginPullsCertificates will get all certificate under Per Hostname AuthenticatedOriginPulls zone. -// -// API reference: https://api.cloudflare.com/#per-hostname-authenticated-origin-pull-list-certificates -func (api *API) ListPerHostnameAuthenticatedOriginPullsCertificates(ctx context.Context, zoneID string) ([]PerHostnameAuthenticatedOriginPullsDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/hostnames/certificates", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []PerHostnameAuthenticatedOriginPullsDetails{}, err - } - var r PerHostnamesAuthenticatedOriginPullsDetailsResponse - if err := json.Unmarshal(res, &r); err != nil { - return []PerHostnameAuthenticatedOriginPullsDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UploadPerHostnameAuthenticatedOriginPullsCertificate will upload the provided certificate and private key to the edge under Per Hostname AuthenticatedOriginPulls. -// -// API reference: https://api.cloudflare.com/#per-hostname-authenticated-origin-pull-upload-a-hostname-client-certificate -func (api *API) UploadPerHostnameAuthenticatedOriginPullsCertificate(ctx context.Context, zoneID string, params PerHostnameAuthenticatedOriginPullsCertificateParams) (PerHostnameAuthenticatedOriginPullsCertificateDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/hostnames/certificates", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, err - } - var r PerHostnameAuthenticatedOriginPullsCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetPerHostnameAuthenticatedOriginPullsCertificate retrieves certificate metadata about the requested Per Hostname certificate. -// -// API reference: https://api.cloudflare.com/#per-hostname-authenticated-origin-pull-get-the-hostname-client-certificate -func (api *API) GetPerHostnameAuthenticatedOriginPullsCertificate(ctx context.Context, zoneID, certificateID string) (PerHostnameAuthenticatedOriginPullsCertificateDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/hostnames/certificates/%s", zoneID, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, err - } - var r PerHostnameAuthenticatedOriginPullsCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeletePerHostnameAuthenticatedOriginPullsCertificate will remove the requested Per Hostname certificate from the edge. -// -// API reference: https://api.cloudflare.com/#per-hostname-authenticated-origin-pull-delete-hostname-client-certificate -func (api *API) DeletePerHostnameAuthenticatedOriginPullsCertificate(ctx context.Context, zoneID, certificateID string) (PerHostnameAuthenticatedOriginPullsCertificateDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/hostnames/certificates/%s", zoneID, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, err - } - var r PerHostnameAuthenticatedOriginPullsCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// EditPerHostnameAuthenticatedOriginPullsConfig applies the supplied Per Hostname AuthenticatedOriginPulls config onto a hostname(s) in the edge. -// -// API reference: https://api.cloudflare.com/#per-hostname-authenticated-origin-pull-enable-or-disable-a-hostname-for-client-authentication -func (api *API) EditPerHostnameAuthenticatedOriginPullsConfig(ctx context.Context, zoneID string, config []PerHostnameAuthenticatedOriginPullsConfig) ([]PerHostnameAuthenticatedOriginPullsDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/hostnames", zoneID) - conf := PerHostnameAuthenticatedOriginPullsConfigParams{ - Config: config, - } - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, conf) - if err != nil { - return []PerHostnameAuthenticatedOriginPullsDetails{}, err - } - var r PerHostnamesAuthenticatedOriginPullsDetailsResponse - if err := json.Unmarshal(res, &r); err != nil { - return []PerHostnameAuthenticatedOriginPullsDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetPerHostnameAuthenticatedOriginPullsConfig returns the config state of Per Hostname AuthenticatedOriginPulls of the provided hostname within a zone. -// -// API reference: https://api.cloudflare.com/#per-hostname-authenticated-origin-pull-get-the-hostname-status-for-client-authentication -func (api *API) GetPerHostnameAuthenticatedOriginPullsConfig(ctx context.Context, zoneID, hostname string) (PerHostnameAuthenticatedOriginPullsDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/hostnames/%s", zoneID, hostname) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PerHostnameAuthenticatedOriginPullsDetails{}, err - } - var r PerHostnameAuthenticatedOriginPullsDetailsResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls_per_zone.go b/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls_per_zone.go deleted file mode 100644 index 6543119..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/authenticated_origin_pulls_per_zone.go +++ /dev/null @@ -1,150 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// PerZoneAuthenticatedOriginPullsSettings represents the settings for Per Zone AuthenticatedOriginPulls. -type PerZoneAuthenticatedOriginPullsSettings struct { - Enabled bool `json:"enabled"` -} - -// PerZoneAuthenticatedOriginPullsSettingsResponse represents the response from the Per Zone AuthenticatedOriginPulls settings endpoint. -type PerZoneAuthenticatedOriginPullsSettingsResponse struct { - Response - Result PerZoneAuthenticatedOriginPullsSettings `json:"result"` -} - -// PerZoneAuthenticatedOriginPullsCertificateDetails represents the metadata for a Per Zone AuthenticatedOriginPulls client certificate. -type PerZoneAuthenticatedOriginPullsCertificateDetails struct { - ID string `json:"id"` - Certificate string `json:"certificate"` - Issuer string `json:"issuer"` - Signature string `json:"signature"` - ExpiresOn time.Time `json:"expires_on"` - Status string `json:"status"` - UploadedOn time.Time `json:"uploaded_on"` -} - -// PerZoneAuthenticatedOriginPullsCertificateResponse represents the response from endpoints relating to creating and deleting a per zone AuthenticatedOriginPulls certificate. -type PerZoneAuthenticatedOriginPullsCertificateResponse struct { - Response - Result PerZoneAuthenticatedOriginPullsCertificateDetails `json:"result"` -} - -// PerZoneAuthenticatedOriginPullsCertificatesResponse represents the response from the per zone AuthenticatedOriginPulls certificate list endpoint. -type PerZoneAuthenticatedOriginPullsCertificatesResponse struct { - Response - Result []PerZoneAuthenticatedOriginPullsCertificateDetails `json:"result"` -} - -// PerZoneAuthenticatedOriginPullsCertificateParams represents the required data related to the client certificate being uploaded to be used in Per Zone AuthenticatedOriginPulls. -type PerZoneAuthenticatedOriginPullsCertificateParams struct { - Certificate string `json:"certificate"` - PrivateKey string `json:"private_key"` -} - -// GetPerZoneAuthenticatedOriginPullsStatus returns whether per zone AuthenticatedOriginPulls is enabled or not. It is false by default. -// -// API reference: https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-get-enablement-setting-for-zone -func (api *API) GetPerZoneAuthenticatedOriginPullsStatus(ctx context.Context, zoneID string) (PerZoneAuthenticatedOriginPullsSettings, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/settings", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PerZoneAuthenticatedOriginPullsSettings{}, err - } - var r PerZoneAuthenticatedOriginPullsSettingsResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// SetPerZoneAuthenticatedOriginPullsStatus will update whether Per Zone AuthenticatedOriginPulls is enabled for the zone. -// -// API reference: https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-set-enablement-for-zone -func (api *API) SetPerZoneAuthenticatedOriginPullsStatus(ctx context.Context, zoneID string, enable bool) (PerZoneAuthenticatedOriginPullsSettings, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/settings", zoneID) - params := struct { - Enabled bool `json:"enabled"` - }{ - Enabled: enable, - } - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return PerZoneAuthenticatedOriginPullsSettings{}, err - } - var r PerZoneAuthenticatedOriginPullsSettingsResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UploadPerZoneAuthenticatedOriginPullsCertificate will upload a provided client certificate and enable it to be used in all AuthenticatedOriginPulls requests for the zone. -// -// API reference: https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-upload-certificate -func (api *API) UploadPerZoneAuthenticatedOriginPullsCertificate(ctx context.Context, zoneID string, params PerZoneAuthenticatedOriginPullsCertificateParams) (PerZoneAuthenticatedOriginPullsCertificateDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, err - } - var r PerZoneAuthenticatedOriginPullsCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListPerZoneAuthenticatedOriginPullsCertificates returns a list of all user uploaded client certificates to Per Zone AuthenticatedOriginPulls. -// -// API reference: https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-list-certificates -func (api *API) ListPerZoneAuthenticatedOriginPullsCertificates(ctx context.Context, zoneID string) ([]PerZoneAuthenticatedOriginPullsCertificateDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []PerZoneAuthenticatedOriginPullsCertificateDetails{}, err - } - var r PerZoneAuthenticatedOriginPullsCertificatesResponse - if err := json.Unmarshal(res, &r); err != nil { - return []PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetPerZoneAuthenticatedOriginPullsCertificateDetails returns the metadata associated with a user uploaded client certificate to Per Zone AuthenticatedOriginPulls. -// -// API reference: https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-get-certificate-details -func (api *API) GetPerZoneAuthenticatedOriginPullsCertificateDetails(ctx context.Context, zoneID, certificateID string) (PerZoneAuthenticatedOriginPullsCertificateDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/%s", zoneID, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, err - } - var r PerZoneAuthenticatedOriginPullsCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeletePerZoneAuthenticatedOriginPullsCertificate removes the specified client certificate from the edge. -// -// API reference: https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-delete-certificate -func (api *API) DeletePerZoneAuthenticatedOriginPullsCertificate(ctx context.Context, zoneID, certificateID string) (PerZoneAuthenticatedOriginPullsCertificateDetails, error) { - uri := fmt.Sprintf("/zones/%s/origin_tls_client_auth/%s", zoneID, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, err - } - var r PerZoneAuthenticatedOriginPullsCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/certificate_packs.go b/vendor/github.com/cloudflare/cloudflare-go/certificate_packs.go deleted file mode 100644 index cf499de..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/certificate_packs.go +++ /dev/null @@ -1,161 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// CertificatePackGeoRestrictions is for the structure of the geographic -// restrictions for a TLS certificate. -type CertificatePackGeoRestrictions struct { - Label string `json:"label"` -} - -// CertificatePackCertificate is the base structure of a TLS certificate that is -// contained within a certificate pack. -type CertificatePackCertificate struct { - ID string `json:"id"` - Hosts []string `json:"hosts"` - Issuer string `json:"issuer"` - Signature string `json:"signature"` - Status string `json:"status"` - BundleMethod string `json:"bundle_method"` - GeoRestrictions CertificatePackGeoRestrictions `json:"geo_restrictions"` - ZoneID string `json:"zone_id"` - UploadedOn time.Time `json:"uploaded_on"` - ModifiedOn time.Time `json:"modified_on"` - ExpiresOn time.Time `json:"expires_on"` - Priority int `json:"priority"` -} - -// CertificatePack is the overarching structure of a certificate pack response. -type CertificatePack struct { - ID string `json:"id"` - Type string `json:"type"` - Hosts []string `json:"hosts"` - Certificates []CertificatePackCertificate `json:"certificates"` - PrimaryCertificate string `json:"primary_certificate"` - ValidationRecords []SSLValidationRecord `json:"validation_records,omitempty"` - ValidationErrors []SSLValidationError `json:"validation_errors,omitempty"` - ValidationMethod string `json:"validation_method"` - ValidityDays int `json:"validity_days"` - CertificateAuthority string `json:"certificate_authority"` - CloudflareBranding bool `json:"cloudflare_branding"` -} - -// CertificatePackRequest is used for requesting a new certificate. -type CertificatePackRequest struct { - Type string `json:"type"` - Hosts []string `json:"hosts"` - ValidationMethod string `json:"validation_method"` - ValidityDays int `json:"validity_days"` - CertificateAuthority string `json:"certificate_authority"` - CloudflareBranding bool `json:"cloudflare_branding"` -} - -// CertificatePacksResponse is for responses where multiple certificates are -// expected. -type CertificatePacksResponse struct { - Response - Result []CertificatePack `json:"result"` -} - -// CertificatePacksDetailResponse contains a single certificate pack in the -// response. -type CertificatePacksDetailResponse struct { - Response - Result CertificatePack `json:"result"` -} - -// ListCertificatePacks returns all available TLS certificate packs for a zone. -// -// API Reference: https://api.cloudflare.com/#certificate-packs-list-certificate-packs -func (api *API) ListCertificatePacks(ctx context.Context, zoneID string) ([]CertificatePack, error) { - uri := fmt.Sprintf("/zones/%s/ssl/certificate_packs?status=all", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []CertificatePack{}, err - } - - var certificatePacksResponse CertificatePacksResponse - err = json.Unmarshal(res, &certificatePacksResponse) - if err != nil { - return []CertificatePack{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return certificatePacksResponse.Result, nil -} - -// CertificatePack returns a single TLS certificate pack on a zone. -// -// API Reference: https://api.cloudflare.com/#certificate-packs-get-certificate-pack -func (api *API) CertificatePack(ctx context.Context, zoneID, certificatePackID string) (CertificatePack, error) { - uri := fmt.Sprintf("/zones/%s/ssl/certificate_packs/%s", zoneID, certificatePackID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return CertificatePack{}, err - } - - var certificatePacksDetailResponse CertificatePacksDetailResponse - err = json.Unmarshal(res, &certificatePacksDetailResponse) - if err != nil { - return CertificatePack{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return certificatePacksDetailResponse.Result, nil -} - -// CreateCertificatePack creates a new certificate pack associated with a zone. -// -// API Reference: https://api.cloudflare.com/#certificate-packs-order-advanced-certificate-manager-certificate-pack -func (api *API) CreateCertificatePack(ctx context.Context, zoneID string, cert CertificatePackRequest) (CertificatePack, error) { - uri := fmt.Sprintf("/zones/%s/ssl/certificate_packs/order", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, cert) - if err != nil { - return CertificatePack{}, err - } - - var certificatePacksDetailResponse CertificatePacksDetailResponse - err = json.Unmarshal(res, &certificatePacksDetailResponse) - if err != nil { - return CertificatePack{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return certificatePacksDetailResponse.Result, nil -} - -// DeleteCertificatePack removes a certificate pack associated with a zone. -// -// API Reference: https://api.cloudflare.com/#certificate-packs-delete-advanced-certificate-manager-certificate-pack -func (api *API) DeleteCertificatePack(ctx context.Context, zoneID, certificateID string) error { - uri := fmt.Sprintf("/zones/%s/ssl/certificate_packs/%s", zoneID, certificateID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} - -// RestartCertificateValidation kicks off the validation process for a -// pending certificate pack. -// -// API Reference: https://api.cloudflare.com/#certificate-packs-restart-validation-for-advanced-certificate-manager-certificate-pack -func (api *API) RestartCertificateValidation(ctx context.Context, zoneID, certificateID string) (CertificatePack, error) { - uri := fmt.Sprintf("/zones/%s/ssl/certificate_packs/%s", zoneID, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, nil) - if err != nil { - return CertificatePack{}, err - } - - var certificatePackResponse CertificatePacksDetailResponse - err = json.Unmarshal(res, &certificatePackResponse) - if err != nil { - return CertificatePack{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return certificatePackResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/cloudflare.go b/vendor/github.com/cloudflare/cloudflare-go/cloudflare.go deleted file mode 100644 index e8d09ff..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/cloudflare.go +++ /dev/null @@ -1,598 +0,0 @@ -// Package cloudflare implements the Cloudflare v4 API. -package cloudflare - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "fmt" - "io" - "log" - "math" - "net/http" - "net/http/httputil" - "net/url" - "regexp" - "strconv" - "strings" - "time" - - "golang.org/x/time/rate" -) - -var ( - Version string = "v4" - - // Deprecated: Use `client.New` configuration instead. - apiURL = fmt.Sprintf("%s://%s%s", defaultScheme, defaultHostname, defaultBasePath) -) - -const ( - // AuthKeyEmail specifies that we should authenticate with API key and email address. - AuthKeyEmail = 1 << iota - // AuthUserService specifies that we should authenticate with a User-Service key. - AuthUserService - // AuthToken specifies that we should authenticate with an API Token. - AuthToken -) - -// API holds the configuration for the current API client. A client should not -// be modified concurrently. -type API struct { - APIKey string - APIEmail string - APIUserServiceKey string - APIToken string - BaseURL string - AccountID string - UserAgent string - headers http.Header - httpClient *http.Client - authType int - rateLimiter *rate.Limiter - retryPolicy RetryPolicy - logger Logger - Debug bool -} - -// newClient provides shared logic for New and NewWithUserServiceKey. -func newClient(opts ...Option) (*API, error) { - silentLogger := log.New(io.Discard, "", log.LstdFlags) - - api := &API{ - BaseURL: fmt.Sprintf("%s://%s%s", defaultScheme, defaultHostname, defaultBasePath), - UserAgent: userAgent + "/" + Version, - headers: make(http.Header), - rateLimiter: rate.NewLimiter(rate.Limit(4), 1), // 4rps equates to default api limit (1200 req/5 min) - retryPolicy: RetryPolicy{ - MaxRetries: 3, - MinRetryDelay: 1 * time.Second, - MaxRetryDelay: 30 * time.Second, - }, - logger: silentLogger, - } - - err := api.parseOptions(opts...) - if err != nil { - return nil, fmt.Errorf("options parsing failed: %w", err) - } - - // Fall back to http.DefaultClient if the package user does not provide - // their own. - if api.httpClient == nil { - api.httpClient = http.DefaultClient - } - - return api, nil -} - -// New creates a new Cloudflare v4 API client. -func New(key, email string, opts ...Option) (*API, error) { - if key == "" || email == "" { - return nil, errors.New(errEmptyCredentials) - } - - api, err := newClient(opts...) - if err != nil { - return nil, err - } - - api.APIKey = key - api.APIEmail = email - api.authType = AuthKeyEmail - - return api, nil -} - -// NewWithAPIToken creates a new Cloudflare v4 API client using API Tokens. -func NewWithAPIToken(token string, opts ...Option) (*API, error) { - if token == "" { - return nil, errors.New(errEmptyAPIToken) - } - - api, err := newClient(opts...) - if err != nil { - return nil, err - } - - api.APIToken = token - api.authType = AuthToken - - return api, nil -} - -// NewWithUserServiceKey creates a new Cloudflare v4 API client using service key authentication. -func NewWithUserServiceKey(key string, opts ...Option) (*API, error) { - if key == "" { - return nil, errors.New(errEmptyCredentials) - } - - api, err := newClient(opts...) - if err != nil { - return nil, err - } - - api.APIUserServiceKey = key - api.authType = AuthUserService - - return api, nil -} - -// SetAuthType sets the authentication method (AuthKeyEmail, AuthToken, or AuthUserService). -func (api *API) SetAuthType(authType int) { - api.authType = authType -} - -// ZoneIDByName retrieves a zone's ID from the name. -func (api *API) ZoneIDByName(zoneName string) (string, error) { - zoneName = normalizeZoneName(zoneName) - res, err := api.ListZonesContext(context.Background(), WithZoneFilters(zoneName, api.AccountID, "")) - if err != nil { - return "", fmt.Errorf("ListZonesContext command failed: %w", err) - } - - switch len(res.Result) { - case 0: - return "", errors.New("zone could not be found") - case 1: - return res.Result[0].ID, nil - default: - return "", errors.New("ambiguous zone name; an account ID might help") - } -} - -// makeRequest makes a HTTP request and returns the body as a byte slice, -// closing it before returning. params will be serialized to JSON. -func (api *API) makeRequest(method, uri string, params interface{}) ([]byte, error) { - return api.makeRequestWithAuthType(context.Background(), method, uri, params, api.authType) -} - -func (api *API) makeRequestContext(ctx context.Context, method, uri string, params interface{}) ([]byte, error) { - return api.makeRequestWithAuthType(ctx, method, uri, params, api.authType) -} - -func (api *API) makeRequestContextWithHeaders(ctx context.Context, method, uri string, params interface{}, headers http.Header) ([]byte, error) { - return api.makeRequestWithAuthTypeAndHeaders(ctx, method, uri, params, api.authType, headers) -} - -func (api *API) makeRequestWithAuthType(ctx context.Context, method, uri string, params interface{}, authType int) ([]byte, error) { - return api.makeRequestWithAuthTypeAndHeaders(ctx, method, uri, params, authType, nil) -} - -// APIResponse holds the structure for a response from the API. It looks alot -// like `http.Response` however, uses a `[]byte` for the `Body` instead of a -// `io.ReadCloser`. -// -// This may go away in the experimental client in favour of `http.Response`. -type APIResponse struct { - Body []byte - Status string - StatusCode int - Headers http.Header -} - -func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, uri string, params interface{}, authType int, headers http.Header) ([]byte, error) { - res, err := api.makeRequestWithAuthTypeAndHeadersComplete(ctx, method, uri, params, authType, headers) - if err != nil { - return nil, err - } - return res.Body, err -} - -// Use this method if an API response can have different Content-Type headers and different body formats. -func (api *API) makeRequestContextWithHeadersComplete(ctx context.Context, method, uri string, params interface{}, headers http.Header) (*APIResponse, error) { - return api.makeRequestWithAuthTypeAndHeadersComplete(ctx, method, uri, params, api.authType, headers) -} - -func (api *API) makeRequestWithAuthTypeAndHeadersComplete(ctx context.Context, method, uri string, params interface{}, authType int, headers http.Header) (*APIResponse, error) { - var err error - var resp *http.Response - var respErr error - var respBody []byte - - for i := 0; i <= api.retryPolicy.MaxRetries; i++ { - var reqBody io.Reader - if params != nil { - if r, ok := params.(io.Reader); ok { - reqBody = r - } else if paramBytes, ok := params.([]byte); ok { - reqBody = bytes.NewReader(paramBytes) - } else { - var jsonBody []byte - jsonBody, err = json.Marshal(params) - if err != nil { - return nil, fmt.Errorf("error marshalling params to JSON: %w", err) - } - reqBody = bytes.NewReader(jsonBody) - } - } - - if i > 0 { - // expect the backoff introduced here on errored requests to dominate the effect of rate limiting - // don't need a random component here as the rate limiter should do something similar - // nb time duration could truncate an arbitrary float. Since our inputs are all ints, we should be ok - sleepDuration := time.Duration(math.Pow(2, float64(i-1)) * float64(api.retryPolicy.MinRetryDelay)) - - if sleepDuration > api.retryPolicy.MaxRetryDelay { - sleepDuration = api.retryPolicy.MaxRetryDelay - } - // useful to do some simple logging here, maybe introduce levels later - api.logger.Printf("Sleeping %s before retry attempt number %d for request %s %s", sleepDuration.String(), i, method, uri) - - select { - case <-time.After(sleepDuration): - case <-ctx.Done(): - return nil, fmt.Errorf("operation aborted during backoff: %w", ctx.Err()) - } - } - - err = api.rateLimiter.Wait(ctx) - if err != nil { - return nil, fmt.Errorf("error caused by request rate limiting: %w", err) - } - - resp, respErr = api.request(ctx, method, uri, reqBody, authType, headers) - - // short circuit processing on context timeouts - if respErr != nil && errors.Is(respErr, context.DeadlineExceeded) { - return nil, respErr - } - - // retry if the server is rate limiting us or if it failed - // assumes server operations are rolled back on failure - if respErr != nil || resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode >= 500 { - if resp != nil && resp.StatusCode == http.StatusTooManyRequests { - respErr = errors.New("exceeded available rate limit retries") - } - - if respErr == nil { - respErr = fmt.Errorf("received %s response (HTTP %d), please try again later", strings.ToLower(http.StatusText(resp.StatusCode)), resp.StatusCode) - } - continue - } else { - respBody, err = io.ReadAll(resp.Body) - defer resp.Body.Close() - if err != nil { - return nil, fmt.Errorf("could not read response body: %w", err) - } - - break - } - } - - // still had an error after all retries - if respErr != nil { - return nil, respErr - } - - if resp.StatusCode >= http.StatusBadRequest { - if strings.HasSuffix(resp.Request.URL.Path, "/filters/validate-expr") { - return nil, fmt.Errorf("%s", respBody) - } - - if resp.StatusCode >= http.StatusInternalServerError { - return nil, &ServiceError{cloudflareError: &Error{ - StatusCode: resp.StatusCode, - RayID: resp.Header.Get("cf-ray"), - Errors: []ResponseInfo{{ - Message: errInternalServiceError, - }}, - }} - } - - errBody := &Response{} - err = json.Unmarshal(respBody, &errBody) - if err != nil { - return nil, fmt.Errorf(errUnmarshalErrorBody+": %w", err) - } - - errCodes := make([]int, 0, len(errBody.Errors)) - errMsgs := make([]string, 0, len(errBody.Errors)) - for _, e := range errBody.Errors { - errCodes = append(errCodes, e.Code) - errMsgs = append(errMsgs, e.Message) - } - - err := &Error{ - StatusCode: resp.StatusCode, - RayID: resp.Header.Get("cf-ray"), - Errors: errBody.Errors, - ErrorCodes: errCodes, - ErrorMessages: errMsgs, - Messages: errBody.Messages, - } - - switch resp.StatusCode { - case http.StatusUnauthorized: - err.Type = ErrorTypeAuthorization - return nil, &AuthorizationError{cloudflareError: err} - case http.StatusForbidden: - err.Type = ErrorTypeAuthentication - return nil, &AuthenticationError{cloudflareError: err} - case http.StatusNotFound: - err.Type = ErrorTypeNotFound - return nil, &NotFoundError{cloudflareError: err} - case http.StatusTooManyRequests: - err.Type = ErrorTypeRateLimit - return nil, &RatelimitError{cloudflareError: err} - default: - err.Type = ErrorTypeRequest - return nil, &RequestError{cloudflareError: err} - } - } - - return &APIResponse{ - Body: respBody, - StatusCode: resp.StatusCode, - Status: resp.Status, - Headers: resp.Header, - }, nil -} - -// request makes a HTTP request to the given API endpoint, returning the raw -// *http.Response, or an error if one occurred. The caller is responsible for -// closing the response body. -func (api *API) request(ctx context.Context, method, uri string, reqBody io.Reader, authType int, headers http.Header) (*http.Response, error) { - req, err := http.NewRequestWithContext(ctx, method, api.BaseURL+uri, reqBody) - if err != nil { - return nil, fmt.Errorf("HTTP request creation failed: %w", err) - } - - combinedHeaders := make(http.Header) - copyHeader(combinedHeaders, api.headers) - copyHeader(combinedHeaders, headers) - req.Header = combinedHeaders - - if authType&AuthKeyEmail != 0 { - req.Header.Set("X-Auth-Key", api.APIKey) - req.Header.Set("X-Auth-Email", api.APIEmail) - } - if authType&AuthUserService != 0 { - req.Header.Set("X-Auth-User-Service-Key", api.APIUserServiceKey) - } - if authType&AuthToken != 0 { - req.Header.Set("Authorization", "Bearer "+api.APIToken) - } - - if api.UserAgent != "" { - req.Header.Set("User-Agent", api.UserAgent) - } - - if req.Header.Get("Content-Type") == "" { - req.Header.Set("Content-Type", "application/json") - } - - if api.Debug { - dump, err := httputil.DumpRequestOut(req, true) - if err != nil { - return nil, err - } - - // Strip out any sensitive information from the request payload. - sensitiveKeys := []string{api.APIKey, api.APIEmail, api.APIToken, api.APIUserServiceKey} - for _, key := range sensitiveKeys { - if key != "" { - valueRegex := regexp.MustCompile(fmt.Sprintf("(?m)%s", key)) - dump = valueRegex.ReplaceAll(dump, []byte("[redacted]")) - } - } - log.Printf("\n%s", string(dump)) - } - - resp, err := api.httpClient.Do(req) - if err != nil { - return nil, fmt.Errorf("HTTP request failed: %w", err) - } - - if api.Debug { - dump, err := httputil.DumpResponse(resp, true) - if err != nil { - return resp, err - } - log.Printf("\n%s", string(dump)) - } - - return resp, nil -} - -// Returns the base URL to use for API endpoints that exist for accounts. -// If an account option was used when creating the API instance, returns -// the account URL. -// -// accountBase is the base URL for endpoints referring to the current user. -// It exists as a parameter because it is not consistent across APIs. -func (api *API) userBaseURL(accountBase string) string { - if api.AccountID != "" { - return "/accounts/" + api.AccountID - } - return accountBase -} - -// copyHeader copies all headers for `source` and sets them on `target`. -// based on https://godoc.org/github.com/golang/gddo/httputil/header#Copy -func copyHeader(target, source http.Header) { - for k, vs := range source { - target[k] = vs - } -} - -// ResponseInfo contains a code and message returned by the API as errors or -// informational messages inside the response. -type ResponseInfo struct { - Code int `json:"code"` - Message string `json:"message"` -} - -// Response is a template. There will also be a result struct. There will be a -// unique response type for each response, which will include this type. -type Response struct { - Success bool `json:"success"` - Errors []ResponseInfo `json:"errors"` - Messages []ResponseInfo `json:"messages"` -} - -// ResultInfoCursors contains information about cursors. -type ResultInfoCursors struct { - Before string `json:"before" url:"before,omitempty"` - After string `json:"after" url:"after,omitempty"` -} - -// ResultInfo contains metadata about the Response. -type ResultInfo struct { - Page int `json:"page" url:"page,omitempty"` - PerPage int `json:"per_page" url:"per_page,omitempty"` - TotalPages int `json:"total_pages" url:"-"` - Count int `json:"count" url:"-"` - Total int `json:"total_count" url:"-"` - Cursor string `json:"cursor" url:"cursor,omitempty"` - Cursors ResultInfoCursors `json:"cursors" url:"cursors,omitempty"` -} - -// RawResponse keeps the result as JSON form. -type RawResponse struct { - Response - Result json.RawMessage `json:"result"` -} - -// Raw makes a HTTP request with user provided params and returns the -// result as untouched JSON. -func (api *API) Raw(ctx context.Context, method, endpoint string, data interface{}, headers http.Header) (json.RawMessage, error) { - res, err := api.makeRequestContextWithHeaders(ctx, method, endpoint, data, headers) - if err != nil { - return nil, err - } - - var r RawResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// PaginationOptions can be passed to a list request to configure paging -// These values will be defaulted if omitted, and PerPage has min/max limits set by resource. -type PaginationOptions struct { - Page int `json:"page,omitempty" url:"page,omitempty"` - PerPage int `json:"per_page,omitempty" url:"per_page,omitempty"` -} - -// RetryPolicy specifies number of retries and min/max retry delays -// This config is used when the client exponentially backs off after errored requests. -type RetryPolicy struct { - MaxRetries int - MinRetryDelay time.Duration - MaxRetryDelay time.Duration -} - -// Logger defines the interface this library needs to use logging -// This is a subset of the methods implemented in the log package. -type Logger interface { - Printf(format string, v ...interface{}) -} - -// ReqOption is a functional option for configuring API requests. -type ReqOption func(opt *reqOption) - -type reqOption struct { - params url.Values -} - -// WithZoneFilters applies a filter based on zone properties. -func WithZoneFilters(zoneName, accountID, status string) ReqOption { - return func(opt *reqOption) { - if zoneName != "" { - opt.params.Set("name", normalizeZoneName(zoneName)) - } - - if accountID != "" { - opt.params.Set("account.id", accountID) - } - - if status != "" { - opt.params.Set("status", status) - } - } -} - -// WithPagination configures the pagination for a response. -func WithPagination(opts PaginationOptions) ReqOption { - return func(opt *reqOption) { - if opts.Page > 0 { - opt.params.Set("page", strconv.Itoa(opts.Page)) - } - - if opts.PerPage > 0 { - opt.params.Set("per_page", strconv.Itoa(opts.PerPage)) - } - } -} - -// checkResultInfo checks whether ResultInfo is reasonable except that it currently -// ignores the cursor information. perPage, page, and count are the requested #items -// per page, the requested page number, and the actual length of the Result array. -// -// Responses from the actual Cloudflare servers should pass all these checks (or we -// discover a serious bug in the Cloudflare servers). However, the unit tests can -// easily violate these constraints and this utility function can help debugging. -// Correct pagination information is crucial for more advanced List* functions that -// handle pagination automatically and fetch different pages in parallel. -// -// TODO: check cursors as well. -func checkResultInfo(perPage, page, count int, info *ResultInfo) bool { - if info.Cursor != "" || info.Cursors.Before != "" || info.Cursors.After != "" { - panic("checkResultInfo could not handle cursors yet.") - } - - switch { - case info.PerPage != perPage || info.Page != page || info.Count != count: - return false - - case info.PerPage <= 0: - return false - - case info.Total == 0 && info.TotalPages == 0 && info.Page == 1 && info.Count == 0: - return true - - case info.Total <= 0 || info.TotalPages <= 0: - return false - - case info.Total > info.PerPage*info.TotalPages || info.Total <= info.PerPage*(info.TotalPages-1): - return false - } - - switch { - case info.Page > info.TotalPages || info.Page <= 0: - return false - - case info.Page < info.TotalPages: - return info.Count == info.PerPage - - case info.Page == info.TotalPages: - return info.Count == info.Total-info.PerPage*(info.TotalPages-1) - - default: - // This is actually impossible, but Go compiler does not know trichotomy - panic("checkResultInfo: impossible") - } -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/cloudflare_experimental.go b/vendor/github.com/cloudflare/cloudflare-go/cloudflare_experimental.go deleted file mode 100644 index c4bc493..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/cloudflare_experimental.go +++ /dev/null @@ -1,342 +0,0 @@ -package cloudflare - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "io" - "log" - "net/http" - "net/http/httputil" - "net/url" - "regexp" - "strings" - "sync" - "time" - - "github.com/hashicorp/go-retryablehttp" -) - -type service struct { - client *Client -} - -type ClientParams struct { - Key string - Email string - UserServiceKey string - Token string - STS *SecurityTokenConfiguration - BaseURL *url.URL - UserAgent string - Headers http.Header - HTTPClient *http.Client - RetryPolicy RetryPolicy - Logger LeveledLoggerInterface - Debug bool -} - -// A Client manages communication with the Cloudflare API. -type Client struct { - clientMu sync.Mutex - - *ClientParams - - common service // Reuse a single struct instead of allocating one for each service on the heap. - - Zones *ZonesService -} - -// Client returns the http.Client used by this Cloudflare client. -func (c *Client) Client() *http.Client { - c.clientMu.Lock() - defer c.clientMu.Unlock() - clientCopy := *c.HTTPClient - return &clientCopy -} - -// Call is the entrypoint to making API calls with the correct request setup. -func (c *Client) Call(ctx context.Context, method, path string, payload interface{}) ([]byte, error) { - return c.makeRequest(ctx, method, path, payload, nil) -} - -// CallWithHeaders is the entrypoint to making API calls with the correct -// request setup (like `Call`) but allows passing in additional HTTP headers -// with the request. -func (c *Client) CallWithHeaders(ctx context.Context, method, path string, payload interface{}, headers http.Header) ([]byte, error) { - return c.makeRequest(ctx, method, path, payload, headers) -} - -// New creates a new instance of the API client by merging ClientParams with the -// default values. -func NewExperimental(config *ClientParams) (*Client, error) { - c := &Client{ClientParams: &ClientParams{}} - c.common.client = c - - defaultURL, _ := url.Parse(defaultScheme + "://" + defaultHostname + defaultBasePath) - if config.BaseURL != nil { - c.ClientParams.BaseURL = config.BaseURL - } else { - c.ClientParams.BaseURL = defaultURL - } - - if config.UserAgent != "" { - c.ClientParams.UserAgent = config.UserAgent - } else { - c.ClientParams.UserAgent = userAgent + "/" + Version - } - - if config.HTTPClient != nil { - c.ClientParams.HTTPClient = config.HTTPClient - } else { - retryClient := retryablehttp.NewClient() - - if c.RetryPolicy.MaxRetries > 0 { - retryClient.RetryMax = c.RetryPolicy.MaxRetries - } else { - retryClient.RetryMax = 4 - } - - if c.RetryPolicy.MinRetryDelay > 0 { - retryClient.RetryWaitMin = c.RetryPolicy.MinRetryDelay - } else { - retryClient.RetryWaitMin = 1 * time.Second - } - - if c.RetryPolicy.MaxRetryDelay > 0 { - retryClient.RetryWaitMax = c.RetryPolicy.MaxRetryDelay - } else { - retryClient.RetryWaitMax = 30 * time.Second - } - - retryClient.Logger = silentRetryLogger - c.ClientParams.HTTPClient = retryClient.StandardClient() - } - - if config.Headers != nil { - c.ClientParams.Headers = config.Headers - } else { - c.ClientParams.Headers = make(http.Header) - } - - if config.Key != "" && config.Token != "" { - return nil, ErrAPIKeysAndTokensAreMutuallyExclusive - } - - if config.Key != "" { - c.ClientParams.Key = config.Key - c.ClientParams.Email = config.Email - } - - if config.Token != "" { - c.ClientParams.Token = config.Token - } - - if config.UserServiceKey != "" { - c.ClientParams.UserServiceKey = config.UserServiceKey - } - - c.ClientParams.Debug = config.Debug - if c.ClientParams.Debug { - c.ClientParams.Logger = &LeveledLogger{Level: 4} - } else { - c.ClientParams.Logger = SilentLeveledLogger - } - - if config.STS != nil { - stsToken, err := fetchSTSCredentials(config.STS) - if err != nil { - return nil, ErrSTSFailure - } - c.ClientParams.Token = stsToken - } - - c.Zones = (*ZonesService)(&c.common) - - return c, nil -} - -// request makes a HTTP request to the given API endpoint, returning the raw -// *http.Response, or an error if one occurred. The caller is responsible for -// closing the response body. -func (c *Client) request(ctx context.Context, method, uri string, reqBody io.Reader, headers http.Header) (*http.Response, error) { - req, err := http.NewRequestWithContext(ctx, method, c.BaseURL.String()+uri, reqBody) - if err != nil { - return nil, fmt.Errorf("HTTP request creation failed: %w", err) - } - - combinedHeaders := make(http.Header) - copyHeader(combinedHeaders, c.Headers) - copyHeader(combinedHeaders, headers) - req.Header = combinedHeaders - - if c.Key == "" && c.Email == "" && c.Token == "" && c.UserServiceKey == "" { - return nil, ErrMissingCredentials - } - - if c.Key != "" { - req.Header.Set("X-Auth-Key", c.ClientParams.Key) - req.Header.Set("X-Auth-Email", c.ClientParams.Email) - } - - if c.UserServiceKey != "" { - req.Header.Set("X-Auth-User-Service-Key", c.ClientParams.UserServiceKey) - } - - if c.Token != "" { - req.Header.Set("Authorization", "Bearer "+c.ClientParams.Token) - } - - if c.UserAgent != "" { - req.Header.Set("User-Agent", c.ClientParams.UserAgent) - } - - if req.Header.Get("Content-Type") == "" { - req.Header.Set("Content-Type", "application/json") - } - - if c.Debug { - dump, err := httputil.DumpRequestOut(req, true) - if err != nil { - return nil, err - } - - // Strip out any sensitive information from the request payload. - sensitiveKeys := []string{c.Key, c.Email, c.Token, c.UserServiceKey} - for _, key := range sensitiveKeys { - if key != "" { - valueRegex := regexp.MustCompile(fmt.Sprintf("(?m)%s", key)) - dump = valueRegex.ReplaceAll(dump, []byte("[redacted]")) - } - } - log.Printf("\n%s", string(dump)) - } - - resp, err := c.HTTPClient.Do(req) - if err != nil { - return nil, fmt.Errorf("HTTP request failed: %w", err) - } - - if c.Debug { - dump, err := httputil.DumpResponse(resp, true) - if err != nil { - return resp, err - } - log.Printf("\n%s", string(dump)) - } - - return resp, nil -} - -func (c *Client) makeRequest(ctx context.Context, method, uri string, params interface{}, headers http.Header) ([]byte, error) { - var reqBody io.Reader - var err error - - if params != nil { - if r, ok := params.(io.Reader); ok { - reqBody = r - } else if paramBytes, ok := params.([]byte); ok { - reqBody = bytes.NewReader(paramBytes) - } else { - var jsonBody []byte - jsonBody, err = json.Marshal(params) - if err != nil { - return nil, fmt.Errorf("error marshalling params to JSON: %w", err) - } - reqBody = bytes.NewReader(jsonBody) - } - } - - var resp *http.Response - var respErr error - var respBody []byte - - resp, respErr = c.request(ctx, method, uri, reqBody, headers) - if respErr != nil { - return nil, respErr - } - - respBody, err = io.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - return nil, fmt.Errorf("could not read response body: %w", err) - } - - if resp.StatusCode >= http.StatusBadRequest { - if strings.HasSuffix(resp.Request.URL.Path, "/filters/validate-expr") { - return nil, fmt.Errorf("%s", respBody) - } - - if resp.StatusCode >= http.StatusInternalServerError { - return nil, &ServiceError{cloudflareError: &Error{ - StatusCode: resp.StatusCode, - RayID: resp.Header.Get("cf-ray"), - Errors: []ResponseInfo{{ - Message: errInternalServiceError, - }}, - }} - } - - errBody := &Response{} - err = json.Unmarshal(respBody, &errBody) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal response body: %w", err) - } - - errCodes := make([]int, 0, len(errBody.Errors)) - errMsgs := make([]string, 0, len(errBody.Errors)) - for _, e := range errBody.Errors { - errCodes = append(errCodes, e.Code) - errMsgs = append(errMsgs, e.Message) - } - - err := &Error{ - StatusCode: resp.StatusCode, - RayID: resp.Header.Get("cf-ray"), - Errors: errBody.Errors, - ErrorCodes: errCodes, - ErrorMessages: errMsgs, - } - - switch resp.StatusCode { - case http.StatusUnauthorized: - err.Type = ErrorTypeAuthorization - return nil, &AuthorizationError{cloudflareError: err} - case http.StatusForbidden: - err.Type = ErrorTypeAuthentication - return nil, &AuthenticationError{cloudflareError: err} - case http.StatusNotFound: - err.Type = ErrorTypeNotFound - return nil, &NotFoundError{cloudflareError: err} - case http.StatusTooManyRequests: - err.Type = ErrorTypeRateLimit - return nil, &RatelimitError{cloudflareError: err} - default: - err.Type = ErrorTypeRequest - return nil, &RequestError{cloudflareError: err} - } - } - - return respBody, nil -} - -func (c *Client) get(ctx context.Context, path string, payload interface{}) ([]byte, error) { - return c.makeRequest(ctx, http.MethodGet, path, payload, nil) -} - -func (c *Client) post(ctx context.Context, path string, payload interface{}) ([]byte, error) { - return c.makeRequest(ctx, http.MethodPost, path, payload, nil) -} - -func (c *Client) patch(ctx context.Context, path string, payload interface{}) ([]byte, error) { - return c.makeRequest(ctx, http.MethodPatch, path, payload, nil) -} - -func (c *Client) put(ctx context.Context, path string, payload interface{}) ([]byte, error) { - return c.makeRequest(ctx, http.MethodPut, path, payload, nil) -} - -func (c *Client) delete(ctx context.Context, path string, payload interface{}) ([]byte, error) { - return c.makeRequest(ctx, http.MethodDelete, path, payload, nil) -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/consts.go b/vendor/github.com/cloudflare/cloudflare-go/consts.go deleted file mode 100644 index 668ddc3..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/consts.go +++ /dev/null @@ -1,27 +0,0 @@ -package cloudflare - -// RouteRoot represents the name of the route namespace. -type RouteRoot string - -const ( - defaultScheme = "https" - defaultHostname = "api.cloudflare.com" - defaultBasePath = "/client/v4" - userAgent = "cloudflare-go" - - // AccountRouteRoot is the accounts route namespace. - AccountRouteRoot RouteRoot = "accounts" - - // ZoneRouteRoot is the zones route namespace. - ZoneRouteRoot RouteRoot = "zones" - - originCARootCertEccURL = "https://developers.cloudflare.com/ssl/static/origin_ca_ecc_root.pem" - originCARootCertRsaURL = "https://developers.cloudflare.com/ssl/static/origin_ca_rsa_root.pem" - - // Used for testing. - testAccountID = "01a7362d577a6c3019a474fd6f485823" - testZoneID = "d56084adb405e0b7e32c52321bf07be6" - testUserID = "a81be4e9b20632860d20a64c054c4150" - testCertPackUUID = "a77f8bd7-3b47-46b4-a6f1-75cf98109948" - testTunnelID = "f174e90a-fafe-4643-bbbc-4a0ed4fc8415" -) diff --git a/vendor/github.com/cloudflare/cloudflare-go/convert_types.go b/vendor/github.com/cloudflare/cloudflare-go/convert_types.go deleted file mode 100644 index 1d45d34..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/convert_types.go +++ /dev/null @@ -1,932 +0,0 @@ -// File contains helper methods for accepting variants (pointers, values, -// slices, etc) of a particular type and returning them in another. A common use -// is pointer to values and back. -// -// _Most_ follow the convention of (where is a Golang type such as Bool): -// -// Ptr: Accepts a value and returns a pointer. -// : Accepts a pointer and returns a value. -// PtrSlice: Accepts a slice of values and returns a slice of pointers. -// Slice: Accepts a slice of pointers and returns a slice of values. -// PtrMap: Accepts a string map of values into a string map of pointers. -// Map: Accepts a string map of pointers into a string map of values. -// -// Not all Golang types are covered here, only those that are commonly used. -package cloudflare - -import ( - "reflect" - "time" -) - -// AnyPtr is a helper routine that allocates a new interface value -// to store v and returns a pointer to it. -// -// Usage: var _ *Type = AnyPtr(Type(value) | value).(*Type) -// -// var _ *bool = AnyPtr(true).(*bool) -// var _ *byte = AnyPtr(byte(1)).(*byte) -// var _ *complex64 = AnyPtr(complex64(1.1)).(*complex64) -// var _ *complex128 = AnyPtr(complex128(1.1)).(*complex128) -// var _ *float32 = AnyPtr(float32(1.1)).(*float32) -// var _ *float64 = AnyPtr(float64(1.1)).(*float64) -// var _ *int = AnyPtr(int(1)).(*int) -// var _ *int8 = AnyPtr(int8(8)).(*int8) -// var _ *int16 = AnyPtr(int16(16)).(*int16) -// var _ *int32 = AnyPtr(int32(32)).(*int32) -// var _ *int64 = AnyPtr(int64(64)).(*int64) -// var _ *rune = AnyPtr(rune(1)).(*rune) -// var _ *string = AnyPtr("ptr").(*string) -// var _ *uint = AnyPtr(uint(1)).(*uint) -// var _ *uint8 = AnyPtr(uint8(8)).(*uint8) -// var _ *uint16 = AnyPtr(uint16(16)).(*uint16) -// var _ *uint32 = AnyPtr(uint32(32)).(*uint32) -// var _ *uint64 = AnyPtr(uint64(64)).(*uint64) -func AnyPtr(v interface{}) interface{} { - r := reflect.New(reflect.TypeOf(v)) - reflect.ValueOf(r.Interface()).Elem().Set(reflect.ValueOf(v)) - return r.Interface() -} - -// BytePtr is a helper routine that allocates a new byte value to store v and -// returns a pointer to it. -func BytePtr(v byte) *byte { return &v } - -// Complex64Ptr is a helper routine that allocates a new complex64 value to -// store v and returns a pointer to it. -func Complex64Ptr(v complex64) *complex64 { return &v } - -// Complex128Ptr is a helper routine that allocates a new complex128 value -// to store v and returns a pointer to it. -func Complex128Ptr(v complex128) *complex128 { return &v } - -// RunePtr is a helper routine that allocates a new rune value to store v -// and returns a pointer to it. -func RunePtr(v rune) *rune { return &v } - -// TimePtr is a helper routine that allocates a new time.Time value -// to store v and returns a pointer to it. -func TimePtr(v time.Time) *time.Time { return &v } - -// DurationPtr is a helper routine that allocates a new time.Duration value -// to store v and returns a pointer to it. -func DurationPtr(v time.Duration) *time.Duration { return &v } - -// BoolPtr is a helper routine that allocates a new bool value to store v and -// returns a pointer to it. -func BoolPtr(v bool) *bool { return &v } - -// Bool is a helper routine that accepts a bool pointer and returns a value -// to it. -func Bool(v *bool) bool { - if v != nil { - return *v - } - return false -} - -// BoolPtrSlice converts a slice of bool values into a slice of bool pointers. -func BoolPtrSlice(src []bool) []*bool { - dst := make([]*bool, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// BoolSlice converts a slice of bool pointers into a slice of bool values. -func BoolSlice(src []*bool) []bool { - dst := make([]bool, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// BoolPtrMap converts a string map of bool values into a string map of bool -// pointers. -func BoolPtrMap(src map[string]bool) map[string]*bool { - dst := make(map[string]*bool) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// BoolMap converts a string map of bool pointers into a string map of bool -// values. -func BoolMap(src map[string]*bool) map[string]bool { - dst := make(map[string]bool) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Byte is a helper routine that accepts a byte pointer and returns a -// value to it. -func Byte(v *byte) byte { - if v != nil { - return *v - } - return byte(0) -} - -// Complex64 is a helper routine that accepts a complex64 pointer and -// returns a value to it. -func Complex64(v *complex64) complex64 { - if v != nil { - return *v - } - return 0 -} - -// Complex128 is a helper routine that accepts a complex128 pointer and -// returns a value to it. -func Complex128(v *complex128) complex128 { - if v != nil { - return *v - } - return 0 -} - -// Float32Ptr is a helper routine that allocates a new float32 value to store v -// and returns a pointer to it. -func Float32Ptr(v float32) *float32 { return &v } - -// Float32 is a helper routine that accepts a float32 pointer and returns a -// value to it. -func Float32(v *float32) float32 { - if v != nil { - return *v - } - return 0 -} - -// Float32PtrSlice converts a slice of float32 values into a slice of float32 -// pointers. -func Float32PtrSlice(src []float32) []*float32 { - dst := make([]*float32, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Float32Slice converts a slice of float32 pointers into a slice of -// float32 values. -func Float32Slice(src []*float32) []float32 { - dst := make([]float32, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Float32PtrMap converts a string map of float32 values into a string map of -// float32 pointers. -func Float32PtrMap(src map[string]float32) map[string]*float32 { - dst := make(map[string]*float32) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Float32Map converts a string map of float32 pointers into a string -// map of float32 values. -func Float32Map(src map[string]*float32) map[string]float32 { - dst := make(map[string]float32) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Float64Ptr is a helper routine that allocates a new float64 value to store v -// and returns a pointer to it. -func Float64Ptr(v float64) *float64 { return &v } - -// Float64 is a helper routine that accepts a float64 pointer and returns a -// value to it. -func Float64(v *float64) float64 { - if v != nil { - return *v - } - return 0 -} - -// Float64PtrSlice converts a slice of float64 values into a slice of float64 -// pointers. -func Float64PtrSlice(src []float64) []*float64 { - dst := make([]*float64, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Float64Slice converts a slice of float64 pointers into a slice of -// float64 values. -func Float64Slice(src []*float64) []float64 { - dst := make([]float64, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Float64PtrMap converts a string map of float64 values into a string map of -// float64 pointers. -func Float64PtrMap(src map[string]float64) map[string]*float64 { - dst := make(map[string]*float64) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Float64Map converts a string map of float64 pointers into a string -// map of float64 values. -func Float64Map(src map[string]*float64) map[string]float64 { - dst := make(map[string]float64) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// IntPtr is a helper routine that allocates a new int value to store v and -// returns a pointer to it. -func IntPtr(v int) *int { return &v } - -// Int is a helper routine that accepts a int pointer and returns a value -// to it. -func Int(v *int) int { - if v != nil { - return *v - } - return 0 -} - -// IntPtrSlice converts a slice of int values into a slice of int pointers. -func IntPtrSlice(src []int) []*int { - dst := make([]*int, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// IntSlice converts a slice of int pointers into a slice of int values. -func IntSlice(src []*int) []int { - dst := make([]int, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// IntPtrMap converts a string map of int values into a string map of int -// pointers. -func IntPtrMap(src map[string]int) map[string]*int { - dst := make(map[string]*int) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// IntMap converts a string map of int pointers into a string map of int -// values. -func IntMap(src map[string]*int) map[string]int { - dst := make(map[string]int) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Int8Ptr is a helper routine that allocates a new int8 value to store v and -// returns a pointer to it. -func Int8Ptr(v int8) *int8 { return &v } - -// Int8 is a helper routine that accepts a int8 pointer and returns a value -// to it. -func Int8(v *int8) int8 { - if v != nil { - return *v - } - return 0 -} - -// Int8PtrSlice converts a slice of int8 values into a slice of int8 pointers. -func Int8PtrSlice(src []int8) []*int8 { - dst := make([]*int8, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Int8Slice converts a slice of int8 pointers into a slice of int8 values. -func Int8Slice(src []*int8) []int8 { - dst := make([]int8, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Int8PtrMap converts a string map of int8 values into a string map of int8 -// pointers. -func Int8PtrMap(src map[string]int8) map[string]*int8 { - dst := make(map[string]*int8) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Int8Map converts a string map of int8 pointers into a string map of int8 -// values. -func Int8Map(src map[string]*int8) map[string]int8 { - dst := make(map[string]int8) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Int16Ptr is a helper routine that allocates a new int16 value to store v -// and returns a pointer to it. -func Int16Ptr(v int16) *int16 { return &v } - -// Int16 is a helper routine that accepts a int16 pointer and returns a -// value to it. -func Int16(v *int16) int16 { - if v != nil { - return *v - } - return 0 -} - -// Int16PtrSlice converts a slice of int16 values into a slice of int16 -// pointers. -func Int16PtrSlice(src []int16) []*int16 { - dst := make([]*int16, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Int16Slice converts a slice of int16 pointers into a slice of int16 -// values. -func Int16Slice(src []*int16) []int16 { - dst := make([]int16, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Int16PtrMap converts a string map of int16 values into a string map of int16 -// pointers. -func Int16PtrMap(src map[string]int16) map[string]*int16 { - dst := make(map[string]*int16) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Int16Map converts a string map of int16 pointers into a string map of -// int16 values. -func Int16Map(src map[string]*int16) map[string]int16 { - dst := make(map[string]int16) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Int32Ptr is a helper routine that allocates a new int32 value to store v -// and returns a pointer to it. -func Int32Ptr(v int32) *int32 { return &v } - -// Int32 is a helper routine that accepts a int32 pointer and returns a -// value to it. -func Int32(v *int32) int32 { - if v != nil { - return *v - } - return 0 -} - -// Int32PtrSlice converts a slice of int32 values into a slice of int32 -// pointers. -func Int32PtrSlice(src []int32) []*int32 { - dst := make([]*int32, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Int32Slice converts a slice of int32 pointers into a slice of int32 -// values. -func Int32Slice(src []*int32) []int32 { - dst := make([]int32, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Int32PtrMap converts a string map of int32 values into a string map of int32 -// pointers. -func Int32PtrMap(src map[string]int32) map[string]*int32 { - dst := make(map[string]*int32) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Int32Map converts a string map of int32 pointers into a string map of -// int32 values. -func Int32Map(src map[string]*int32) map[string]int32 { - dst := make(map[string]int32) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Int64Ptr is a helper routine that allocates a new int64 value to store v -// and returns a pointer to it. -func Int64Ptr(v int64) *int64 { return &v } - -// Int64 is a helper routine that accepts a int64 pointer and returns a -// value to it. -func Int64(v *int64) int64 { - if v != nil { - return *v - } - return 0 -} - -// Int64PtrSlice converts a slice of int64 values into a slice of int64 -// pointers. -func Int64PtrSlice(src []int64) []*int64 { - dst := make([]*int64, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Int64Slice converts a slice of int64 pointers into a slice of int64 -// values. -func Int64Slice(src []*int64) []int64 { - dst := make([]int64, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Int64PtrMap converts a string map of int64 values into a string map of int64 -// pointers. -func Int64PtrMap(src map[string]int64) map[string]*int64 { - dst := make(map[string]*int64) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Int64Map converts a string map of int64 pointers into a string map of -// int64 values. -func Int64Map(src map[string]*int64) map[string]int64 { - dst := make(map[string]int64) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Rune is a helper routine that accepts a rune pointer and returns a value -// to it. -func Rune(v *rune) rune { - if v != nil { - return *v - } - return rune(0) -} - -// StringPtr is a helper routine that allocates a new string value to store v -// and returns a pointer to it. -func StringPtr(v string) *string { return &v } - -// String is a helper routine that accepts a string pointer and returns a -// value to it. -func String(v *string) string { - if v != nil { - return *v - } - return "" -} - -// StringPtrSlice converts a slice of string values into a slice of string -// pointers. -func StringPtrSlice(src []string) []*string { - dst := make([]*string, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// StringSlice converts a slice of string pointers into a slice of string -// values. -func StringSlice(src []*string) []string { - dst := make([]string, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// StringPtrMap converts a string map of string values into a string map of -// string pointers. -func StringPtrMap(src map[string]string) map[string]*string { - dst := make(map[string]*string) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// StringMap converts a string map of string pointers into a string map of -// string values. -func StringMap(src map[string]*string) map[string]string { - dst := make(map[string]string) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// UintPtr is a helper routine that allocates a new uint value to store v -// and returns a pointer to it. -func UintPtr(v uint) *uint { return &v } - -// Uint is a helper routine that accepts a uint pointer and returns a value -// to it. -func Uint(v *uint) uint { - if v != nil { - return *v - } - return 0 -} - -// UintPtrSlice converts a slice of uint values uinto a slice of uint pointers. -func UintPtrSlice(src []uint) []*uint { - dst := make([]*uint, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// UintSlice converts a slice of uint pointers uinto a slice of uint -// values. -func UintSlice(src []*uint) []uint { - dst := make([]uint, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// UintPtrMap converts a string map of uint values uinto a string map of uint -// pointers. -func UintPtrMap(src map[string]uint) map[string]*uint { - dst := make(map[string]*uint) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// UintMap converts a string map of uint pointers uinto a string map of -// uint values. -func UintMap(src map[string]*uint) map[string]uint { - dst := make(map[string]uint) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Uint8Ptr is a helper routine that allocates a new uint8 value to store v -// and returns a pointer to it. -func Uint8Ptr(v uint8) *uint8 { return &v } - -// Uint8 is a helper routine that accepts a uint8 pointer and returns a -// value to it. -func Uint8(v *uint8) uint8 { - if v != nil { - return *v - } - return 0 -} - -// Uint8PtrSlice converts a slice of uint8 values into a slice of uint8 -// pointers. -func Uint8PtrSlice(src []uint8) []*uint8 { - dst := make([]*uint8, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Uint8Slice converts a slice of uint8 pointers into a slice of uint8 -// values. -func Uint8Slice(src []*uint8) []uint8 { - dst := make([]uint8, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Uint8PtrMap converts a string map of uint8 values into a string map of uint8 -// pointers. -func Uint8PtrMap(src map[string]uint8) map[string]*uint8 { - dst := make(map[string]*uint8) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Uint8Map converts a string map of uint8 pointers into a string -// map of uint8 values. -func Uint8Map(src map[string]*uint8) map[string]uint8 { - dst := make(map[string]uint8) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Uint16Ptr is a helper routine that allocates a new uint16 value to store v -// and returns a pointer to it. -func Uint16Ptr(v uint16) *uint16 { return &v } - -// Uint16 is a helper routine that accepts a uint16 pointer and returns a -// value to it. -func Uint16(v *uint16) uint16 { - if v != nil { - return *v - } - return 0 -} - -// Uint16PtrSlice converts a slice of uint16 values into a slice of uint16 -// pointers. -func Uint16PtrSlice(src []uint16) []*uint16 { - dst := make([]*uint16, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Uint16Slice converts a slice of uint16 pointers into a slice of uint16 -// values. -func Uint16Slice(src []*uint16) []uint16 { - dst := make([]uint16, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Uint16PtrMap converts a string map of uint16 values into a string map of -// uint16 pointers. -func Uint16PtrMap(src map[string]uint16) map[string]*uint16 { - dst := make(map[string]*uint16) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Uint16Map converts a string map of uint16 pointers into a string map of -// uint16 values. -func Uint16Map(src map[string]*uint16) map[string]uint16 { - dst := make(map[string]uint16) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Uint32Ptr is a helper routine that allocates a new uint32 value to store v -// and returns a pointer to it. -func Uint32Ptr(v uint32) *uint32 { return &v } - -// Uint32 is a helper routine that accepts a uint32 pointer and returns a -// value to it. -func Uint32(v *uint32) uint32 { - if v != nil { - return *v - } - return 0 -} - -// Uint32PtrSlice converts a slice of uint32 values into a slice of uint32 -// pointers. -func Uint32PtrSlice(src []uint32) []*uint32 { - dst := make([]*uint32, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Uint32Slice converts a slice of uint32 pointers into a slice of uint32 -// values. -func Uint32Slice(src []*uint32) []uint32 { - dst := make([]uint32, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Uint32PtrMap converts a string map of uint32 values into a string map of -// uint32 pointers. -func Uint32PtrMap(src map[string]uint32) map[string]*uint32 { - dst := make(map[string]*uint32) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Uint32Map converts a string map of uint32 pointers into a string -// map of uint32 values. -func Uint32Map(src map[string]*uint32) map[string]uint32 { - dst := make(map[string]uint32) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Uint64Ptr is a helper routine that allocates a new uint64 value to store v -// and returns a pointer to it. -func Uint64Ptr(v uint64) *uint64 { return &v } - -// Uint64 is a helper routine that accepts a uint64 pointer and returns a -// value to it. -func Uint64(v *uint64) uint64 { - if v != nil { - return *v - } - return 0 -} - -// Uint64PtrSlice converts a slice of uint64 values into a slice of uint64 -// pointers. -func Uint64PtrSlice(src []uint64) []*uint64 { - dst := make([]*uint64, len(src)) - for i := 0; i < len(src); i++ { - dst[i] = &(src[i]) - } - return dst -} - -// Uint64Slice converts a slice of uint64 pointers into a slice of uint64 -// values. -func Uint64Slice(src []*uint64) []uint64 { - dst := make([]uint64, len(src)) - for i := 0; i < len(src); i++ { - if src[i] != nil { - dst[i] = *(src[i]) - } - } - return dst -} - -// Uint64PtrMap converts a string map of uint64 values into a string map of -// uint64 pointers. -func Uint64PtrMap(src map[string]uint64) map[string]*uint64 { - dst := make(map[string]*uint64) - for k, val := range src { - v := val - dst[k] = &v - } - return dst -} - -// Uint64Map converts a string map of uint64 pointers into a string map of -// uint64 values. -func Uint64Map(src map[string]*uint64) map[string]uint64 { - dst := make(map[string]uint64) - for k, val := range src { - if val != nil { - dst[k] = *val - } - } - return dst -} - -// Time is a helper routine that accepts a time pointer value and returns a -// value to it. -func Time(v *time.Time) time.Time { - if v != nil { - return *v - } - return time.Time{} -} - -// Duration is a helper routine that accepts a time pointer ion value -// and returns a value to it. -// func Duration(v *time.Duration) time.Duration { -// if v != nil { -// return *v -// } -// return time.Duration(0) -// } diff --git a/vendor/github.com/cloudflare/cloudflare-go/custom_hostname.go b/vendor/github.com/cloudflare/cloudflare-go/custom_hostname.go deleted file mode 100644 index 29bbdb9..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/custom_hostname.go +++ /dev/null @@ -1,328 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" - "strconv" - "time" -) - -// CustomHostnameStatus is the enumeration of valid state values in the CustomHostnameSSL. -type CustomHostnameStatus string - -const ( - // PENDING status represents state of CustomHostname is pending. - PENDING CustomHostnameStatus = "pending" - // ACTIVE status represents state of CustomHostname is active. - ACTIVE CustomHostnameStatus = "active" - // MOVED status represents state of CustomHostname is moved. - MOVED CustomHostnameStatus = "moved" - // DELETED status represents state of CustomHostname is deleted. - DELETED CustomHostnameStatus = "deleted" - // BLOCKED status represents state of CustomHostname is blocked from going active. - BLOCKED CustomHostnameStatus = "blocked" -) - -// CustomHostnameSSLSettings represents the SSL settings for a custom hostname. -type CustomHostnameSSLSettings struct { - HTTP2 string `json:"http2,omitempty"` - HTTP3 string `json:"http3,omitempty"` - TLS13 string `json:"tls_1_3,omitempty"` - MinTLSVersion string `json:"min_tls_version,omitempty"` - Ciphers []string `json:"ciphers,omitempty"` - EarlyHints string `json:"early_hints,omitempty"` -} - -// CustomHostnameOwnershipVerification represents ownership verification status of a given custom hostname. -type CustomHostnameOwnershipVerification struct { - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` -} - -// SSLValidationError represents errors that occurred during SSL validation. -type SSLValidationError struct { - Message string `json:"message,omitempty"` -} - -// CustomHostnameSSLCertificates represent certificate properties like issuer, expires date and etc. -type CustomHostnameSSLCertificates struct { - Issuer string `json:"issuer"` - SerialNumber string `json:"serial_number"` - Signature string `json:"signature"` - ExpiresOn *time.Time `json:"expires_on"` - IssuedOn *time.Time `json:"issued_on"` - FingerprintSha256 string `json:"fingerprint_sha256"` - ID string `json:"id"` -} - -// CustomHostnameSSL represents the SSL section in a given custom hostname. -type CustomHostnameSSL struct { - ID string `json:"id,omitempty"` - Status string `json:"status,omitempty"` - Method string `json:"method,omitempty"` - Type string `json:"type,omitempty"` - Wildcard *bool `json:"wildcard,omitempty"` - CustomCertificate string `json:"custom_certificate,omitempty"` - CustomKey string `json:"custom_key,omitempty"` - CertificateAuthority string `json:"certificate_authority,omitempty"` - Issuer string `json:"issuer,omitempty"` - SerialNumber string `json:"serial_number,omitempty"` - Settings CustomHostnameSSLSettings `json:"settings,omitempty"` - Certificates []CustomHostnameSSLCertificates `json:"certificates,omitempty"` - // Deprecated: use ValidationRecords. - // If there a single validation record, this will equal ValidationRecords[0] for backwards compatibility. - SSLValidationRecord - ValidationRecords []SSLValidationRecord `json:"validation_records,omitempty"` - ValidationErrors []SSLValidationError `json:"validation_errors,omitempty"` -} - -// CustomMetadata defines custom metadata for the hostname. This requires logic to be implemented by Cloudflare to act on the data provided. -type CustomMetadata map[string]interface{} - -// CustomHostname represents a custom hostname in a zone. -type CustomHostname struct { - ID string `json:"id,omitempty"` - Hostname string `json:"hostname,omitempty"` - CustomOriginServer string `json:"custom_origin_server,omitempty"` - CustomOriginSNI string `json:"custom_origin_sni,omitempty"` - SSL *CustomHostnameSSL `json:"ssl,omitempty"` - CustomMetadata *CustomMetadata `json:"custom_metadata,omitempty"` - Status CustomHostnameStatus `json:"status,omitempty"` - VerificationErrors []string `json:"verification_errors,omitempty"` - OwnershipVerification CustomHostnameOwnershipVerification `json:"ownership_verification,omitempty"` - OwnershipVerificationHTTP CustomHostnameOwnershipVerificationHTTP `json:"ownership_verification_http,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` -} - -// CustomHostnameOwnershipVerificationHTTP represents a response from the Custom Hostnames endpoints. -type CustomHostnameOwnershipVerificationHTTP struct { - HTTPUrl string `json:"http_url,omitempty"` - HTTPBody string `json:"http_body,omitempty"` -} - -// CustomHostnameResponse represents a response from the Custom Hostnames endpoints. -type CustomHostnameResponse struct { - Result CustomHostname `json:"result"` - Response -} - -// CustomHostnameListResponse represents a response from the Custom Hostnames endpoints. -type CustomHostnameListResponse struct { - Result []CustomHostname `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// CustomHostnameFallbackOrigin represents a Custom Hostnames Fallback Origin. -type CustomHostnameFallbackOrigin struct { - Origin string `json:"origin,omitempty"` - Status string `json:"status,omitempty"` - Errors []string `json:"errors,omitempty"` -} - -// CustomHostnameFallbackOriginResponse represents a response from the Custom Hostnames Fallback Origin endpoint. -type CustomHostnameFallbackOriginResponse struct { - Result CustomHostnameFallbackOrigin `json:"result"` - Response -} - -// UpdateCustomHostnameSSL modifies SSL configuration for the given custom -// hostname in the given zone. -// -// API reference: https://api.cloudflare.com/#custom-hostname-for-a-zone-update-custom-hostname-configuration -func (api *API) UpdateCustomHostnameSSL(ctx context.Context, zoneID string, customHostnameID string, ssl *CustomHostnameSSL) (*CustomHostnameResponse, error) { - uri := fmt.Sprintf("/zones/%s/custom_hostnames/%s", zoneID, customHostnameID) - ch := CustomHostname{ - SSL: ssl, - } - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, ch) - if err != nil { - return nil, err - } - - var response *CustomHostnameResponse - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return response, nil -} - -// UpdateCustomHostname modifies configuration for the given custom -// hostname in the given zone. -// -// API reference: https://api.cloudflare.com/#custom-hostname-for-a-zone-update-custom-hostname-configuration -func (api *API) UpdateCustomHostname(ctx context.Context, zoneID string, customHostnameID string, ch CustomHostname) (*CustomHostnameResponse, error) { - uri := fmt.Sprintf("/zones/%s/custom_hostnames/%s", zoneID, customHostnameID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, ch) - if err != nil { - return nil, err - } - - var response *CustomHostnameResponse - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return response, nil -} - -// DeleteCustomHostname deletes a custom hostname (and any issued SSL -// certificates). -// -// API reference: https://api.cloudflare.com/#custom-hostname-for-a-zone-delete-a-custom-hostname-and-any-issued-ssl-certificates- -func (api *API) DeleteCustomHostname(ctx context.Context, zoneID string, customHostnameID string) error { - uri := fmt.Sprintf("/zones/%s/custom_hostnames/%s", zoneID, customHostnameID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - var response *CustomHostnameResponse - err = json.Unmarshal(res, &response) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// CreateCustomHostname creates a new custom hostname and requests that an SSL certificate be issued for it. -// -// API reference: https://api.cloudflare.com/#custom-hostname-for-a-zone-create-custom-hostname -func (api *API) CreateCustomHostname(ctx context.Context, zoneID string, ch CustomHostname) (*CustomHostnameResponse, error) { - uri := fmt.Sprintf("/zones/%s/custom_hostnames", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, ch) - if err != nil { - return nil, err - } - - var response *CustomHostnameResponse - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// CustomHostnames fetches custom hostnames for the given zone, -// by applying filter.Hostname if not empty and scoping the result to page'th 50 items. -// -// The returned ResultInfo can be used to implement pagination. -// -// API reference: https://api.cloudflare.com/#custom-hostname-for-a-zone-list-custom-hostnames -func (api *API) CustomHostnames(ctx context.Context, zoneID string, page int, filter CustomHostname) ([]CustomHostname, ResultInfo, error) { - v := url.Values{} - v.Set("per_page", "50") - v.Set("page", strconv.Itoa(page)) - if filter.Hostname != "" { - v.Set("hostname", filter.Hostname) - } - - uri := fmt.Sprintf("/zones/%s/custom_hostnames?%s", zoneID, v.Encode()) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []CustomHostname{}, ResultInfo{}, err - } - var customHostnameListResponse CustomHostnameListResponse - err = json.Unmarshal(res, &customHostnameListResponse) - if err != nil { - return []CustomHostname{}, ResultInfo{}, err - } - - return customHostnameListResponse.Result, customHostnameListResponse.ResultInfo, nil -} - -// CustomHostname inspects the given custom hostname in the given zone. -// -// API reference: https://api.cloudflare.com/#custom-hostname-for-a-zone-custom-hostname-configuration-details -func (api *API) CustomHostname(ctx context.Context, zoneID string, customHostnameID string) (CustomHostname, error) { - uri := fmt.Sprintf("/zones/%s/custom_hostnames/%s", zoneID, customHostnameID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return CustomHostname{}, err - } - - var response CustomHostnameResponse - err = json.Unmarshal(res, &response) - if err != nil { - return CustomHostname{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// CustomHostnameIDByName retrieves the ID for the given hostname in the given zone. -func (api *API) CustomHostnameIDByName(ctx context.Context, zoneID string, hostname string) (string, error) { - customHostnames, _, err := api.CustomHostnames(ctx, zoneID, 1, CustomHostname{Hostname: hostname}) - if err != nil { - return "", fmt.Errorf("CustomHostnames command failed: %w", err) - } - for _, ch := range customHostnames { - if ch.Hostname == hostname { - return ch.ID, nil - } - } - return "", errors.New("CustomHostname could not be found") -} - -// UpdateCustomHostnameFallbackOrigin modifies the Custom Hostname Fallback origin in the given zone. -// -// API reference: https://api.cloudflare.com/#custom-hostname-fallback-origin-for-a-zone-update-fallback-origin-for-custom-hostnames -func (api *API) UpdateCustomHostnameFallbackOrigin(ctx context.Context, zoneID string, chfo CustomHostnameFallbackOrigin) (*CustomHostnameFallbackOriginResponse, error) { - uri := fmt.Sprintf("/zones/%s/custom_hostnames/fallback_origin", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, chfo) - if err != nil { - return nil, err - } - - var response *CustomHostnameFallbackOriginResponse - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return response, nil -} - -// DeleteCustomHostnameFallbackOrigin deletes the Custom Hostname Fallback origin in the given zone. -// -// API reference: https://api.cloudflare.com/#custom-hostname-fallback-origin-for-a-zone-delete-fallback-origin-for-custom-hostnames -func (api *API) DeleteCustomHostnameFallbackOrigin(ctx context.Context, zoneID string) error { - uri := fmt.Sprintf("/zones/%s/custom_hostnames/fallback_origin", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - var response *CustomHostnameFallbackOriginResponse - err = json.Unmarshal(res, &response) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// CustomHostnameFallbackOrigin inspects the Custom Hostname Fallback origin in the given zone. -// -// API reference: https://api.cloudflare.com/#custom-hostname-fallback-origin-for-a-zone-properties -func (api *API) CustomHostnameFallbackOrigin(ctx context.Context, zoneID string) (CustomHostnameFallbackOrigin, error) { - uri := fmt.Sprintf("/zones/%s/custom_hostnames/fallback_origin", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return CustomHostnameFallbackOrigin{}, err - } - - var response CustomHostnameFallbackOriginResponse - err = json.Unmarshal(res, &response) - if err != nil { - return CustomHostnameFallbackOrigin{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/custom_pages.go b/vendor/github.com/cloudflare/cloudflare-go/custom_pages.go deleted file mode 100644 index 9f60222..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/custom_pages.go +++ /dev/null @@ -1,176 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// CustomPage represents a custom page configuration. -type CustomPage struct { - CreatedOn time.Time `json:"created_on"` - ModifiedOn time.Time `json:"modified_on"` - URL interface{} `json:"url"` - State string `json:"state"` - RequiredTokens []string `json:"required_tokens"` - PreviewTarget string `json:"preview_target"` - Description string `json:"description"` - ID string `json:"id"` -} - -// CustomPageResponse represents the response from the custom pages endpoint. -type CustomPageResponse struct { - Response - Result []CustomPage `json:"result"` -} - -// CustomPageDetailResponse represents the response from the custom page endpoint. -type CustomPageDetailResponse struct { - Response - Result CustomPage `json:"result"` -} - -// CustomPageOptions is used to determine whether or not the operation -// should take place on an account or zone level based on which is -// provided to the function. -// -// A non-empty value denotes desired use. -type CustomPageOptions struct { - AccountID string - ZoneID string -} - -// CustomPageParameters is used to update a particular custom page with -// the values provided. -type CustomPageParameters struct { - URL interface{} `json:"url"` - State string `json:"state"` -} - -// CustomPages lists custom pages for a zone or account. -// -// Zone API reference: https://api.cloudflare.com/#custom-pages-for-a-zone-list-available-custom-pages -// Account API reference: https://api.cloudflare.com/#custom-pages-account--list-custom-pages -func (api *API) CustomPages(ctx context.Context, options *CustomPageOptions) ([]CustomPage, error) { - var ( - pageType, identifier string - ) - - if options.AccountID == "" && options.ZoneID == "" { - return nil, ErrAccountIDOrZoneIDAreRequired - } - - if options.AccountID != "" && options.ZoneID != "" { - return nil, ErrAccountIDAndZoneIDAreMutuallyExclusive - } - - // Should the account ID be defined, treat this as an account level operation. - if options.AccountID != "" { - pageType = "accounts" - identifier = options.AccountID - } else { - pageType = "zones" - identifier = options.ZoneID - } - - uri := fmt.Sprintf("/%s/%s/custom_pages", pageType, identifier) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - var customPageResponse CustomPageResponse - err = json.Unmarshal(res, &customPageResponse) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return customPageResponse.Result, nil -} - -// CustomPage lists a single custom page based on the ID. -// -// Zone API reference: https://api.cloudflare.com/#custom-pages-for-a-zone-custom-page-details -// Account API reference: https://api.cloudflare.com/#custom-pages-account--custom-page-details -func (api *API) CustomPage(ctx context.Context, options *CustomPageOptions, customPageID string) (CustomPage, error) { - var ( - pageType, identifier string - ) - - if options.AccountID == "" && options.ZoneID == "" { - return CustomPage{}, ErrAccountIDOrZoneIDAreRequired - } - - if options.AccountID != "" && options.ZoneID != "" { - return CustomPage{}, ErrAccountIDAndZoneIDAreMutuallyExclusive - } - - // Should the account ID be defined, treat this as an account level operation. - if options.AccountID != "" { - pageType = "accounts" - identifier = options.AccountID - } else { - pageType = "zones" - identifier = options.ZoneID - } - - uri := fmt.Sprintf("/%s/%s/custom_pages/%s", pageType, identifier, customPageID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return CustomPage{}, err - } - - var customPageResponse CustomPageDetailResponse - err = json.Unmarshal(res, &customPageResponse) - if err != nil { - return CustomPage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return customPageResponse.Result, nil -} - -// UpdateCustomPage updates a single custom page setting. -// -// Zone API reference: https://api.cloudflare.com/#custom-pages-for-a-zone-update-custom-page-url -// Account API reference: https://api.cloudflare.com/#custom-pages-account--update-custom-page -func (api *API) UpdateCustomPage(ctx context.Context, options *CustomPageOptions, customPageID string, pageParameters CustomPageParameters) (CustomPage, error) { - var ( - pageType, identifier string - ) - - if options.AccountID == "" && options.ZoneID == "" { - return CustomPage{}, ErrAccountIDOrZoneIDAreRequired - } - - if options.AccountID != "" && options.ZoneID != "" { - return CustomPage{}, ErrAccountIDAndZoneIDAreMutuallyExclusive - } - - // Should the account ID be defined, treat this as an account level operation. - if options.AccountID != "" { - pageType = "accounts" - identifier = options.AccountID - } else { - pageType = "zones" - identifier = options.ZoneID - } - - uri := fmt.Sprintf("/%s/%s/custom_pages/%s", pageType, identifier, customPageID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, pageParameters) - if err != nil { - return CustomPage{}, err - } - - var customPageResponse CustomPageDetailResponse - err = json.Unmarshal(res, &customPageResponse) - if err != nil { - return CustomPage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return customPageResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/device_posture_rule.go b/vendor/github.com/cloudflare/cloudflare-go/device_posture_rule.go deleted file mode 100644 index 288d5a2..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/device_posture_rule.go +++ /dev/null @@ -1,312 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// DevicePostureIntegrationConfig contains authentication information -// for a device posture integration. -type DevicePostureIntegrationConfig struct { - ClientID string `json:"client_id,omitempty"` - ClientSecret string `json:"client_secret,omitempty"` - AuthUrl string `json:"auth_url,omitempty"` - ApiUrl string `json:"api_url,omitempty"` - ClientKey string `json:"client_key,omitempty"` - CustomerID string `json:"customer_id,omitempty"` -} - -// DevicePostureIntegration represents a device posture integration. -type DevicePostureIntegration struct { - IntegrationID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` - Interval string `json:"interval,omitempty"` - Config DevicePostureIntegrationConfig `json:"config,omitempty"` -} - -// DevicePostureIntegrationResponse represents the response from the get -// device posture integrations endpoint. -type DevicePostureIntegrationResponse struct { - Result DevicePostureIntegration `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// DevicePostureIntegrationListResponse represents the response from the list -// device posture integrations endpoint. -type DevicePostureIntegrationListResponse struct { - Result []DevicePostureIntegration `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// CreateDevicePostureIntegration creates a device posture integration within an account. -// -// API reference: https://api.cloudflare.com/#device-posture-integrations-create-device-posture-integration -func (api *API) CreateDevicePostureIntegration(ctx context.Context, accountID string, integration DevicePostureIntegration) (DevicePostureIntegration, error) { - uri := fmt.Sprintf("/%s/%s/devices/posture/integration", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, integration) - if err != nil { - fmt.Printf("err:%+v res:%+v\n", err, res) - return DevicePostureIntegration{}, err - } - - var devicePostureIntegrationResponse DevicePostureIntegrationResponse - err = json.Unmarshal(res, &devicePostureIntegrationResponse) - if err != nil { - return DevicePostureIntegration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureIntegrationResponse.Result, nil -} - -// UpdateDevicePostureIntegration updates a device posture integration within an account. -// -// API reference: https://api.cloudflare.com/#device-posture-integrations-update-device-posture-integration -func (api *API) UpdateDevicePostureIntegration(ctx context.Context, accountID string, integration DevicePostureIntegration) (DevicePostureIntegration, error) { - uri := fmt.Sprintf("/%s/%s/devices/posture/integration/%s", AccountRouteRoot, accountID, integration.IntegrationID) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, integration) - if err != nil { - return DevicePostureIntegration{}, err - } - - var devicePostureIntegrationResponse DevicePostureIntegrationResponse - err = json.Unmarshal(res, &devicePostureIntegrationResponse) - if err != nil { - return DevicePostureIntegration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureIntegrationResponse.Result, nil -} - -// DevicePostureIntegration returns a specific device posture integrations within an account. -// -// API reference: https://api.cloudflare.com/#device-posture-integrations-device-posture-integration-details -func (api *API) DevicePostureIntegration(ctx context.Context, accountID, integrationID string) (DevicePostureIntegration, error) { - uri := fmt.Sprintf("/%s/%s/devices/posture/integration/%s", AccountRouteRoot, accountID, integrationID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return DevicePostureIntegration{}, err - } - - var devicePostureIntegrationResponse DevicePostureIntegrationResponse - err = json.Unmarshal(res, &devicePostureIntegrationResponse) - if err != nil { - return DevicePostureIntegration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureIntegrationResponse.Result, nil -} - -// DevicePostureIntegrations returns all device posture integrations within an account. -// -// API reference: https://api.cloudflare.com/#device-posture-integrations-list-device-posture-integrations -func (api *API) DevicePostureIntegrations(ctx context.Context, accountID string) ([]DevicePostureIntegration, ResultInfo, error) { - uri := fmt.Sprintf("/%s/%s/devices/posture/integration", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DevicePostureIntegration{}, ResultInfo{}, err - } - - var devicePostureIntegrationListResponse DevicePostureIntegrationListResponse - err = json.Unmarshal(res, &devicePostureIntegrationListResponse) - if err != nil { - return []DevicePostureIntegration{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureIntegrationListResponse.Result, devicePostureIntegrationListResponse.ResultInfo, nil -} - -// DeleteDevicePostureIntegration deletes a device posture integration. -// -// API reference: https://api.cloudflare.com/#device-posture-integrations-delete-device-posture-integration -func (api *API) DeleteDevicePostureIntegration(ctx context.Context, accountID, ruleID string) error { - uri := fmt.Sprintf( - "/%s/%s/devices/posture/integration/%s", - AccountRouteRoot, - accountID, - ruleID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} - -// DevicePostureRule represents a device posture rule. -type DevicePostureRule struct { - ID string `json:"id,omitempty"` - Type string `json:"type"` - Name string `json:"name"` - Description string `json:"description,omitempty"` - Schedule string `json:"schedule,omitempty"` - Match []DevicePostureRuleMatch `json:"match,omitempty"` - Input DevicePostureRuleInput `json:"input,omitempty"` - Expiration string `json:"expiration,omitempty"` -} - -// DevicePostureRuleMatch represents the conditions that the client must match to run the rule. -type DevicePostureRuleMatch struct { - Platform string `json:"platform,omitempty"` -} - -// DevicePostureRuleInput represents the value to be checked against. -type DevicePostureRuleInput struct { - ID string `json:"id,omitempty"` - Path string `json:"path,omitempty"` - Exists bool `json:"exists,omitempty"` - Thumbprint string `json:"thumbprint,omitempty"` - Sha256 string `json:"sha256,omitempty"` - Running bool `json:"running,omitempty"` - RequireAll bool `json:"requireAll,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Version string `json:"version,omitempty"` - VersionOperator string `json:"versionOperator,omitempty"` - Overall string `json:"overall,omitempty"` - SensorConfig string `json:"sensor_config,omitempty"` - Os string `json:"os,omitempty"` - OsDistroName string `json:"os_distro_name,omitempty"` - OsDistroRevision string `json:"os_distro_revision,omitempty"` - Operator string `json:"operator,omitempty"` - Domain string `json:"domain,omitempty"` - ComplianceStatus string `json:"compliance_status,omitempty"` - ConnectionID string `json:"connection_id,omitempty"` -} - -// DevicePostureRuleListResponse represents the response from the list -// device posture rules endpoint. -type DevicePostureRuleListResponse struct { - Result []DevicePostureRule `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// DevicePostureRuleDetailResponse is the API response, containing a single -// device posture rule. -type DevicePostureRuleDetailResponse struct { - Response - Result DevicePostureRule `json:"result"` -} - -// DevicePostureRules returns all device posture rules within an account. -// -// API reference: https://api.cloudflare.com/#device-posture-rules-list-device-posture-rules -func (api *API) DevicePostureRules(ctx context.Context, accountID string) ([]DevicePostureRule, ResultInfo, error) { - uri := fmt.Sprintf("/%s/%s/devices/posture", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DevicePostureRule{}, ResultInfo{}, err - } - - var devicePostureRuleListResponse DevicePostureRuleListResponse - err = json.Unmarshal(res, &devicePostureRuleListResponse) - if err != nil { - return []DevicePostureRule{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureRuleListResponse.Result, devicePostureRuleListResponse.ResultInfo, nil -} - -// DevicePostureRule returns a single device posture rule based on the rule ID. -// -// API reference: https://api.cloudflare.com/#device-posture-rules-device-posture-rules-details -func (api *API) DevicePostureRule(ctx context.Context, accountID, ruleID string) (DevicePostureRule, error) { - uri := fmt.Sprintf( - "/%s/%s/devices/posture/%s", - AccountRouteRoot, - accountID, - ruleID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return DevicePostureRule{}, err - } - - var devicePostureRuleDetailResponse DevicePostureRuleDetailResponse - err = json.Unmarshal(res, &devicePostureRuleDetailResponse) - if err != nil { - return DevicePostureRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureRuleDetailResponse.Result, nil -} - -// CreateDevicePostureRule creates a new device posture rule. -// -// API reference: https://api.cloudflare.com/#device-posture-rules-create-device-posture-rule -func (api *API) CreateDevicePostureRule(ctx context.Context, accountID string, rule DevicePostureRule) (DevicePostureRule, error) { - uri := fmt.Sprintf("/%s/%s/devices/posture", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, rule) - if err != nil { - return DevicePostureRule{}, err - } - - var devicePostureRuleDetailResponse DevicePostureRuleDetailResponse - err = json.Unmarshal(res, &devicePostureRuleDetailResponse) - if err != nil { - return DevicePostureRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureRuleDetailResponse.Result, nil -} - -// UpdateDevicePostureRule updates an existing device posture rule. -// -// API reference: https://api.cloudflare.com/#device-posture-rules-update-device-posture-rule -func (api *API) UpdateDevicePostureRule(ctx context.Context, accountID string, rule DevicePostureRule) (DevicePostureRule, error) { - if rule.ID == "" { - return DevicePostureRule{}, fmt.Errorf("device posture rule ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/devices/posture/%s", - AccountRouteRoot, - accountID, - rule.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, rule) - if err != nil { - return DevicePostureRule{}, err - } - - var devicePostureRuleDetailResponse DevicePostureRuleDetailResponse - err = json.Unmarshal(res, &devicePostureRuleDetailResponse) - if err != nil { - return DevicePostureRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return devicePostureRuleDetailResponse.Result, nil -} - -// DeleteDevicePostureRule deletes a device posture rule. -// -// API reference: https://api.cloudflare.com/#device-posture-rules-delete-device-posture-rule -func (api *API) DeleteDevicePostureRule(ctx context.Context, accountID, ruleID string) error { - uri := fmt.Sprintf( - "/%s/%s/devices/posture/%s", - AccountRouteRoot, - accountID, - ruleID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/devices_managed_networks.go b/vendor/github.com/cloudflare/cloudflare-go/devices_managed_networks.go deleted file mode 100644 index 2e308eb..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/devices_managed_networks.go +++ /dev/null @@ -1,164 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type Config struct { - TlsSockAddr string `json:"tls_sockaddr,omitempty"` - Sha256 string `json:"sha256,omitempty"` -} - -type DeviceManagedNetwork struct { - NetworkID string `json:"network_id,omitempty"` - Type string `json:"type"` - Name string `json:"name"` - Config *Config `json:"config"` -} - -type DeviceManagedNetworkResponse struct { - Response - Result DeviceManagedNetwork `json:"result"` -} - -type DeviceManagedNetworkListResponse struct { - Response - Result []DeviceManagedNetwork `json:"result"` -} - -type ListDeviceManagedNetworksParams struct{} - -type CreateDeviceManagedNetworkParams struct { - NetworkID string `json:"network_id,omitempty"` - Type string `json:"type"` - Name string `json:"name"` - Config *Config `json:"config"` -} - -type UpdateDeviceManagedNetworkParams struct { - NetworkID string `json:"network_id,omitempty"` - Type string `json:"type"` - Name string `json:"name"` - Config *Config `json:"config"` -} - -// ListDeviceManagedNetwork returns all Device Managed Networks for a given -// account. -// -// API reference : https://api.cloudflare.com/#device-managed-networks-list-device-managed-networks -func (api *API) ListDeviceManagedNetworks(ctx context.Context, rc *ResourceContainer, params ListDeviceManagedNetworksParams) ([]DeviceManagedNetwork, error) { - if rc.Level != AccountRouteLevel { - return []DeviceManagedNetwork{}, ErrRequiredAccountLevelResourceContainer - } - - uri := fmt.Sprintf("/%s/%s/devices/networks", rc.Level, rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DeviceManagedNetwork{}, err - } - - var response DeviceManagedNetworkListResponse - err = json.Unmarshal(res, &response) - if err != nil { - return []DeviceManagedNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// CreateDeviceManagedNetwork creates a new Device Managed Network. -// -// API reference: https://api.cloudflare.com/#device-managed-networks-create-device-managed-network -func (api *API) CreateDeviceManagedNetwork(ctx context.Context, rc *ResourceContainer, params CreateDeviceManagedNetworkParams) (DeviceManagedNetwork, error) { - if rc.Level != AccountRouteLevel { - return DeviceManagedNetwork{}, ErrRequiredAccountLevelResourceContainer - } - - uri := fmt.Sprintf("/%s/%s/devices/networks", rc.Level, rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return DeviceManagedNetwork{}, err - } - - var deviceManagedNetworksResponse DeviceManagedNetworkResponse - if err := json.Unmarshal(res, &deviceManagedNetworksResponse); err != nil { - return DeviceManagedNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return deviceManagedNetworksResponse.Result, err -} - -// UpdateDeviceManagedNetwork Update a Device Managed Network. -// -// API reference: https://api.cloudflare.com/#device-managed-networks-update-device-managed-network -func (api *API) UpdateDeviceManagedNetwork(ctx context.Context, rc *ResourceContainer, params UpdateDeviceManagedNetworkParams) (DeviceManagedNetwork, error) { - if rc.Level != AccountRouteLevel { - return DeviceManagedNetwork{}, ErrRequiredAccountLevelResourceContainer - } - - uri := fmt.Sprintf("/%s/%s/devices/networks/%s", rc.Level, rc.Identifier, params.NetworkID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return DeviceManagedNetwork{}, err - } - - var deviceManagedNetworksResponse DeviceManagedNetworkResponse - - if err := json.Unmarshal(res, &deviceManagedNetworksResponse); err != nil { - return DeviceManagedNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return deviceManagedNetworksResponse.Result, err -} - -// GetDeviceManagedNetwork gets a single Device Managed Network. -// -// API reference: https://api.cloudflare.com/#device-managed-networks-device-managed-network-details -func (api *API) GetDeviceManagedNetwork(ctx context.Context, rc *ResourceContainer, networkID string) (DeviceManagedNetwork, error) { - if rc.Level != AccountRouteLevel { - return DeviceManagedNetwork{}, ErrRequiredAccountLevelResourceContainer - } - - uri := fmt.Sprintf("/%s/%s/devices/networks/%s", rc.Level, rc.Identifier, networkID) - - deviceManagedNetworksResponse := DeviceManagedNetworkResponse{} - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return DeviceManagedNetwork{}, err - } - - if err := json.Unmarshal(res, &deviceManagedNetworksResponse); err != nil { - return DeviceManagedNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return deviceManagedNetworksResponse.Result, err -} - -// DeleteManagedNetworks deletes a Device Managed Network. -// -// API reference: https://api.cloudflare.com/#device-managed-networks-delete-device-managed-network -func (api *API) DeleteManagedNetworks(ctx context.Context, rc *ResourceContainer, networkID string) ([]DeviceManagedNetwork, error) { - if rc.Level != AccountRouteLevel { - return []DeviceManagedNetwork{}, ErrRequiredAccountLevelResourceContainer - } - - uri := fmt.Sprintf("/%s/%s/devices/networks/%s", rc.Level, rc.Identifier, networkID) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return []DeviceManagedNetwork{}, err - } - - var response DeviceManagedNetworkListResponse - if err := json.Unmarshal(res, &response); err != nil { - return []DeviceManagedNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, err -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/devices_policy.go b/vendor/github.com/cloudflare/cloudflare-go/devices_policy.go deleted file mode 100644 index 2e53775..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/devices_policy.go +++ /dev/null @@ -1,225 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type Enabled struct { - Enabled bool `json:"enabled"` -} - -// DeviceClientCertificatesZone identifies if the zero trust zone is configured for an account. -type DeviceClientCertificatesZone struct { - Response - Result Enabled -} - -type ServiceModeV2 struct { - Mode string `json:"mode,omitempty"` - Port int `json:"port,omitempty"` -} - -type DeviceSettingsPolicy struct { - ServiceModeV2 *ServiceModeV2 `json:"service_mode_v2"` - DisableAutoFallback *bool `json:"disable_auto_fallback"` - FallbackDomains *[]FallbackDomain `json:"fallback_domains"` - Include *[]SplitTunnel `json:"include"` - Exclude *[]SplitTunnel `json:"exclude"` - GatewayUniqueID *string `json:"gateway_unique_id"` - SupportURL *string `json:"support_url"` - CaptivePortal *int `json:"captive_portal"` - AllowModeSwitch *bool `json:"allow_mode_switch"` - SwitchLocked *bool `json:"switch_locked"` - AllowUpdates *bool `json:"allow_updates"` - AutoConnect *int `json:"auto_connect"` - AllowedToLeave *bool `json:"allowed_to_leave"` - PolicyID *string `json:"policy_id"` - Enabled *bool `json:"enabled"` - Name *string `json:"name"` - Match *string `json:"match"` - Precedence *int `json:"precedence"` - Default bool `json:"default"` - ExcludeOfficeIps *bool `json:"exclude_office_ips"` -} - -type DeviceSettingsPolicyResponse struct { - Response - Result DeviceSettingsPolicy -} - -type DeleteDeviceSettingsPolicyResponse struct { - Response - Result []DeviceSettingsPolicy -} - -type DeviceSettingsPolicyRequest struct { - DisableAutoFallback *bool `json:"disable_auto_fallback,omitempty"` - CaptivePortal *int `json:"captive_portal,omitempty"` - AllowModeSwitch *bool `json:"allow_mode_switch,omitempty"` - SwitchLocked *bool `json:"switch_locked,omitempty"` - AllowUpdates *bool `json:"allow_updates,omitempty"` - AutoConnect *int `json:"auto_connect,omitempty"` - AllowedToLeave *bool `json:"allowed_to_leave,omitempty"` - SupportURL *string `json:"support_url,omitempty"` - ServiceModeV2 *ServiceModeV2 `json:"service_mode_v2,omitempty"` - Precedence *int `json:"precedence,omitempty"` - Name *string `json:"name,omitempty"` - Match *string `json:"match,omitempty"` - Enabled *bool `json:"enabled,omitempty"` - ExcludeOfficeIps *bool `json:"exclude_office_ips"` -} - -// UpdateDeviceClientCertificates controls the zero trust zone used to provision client certificates. -// -// API reference: https://api.cloudflare.com/#device-client-certificates -func (api *API) UpdateDeviceClientCertificatesZone(ctx context.Context, zoneID string, enable bool) (DeviceClientCertificatesZone, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/certificates", ZoneRouteRoot, zoneID) - - result := DeviceClientCertificatesZone{} - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, Enabled{enable}) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// GetDeviceClientCertificatesZone controls the zero trust zone used to provision client certificates. -// -// API reference: https://api.cloudflare.com/#device-client-certificates -func (api *API) GetDeviceClientCertificatesZone(ctx context.Context, zoneID string) (DeviceClientCertificatesZone, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/certificates", ZoneRouteRoot, zoneID) - - result := DeviceClientCertificatesZone{} - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// CreateDeviceSettingsPolicy creates a settings policy against devices that match the policy -// -// API reference: https://api.cloudflare.com/#devices-create-device-settings-policy -func (api *API) CreateDeviceSettingsPolicy(ctx context.Context, accountID string, req DeviceSettingsPolicyRequest) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy", AccountRouteRoot, accountID) - - result := DeviceSettingsPolicyResponse{} - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, req) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// UpdateDefaultDeviceSettingsPolicy updates the default settings policy for an account -// -// API reference: https://api.cloudflare.com/#devices-update-default-device-settings-policy -func (api *API) UpdateDefaultDeviceSettingsPolicy(ctx context.Context, accountID string, req DeviceSettingsPolicyRequest) (DeviceSettingsPolicyResponse, error) { - result := DeviceSettingsPolicyResponse{} - uri := fmt.Sprintf("/%s/%s/devices/policy", AccountRouteRoot, accountID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, req) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// UpdateDeviceSettingsPolicy updates a settings policy -// -// API reference: https://api.cloudflare.com/#devices-update-device-settings-policy -func (api *API) UpdateDeviceSettingsPolicy(ctx context.Context, accountID, policyID string, req DeviceSettingsPolicyRequest) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, policyID) - - result := DeviceSettingsPolicyResponse{} - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, req) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// DeleteDeviceSettingsPolicy deletes a settings policy and returns a list -// of all of the other policies in the account -// -// API reference: https://api.cloudflare.com/#devices-delete-device-settings-policy -func (api *API) DeleteDeviceSettingsPolicy(ctx context.Context, accountID, policyID string) (DeleteDeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, policyID) - - result := DeleteDeviceSettingsPolicyResponse{} - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// GetDefaultDeviceSettings gets the default device settings policy -// -// API reference: https://api.cloudflare.com/#devices-get-default-device-settings-policy -func (api *API) GetDefaultDeviceSettingsPolicy(ctx context.Context, accountID string) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy", AccountRouteRoot, accountID) - - result := DeviceSettingsPolicyResponse{} - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// GetDefaultDeviceSettings gets the device settings policy by its policyID -// -// API reference: https://api.cloudflare.com/#devices-get-device-settings-policy-by-id -func (api *API) GetDeviceSettingsPolicy(ctx context.Context, accountID, policyID string) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, policyID) - - result := DeviceSettingsPolicyResponse{} - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return result, err - } - - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/diagnostics.go b/vendor/github.com/cloudflare/cloudflare-go/diagnostics.go deleted file mode 100644 index a6a8bfe..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/diagnostics.go +++ /dev/null @@ -1,101 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// DiagnosticsTracerouteConfiguration is the overarching structure of the -// diagnostics traceroute requests. -type DiagnosticsTracerouteConfiguration struct { - Targets []string `json:"targets"` - Colos []string `json:"colos,omitempty"` - Options DiagnosticsTracerouteConfigurationOptions `json:"options,omitempty"` -} - -// DiagnosticsTracerouteConfigurationOptions contains the options for performing -// traceroutes. -type DiagnosticsTracerouteConfigurationOptions struct { - PacketsPerTTL int `json:"packets_per_ttl"` - PacketType string `json:"packet_type"` - MaxTTL int `json:"max_ttl"` - WaitTime int `json:"wait_time"` -} - -// DiagnosticsTracerouteResponse is the outer response of the API response. -type DiagnosticsTracerouteResponse struct { - Response - Result []DiagnosticsTracerouteResponseResult `json:"result"` -} - -// DiagnosticsTracerouteResponseResult is the inner API response for the -// traceroute request. -type DiagnosticsTracerouteResponseResult struct { - Target string `json:"target"` - Colos []DiagnosticsTracerouteResponseColos `json:"colos"` -} - -// DiagnosticsTracerouteResponseColo contains the Name and City of a colocation. -type DiagnosticsTracerouteResponseColo struct { - Name string `json:"name"` - City string `json:"city"` -} - -// DiagnosticsTracerouteResponseNodes holds a summary of nodes contacted in the -// traceroute. -type DiagnosticsTracerouteResponseNodes struct { - Asn string `json:"asn"` - IP string `json:"ip"` - Name string `json:"name"` - PacketCount int `json:"packet_count"` - MeanRttMs float64 `json:"mean_rtt_ms"` - StdDevRttMs float64 `json:"std_dev_rtt_ms"` - MinRttMs float64 `json:"min_rtt_ms"` - MaxRttMs float64 `json:"max_rtt_ms"` -} - -// DiagnosticsTracerouteResponseHops holds packet and node information of the -// hops. -type DiagnosticsTracerouteResponseHops struct { - PacketsTTL int `json:"packets_ttl"` - PacketsSent int `json:"packets_sent"` - PacketsLost int `json:"packets_lost"` - Nodes []DiagnosticsTracerouteResponseNodes `json:"nodes"` -} - -// DiagnosticsTracerouteResponseColos is the summary struct of a colocation test. -type DiagnosticsTracerouteResponseColos struct { - Error string `json:"error"` - Colo DiagnosticsTracerouteResponseColo `json:"colo"` - TracerouteTimeMs int `json:"traceroute_time_ms"` - TargetSummary DiagnosticsTracerouteResponseNodes `json:"target_summary"` - Hops []DiagnosticsTracerouteResponseHops `json:"hops"` -} - -// PerformTraceroute initiates a traceroute from the Cloudflare network to the -// requested targets. -// -// API documentation: https://api.cloudflare.com/#diagnostics-traceroute -func (api *API) PerformTraceroute(ctx context.Context, accountID string, targets, colos []string, tracerouteOptions DiagnosticsTracerouteConfigurationOptions) ([]DiagnosticsTracerouteResponseResult, error) { - uri := fmt.Sprintf("/accounts/%s/diagnostics/traceroute", accountID) - diagnosticsPayload := DiagnosticsTracerouteConfiguration{ - Targets: targets, - Colos: colos, - Options: tracerouteOptions, - } - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, diagnosticsPayload) - if err != nil { - return []DiagnosticsTracerouteResponseResult{}, err - } - - var diagnosticsResponse DiagnosticsTracerouteResponse - err = json.Unmarshal(res, &diagnosticsResponse) - if err != nil { - return []DiagnosticsTracerouteResponseResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return diagnosticsResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/dlp_profile.go b/vendor/github.com/cloudflare/cloudflare-go/dlp_profile.go deleted file mode 100644 index 4eb0b5f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/dlp_profile.go +++ /dev/null @@ -1,218 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -var ( - ErrMissingProfileID = errors.New("missing required profile ID") -) - -// DLPPattern represents a DLP Pattern that matches an entry. -type DLPPattern struct { - Regex string `json:"regex,omitempty"` - Validation string `json:"validation,omitempty"` -} - -// DLPEntry represents a DLP Entry, which can be matched in HTTP bodies or files. -type DLPEntry struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - ProfileID string `json:"profile_id,omitempty"` - Enabled *bool `json:"enabled,omitempty"` - Type string `json:"type,omitempty"` - - // The following fields are only present for custom entries. - - Pattern *DLPPattern `json:"pattern,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -// DLPProfile represents a DLP Profile, which contains a set -// of entries. -type DLPProfile struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` - Description string `json:"description,omitempty"` - AllowedMatchCount int `json:"allowed_match_count"` - - // The following fields are omitted for predefined DLP - // profiles - Entries []DLPEntry `json:"entries,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -// DLPProfilesCreateRequest represents a request to create a -// set of profiles. -type DLPProfilesCreateRequest struct { - Profiles []DLPProfile `json:"profiles"` -} - -// DLPProfileListResponse represents the response from the list -// dlp profiles endpoint. -type DLPProfileListResponse struct { - Result []DLPProfile `json:"result"` - Response -} - -// DLPProfileResponse is the API response, containing a single -// access application. -type DLPProfileResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result DLPProfile `json:"result"` -} - -type ListDLPProfilesParams struct{} - -type CreateDLPProfilesParams struct { - Profiles []DLPProfile `json:"profiles"` - Type string -} - -type UpdateDLPProfileParams struct { - ProfileID string - Profile DLPProfile - Type string -} - -// ListDLPProfiles returns all DLP profiles within an account. -// -// API reference: https://api.cloudflare.com/#dlp-profiles-list-all-profiles -func (api *API) ListDLPProfiles(ctx context.Context, rc *ResourceContainer, params ListDLPProfilesParams) ([]DLPProfile, error) { - if rc.Identifier == "" { - return []DLPProfile{}, ErrMissingResourceIdentifier - } - - uri := buildURI(fmt.Sprintf("/%s/%s/dlp/profiles", rc.Level, rc.Identifier), nil) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DLPProfile{}, err - } - - var dlpProfilesListResponse DLPProfileListResponse - err = json.Unmarshal(res, &dlpProfilesListResponse) - if err != nil { - return []DLPProfile{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return dlpProfilesListResponse.Result, nil -} - -// GetDLPProfile returns a single DLP profile (custom or predefined) based on -// the profile ID. -// -// API reference: https://api.cloudflare.com/#dlp-profiles-get-dlp-profile -func (api *API) GetDLPProfile(ctx context.Context, rc *ResourceContainer, profileID string) (DLPProfile, error) { - if rc.Identifier == "" { - return DLPProfile{}, ErrMissingResourceIdentifier - } - - if profileID == "" { - return DLPProfile{}, ErrMissingProfileID - } - - uri := buildURI(fmt.Sprintf("/%s/%s/dlp/profiles/%s", rc.Level, rc.Identifier, profileID), nil) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return DLPProfile{}, err - } - - var dlpProfileResponse DLPProfileResponse - err = json.Unmarshal(res, &dlpProfileResponse) - if err != nil { - return DLPProfile{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return dlpProfileResponse.Result, nil -} - -// CreateDLPProfiles creates a set of DLP Profile. -// -// API reference: https://api.cloudflare.com/#dlp-profiles-create-custom-profiles -func (api *API) CreateDLPProfiles(ctx context.Context, rc *ResourceContainer, params CreateDLPProfilesParams) ([]DLPProfile, error) { - if rc.Identifier == "" { - return []DLPProfile{}, ErrMissingResourceIdentifier - } - - if params.Type == "" || params.Type != "custom" { - return []DLPProfile{}, fmt.Errorf("unsupported DLP profile type: %q", params.Type) - } - - uri := buildURI(fmt.Sprintf("/%s/%s/dlp/profiles/%s", rc.Level, rc.Identifier, params.Type), nil) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return []DLPProfile{}, err - } - - var dLPCustomProfilesResponse DLPProfileListResponse - err = json.Unmarshal(res, &dLPCustomProfilesResponse) - if err != nil { - return []DLPProfile{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return dLPCustomProfilesResponse.Result, nil -} - -// DeleteDLPProfile deletes a DLP profile. Only custom profiles can be deleted. -// -// API reference: https://api.cloudflare.com/#dlp-profiles-delete-custom-profile -func (api *API) DeleteDLPProfile(ctx context.Context, rc *ResourceContainer, profileID string) error { - if rc.Identifier == "" { - return ErrMissingResourceIdentifier - } - - if profileID == "" { - return ErrMissingProfileID - } - - uri := buildURI(fmt.Sprintf("/%s/%s/dlp/profiles/custom/%s", rc.Level, rc.Identifier, profileID), nil) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - return err -} - -// UpdateDLPProfile updates a DLP profile. -// -// API reference: https://api.cloudflare.com/#dlp-profiles-update-custom-profile -// API reference: https://api.cloudflare.com/#dlp-profiles-update-predefined-profile -func (api *API) UpdateDLPProfile(ctx context.Context, rc *ResourceContainer, params UpdateDLPProfileParams) (DLPProfile, error) { - if rc.Identifier == "" { - return DLPProfile{}, ErrMissingResourceIdentifier - } - - if params.Type == "" { - params.Type = "custom" - } - - if params.ProfileID == "" { - return DLPProfile{}, ErrMissingProfileID - } - - uri := buildURI(fmt.Sprintf("/%s/%s/dlp/profiles/%s/%s", rc.Level, rc.Identifier, params.Type, params.ProfileID), nil) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.Profile) - if err != nil { - return DLPProfile{}, err - } - - var dlpProfileResponse DLPProfileResponse - err = json.Unmarshal(res, &dlpProfileResponse) - if err != nil { - return DLPProfile{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return dlpProfileResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/dns.go b/vendor/github.com/cloudflare/cloudflare-go/dns.go deleted file mode 100644 index aa8cc22..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/dns.go +++ /dev/null @@ -1,275 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" - - "golang.org/x/net/idna" -) - -// DNSRecord represents a DNS record in a zone. -type DNSRecord struct { - CreatedOn time.Time `json:"created_on,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty"` - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Content string `json:"content,omitempty"` - Meta interface{} `json:"meta,omitempty"` - Data interface{} `json:"data,omitempty"` // data returned by: SRV, LOC - ID string `json:"id,omitempty"` - ZoneID string `json:"zone_id,omitempty"` - ZoneName string `json:"zone_name,omitempty"` - Priority *uint16 `json:"priority,omitempty"` - TTL int `json:"ttl,omitempty"` - Proxied *bool `json:"proxied,omitempty"` - Proxiable bool `json:"proxiable,omitempty"` - Locked bool `json:"locked,omitempty"` - Comment string `json:"comment,omitempty"` - Tags []string `json:"tags,omitempty"` -} - -// DNSRecordResponse represents the response from the DNS endpoint. -type DNSRecordResponse struct { - Result DNSRecord `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -type ListDirection string - -const ( - ListDirectionAsc ListDirection = "asc" - ListDirectionDesc ListDirection = "desc" -) - -type ListDNSRecordsParams struct { - Type string `url:"type,omitempty"` - Name string `url:"name,omitempty"` - Content string `url:"content,omitempty"` - Proxied *bool `url:"proxied,omitempty"` - Comment string `url:"comment,omitempty"` - Tags []string `url:"tag,omitempty"` // potentially multiple `tag=` - TagMatch string `url:"tag-match,omitempty"` - Order string `url:"order,omitempty"` - Direction ListDirection `url:"direction,omitempty"` - Match string `url:"match,omitempty"` - Priority *uint16 `url:"-"` - - ResultInfo -} - -type UpdateDNSRecordParams struct { - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Content string `json:"content,omitempty"` - Data interface{} `json:"data,omitempty"` // data for: SRV, LOC - ID string `json:"-"` - Priority *uint16 `json:"-"` // internal use only - TTL int `json:"ttl,omitempty"` - Proxied *bool `json:"proxied,omitempty"` - Comment string `json:"comment"` - Tags []string `json:"tags"` -} - -// DNSListResponse represents the response from the list DNS records endpoint. -type DNSListResponse struct { - Result []DNSRecord `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// listDNSRecordsDefaultPageSize represents the default per_page size of the API. -var listDNSRecordsDefaultPageSize int = 100 - -// nontransitionalLookup implements the nontransitional processing as specified in -// Unicode Technical Standard 46 with almost all checkings off to maximize user freedom. -var nontransitionalLookup = idna.New( - idna.MapForLookup(), - idna.StrictDomainName(false), - idna.ValidateLabels(false), -) - -// toUTS46ASCII tries to convert IDNs (international domain names) -// from Unicode form to Punycode, using non-transitional process specified -// in UTS 46. -// -// Note: conversion errors are silently discarded and partial conversion -// results are used. -func toUTS46ASCII(name string) string { - name, _ = nontransitionalLookup.ToASCII(name) - return name -} - -type CreateDNSRecordParams struct { - CreatedOn time.Time `json:"created_on,omitempty" url:"created_on,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty" url:"modified_on,omitempty"` - Type string `json:"type,omitempty" url:"type,omitempty"` - Name string `json:"name,omitempty" url:"name,omitempty"` - Content string `json:"content,omitempty" url:"content,omitempty"` - Meta interface{} `json:"meta,omitempty"` - Data interface{} `json:"data,omitempty"` // data returned by: SRV, LOC - ID string `json:"id,omitempty"` - ZoneID string `json:"zone_id,omitempty"` - ZoneName string `json:"zone_name,omitempty"` - Priority *uint16 `json:"priority,omitempty"` - TTL int `json:"ttl,omitempty"` - Proxied *bool `json:"proxied,omitempty" url:"proxied,omitempty"` - Proxiable bool `json:"proxiable,omitempty"` - Locked bool `json:"locked,omitempty"` - Comment string `json:"comment,omitempty" url:"comment,omitempty"` - Tags []string `json:"tags,omitempty"` -} - -// CreateDNSRecord creates a DNS record for the zone identifier. -// -// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record -func (api *API) CreateDNSRecord(ctx context.Context, rc *ResourceContainer, params CreateDNSRecordParams) (*DNSRecordResponse, error) { - if rc.Identifier == "" { - return nil, ErrMissingZoneID - } - params.Name = toUTS46ASCII(params.Name) - - uri := fmt.Sprintf("/zones/%s/dns_records", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return nil, err - } - - var recordResp *DNSRecordResponse - err = json.Unmarshal(res, &recordResp) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return recordResp, nil -} - -// ListDNSRecords returns a slice of DNS records for the given zone identifier. -// -// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records -func (api *API) ListDNSRecords(ctx context.Context, rc *ResourceContainer, params ListDNSRecordsParams) ([]DNSRecord, *ResultInfo, error) { - if rc.Identifier == "" { - return nil, nil, ErrMissingZoneID - } - - params.Name = toUTS46ASCII(params.Name) - - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - - if params.PerPage < 1 { - params.PerPage = listDNSRecordsDefaultPageSize - } - - if params.Page < 1 { - params.Page = 1 - } - - var records []DNSRecord - var listResponse DNSListResponse - - for { - uri := buildURI(fmt.Sprintf("/zones/%s/dns_records", rc.Identifier), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DNSRecord{}, &ResultInfo{}, err - } - err = json.Unmarshal(res, &listResponse) - if err != nil { - return []DNSRecord{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - records = append(records, listResponse.Result...) - params.ResultInfo = listResponse.ResultInfo.Next() - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - return records, &listResponse.ResultInfo, nil -} - -// ErrMissingDNSRecordID is for when DNS record ID is needed but not given. -var ErrMissingDNSRecordID = errors.New("required DNS record ID missing") - -// GetDNSRecord returns a single DNS record for the given zone & record -// identifiers. -// -// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-dns-record-details -func (api *API) GetDNSRecord(ctx context.Context, rc *ResourceContainer, recordID string) (DNSRecord, error) { - if rc.Identifier == "" { - return DNSRecord{}, ErrMissingZoneID - } - if recordID == "" { - return DNSRecord{}, ErrMissingDNSRecordID - } - - uri := fmt.Sprintf("/zones/%s/dns_records/%s", rc.Identifier, recordID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return DNSRecord{}, err - } - var r DNSRecordResponse - err = json.Unmarshal(res, &r) - if err != nil { - return DNSRecord{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateDNSRecord updates a single DNS record for the given zone & record -// identifiers. -// -// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record -func (api *API) UpdateDNSRecord(ctx context.Context, rc *ResourceContainer, params UpdateDNSRecordParams) error { - if rc.Identifier == "" { - return ErrMissingZoneID - } - - if params.ID == "" { - return ErrMissingDNSRecordID - } - - params.Name = toUTS46ASCII(params.Name) - - uri := fmt.Sprintf("/zones/%s/dns_records/%s", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) - if err != nil { - return err - } - var r DNSRecordResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// DeleteDNSRecord deletes a single DNS record for the given zone & record -// identifiers. -// -// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-delete-dns-record -func (api *API) DeleteDNSRecord(ctx context.Context, rc *ResourceContainer, recordID string) error { - if rc.Identifier == "" { - return ErrMissingZoneID - } - if recordID == "" { - return ErrMissingDNSRecordID - } - - uri := fmt.Sprintf("/zones/%s/dns_records/%s", rc.Identifier, recordID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r DNSRecordResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/dns_firewall.go b/vendor/github.com/cloudflare/cloudflare-go/dns_firewall.go deleted file mode 100644 index f2cfa42..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/dns_firewall.go +++ /dev/null @@ -1,195 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "strings" - "time" -) - -// DNSFirewallCluster represents a DNS Firewall configuration. -type DNSFirewallCluster struct { - ID string `json:"id,omitempty"` - Name string `json:"name"` - OriginIPs []string `json:"origin_ips"` - DNSFirewallIPs []string `json:"dns_firewall_ips,omitempty"` - MinimumCacheTTL uint `json:"minimum_cache_ttl,omitempty"` - MaximumCacheTTL uint `json:"maximum_cache_ttl,omitempty"` - DeprecateAnyRequests bool `json:"deprecate_any_requests"` - ModifiedOn string `json:"modified_on,omitempty"` -} - -// DNSFirewallAnalyticsMetrics represents a group of aggregated DNS Firewall metrics. -type DNSFirewallAnalyticsMetrics struct { - QueryCount *int64 `json:"queryCount"` - UncachedCount *int64 `json:"uncachedCount"` - StaleCount *int64 `json:"staleCount"` - ResponseTimeAvg *float64 `json:"responseTimeAvg"` - ResponseTimeMedian *float64 `json:"responseTimeMedian"` - ResponseTime90th *float64 `json:"responseTime90th"` - ResponseTime99th *float64 `json:"responseTime99th"` -} - -// DNSFirewallAnalytics represents a set of aggregated DNS Firewall metrics. -// TODO: Add the queried data and not only the aggregated values. -type DNSFirewallAnalytics struct { - Totals DNSFirewallAnalyticsMetrics `json:"totals"` - Min DNSFirewallAnalyticsMetrics `json:"min"` - Max DNSFirewallAnalyticsMetrics `json:"max"` -} - -// DNSFirewallUserAnalyticsOptions represents range and dimension selection on analytics endpoint. -type DNSFirewallUserAnalyticsOptions struct { - Metrics []string - Since *time.Time - Until *time.Time -} - -// dnsFirewallResponse represents a DNS Firewall response. -type dnsFirewallResponse struct { - Response - Result *DNSFirewallCluster `json:"result"` -} - -// dnsFirewallListResponse represents an array of DNS Firewall responses. -type dnsFirewallListResponse struct { - Response - Result []*DNSFirewallCluster `json:"result"` -} - -// dnsFirewallAnalyticsResponse represents a DNS Firewall analytics response. -type dnsFirewallAnalyticsResponse struct { - Response - Result DNSFirewallAnalytics `json:"result"` -} - -// CreateDNSFirewallCluster creates a new DNS Firewall cluster. -// -// API reference: https://api.cloudflare.com/#dns-firewall-create-dns-firewall-cluster -func (api *API) CreateDNSFirewallCluster(ctx context.Context, v DNSFirewallCluster) (*DNSFirewallCluster, error) { - uri := fmt.Sprintf("%s/dns_firewall", api.userBaseURL("/user")) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, v) - if err != nil { - return nil, err - } - - response := &dnsFirewallResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// DNSFirewallCluster fetches a single DNS Firewall cluster. -// -// API reference: https://api.cloudflare.com/#dns-firewall-dns-firewall-cluster-details -func (api *API) DNSFirewallCluster(ctx context.Context, clusterID string) (*DNSFirewallCluster, error) { - uri := fmt.Sprintf("%s/dns_firewall/%s", api.userBaseURL("/user"), clusterID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - response := &dnsFirewallResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// ListDNSFirewallClusters lists the DNS Firewall clusters associated with an account. -// -// API reference: https://api.cloudflare.com/#dns-firewall-list-dns-firewall-clusters -func (api *API) ListDNSFirewallClusters(ctx context.Context) ([]*DNSFirewallCluster, error) { - uri := fmt.Sprintf("%s/dns_firewall", api.userBaseURL("/user")) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - response := &dnsFirewallListResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// UpdateDNSFirewallCluster updates a DNS Firewall cluster. -// -// API reference: https://api.cloudflare.com/#dns-firewall-update-dns-firewall-cluster -func (api *API) UpdateDNSFirewallCluster(ctx context.Context, clusterID string, vv DNSFirewallCluster) error { - uri := fmt.Sprintf("%s/dns_firewall/%s", api.userBaseURL("/user"), clusterID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, vv) - if err != nil { - return err - } - - response := &dnsFirewallResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// DeleteDNSFirewallCluster deletes a DNS Firewall cluster. Note that this cannot be -// undone, and will stop all traffic to that cluster. -// -// API reference: https://api.cloudflare.com/#dns-firewall-delete-dns-firewall-cluster -func (api *API) DeleteDNSFirewallCluster(ctx context.Context, clusterID string) error { - uri := fmt.Sprintf("%s/dns_firewall/%s", api.userBaseURL("/user"), clusterID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - response := &dnsFirewallResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// encode encodes non-nil fields into URL encoded form. -func (o DNSFirewallUserAnalyticsOptions) encode() string { - v := url.Values{} - if o.Since != nil { - v.Set("since", (*o.Since).UTC().Format(time.RFC3339)) - } - if o.Until != nil { - v.Set("until", (*o.Until).UTC().Format(time.RFC3339)) - } - if o.Metrics != nil { - v.Set("metrics", strings.Join(o.Metrics, ",")) - } - return v.Encode() -} - -// DNSFirewallUserAnalytics retrieves analytics report for a specified dimension and time range. -func (api *API) DNSFirewallUserAnalytics(ctx context.Context, clusterID string, o DNSFirewallUserAnalyticsOptions) (DNSFirewallAnalytics, error) { - uri := fmt.Sprintf("%s/dns_firewall/%s/dns_analytics/report?%s", api.userBaseURL("/user"), clusterID, o.encode()) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return DNSFirewallAnalytics{}, err - } - - response := dnsFirewallAnalyticsResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return DNSFirewallAnalytics{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/duration.go b/vendor/github.com/cloudflare/cloudflare-go/duration.go deleted file mode 100644 index ba2418a..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/duration.go +++ /dev/null @@ -1,40 +0,0 @@ -package cloudflare - -import ( - "encoding/json" - "time" -) - -// Duration implements json.Marshaler and json.Unmarshaler for time.Duration -// using the fmt.Stringer interface of time.Duration and time.ParseDuration. -type Duration struct { - time.Duration -} - -// MarshalJSON encodes a Duration as a JSON string formatted using String. -func (d Duration) MarshalJSON() ([]byte, error) { - return json.Marshal(d.Duration.String()) -} - -// UnmarshalJSON decodes a Duration from a JSON string parsed using time.ParseDuration. -func (d *Duration) UnmarshalJSON(buf []byte) error { - var str string - - err := json.Unmarshal(buf, &str) - if err != nil { - return err - } - - dur, err := time.ParseDuration(str) - if err != nil { - return err - } - - d.Duration = dur - return nil -} - -var ( - _ = json.Marshaler((*Duration)(nil)) - _ = json.Unmarshaler((*Duration)(nil)) -) diff --git a/vendor/github.com/cloudflare/cloudflare-go/email_routing_destination.go b/vendor/github.com/cloudflare/cloudflare-go/email_routing_destination.go deleted file mode 100644 index cb9e30a..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/email_routing_destination.go +++ /dev/null @@ -1,156 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type EmailRoutingDestinationAddress struct { - Tag string `json:"tag,omitempty"` - Email string `json:"email,omitempty"` - Verified *time.Time `json:"verified,omitempty"` - Created *time.Time `json:"created,omitempty"` - Modified *time.Time `json:"modified,omitempty"` -} - -type ListEmailRoutingAddressParameters struct { - ResultInfo - Direction string `url:"direction,omitempty"` - Verified *bool `url:"verified,omitempty"` -} - -type ListEmailRoutingAddressResponse struct { - Result []EmailRoutingDestinationAddress `json:"result"` - ResultInfo `json:"result_info"` - Response -} - -type CreateEmailRoutingAddressParameters struct { - Email string `json:"email,omitempty"` -} - -type CreateEmailRoutingAddressResponse struct { - Result EmailRoutingDestinationAddress `json:"result,omitempty"` - Response -} - -// ListEmailRoutingDestinationAddresses Lists existing destination addresses. -// -// API reference: https://api.cloudflare.com/#email-routing-destination-addresses-list-destination-addresses -func (api *API) ListEmailRoutingDestinationAddresses(ctx context.Context, rc *ResourceContainer, params ListEmailRoutingAddressParameters) ([]EmailRoutingDestinationAddress, *ResultInfo, error) { - if rc.Identifier == "" { - return []EmailRoutingDestinationAddress{}, &ResultInfo{}, ErrMissingAccountID - } - - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - - if params.PerPage < 1 { - params.PerPage = 50 - } - - if params.Page < 1 { - params.Page = 1 - } - - var addresses []EmailRoutingDestinationAddress - var eResponse ListEmailRoutingAddressResponse - for { - eResponse = ListEmailRoutingAddressResponse{} - uri := buildURI(fmt.Sprintf("/accounts/%s/email/routing/addresses", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []EmailRoutingDestinationAddress{}, &ResultInfo{}, err - } - err = json.Unmarshal(res, &eResponse) - if err != nil { - return []EmailRoutingDestinationAddress{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - addresses = append(addresses, eResponse.Result...) - params.ResultInfo = eResponse.ResultInfo.Next() - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return addresses, &eResponse.ResultInfo, nil -} - -// CreateEmailRoutingDestinationAddress Create a destination address to forward your emails to. -// Destination addresses need to be verified before they become active. -// -// API reference: https://api.cloudflare.com/#email-routing-destination-addresses-create-a-destination-address -func (api *API) CreateEmailRoutingDestinationAddress(ctx context.Context, rc *ResourceContainer, params CreateEmailRoutingAddressParameters) (EmailRoutingDestinationAddress, error) { - if rc.Identifier == "" { - return EmailRoutingDestinationAddress{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/email/routing/addresses", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return EmailRoutingDestinationAddress{}, ErrMissingAccountID - } - - var r CreateEmailRoutingAddressResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingDestinationAddress{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// GetEmailRoutingDestinationAddress Gets information for a specific destination email already created. -// -// API reference: https://api.cloudflare.com/#email-routing-destination-addresses-get-a-destination-address -func (api *API) GetEmailRoutingDestinationAddress(ctx context.Context, rc *ResourceContainer, addressID string) (EmailRoutingDestinationAddress, error) { - if rc.Identifier == "" { - return EmailRoutingDestinationAddress{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/email/routing/addresses/%s", rc.Identifier, addressID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return EmailRoutingDestinationAddress{}, ErrMissingAccountID - } - - var r CreateEmailRoutingAddressResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingDestinationAddress{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// DeleteEmailRoutingDestinationAddress Deletes a specific destination address. -// -// API reference: https://api.cloudflare.com/#email-routing-destination-addresses-delete-destination-address -func (api *API) DeleteEmailRoutingDestinationAddress(ctx context.Context, rc *ResourceContainer, addressID string) (EmailRoutingDestinationAddress, error) { - if rc.Identifier == "" { - return EmailRoutingDestinationAddress{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/email/routing/addresses/%s", rc.Identifier, addressID) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return EmailRoutingDestinationAddress{}, ErrMissingAccountID - } - - var r CreateEmailRoutingAddressResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingDestinationAddress{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/email_routing_rules.go b/vendor/github.com/cloudflare/cloudflare-go/email_routing_rules.go deleted file mode 100644 index a6c075f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/email_routing_rules.go +++ /dev/null @@ -1,273 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -var ErrMissingRuleID = errors.New("required rule id missing") - -type EmailRoutingRuleMatcher struct { - Type string `json:"type,omitempty"` - Field string `json:"field,omitempty"` - Value string `json:"value,omitempty"` -} - -type EmailRoutingRuleAction struct { - Type string `json:"type,omitempty"` - Value []string `json:"value,omitempty"` -} - -type EmailRoutingRule struct { - Tag string `json:"tag,omitempty"` - Name string `json:"name,omitempty"` - Priority int `json:"priority,omitempty"` - Enabled *bool `json:"enabled,omitempty"` - Matchers []EmailRoutingRuleMatcher `json:"matchers,omitempty"` - Actions []EmailRoutingRuleAction `json:"actions,omitempty"` -} - -type ListEmailRoutingRulesParameters struct { - Enabled *bool `url:"enabled,omitempty"` - ResultInfo -} - -type ListEmailRoutingRuleResponse struct { - Result []EmailRoutingRule `json:"result"` - ResultInfo `json:"result_info,omitempty"` - Response -} - -type CreateEmailRoutingRuleParameters struct { - Matchers []EmailRoutingRuleMatcher `json:"matchers,omitempty"` - Actions []EmailRoutingRuleAction `json:"actions,omitempty"` - Name string `json:"name,omitempty"` - Enabled *bool `json:"enabled,omitempty"` - Priority int `json:"priority,omitempty"` -} - -type CreateEmailRoutingRuleResponse struct { - Result EmailRoutingRule `json:"result"` - Response -} - -type GetEmailRoutingRuleResponse struct { - Result EmailRoutingRule `json:"result"` - Response -} - -type UpdateEmailRoutingRuleParameters struct { - Matchers []EmailRoutingRuleMatcher `json:"matchers,omitempty"` - Actions []EmailRoutingRuleAction `json:"actions,omitempty"` - Name string `json:"name,omitempty"` - Enabled *bool `json:"enabled,omitempty"` - Priority int `json:"priority,omitempty"` - RuleID string -} - -type EmailRoutingCatchAllRule struct { - Tag string `json:"tag,omitempty"` - Name string `json:"name,omitempty"` - Enabled *bool `json:"enabled,omitempty"` - Matchers []EmailRoutingRuleMatcher `json:"matchers,omitempty"` - Actions []EmailRoutingRuleAction `json:"actions,omitempty"` -} - -type EmailRoutingCatchAllRuleResponse struct { - Result EmailRoutingCatchAllRule `json:"result"` - Response -} - -// ListEmailRoutingRules Lists existing routing rules. -// -// API reference: https://api.cloudflare.com/#email-routing-routing-rules-list-routing-rules -func (api *API) ListEmailRoutingRules(ctx context.Context, rc *ResourceContainer, params ListEmailRoutingRulesParameters) ([]EmailRoutingRule, *ResultInfo, error) { - if rc.Identifier == "" { - return []EmailRoutingRule{}, &ResultInfo{}, ErrMissingZoneID - } - - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - if params.PerPage < 1 { - params.PerPage = 50 - } - if params.Page < 1 { - params.Page = 1 - } - - var rules []EmailRoutingRule - var rResponse ListEmailRoutingRuleResponse - for { - rResponse = ListEmailRoutingRuleResponse{} - uri := buildURI(fmt.Sprintf("/zones/%s/email/routing/rules", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []EmailRoutingRule{}, &ResultInfo{}, err - } - - err = json.Unmarshal(res, &rResponse) - if err != nil { - return []EmailRoutingRule{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - rules = append(rules, rResponse.Result...) - params.ResultInfo = rResponse.ResultInfo.Next() - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return rules, &rResponse.ResultInfo, nil -} - -// CreateEmailRoutingRule Rules consist of a set of criteria for matching emails (such as an email being sent to a specific custom email address) plus a set of actions to take on the email (like forwarding it to a specific destination address). -// -// API reference: https://api.cloudflare.com/#email-routing-routing-rules-create-routing-rule -func (api *API) CreateEmailRoutingRule(ctx context.Context, rc *ResourceContainer, params CreateEmailRoutingRuleParameters) (EmailRoutingRule, error) { - if rc.Identifier == "" { - return EmailRoutingRule{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/email/routing/rules", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return EmailRoutingRule{}, err - } - - var r CreateEmailRoutingRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// GetEmailRoutingRule Get information for a specific routing rule already created. -// -// API reference: https://api.cloudflare.com/#email-routing-routing-rules-get-routing-rule -func (api *API) GetEmailRoutingRule(ctx context.Context, rc *ResourceContainer, ruleID string) (EmailRoutingRule, error) { - if rc.Identifier == "" { - return EmailRoutingRule{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/email/routing/rules/%s", rc.Identifier, ruleID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return EmailRoutingRule{}, err - } - - var r GetEmailRoutingRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateEmailRoutingRule Update actions, matches, or enable/disable specific routing rules -// -// API reference: https://api.cloudflare.com/#email-routing-routing-rules-update-routing-rule -func (api *API) UpdateEmailRoutingRule(ctx context.Context, rc *ResourceContainer, params UpdateEmailRoutingRuleParameters) (EmailRoutingRule, error) { - if rc.Identifier == "" { - return EmailRoutingRule{}, ErrMissingZoneID - } - - if params.RuleID == "" { - return EmailRoutingRule{}, ErrMissingRuleID - } - - uri := fmt.Sprintf("/zones/%s/email/routing/rules/%s", rc.Identifier, params.RuleID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return EmailRoutingRule{}, err - } - - var r GetEmailRoutingRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// DeleteEmailRoutingRule Delete a specific routing rule. -// -// API reference: https://api.cloudflare.com/#email-routing-routing-rules-delete-routing-rule -func (api *API) DeleteEmailRoutingRule(ctx context.Context, rc *ResourceContainer, ruleID string) (EmailRoutingRule, error) { - if rc.Identifier == "" { - return EmailRoutingRule{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/email/routing/rules/%s", rc.Identifier, ruleID) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return EmailRoutingRule{}, err - } - - var r GetEmailRoutingRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// GetEmailRoutingCatchAllRule Get information on the default catch-all routing rule. -// -// API reference: https://api.cloudflare.com/#email-routing-routing-rules-get-catch-all-rule -func (api *API) GetEmailRoutingCatchAllRule(ctx context.Context, rc *ResourceContainer) (EmailRoutingCatchAllRule, error) { - if rc.Identifier == "" { - return EmailRoutingCatchAllRule{}, ErrMissingZoneID - } - uri := fmt.Sprintf("/zones/%s/email/routing/rules/catch_all", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return EmailRoutingCatchAllRule{}, err - } - - var r EmailRoutingCatchAllRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingCatchAllRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateEmailRoutingCatchAllRule Enable or disable catch-all routing rule, or change action to forward to specific destination address. -// -// API reference: https://api.cloudflare.com/#email-routing-routing-rules-update-catch-all-rule -func (api *API) UpdateEmailRoutingCatchAllRule(ctx context.Context, rc *ResourceContainer, params EmailRoutingCatchAllRule) (EmailRoutingCatchAllRule, error) { - if rc.Identifier == "" { - return EmailRoutingCatchAllRule{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/email/routing/rules/catch_all", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return EmailRoutingCatchAllRule{}, err - } - - var r EmailRoutingCatchAllRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingCatchAllRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/email_routing_settings.go b/vendor/github.com/cloudflare/cloudflare-go/email_routing_settings.go deleted file mode 100644 index 9e27c0c..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/email_routing_settings.go +++ /dev/null @@ -1,117 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type EmailRoutingSettings struct { - Tag string `json:"tag,omitempty"` - Name string `json:"name,omitempty"` - Enabled bool `json:"enabled,omitempty"` - Created *time.Time `json:"created,omitempty"` - Modified *time.Time `json:"modified,omitempty"` - SkipWizard *bool `json:"skip_wizard,omitempty"` - Status string `json:"status,omitempty"` -} - -type EmailRoutingSettingsResponse struct { - Result EmailRoutingSettings `json:"result,omitempty"` - Response -} - -type EmailRoutingDNSSettingsResponse struct { - Result []DNSRecord `json:"result,omitempty"` - Response -} - -// GetEmailRoutingSettings Get information about the settings for your Email Routing zone. -// -// API reference: https://api.cloudflare.com/#email-routing-settings-get-email-routing-settings -func (api *API) GetEmailRoutingSettings(ctx context.Context, rc *ResourceContainer) (EmailRoutingSettings, error) { - if rc.Identifier == "" { - return EmailRoutingSettings{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/email/routing", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return EmailRoutingSettings{}, err - } - - var r EmailRoutingSettingsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// EnableEmailRouting Enable you Email Routing zone. Add and lock the necessary MX and SPF records. -// -// API reference: https://api.cloudflare.com/#email-routing-settings-enable-email-routing -func (api *API) EnableEmailRouting(ctx context.Context, rc *ResourceContainer) (EmailRoutingSettings, error) { - if rc.Identifier == "" { - return EmailRoutingSettings{}, ErrMissingZoneID - } - uri := fmt.Sprintf("/zones/%s/email/routing/enable", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return EmailRoutingSettings{}, err - } - - var r EmailRoutingSettingsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// DisableEmailRouting Disable your Email Routing zone. Also removes additional MX records previously required for Email Routing to work. -// -// API reference: https://api.cloudflare.com/#email-routing-settings-disable-email-routing -func (api *API) DisableEmailRouting(ctx context.Context, rc *ResourceContainer) (EmailRoutingSettings, error) { - if rc.Identifier == "" { - return EmailRoutingSettings{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/email/routing/disable", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return EmailRoutingSettings{}, err - } - - var r EmailRoutingSettingsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return EmailRoutingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetEmailRoutingDNSSettings Show the DNS records needed to configure your Email Routing zone. -// -// API reference: https://api.cloudflare.com/#email-routing-settings-email-routing---dns-settings -func (api *API) GetEmailRoutingDNSSettings(ctx context.Context, rc *ResourceContainer) ([]DNSRecord, error) { - if rc.Identifier == "" { - return []DNSRecord{}, ErrMissingZoneID - } - uri := fmt.Sprintf("/zones/%s/email/routing/dns", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DNSRecord{}, err - } - - var r EmailRoutingDNSSettingsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []DNSRecord{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/errors.go b/vendor/github.com/cloudflare/cloudflare-go/errors.go deleted file mode 100644 index 723c18b..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/errors.go +++ /dev/null @@ -1,389 +0,0 @@ -package cloudflare - -import ( - "errors" - "fmt" - "net/http" - "strings" -) - -const ( - errEmptyCredentials = "invalid credentials: key & email must not be empty" //nolint:gosec,unused - errEmptyAPIToken = "invalid credentials: API Token must not be empty" //nolint:gosec,unused - errInternalServiceError = "internal service error" - errMakeRequestError = "error from makeRequest" - errUnmarshalError = "error unmarshalling the JSON response" - errUnmarshalErrorBody = "error unmarshalling the JSON response error body" - errRequestNotSuccessful = "error reported by API" - errMissingAccountID = "required missing account ID" - errMissingZoneID = "required missing zone ID" - errMissingAccountOrZoneID = "either account ID or zone ID must be provided" - errAccountIDAndZoneIDAreMutuallyExclusive = "account ID and zone ID are mutually exclusive" - errMissingResourceIdentifier = "required missing resource identifier" - errOperationStillRunning = "bulk operation did not finish before timeout" - errOperationUnexpectedStatus = "bulk operation returned an unexpected status" - errResultInfo = "incorrect pagination info (result_info) in responses" - errManualPagination = "unexpected pagination options passed to functions that handle pagination automatically" - errInvalidResourceIdentifer = "invalid resource identifier: %s" - errInvalidZoneIdentifer = "invalid zone identifier: %s" - errAPIKeysAndTokensAreMutuallyExclusive = "API keys and tokens are mutually exclusive" //nolint:gosec - errMissingCredentials = "no credentials provided" - - errInvalidResourceContainerAccess = "requested resource container (%q) is not supported for this endpoint" - errRequiredAccountLevelResourceContainer = "this endpoint requires using an account level resource container and identifiers" -) - -var ( - ErrAPIKeysAndTokensAreMutuallyExclusive = errors.New(errAPIKeysAndTokensAreMutuallyExclusive) - ErrMissingCredentials = errors.New(errMissingCredentials) - ErrMissingAccountID = errors.New(errMissingAccountID) - ErrMissingZoneID = errors.New(errMissingZoneID) - ErrAccountIDOrZoneIDAreRequired = errors.New(errMissingAccountOrZoneID) - ErrAccountIDAndZoneIDAreMutuallyExclusive = errors.New(errAccountIDAndZoneIDAreMutuallyExclusive) - ErrMissingResourceIdentifier = errors.New(errMissingResourceIdentifier) - - ErrRequiredAccountLevelResourceContainer = errors.New(errRequiredAccountLevelResourceContainer) -) - -type ErrorType string - -const ( - ErrorTypeRequest ErrorType = "request" - ErrorTypeAuthentication ErrorType = "authentication" - ErrorTypeAuthorization ErrorType = "authorization" - ErrorTypeNotFound ErrorType = "not_found" - ErrorTypeRateLimit ErrorType = "rate_limit" - ErrorTypeService ErrorType = "service" -) - -type Error struct { - // The classification of error encountered. - Type ErrorType - - // StatusCode is the HTTP status code from the response. - StatusCode int - - // Errors is all of the error messages and codes, combined. - Errors []ResponseInfo - - // ErrorCodes is a list of all the error codes. - ErrorCodes []int - - // ErrorMessages is a list of all the error codes. - ErrorMessages []string - - // Messages is a list of informational messages provided by the endpoint. - Messages []ResponseInfo - - // RayID is the internal identifier for the request that was made. - RayID string -} - -func (e Error) Error() string { - var errString string - errMessages := []string{} - for _, err := range e.Errors { - m := "" - if err.Message != "" { - m += err.Message - } - - if err.Code != 0 { - m += fmt.Sprintf(" (%d)", err.Code) - } - - errMessages = append(errMessages, m) - } - - msgs := []string{} - for _, m := range e.Messages { - msgs = append(msgs, m.Message) - } - - errString += strings.Join(errMessages, ", ") - - // `Messages` is primarily used for additional validation failure notes in - // page rules. This shouldn't be used going forward but instead, use the - // error fields appropriately. - if len(msgs) > 0 { - errString += "\n" + strings.Join(msgs, " \n") - } - - return errString -} - -// RequestError is for 4xx errors that we encounter not covered elsewhere -// (generally bad payloads). -type RequestError struct { - cloudflareError *Error -} - -func (e RequestError) Error() string { - return e.cloudflareError.Error() -} - -func (e RequestError) Errors() []ResponseInfo { - return e.cloudflareError.Errors -} - -func (e RequestError) ErrorCodes() []int { - return e.cloudflareError.ErrorCodes -} - -func (e RequestError) ErrorMessages() []string { - return e.cloudflareError.ErrorMessages -} - -func (e RequestError) InternalErrorCodeIs(code int) bool { - return e.cloudflareError.InternalErrorCodeIs(code) -} - -func (e RequestError) Messages() []ResponseInfo { - return e.cloudflareError.Messages -} - -func (e RequestError) RayID() string { - return e.cloudflareError.RayID -} - -func (e RequestError) Type() ErrorType { - return e.cloudflareError.Type -} - -func NewRequestError(e *Error) RequestError { - return RequestError{ - cloudflareError: e, - } -} - -// RatelimitError is for HTTP 429s where the service is telling the client to -// slow down. -type RatelimitError struct { - cloudflareError *Error -} - -func (e RatelimitError) Error() string { - return e.cloudflareError.Error() -} - -func (e RatelimitError) Errors() []ResponseInfo { - return e.cloudflareError.Errors -} - -func (e RatelimitError) ErrorCodes() []int { - return e.cloudflareError.ErrorCodes -} - -func (e RatelimitError) ErrorMessages() []string { - return e.cloudflareError.ErrorMessages -} - -func (e RatelimitError) InternalErrorCodeIs(code int) bool { - return e.cloudflareError.InternalErrorCodeIs(code) -} - -func (e RatelimitError) RayID() string { - return e.cloudflareError.RayID -} - -func (e RatelimitError) Type() ErrorType { - return e.cloudflareError.Type -} - -func NewRatelimitError(e *Error) RatelimitError { - return RatelimitError{ - cloudflareError: e, - } -} - -// ServiceError is a handler for 5xx errors returned to the client. -type ServiceError struct { - cloudflareError *Error -} - -func (e ServiceError) Error() string { - return e.cloudflareError.Error() -} - -func (e ServiceError) Errors() []ResponseInfo { - return e.cloudflareError.Errors -} - -func (e ServiceError) ErrorCodes() []int { - return e.cloudflareError.ErrorCodes -} - -func (e ServiceError) ErrorMessages() []string { - return e.cloudflareError.ErrorMessages -} - -func (e ServiceError) InternalErrorCodeIs(code int) bool { - return e.cloudflareError.InternalErrorCodeIs(code) -} - -func (e ServiceError) RayID() string { - return e.cloudflareError.RayID -} - -func (e ServiceError) Type() ErrorType { - return e.cloudflareError.Type -} - -func NewServiceError(e *Error) ServiceError { - return ServiceError{ - cloudflareError: e, - } -} - -// AuthenticationError is for HTTP 401 responses. -type AuthenticationError struct { - cloudflareError *Error -} - -func (e AuthenticationError) Error() string { - return e.cloudflareError.Error() -} - -func (e AuthenticationError) Errors() []ResponseInfo { - return e.cloudflareError.Errors -} - -func (e AuthenticationError) ErrorCodes() []int { - return e.cloudflareError.ErrorCodes -} - -func (e AuthenticationError) ErrorMessages() []string { - return e.cloudflareError.ErrorMessages -} - -func (e AuthenticationError) InternalErrorCodeIs(code int) bool { - return e.cloudflareError.InternalErrorCodeIs(code) -} - -func (e AuthenticationError) RayID() string { - return e.cloudflareError.RayID -} - -func (e AuthenticationError) Type() ErrorType { - return e.cloudflareError.Type -} - -func NewAuthenticationError(e *Error) AuthenticationError { - return AuthenticationError{ - cloudflareError: e, - } -} - -// AuthorizationError is for HTTP 403 responses. -type AuthorizationError struct { - cloudflareError *Error -} - -func (e AuthorizationError) Error() string { - return e.cloudflareError.Error() -} - -func (e AuthorizationError) Errors() []ResponseInfo { - return e.cloudflareError.Errors -} - -func (e AuthorizationError) ErrorCodes() []int { - return e.cloudflareError.ErrorCodes -} - -func (e AuthorizationError) ErrorMessages() []string { - return e.cloudflareError.ErrorMessages -} - -func (e AuthorizationError) InternalErrorCodeIs(code int) bool { - return e.cloudflareError.InternalErrorCodeIs(code) -} - -func (e AuthorizationError) RayID() string { - return e.cloudflareError.RayID -} - -func (e AuthorizationError) Type() ErrorType { - return e.cloudflareError.Type -} - -func NewAuthorizationError(e *Error) AuthorizationError { - return AuthorizationError{ - cloudflareError: e, - } -} - -// NotFoundError is for HTTP 404 responses. -type NotFoundError struct { - cloudflareError *Error -} - -func (e NotFoundError) Error() string { - return e.cloudflareError.Error() -} - -func (e NotFoundError) Errors() []ResponseInfo { - return e.cloudflareError.Errors -} - -func (e NotFoundError) ErrorCodes() []int { - return e.cloudflareError.ErrorCodes -} - -func (e NotFoundError) ErrorMessages() []string { - return e.cloudflareError.ErrorMessages -} - -func (e NotFoundError) InternalErrorCodeIs(code int) bool { - return e.cloudflareError.InternalErrorCodeIs(code) -} - -func (e NotFoundError) RayID() string { - return e.cloudflareError.RayID -} - -func (e NotFoundError) Type() ErrorType { - return e.cloudflareError.Type -} - -func NewNotFoundError(e *Error) NotFoundError { - return NotFoundError{ - cloudflareError: e, - } -} - -// ClientError returns a boolean whether or not the raised error was caused by -// something client side. -func (e *Error) ClientError() bool { - return e.StatusCode >= http.StatusBadRequest && - e.StatusCode < http.StatusInternalServerError -} - -// ClientRateLimited returns a boolean whether or not the raised error was -// caused by too many requests from the client. -func (e *Error) ClientRateLimited() bool { - return e.Type == ErrorTypeRateLimit -} - -// InternalErrorCodeIs returns a boolean whether or not the desired internal -// error code is present in `e.InternalErrorCodes`. -func (e *Error) InternalErrorCodeIs(code int) bool { - for _, errCode := range e.ErrorCodes { - if errCode == code { - return true - } - } - - return false -} - -// ErrorMessageContains returns a boolean whether or not a substring exists in -// any of the `e.ErrorMessages` slice entries. -func (e *Error) ErrorMessageContains(s string) bool { - for _, errMsg := range e.ErrorMessages { - if strings.Contains(errMsg, s) { - return true - } - } - return false -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/fallback_domain.go b/vendor/github.com/cloudflare/cloudflare-go/fallback_domain.go deleted file mode 100644 index e0b9132..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/fallback_domain.go +++ /dev/null @@ -1,132 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// FallbackDomainResponse represents the response from the get fallback -// domain endpoints. -type FallbackDomainResponse struct { - Response - Result []FallbackDomain `json:"result"` -} - -// FallbackDomain represents the individual domain struct. -type FallbackDomain struct { - Suffix string `json:"suffix,omitempty"` - Description string `json:"description,omitempty"` - DNSServer []string `json:"dns_server,omitempty"` -} - -// ListFallbackDomains returns all fallback domains within an account. -// -// API reference: https://api.cloudflare.com/#devices-get-local-domain-fallback-list -func (api *API) ListFallbackDomains(ctx context.Context, accountID string) ([]FallbackDomain, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/fallback_domains", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []FallbackDomain{}, err - } - - var fallbackDomainResponse FallbackDomainResponse - err = json.Unmarshal(res, &fallbackDomainResponse) - if err != nil { - return []FallbackDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return fallbackDomainResponse.Result, nil -} - -// ListFallbackDomainsDeviceSettingsPolicy returns all fallback domains within an account for a specific device settings policy. -// -// API reference: https://api.cloudflare.com/#devices-get-local-domain-fallback-list -func (api *API) ListFallbackDomainsDeviceSettingsPolicy(ctx context.Context, accountID, policyID string) ([]FallbackDomain, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s/fallback_domains", AccountRouteRoot, accountID, policyID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []FallbackDomain{}, err - } - - var fallbackDomainResponse FallbackDomainResponse - err = json.Unmarshal(res, &fallbackDomainResponse) - if err != nil { - return []FallbackDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return fallbackDomainResponse.Result, nil -} - -// UpdateFallbackDomain updates the existing fallback domain policy. -// -// API reference: https://api.cloudflare.com/#devices-set-local-domain-fallback-list -func (api *API) UpdateFallbackDomain(ctx context.Context, accountID string, domains []FallbackDomain) ([]FallbackDomain, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/fallback_domains", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, domains) - if err != nil { - return []FallbackDomain{}, err - } - - var fallbackDomainResponse FallbackDomainResponse - err = json.Unmarshal(res, &fallbackDomainResponse) - if err != nil { - return []FallbackDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return fallbackDomainResponse.Result, nil -} - -// UpdateFallbackDomainDeviceSettingsPolicy updates the existing fallback domain policy for a specific device settings policy. -// -// API reference: https://api.cloudflare.com/#devices-set-local-domain-fallback-list -func (api *API) UpdateFallbackDomainDeviceSettingsPolicy(ctx context.Context, accountID, policyID string, domains []FallbackDomain) ([]FallbackDomain, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s/fallback_domains", AccountRouteRoot, accountID, policyID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, domains) - if err != nil { - return []FallbackDomain{}, err - } - - var fallbackDomainResponse FallbackDomainResponse - err = json.Unmarshal(res, &fallbackDomainResponse) - if err != nil { - return []FallbackDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return fallbackDomainResponse.Result, nil -} - -// RestoreFallbackDomainDefaultsDeviceSettingsPolicy resets the domain fallback values to the default -// list for a specific device settings policy. -// -// API reference: TBA. -func (api *API) RestoreFallbackDomainDefaults(ctx context.Context, accountID string) error { - uri := fmt.Sprintf("/%s/%s/devices/policy/fallback_domains?reset_defaults=true", AccountRouteRoot, accountID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, []string{}) - if err != nil { - return err - } - - return nil -} - -// RestoreFallbackDomainDefaults resets the domain fallback values to the default -// list. -// -// API reference: TBA. -func (api *API) RestoreFallbackDomainDefaultsDeviceSettingsPolicy(ctx context.Context, accountID, policyID string) error { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s/fallback_domains?reset_defaults=true", AccountRouteRoot, accountID, policyID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, []string{}) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/filter.go b/vendor/github.com/cloudflare/cloudflare-go/filter.go deleted file mode 100644 index b5f0846..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/filter.go +++ /dev/null @@ -1,289 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" -) - -var ErrNotEnoughFilterIDsProvided = errors.New("at least one filter ID must be provided.") - -// Filter holds the structure of the filter type. -type Filter struct { - ID string `json:"id,omitempty"` - Expression string `json:"expression"` - Paused bool `json:"paused"` - Description string `json:"description"` - - // Property is mentioned in documentation however isn't populated in - // any of the API requests. For now, let's just omit it unless it's - // provided. - Ref string `json:"ref,omitempty"` -} - -// FiltersDetailResponse is the API response that is returned -// for requesting all filters on a zone. -type FiltersDetailResponse struct { - Result []Filter `json:"result"` - ResultInfo `json:"result_info"` - Response -} - -// FilterDetailResponse is the API response that is returned -// for requesting a single filter on a zone. -type FilterDetailResponse struct { - Result Filter `json:"result"` - ResultInfo `json:"result_info"` - Response -} - -// FilterValidateExpression represents the JSON payload for checking -// an expression. -type FilterValidateExpression struct { - Expression string `json:"expression"` -} - -// FilterValidateExpressionResponse represents the API response for -// checking the expression. It conforms to the JSON API approach however -// we don't need all of the fields exposed. -type FilterValidateExpressionResponse struct { - Success bool `json:"success"` - Errors []FilterValidationExpressionMessage `json:"errors"` -} - -// FilterValidationExpressionMessage represents the API error message. -type FilterValidationExpressionMessage struct { - Message string `json:"message"` -} - -// FilterCreateParams contains required and optional params -// for creating a filter. -type FilterCreateParams struct { - ID string `json:"id,omitempty"` - Expression string `json:"expression"` - Paused bool `json:"paused"` - Description string `json:"description"` - Ref string `json:"ref,omitempty"` -} - -// FilterUpdateParams contains required and optional params -// for updating a filter. -type FilterUpdateParams struct { - ID string `json:"id"` - Expression string `json:"expression"` - Paused bool `json:"paused"` - Description string `json:"description"` - Ref string `json:"ref,omitempty"` -} - -type FilterListParams struct { - ResultInfo -} - -// Filter returns a single filter in a zone based on the filter ID. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/get/#get-by-filter-id -func (api *API) Filter(ctx context.Context, rc *ResourceContainer, filterID string) (Filter, error) { - uri := fmt.Sprintf("/zones/%s/filters/%s", rc.Identifier, filterID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Filter{}, err - } - - var filterResponse FilterDetailResponse - err = json.Unmarshal(res, &filterResponse) - if err != nil { - return Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return filterResponse.Result, nil -} - -// Filters returns filters for a zone. -// -// Automatically paginates all results unless `params.PerPage` and `params.Page` -// is set. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/get/#get-all-filters -func (api *API) Filters(ctx context.Context, rc *ResourceContainer, params FilterListParams) ([]Filter, *ResultInfo, error) { - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - if params.PerPage < 1 { - params.PerPage = 50 - } - if params.Page < 1 { - params.Page = 1 - } - - var filters []Filter - var fResponse FiltersDetailResponse - for { - fResponse = FiltersDetailResponse{} - uri := buildURI(fmt.Sprintf("/zones/%s/filters", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Filter{}, &ResultInfo{}, err - } - - err = json.Unmarshal(res, &fResponse) - if err != nil { - return []Filter{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal filters JSON data: %w", err) - } - - filters = append(filters, fResponse.Result...) - params.ResultInfo = fResponse.ResultInfo.Next() - - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return filters, &fResponse.ResultInfo, nil -} - -// CreateFilters creates new filters. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/post/ -func (api *API) CreateFilters(ctx context.Context, rc *ResourceContainer, params []FilterCreateParams) ([]Filter, error) { - uri := fmt.Sprintf("/zones/%s/filters", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return []Filter{}, err - } - - var filtersResponse FiltersDetailResponse - err = json.Unmarshal(res, &filtersResponse) - if err != nil { - return []Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return filtersResponse.Result, nil -} - -// UpdateFilter updates a single filter. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/put/#update-a-single-filter -func (api *API) UpdateFilter(ctx context.Context, rc *ResourceContainer, params FilterUpdateParams) (Filter, error) { - if params.ID == "" { - return Filter{}, fmt.Errorf("filter ID cannot be empty") - } - - uri := fmt.Sprintf("/zones/%s/filters/%s", rc.Identifier, params.ID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return Filter{}, err - } - - var filterResponse FilterDetailResponse - err = json.Unmarshal(res, &filterResponse) - if err != nil { - return Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return filterResponse.Result, nil -} - -// UpdateFilters updates many filters at once. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/put/#update-multiple-filters -func (api *API) UpdateFilters(ctx context.Context, rc *ResourceContainer, params []FilterUpdateParams) ([]Filter, error) { - for _, filter := range params { - if filter.ID == "" { - return []Filter{}, fmt.Errorf("filter ID cannot be empty") - } - } - - uri := fmt.Sprintf("/zones/%s/filters", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return []Filter{}, err - } - - var filtersResponse FiltersDetailResponse - err = json.Unmarshal(res, &filtersResponse) - if err != nil { - return []Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return filtersResponse.Result, nil -} - -// DeleteFilter deletes a single filter. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/delete/#delete-a-single-filter -func (api *API) DeleteFilter(ctx context.Context, rc *ResourceContainer, filterID string) error { - if filterID == "" { - return fmt.Errorf("filter ID cannot be empty") - } - - uri := fmt.Sprintf("/zones/%s/filters/%s", rc.Identifier, filterID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} - -// DeleteFilters deletes multiple filters. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/delete/#delete-multiple-filters -func (api *API) DeleteFilters(ctx context.Context, rc *ResourceContainer, filterIDs []string) error { - if len(filterIDs) == 0 { - return ErrNotEnoughFilterIDsProvided - } - - // Swap this to a typed struct and passing in all parameters together. - q := url.Values{} - for _, id := range filterIDs { - q.Add("id", id) - } - - uri := (&url.URL{ - Path: fmt.Sprintf("/zones/%s/filters", rc.Identifier), - RawQuery: q.Encode(), - }).String() - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} - -// ValidateFilterExpression checks correctness of a filter expression. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/validation/ -func (api *API) ValidateFilterExpression(ctx context.Context, expression string) error { - expressionPayload := FilterValidateExpression{Expression: expression} - - _, err := api.makeRequestContext(ctx, http.MethodPost, "/filters/validate-expr", expressionPayload) - if err != nil { - var filterValidationResponse FilterValidateExpressionResponse - - jsonErr := json.Unmarshal([]byte(err.Error()), &filterValidationResponse) - if jsonErr != nil { - return fmt.Errorf(errUnmarshalError+": %w", jsonErr) - } - - if !filterValidationResponse.Success { - // Unsure why but the API returns `errors` as an array but it only - // ever shows the issue with one problem at a time ¯\_(ツ)_/¯ - return fmt.Errorf(filterValidationResponse.Errors[0].Message) - } - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/firewall.go b/vendor/github.com/cloudflare/cloudflare-go/firewall.go deleted file mode 100644 index 51f004a..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/firewall.go +++ /dev/null @@ -1,280 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "strconv" - "time" -) - -// AccessRule represents a firewall access rule. -type AccessRule struct { - ID string `json:"id,omitempty"` - Notes string `json:"notes,omitempty"` - AllowedModes []string `json:"allowed_modes,omitempty"` - Mode string `json:"mode,omitempty"` - Configuration AccessRuleConfiguration `json:"configuration,omitempty"` - Scope AccessRuleScope `json:"scope,omitempty"` - CreatedOn time.Time `json:"created_on,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty"` -} - -// AccessRuleConfiguration represents the configuration of a firewall -// access rule. -type AccessRuleConfiguration struct { - Target string `json:"target,omitempty"` - Value string `json:"value,omitempty"` -} - -// AccessRuleScope represents the scope of a firewall access rule. -type AccessRuleScope struct { - ID string `json:"id,omitempty"` - Email string `json:"email,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` -} - -// AccessRuleResponse represents the response from the firewall access -// rule endpoint. -type AccessRuleResponse struct { - Result AccessRule `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// AccessRuleListResponse represents the response from the list access rules -// endpoint. -type AccessRuleListResponse struct { - Result []AccessRule `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// ListUserAccessRules returns a slice of access rules for the logged-in user. -// -// This takes an AccessRule to allow filtering of the results returned. -// -// API reference: https://api.cloudflare.com/#user-level-firewall-access-rule-list-access-rules -func (api *API) ListUserAccessRules(ctx context.Context, accessRule AccessRule, page int) (*AccessRuleListResponse, error) { - return api.listAccessRules(ctx, "/user", accessRule, page) -} - -// CreateUserAccessRule creates a firewall access rule for the logged-in user. -// -// API reference: https://api.cloudflare.com/#user-level-firewall-access-rule-create-access-rule -func (api *API) CreateUserAccessRule(ctx context.Context, accessRule AccessRule) (*AccessRuleResponse, error) { - return api.createAccessRule(ctx, "/user", accessRule) -} - -// UserAccessRule returns the details of a user's account access rule. -// -// API reference: https://api.cloudflare.com/#user-level-firewall-access-rule-list-access-rules -func (api *API) UserAccessRule(ctx context.Context, accessRuleID string) (*AccessRuleResponse, error) { - return api.retrieveAccessRule(ctx, "/user", accessRuleID) -} - -// UpdateUserAccessRule updates a single access rule for the logged-in user & -// given access rule identifier. -// -// API reference: https://api.cloudflare.com/#user-level-firewall-access-rule-update-access-rule -func (api *API) UpdateUserAccessRule(ctx context.Context, accessRuleID string, accessRule AccessRule) (*AccessRuleResponse, error) { - return api.updateAccessRule(ctx, "/user", accessRuleID, accessRule) -} - -// DeleteUserAccessRule deletes a single access rule for the logged-in user and -// access rule identifiers. -// -// API reference: https://api.cloudflare.com/#user-level-firewall-access-rule-update-access-rule -func (api *API) DeleteUserAccessRule(ctx context.Context, accessRuleID string) (*AccessRuleResponse, error) { - return api.deleteAccessRule(ctx, "/user", accessRuleID) -} - -// ListZoneAccessRules returns a slice of access rules for the given zone -// identifier. -// -// This takes an AccessRule to allow filtering of the results returned. -// -// API reference: https://api.cloudflare.com/#firewall-access-rule-for-a-zone-list-access-rules -func (api *API) ListZoneAccessRules(ctx context.Context, zoneID string, accessRule AccessRule, page int) (*AccessRuleListResponse, error) { - return api.listAccessRules(ctx, fmt.Sprintf("/zones/%s", zoneID), accessRule, page) -} - -// CreateZoneAccessRule creates a firewall access rule for the given zone -// identifier. -// -// API reference: https://api.cloudflare.com/#firewall-access-rule-for-a-zone-create-access-rule -func (api *API) CreateZoneAccessRule(ctx context.Context, zoneID string, accessRule AccessRule) (*AccessRuleResponse, error) { - return api.createAccessRule(ctx, fmt.Sprintf("/zones/%s", zoneID), accessRule) -} - -// ZoneAccessRule returns the details of a zone's access rule. -// -// API reference: https://api.cloudflare.com/#firewall-access-rule-for-a-zone-list-access-rules -func (api *API) ZoneAccessRule(ctx context.Context, zoneID string, accessRuleID string) (*AccessRuleResponse, error) { - return api.retrieveAccessRule(ctx, fmt.Sprintf("/zones/%s", zoneID), accessRuleID) -} - -// UpdateZoneAccessRule updates a single access rule for the given zone & -// access rule identifiers. -// -// API reference: https://api.cloudflare.com/#firewall-access-rule-for-a-zone-update-access-rule -func (api *API) UpdateZoneAccessRule(ctx context.Context, zoneID, accessRuleID string, accessRule AccessRule) (*AccessRuleResponse, error) { - return api.updateAccessRule(ctx, fmt.Sprintf("/zones/%s", zoneID), accessRuleID, accessRule) -} - -// DeleteZoneAccessRule deletes a single access rule for the given zone and -// access rule identifiers. -// -// API reference: https://api.cloudflare.com/#firewall-access-rule-for-a-zone-delete-access-rule -func (api *API) DeleteZoneAccessRule(ctx context.Context, zoneID, accessRuleID string) (*AccessRuleResponse, error) { - return api.deleteAccessRule(ctx, fmt.Sprintf("/zones/%s", zoneID), accessRuleID) -} - -// ListAccountAccessRules returns a slice of access rules for the given -// account identifier. -// -// This takes an AccessRule to allow filtering of the results returned. -// -// API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-list-access-rules -func (api *API) ListAccountAccessRules(ctx context.Context, accountID string, accessRule AccessRule, page int) (*AccessRuleListResponse, error) { - return api.listAccessRules(ctx, fmt.Sprintf("/accounts/%s", accountID), accessRule, page) -} - -// CreateAccountAccessRule creates a firewall access rule for the given -// account identifier. -// -// API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-create-access-rule -func (api *API) CreateAccountAccessRule(ctx context.Context, accountID string, accessRule AccessRule) (*AccessRuleResponse, error) { - return api.createAccessRule(ctx, fmt.Sprintf("/accounts/%s", accountID), accessRule) -} - -// AccountAccessRule returns the details of an account's access rule. -// -// API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-access-rule-details -func (api *API) AccountAccessRule(ctx context.Context, accountID string, accessRuleID string) (*AccessRuleResponse, error) { - return api.retrieveAccessRule(ctx, fmt.Sprintf("/accounts/%s", accountID), accessRuleID) -} - -// UpdateAccountAccessRule updates a single access rule for the given -// account & access rule identifiers. -// -// API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-update-access-rule -func (api *API) UpdateAccountAccessRule(ctx context.Context, accountID, accessRuleID string, accessRule AccessRule) (*AccessRuleResponse, error) { - return api.updateAccessRule(ctx, fmt.Sprintf("/accounts/%s", accountID), accessRuleID, accessRule) -} - -// DeleteAccountAccessRule deletes a single access rule for the given -// account and access rule identifiers. -// -// API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-delete-access-rule -func (api *API) DeleteAccountAccessRule(ctx context.Context, accountID, accessRuleID string) (*AccessRuleResponse, error) { - return api.deleteAccessRule(ctx, fmt.Sprintf("/accounts/%s", accountID), accessRuleID) -} - -func (api *API) listAccessRules(ctx context.Context, prefix string, accessRule AccessRule, page int) (*AccessRuleListResponse, error) { - // Construct a query string - v := url.Values{} - if page <= 0 { - page = 1 - } - v.Set("page", strconv.Itoa(page)) - // Request as many rules as possible per page - API max is 100 - v.Set("per_page", "100") - if accessRule.Notes != "" { - v.Set("notes", accessRule.Notes) - } - if accessRule.Mode != "" { - v.Set("mode", accessRule.Mode) - } - if accessRule.Scope.Type != "" { - v.Set("scope_type", accessRule.Scope.Type) - } - if accessRule.Configuration.Value != "" { - v.Set("configuration_value", accessRule.Configuration.Value) - } - if accessRule.Configuration.Target != "" { - v.Set("configuration_target", accessRule.Configuration.Target) - } - v.Set("page", strconv.Itoa(page)) - - uri := fmt.Sprintf("%s/firewall/access_rules/rules?%s", prefix, v.Encode()) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - response := &AccessRuleListResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return response, nil -} - -func (api *API) createAccessRule(ctx context.Context, prefix string, accessRule AccessRule) (*AccessRuleResponse, error) { - uri := fmt.Sprintf("%s/firewall/access_rules/rules", prefix) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, accessRule) - if err != nil { - return nil, err - } - - response := &AccessRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -func (api *API) retrieveAccessRule(ctx context.Context, prefix, accessRuleID string) (*AccessRuleResponse, error) { - uri := fmt.Sprintf("%s/firewall/access_rules/rules/%s", prefix, accessRuleID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - - if err != nil { - return nil, err - } - - response := &AccessRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -func (api *API) updateAccessRule(ctx context.Context, prefix, accessRuleID string, accessRule AccessRule) (*AccessRuleResponse, error) { - uri := fmt.Sprintf("%s/firewall/access_rules/rules/%s", prefix, accessRuleID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, accessRule) - if err != nil { - return nil, err - } - - response := &AccessRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return response, nil -} - -func (api *API) deleteAccessRule(ctx context.Context, prefix, accessRuleID string) (*AccessRuleResponse, error) { - uri := fmt.Sprintf("%s/firewall/access_rules/rules/%s", prefix, accessRuleID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return nil, err - } - - response := &AccessRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/firewall_rules.go b/vendor/github.com/cloudflare/cloudflare-go/firewall_rules.go deleted file mode 100644 index 51b4ae8..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/firewall_rules.go +++ /dev/null @@ -1,243 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "time" -) - -// FirewallRule is the struct of the firewall rule. -type FirewallRule struct { - ID string `json:"id,omitempty"` - Paused bool `json:"paused"` - Description string `json:"description"` - Action string `json:"action"` - Priority interface{} `json:"priority"` - Filter Filter `json:"filter"` - Products []string `json:"products,omitempty"` - Ref string `json:"ref,omitempty"` - CreatedOn time.Time `json:"created_on,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty"` -} - -// FirewallRulesDetailResponse is the API response for the firewall -// rules. -type FirewallRulesDetailResponse struct { - Result []FirewallRule `json:"result"` - ResultInfo `json:"result_info"` - Response -} - -// FirewallRuleResponse is the API response that is returned -// for requesting a single firewall rule on a zone. -type FirewallRuleResponse struct { - Result FirewallRule `json:"result"` - ResultInfo `json:"result_info"` - Response -} - -// FirewallRuleCreateParams contains required and optional params -// for creating a firewall rule. -type FirewallRuleCreateParams struct { - ID string `json:"id,omitempty"` - Paused bool `json:"paused"` - Description string `json:"description"` - Action string `json:"action"` - Priority interface{} `json:"priority"` - Filter Filter `json:"filter"` - Products []string `json:"products,omitempty"` - Ref string `json:"ref,omitempty"` -} - -// FirewallRuleUpdateParams contains required and optional params -// for updating a firewall rule. -type FirewallRuleUpdateParams struct { - ID string `json:"id"` - Paused bool `json:"paused"` - Description string `json:"description"` - Action string `json:"action"` - Priority interface{} `json:"priority"` - Filter Filter `json:"filter"` - Products []string `json:"products,omitempty"` - Ref string `json:"ref,omitempty"` -} - -type FirewallRuleListParams struct { - ResultInfo -} - -// FirewallRules returns all firewall rules. -// -// Automatically paginates all results unless `params.PerPage` and `params.Page` -// is set. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/get/#get-all-rules -func (api *API) FirewallRules(ctx context.Context, rc *ResourceContainer, params FirewallRuleListParams) ([]FirewallRule, *ResultInfo, error) { - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - if params.PerPage < 1 { - params.PerPage = 50 - } - if params.Page < 1 { - params.Page = 1 - } - - var firewallRules []FirewallRule - var fResponse FirewallRulesDetailResponse - for { - fResponse = FirewallRulesDetailResponse{} - uri := buildURI(fmt.Sprintf("/zones/%s/firewall/rules", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []FirewallRule{}, &ResultInfo{}, err - } - - err = json.Unmarshal(res, &fResponse) - if err != nil { - return []FirewallRule{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal filters JSON data: %w", err) - } - - firewallRules = append(firewallRules, fResponse.Result...) - params.ResultInfo = fResponse.ResultInfo.Next() - - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return firewallRules, &fResponse.ResultInfo, nil -} - -// FirewallRule returns a single firewall rule based on the ID. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/get/#get-by-rule-id -func (api *API) FirewallRule(ctx context.Context, rc *ResourceContainer, firewallRuleID string) (FirewallRule, error) { - uri := fmt.Sprintf("/zones/%s/firewall/rules/%s", rc.Identifier, firewallRuleID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return FirewallRule{}, err - } - - var firewallRuleResponse FirewallRuleResponse - err = json.Unmarshal(res, &firewallRuleResponse) - if err != nil { - return FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return firewallRuleResponse.Result, nil -} - -// CreateFirewallRules creates new firewall rules. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/post/ -func (api *API) CreateFirewallRules(ctx context.Context, rc *ResourceContainer, params []FirewallRuleCreateParams) ([]FirewallRule, error) { - uri := fmt.Sprintf("/zones/%s/firewall/rules", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return []FirewallRule{}, err - } - - var firewallRulesDetailResponse FirewallRulesDetailResponse - err = json.Unmarshal(res, &firewallRulesDetailResponse) - if err != nil { - return []FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return firewallRulesDetailResponse.Result, nil -} - -// UpdateFirewallRule updates a single firewall rule. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/put/#update-a-single-rule -func (api *API) UpdateFirewallRule(ctx context.Context, rc *ResourceContainer, params FirewallRuleUpdateParams) (FirewallRule, error) { - if params.ID == "" { - return FirewallRule{}, fmt.Errorf("firewall rule ID cannot be empty") - } - - uri := fmt.Sprintf("/zones/%s/firewall/rules/%s", rc.Identifier, params.ID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return FirewallRule{}, err - } - - var firewallRuleResponse FirewallRuleResponse - err = json.Unmarshal(res, &firewallRuleResponse) - if err != nil { - return FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return firewallRuleResponse.Result, nil -} - -// UpdateFirewallRules updates a single firewall rule. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/put/#update-multiple-rules -func (api *API) UpdateFirewallRules(ctx context.Context, rc *ResourceContainer, params []FirewallRuleUpdateParams) ([]FirewallRule, error) { - for _, firewallRule := range params { - if firewallRule.ID == "" { - return []FirewallRule{}, fmt.Errorf("firewall ID cannot be empty") - } - } - - uri := fmt.Sprintf("/zones/%s/firewall/rules", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return []FirewallRule{}, err - } - - var firewallRulesDetailResponse FirewallRulesDetailResponse - err = json.Unmarshal(res, &firewallRulesDetailResponse) - if err != nil { - return []FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return firewallRulesDetailResponse.Result, nil -} - -// DeleteFirewallRule deletes a single firewall rule. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/delete/#delete-a-single-rule -func (api *API) DeleteFirewallRule(ctx context.Context, rc *ResourceContainer, firewallRuleID string) error { - if firewallRuleID == "" { - return fmt.Errorf("firewall rule ID cannot be empty") - } - - uri := fmt.Sprintf("/zones/%s/firewall/rules/%s", rc.Identifier, firewallRuleID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} - -// DeleteFirewallRules deletes multiple firewall rules at once. -// -// API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/delete/#delete-multiple-rules -func (api *API) DeleteFirewallRules(ctx context.Context, rc *ResourceContainer, firewallRuleIDs []string) error { - v := url.Values{} - - for _, ruleID := range firewallRuleIDs { - v.Add("id", ruleID) - } - - uri := fmt.Sprintf("/zones/%s/firewall/rules?%s", rc.Identifier, v.Encode()) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/healthchecks.go b/vendor/github.com/cloudflare/cloudflare-go/healthchecks.go deleted file mode 100644 index 1239d01..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/healthchecks.go +++ /dev/null @@ -1,198 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// Healthcheck describes a Healthcheck object. -type Healthcheck struct { - ID string `json:"id,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - Name string `json:"name"` - Description string `json:"description"` - Suspended bool `json:"suspended"` - Address string `json:"address"` - Retries int `json:"retries,omitempty"` - Timeout int `json:"timeout,omitempty"` - Interval int `json:"interval,omitempty"` - ConsecutiveSuccesses int `json:"consecutive_successes,omitempty"` - ConsecutiveFails int `json:"consecutive_fails,omitempty"` - Type string `json:"type,omitempty"` - CheckRegions []string `json:"check_regions"` - HTTPConfig *HealthcheckHTTPConfig `json:"http_config,omitempty"` - TCPConfig *HealthcheckTCPConfig `json:"tcp_config,omitempty"` - Status string `json:"status"` - FailureReason string `json:"failure_reason"` -} - -// HealthcheckHTTPConfig describes configuration for a HTTP healthcheck. -type HealthcheckHTTPConfig struct { - Method string `json:"method"` - Port uint16 `json:"port,omitempty"` - Path string `json:"path"` - ExpectedCodes []string `json:"expected_codes"` - ExpectedBody string `json:"expected_body"` - FollowRedirects bool `json:"follow_redirects"` - AllowInsecure bool `json:"allow_insecure"` - Header map[string][]string `json:"header"` -} - -// HealthcheckTCPConfig describes configuration for a TCP healthcheck. -type HealthcheckTCPConfig struct { - Method string `json:"method"` - Port uint16 `json:"port,omitempty"` -} - -// HealthcheckListResponse is the API response, containing an array of healthchecks. -type HealthcheckListResponse struct { - Response - Result []Healthcheck `json:"result"` - ResultInfo `json:"result_info"` -} - -// HealthcheckResponse is the API response, containing a single healthcheck. -type HealthcheckResponse struct { - Response - Result Healthcheck `json:"result"` -} - -// Healthchecks returns all healthchecks for a zone. -// -// API reference: https://api.cloudflare.com/#health-checks-list-health-checks -func (api *API) Healthchecks(ctx context.Context, zoneID string) ([]Healthcheck, error) { - uri := fmt.Sprintf("/zones/%s/healthchecks", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Healthcheck{}, err - } - var r HealthcheckListResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// Healthcheck returns a single healthcheck by ID. -// -// API reference: https://api.cloudflare.com/#health-checks-health-check-details -func (api *API) Healthcheck(ctx context.Context, zoneID, healthcheckID string) (Healthcheck, error) { - uri := fmt.Sprintf("/zones/%s/healthchecks/%s", zoneID, healthcheckID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Healthcheck{}, err - } - var r HealthcheckResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateHealthcheck creates a new healthcheck in a zone. -// -// API reference: https://api.cloudflare.com/#health-checks-create-health-check -func (api *API) CreateHealthcheck(ctx context.Context, zoneID string, healthcheck Healthcheck) (Healthcheck, error) { - uri := fmt.Sprintf("/zones/%s/healthchecks", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, healthcheck) - if err != nil { - return Healthcheck{}, err - } - var r HealthcheckResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateHealthcheck updates an existing healthcheck. -// -// API reference: https://api.cloudflare.com/#health-checks-update-health-check -func (api *API) UpdateHealthcheck(ctx context.Context, zoneID string, healthcheckID string, healthcheck Healthcheck) (Healthcheck, error) { - uri := fmt.Sprintf("/zones/%s/healthchecks/%s", zoneID, healthcheckID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, healthcheck) - if err != nil { - return Healthcheck{}, err - } - var r HealthcheckResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteHealthcheck deletes a healthcheck in a zone. -// -// API reference: https://api.cloudflare.com/#health-checks-delete-health-check -func (api *API) DeleteHealthcheck(ctx context.Context, zoneID string, healthcheckID string) error { - uri := fmt.Sprintf("/zones/%s/healthchecks/%s", zoneID, healthcheckID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r HealthcheckResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// CreateHealthcheckPreview creates a new preview of a healthcheck in a zone. -// -// API reference: https://api.cloudflare.com/#health-checks-create-preview-health-check -func (api *API) CreateHealthcheckPreview(ctx context.Context, zoneID string, healthcheck Healthcheck) (Healthcheck, error) { - uri := fmt.Sprintf("/zones/%s/healthchecks/preview", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, healthcheck) - if err != nil { - return Healthcheck{}, err - } - var r HealthcheckResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// HealthcheckPreview returns a single healthcheck preview by its ID. -// -// API reference: https://api.cloudflare.com/#health-checks-health-check-preview-details -func (api *API) HealthcheckPreview(ctx context.Context, zoneID, id string) (Healthcheck, error) { - uri := fmt.Sprintf("/zones/%s/healthchecks/preview/%s", zoneID, id) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Healthcheck{}, err - } - var r HealthcheckResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteHealthcheckPreview deletes a healthcheck preview in a zone if it exists. -// -// API reference: https://api.cloudflare.com/#health-checks-delete-preview-health-check -func (api *API) DeleteHealthcheckPreview(ctx context.Context, zoneID string, id string) error { - uri := fmt.Sprintf("/zones/%s/healthchecks/preview/%s", zoneID, id) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r HealthcheckResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/images.go b/vendor/github.com/cloudflare/cloudflare-go/images.go deleted file mode 100644 index 8cb9fd2..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/images.go +++ /dev/null @@ -1,281 +0,0 @@ -package cloudflare - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "fmt" - "io" - "mime/multipart" - "net/http" - "time" -) - -// Image represents a Cloudflare Image. -type Image struct { - ID string `json:"id"` - Filename string `json:"filename"` - Metadata map[string]interface{} `json:"metadata,omitempty"` - RequireSignedURLs bool `json:"requireSignedURLs"` - Variants []string `json:"variants"` - Uploaded time.Time `json:"uploaded"` -} - -// ImageUploadRequest is the data required for an Image Upload request. -type ImageUploadRequest struct { - File io.ReadCloser - Name string - RequireSignedURLs bool - Metadata map[string]interface{} -} - -// write writes the image upload data to a multipart writer, so -// it can be used in an HTTP request. -func (b ImageUploadRequest) write(mpw *multipart.Writer) error { - if b.File == nil { - return errors.New("a file to upload must be specified") - } - name := b.Name - part, err := mpw.CreateFormFile("file", name) - if err != nil { - return err - } - _, err = io.Copy(part, b.File) - if err != nil { - _ = b.File.Close() - return err - } - _ = b.File.Close() - - // According to the Cloudflare docs, this field defaults to false. - // For simplicity, we will only send it if the value is true, however - // if the default is changed to true, this logic will need to be updated. - if b.RequireSignedURLs { - err = mpw.WriteField("requireSignedURLs", "true") - if err != nil { - return err - } - } - - if b.Metadata != nil { - part, err = mpw.CreateFormField("metadata") - if err != nil { - return err - } - err = json.NewEncoder(part).Encode(b.Metadata) - if err != nil { - return err - } - } - - return nil -} - -// ImageUpdateRequest is the data required for an UpdateImage request. -type ImageUpdateRequest struct { - RequireSignedURLs bool `json:"requireSignedURLs"` - Metadata map[string]interface{} `json:"metadata,omitempty"` -} - -// ImageDirectUploadURLRequest is the data required for a CreateImageDirectUploadURL request. -type ImageDirectUploadURLRequest struct { - Expiry time.Time `json:"expiry"` -} - -// ImageDirectUploadURLResponse is the API response for a direct image upload url. -type ImageDirectUploadURLResponse struct { - Result ImageDirectUploadURL `json:"result"` - Response -} - -// ImageDirectUploadURL . -type ImageDirectUploadURL struct { - ID string `json:"id"` - UploadURL string `json:"uploadURL"` -} - -// ImagesListResponse is the API response for listing all images. -type ImagesListResponse struct { - Result struct { - Images []Image `json:"images"` - } `json:"result"` - Response -} - -// ImageDetailsResponse is the API response for getting an image's details. -type ImageDetailsResponse struct { - Result Image `json:"result"` - Response -} - -// ImagesStatsResponse is the API response for image stats. -type ImagesStatsResponse struct { - Result struct { - Count ImagesStatsCount `json:"count"` - } `json:"result"` - Response -} - -// ImagesStatsCount is the stats attached to a ImagesStatsResponse. -type ImagesStatsCount struct { - Current int64 `json:"current"` - Allowed int64 `json:"allowed"` -} - -// UploadImage uploads a single image. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-upload-an-image-using-a-single-http-request -func (api *API) UploadImage(ctx context.Context, accountID string, upload ImageUploadRequest) (Image, error) { - uri := fmt.Sprintf("/accounts/%s/images/v1", accountID) - - body := &bytes.Buffer{} - w := multipart.NewWriter(body) - if err := upload.write(w); err != nil { - _ = w.Close() - return Image{}, fmt.Errorf("error writing multipart body: %w", err) - } - _ = w.Close() - - res, err := api.makeRequestContextWithHeaders( - ctx, - http.MethodPost, - uri, - body, - http.Header{ - "Accept": []string{"application/json"}, - "Content-Type": []string{w.FormDataContentType()}, - }, - ) - if err != nil { - return Image{}, err - } - - var imageDetailsResponse ImageDetailsResponse - err = json.Unmarshal(res, &imageDetailsResponse) - if err != nil { - return Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return imageDetailsResponse.Result, nil -} - -// UpdateImage updates an existing image's metadata. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-update-image -func (api *API) UpdateImage(ctx context.Context, accountID string, id string, image ImageUpdateRequest) (Image, error) { - uri := fmt.Sprintf("/accounts/%s/images/v1/%s", accountID, id) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, image) - if err != nil { - return Image{}, err - } - - var imageDetailsResponse ImageDetailsResponse - err = json.Unmarshal(res, &imageDetailsResponse) - if err != nil { - return Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return imageDetailsResponse.Result, nil -} - -// CreateImageDirectUploadURL creates an authenticated direct upload url. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-create-authenticated-direct-upload-url -func (api *API) CreateImageDirectUploadURL(ctx context.Context, accountID string, params ImageDirectUploadURLRequest) (ImageDirectUploadURL, error) { - uri := fmt.Sprintf("/accounts/%s/images/v1/direct_upload", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return ImageDirectUploadURL{}, err - } - - var imageDirectUploadURLResponse ImageDirectUploadURLResponse - err = json.Unmarshal(res, &imageDirectUploadURLResponse) - if err != nil { - return ImageDirectUploadURL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return imageDirectUploadURLResponse.Result, nil -} - -// ListImages lists all images. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-list-images -func (api *API) ListImages(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]Image, error) { - uri := buildURI(fmt.Sprintf("/accounts/%s/images/v1", accountID), pageOpts) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Image{}, err - } - - var imagesListResponse ImagesListResponse - err = json.Unmarshal(res, &imagesListResponse) - if err != nil { - return []Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return imagesListResponse.Result.Images, nil -} - -// ImageDetails gets the details of an uploaded image. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-image-details -func (api *API) ImageDetails(ctx context.Context, accountID string, id string) (Image, error) { - uri := fmt.Sprintf("/accounts/%s/images/v1/%s", accountID, id) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Image{}, err - } - - var imageDetailsResponse ImageDetailsResponse - err = json.Unmarshal(res, &imageDetailsResponse) - if err != nil { - return Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return imageDetailsResponse.Result, nil -} - -// BaseImage gets the base image used to derive variants. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-base-image -func (api *API) BaseImage(ctx context.Context, accountID string, id string) ([]byte, error) { - uri := fmt.Sprintf("/accounts/%s/images/v1/%s/blob", accountID, id) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - return res, nil -} - -// DeleteImage deletes an image. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-delete-image -func (api *API) DeleteImage(ctx context.Context, accountID string, id string) error { - uri := fmt.Sprintf("/accounts/%s/images/v1/%s", accountID, id) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - return nil -} - -// ImagesStats gets an account's statistics for Cloudflare Images. -// -// API Reference: https://api.cloudflare.com/#cloudflare-images-images-usage-statistics -func (api *API) ImagesStats(ctx context.Context, accountID string) (ImagesStatsCount, error) { - uri := fmt.Sprintf("/accounts/%s/images/v1/stats", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ImagesStatsCount{}, err - } - - var imagesStatsResponse ImagesStatsResponse - err = json.Unmarshal(res, &imagesStatsResponse) - if err != nil { - return ImagesStatsCount{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return imagesStatsResponse.Result.Count, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/intelligence_asn.go b/vendor/github.com/cloudflare/cloudflare-go/intelligence_asn.go deleted file mode 100644 index 04e8e5a..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/intelligence_asn.go +++ /dev/null @@ -1,100 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -// ErrMissingASN is for when ASN is required but not set. -var ErrMissingASN = errors.New("required asn missing") - -// ASNInfo represents ASN information. -type ASNInfo struct { - ASN int `json:"asn"` - Description string `json:"description"` - Country string `json:"country"` - Type string `json:"type"` - DomainCount int `json:"domain_count"` - TopDomains []string `json:"top_domains"` -} - -// IntelligenceASNOverviewParameters represents parameters for an ASN request. -type IntelligenceASNOverviewParameters struct { - AccountID string - ASN int -} - -// IntelligenceASNResponse represents an API response for ASN info. -type IntelligenceASNResponse struct { - Response - Result []ASNInfo `json:"result,omitempty"` -} - -// IntelligenceASNSubnetsParameters represents parameters for an ASN subnet request. -type IntelligenceASNSubnetsParameters struct { - AccountID string - ASN int -} - -// IntelligenceASNSubnetResponse represents an ASN subnet API response. -type IntelligenceASNSubnetResponse struct { - ASN int `json:"asn,omitempty"` - IPCountTotal int `json:"ip_count_total,omitempty"` - Subnets []string `json:"subnets,omitempty"` - Count int `json:"count,omitempty"` - Page int `json:"page,omitempty"` - PerPage int `json:"per_page,omitempty"` -} - -// IntelligenceASNOverview get overview for an ASN number -// -// API Reference: https://api.cloudflare.com/#asn-intelligence-get-asn-overview -func (api *API) IntelligenceASNOverview(ctx context.Context, params IntelligenceASNOverviewParameters) ([]ASNInfo, error) { - if params.AccountID == "" { - return []ASNInfo{}, ErrMissingAccountID - } - - if params.ASN == 0 { - return []ASNInfo{}, ErrMissingASN - } - - uri := fmt.Sprintf("/accounts/%s/intel/asn/%d", params.AccountID, params.ASN) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []ASNInfo{}, err - } - - var asnInfoResponse IntelligenceASNResponse - if err := json.Unmarshal(res, &asnInfoResponse); err != nil { - return []ASNInfo{}, err - } - return asnInfoResponse.Result, nil -} - -// IntelligenceASNSubnets gets all subnets of an ASN -// -// API Reference: https://api.cloudflare.com/#asn-intelligence-get-asn-subnets -func (api *API) IntelligenceASNSubnets(ctx context.Context, params IntelligenceASNSubnetsParameters) (IntelligenceASNSubnetResponse, error) { - if params.AccountID == "" { - return IntelligenceASNSubnetResponse{}, ErrMissingAccountID - } - - if params.ASN == 0 { - return IntelligenceASNSubnetResponse{}, ErrMissingASN - } - - uri := fmt.Sprintf("/accounts/%s/intel/asn/%d/subnets", params.AccountID, params.ASN) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return IntelligenceASNSubnetResponse{}, err - } - - var intelligenceASNSubnetResponse IntelligenceASNSubnetResponse - if err := json.Unmarshal(res, &intelligenceASNSubnetResponse); err != nil { - return IntelligenceASNSubnetResponse{}, err - } - return intelligenceASNSubnetResponse, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/intelligence_domain.go b/vendor/github.com/cloudflare/cloudflare-go/intelligence_domain.go deleted file mode 100644 index abbafba..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/intelligence_domain.go +++ /dev/null @@ -1,176 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -// ErrMissingDomain is for when domain is needed but not given. -var ErrMissingDomain = errors.New("required domain missing") - -// DomainDetails represents details for a domain. -type DomainDetails struct { - Domain string `json:"domain"` - ResolvesToRefs []ResolvesToRefs `json:"resolves_to_refs"` - PopularityRank int `json:"popularity_rank"` - Application Application `json:"application"` - RiskTypes []interface{} `json:"risk_types"` - ContentCategories []ContentCategories `json:"content_categories"` - AdditionalInformation AdditionalInformation `json:"additional_information"` -} - -// ResolvesToRefs what a domain resolves to. -type ResolvesToRefs struct { - ID string `json:"id"` - Value string `json:"value"` -} - -type Application struct { - ID int `json:"id"` - Name string `json:"name"` -} - -// ContentCategories represents the categories for a domain. -type ContentCategories struct { - ID int `json:"id"` - SuperCategoryID int `json:"super_category_id"` - Name string `json:"name"` -} - -// AdditionalInformation represents any additional information for a domain. -type AdditionalInformation struct { - SuspectedMalwareFamily string `json:"suspected_malware_family"` -} - -// DomainHistory represents the history for a domain. -type DomainHistory struct { - Domain string `json:"domain"` - Categorizations []Categorizations `json:"categorizations"` -} - -// Categories represents categories for a domain. -type Categories struct { - ID int `json:"id"` - Name string `json:"name"` -} - -// Categorizations represents the categories and when those categories were set. -type Categorizations struct { - Categories []Categories `json:"categories"` - Start string `json:"start"` - End string `json:"end"` -} - -// GetDomainDetailsParameters represent the parameters for a domain details request. -type GetDomainDetailsParameters struct { - AccountID string `url:"-"` - Domain string `url:"domain,omitempty"` -} - -// DomainDetailsResponse represents an API response for domain details. -type DomainDetailsResponse struct { - Response - Result DomainDetails `json:"result,omitempty"` -} - -// GetBulkDomainDetailsParameters represents the parameters for bulk domain details request. -type GetBulkDomainDetailsParameters struct { - AccountID string `url:"-"` - Domains []string `url:"domain"` -} - -// GetBulkDomainDetailsResponse represents an API response for bulk domain details. -type GetBulkDomainDetailsResponse struct { - Response - Result []DomainDetails `json:"result,omitempty"` -} - -// GetDomainHistoryParameters represents the parameters for domain history request. -type GetDomainHistoryParameters struct { - AccountID string `url:"-"` - Domain string `url:"domain,omitempty"` -} - -// GetDomainHistoryResponse represents an API response for domain history. -type GetDomainHistoryResponse struct { - Response - Result []DomainHistory `json:"result,omitempty"` -} - -// IntelligenceDomainDetails gets domain information. -// -// API Reference: https://api.cloudflare.com/#domain-intelligence-get-domain-details -func (api *API) IntelligenceDomainDetails(ctx context.Context, params GetDomainDetailsParameters) (DomainDetails, error) { - if params.AccountID == "" { - return DomainDetails{}, ErrMissingAccountID - } - - if params.Domain == "" { - return DomainDetails{}, ErrMissingDomain - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/intel/domain", params.AccountID), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return DomainDetails{}, err - } - - var domainDetails DomainDetailsResponse - if err := json.Unmarshal(res, &domainDetails); err != nil { - return DomainDetails{}, err - } - return domainDetails.Result, nil -} - -// IntelligenceBulkDomainDetails gets domain information for a list of domains. -// -// API Reference: https://api.cloudflare.com/#domain-intelligence-get-multiple-domain-details -func (api *API) IntelligenceBulkDomainDetails(ctx context.Context, params GetBulkDomainDetailsParameters) ([]DomainDetails, error) { - if params.AccountID == "" { - return []DomainDetails{}, ErrMissingAccountID - } - - if len(params.Domains) == 0 { - return []DomainDetails{}, ErrMissingDomain - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/intel/domain/bulk", params.AccountID), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DomainDetails{}, err - } - - var domainDetails GetBulkDomainDetailsResponse - if err := json.Unmarshal(res, &domainDetails); err != nil { - return []DomainDetails{}, err - } - return domainDetails.Result, nil -} - -// IntelligenceDomainHistory get domain history for given domain -// -// API Reference: https://api.cloudflare.com/#domain-history-get-domain-history -func (api *API) IntelligenceDomainHistory(ctx context.Context, params GetDomainHistoryParameters) ([]DomainHistory, error) { - if params.AccountID == "" { - return []DomainHistory{}, ErrMissingAccountID - } - - if params.Domain == "" { - return []DomainHistory{}, ErrMissingDomain - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/intel/domain-history", params.AccountID), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []DomainHistory{}, err - } - - var domainDetails GetDomainHistoryResponse - if err := json.Unmarshal(res, &domainDetails); err != nil { - return []DomainHistory{}, err - } - return domainDetails.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/intelligence_ip.go b/vendor/github.com/cloudflare/cloudflare-go/intelligence_ip.go deleted file mode 100644 index 1a8948b..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/intelligence_ip.go +++ /dev/null @@ -1,155 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// IPIntelligence represents IP intelligence information. -type IPIntelligence struct { - IP string `json:"ip"` - BelongsToRef BelongsToRef `json:"belongs_to_ref"` - RiskTypes []RiskTypes `json:"risk_types"` -} - -// BelongsToRef represents information about who owns an IP address. -type BelongsToRef struct { - ID string `json:"id"` - Value int `json:"value"` - Type string `json:"type"` - Country string `json:"country"` - Description string `json:"description"` -} - -// RiskTypes represent risk types for an IP. -type RiskTypes struct { - ID int `json:"id"` - SuperCategoryID int `json:"super_category_id"` - Name string `json:"name"` -} - -// IPPassiveDNS represent DNS response. -type IPPassiveDNS struct { - ReverseRecords []ReverseRecords `json:"reverse_records,omitempty"` - Count int `json:"count,omitempty"` - Page int `json:"page,omitempty"` - PerPage int `json:"per_page,omitempty"` -} - -// ReverseRecords represent records for passive DNS. -type ReverseRecords struct { - FirstSeen string `json:"first_seen,omitempty"` - LastSeen string `json:"last_seen,omitempty"` - Hostname string `json:"hostname,omitempty"` -} - -// IPIntelligenceParameters represents parameters for an IP Intelligence request. -type IPIntelligenceParameters struct { - AccountID string `url:"-"` - IPv4 string `url:"ipv4,omitempty"` - IPv6 string `url:"ipv6,omitempty"` -} - -// IPIntelligenceResponse represents an IP Intelligence API response. -type IPIntelligenceResponse struct { - Response - Result []IPIntelligence `json:"result,omitempty"` -} - -// IPIntelligenceListParameters represents the parameters for an IP list request. -type IPIntelligenceListParameters struct { - AccountID string -} - -// IPIntelligenceItem represents an item in an IP list. -type IPIntelligenceItem struct { - ID int `json:"id,omitempty"` - Name string `json:"name,omitempty"` -} - -// IPIntelligenceListResponse represents the response for an IP list API response. -type IPIntelligenceListResponse struct { - Response - Result []IPIntelligenceItem `json:"result,omitempty"` -} - -// IPIntelligencePassiveDNSParameters represents the parameters for a passive DNS request. -type IPIntelligencePassiveDNSParameters struct { - AccountID string `url:"-"` - IPv4 string `url:"ipv4,omitempty"` - Start string `url:"start,omitempty"` - End string `url:"end,omitempty"` - Page int `url:"page,omitempty"` - PerPage int `url:"per_page,omitempty"` -} - -// IPIntelligencePassiveDNSResponse represents a passive API response. -type IPIntelligencePassiveDNSResponse struct { - Response - Result IPPassiveDNS `json:"result,omitempty"` -} - -// IntelligenceGetIPOverview gets information about ipv4 or ipv6 address. -// -// API Reference: https://api.cloudflare.com/#ip-intelligence-get-ip-overview -func (api *API) IntelligenceGetIPOverview(ctx context.Context, params IPIntelligenceParameters) ([]IPIntelligence, error) { - if params.AccountID == "" { - return []IPIntelligence{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/intel/ip", params.AccountID), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []IPIntelligence{}, err - } - - var ipDetails IPIntelligenceResponse - if err := json.Unmarshal(res, &ipDetails); err != nil { - return []IPIntelligence{}, err - } - return ipDetails.Result, nil -} - -// IntelligenceGetIPList gets intelligence ip-lists. -// -// API Reference: https://api.cloudflare.com/#ip-list-get-ip-lists -func (api *API) IntelligenceGetIPList(ctx context.Context, params IPIntelligenceListParameters) ([]IPIntelligenceItem, error) { - if params.AccountID == "" { - return []IPIntelligenceItem{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/intel/ip-list", params.AccountID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []IPIntelligenceItem{}, err - } - - var ipListItem IPIntelligenceListResponse - if err := json.Unmarshal(res, &ipListItem); err != nil { - return []IPIntelligenceItem{}, err - } - return ipListItem.Result, nil -} - -// IntelligencePassiveDNS gets a history of DNS for an ip. -// -// API Reference: https://api.cloudflare.com/#passive-dns-by-ip-get-passive-dns-by-ip -func (api *API) IntelligencePassiveDNS(ctx context.Context, params IPIntelligencePassiveDNSParameters) (IPPassiveDNS, error) { - if params.AccountID == "" { - return IPPassiveDNS{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/intel/dns", params.AccountID), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return IPPassiveDNS{}, err - } - - var passiveDNS IPIntelligencePassiveDNSResponse - if err := json.Unmarshal(res, &passiveDNS); err != nil { - return IPPassiveDNS{}, err - } - return passiveDNS.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/intelligence_phishing.go b/vendor/github.com/cloudflare/cloudflare-go/intelligence_phishing.go deleted file mode 100644 index 2d649ff..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/intelligence_phishing.go +++ /dev/null @@ -1,51 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// PhishingScan represent information about a phishing scan. -type PhishingScan struct { - URL string `json:"url"` - Phishing bool `json:"phishing"` - Verified bool `json:"verified"` - Score float64 `json:"score"` - Classifier string `json:"classifier"` -} - -// PhishingScanParameters represent parameters for a phishing scan request. -type PhishingScanParameters struct { - AccountID string `url:"-"` - URL string `url:"url,omitempty"` - Skip bool `url:"skip,omitempty"` -} - -// PhishingScanResponse represent an API response for a phishing scan. -type PhishingScanResponse struct { - Response - Result PhishingScan `json:"result,omitempty"` -} - -// IntelligencePhishingScan scans a URL for suspected phishing -// -// API Reference: https://api.cloudflare.com/#phishing-url-scanner-scan-suspicious-url -func (api *API) IntelligencePhishingScan(ctx context.Context, params PhishingScanParameters) (PhishingScan, error) { - if params.AccountID == "" { - return PhishingScan{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/intel-phishing/predict", params.AccountID), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PhishingScan{}, err - } - - var phishingScanResponse PhishingScanResponse - if err := json.Unmarshal(res, &phishingScanResponse); err != nil { - return PhishingScan{}, err - } - return phishingScanResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/intelligence_whois.go b/vendor/github.com/cloudflare/cloudflare-go/intelligence_whois.go deleted file mode 100644 index a3bda99..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/intelligence_whois.go +++ /dev/null @@ -1,59 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// WHOIS represents whois information. -type WHOIS struct { - Domain string `json:"domain,omitempty"` - CreatedDate string `json:"created_date,omitempty"` - UpdatedDate string `json:"updated_date,omitempty"` - Registrant string `json:"registrant,omitempty"` - RegistrantOrg string `json:"registrant_org,omitempty"` - RegistrantCountry string `json:"registrant_country,omitempty"` - RegistrantEmail string `json:"registrant_email,omitempty"` - Registrar string `json:"registrar,omitempty"` - Nameservers []string `json:"nameservers,omitempty"` -} - -// WHOISParameters represents parameters for a who is request. -type WHOISParameters struct { - AccountID string `url:"-"` - Domain string `url:"domain"` -} - -// WHOISResponse represents an API response for a whois request. -type WHOISResponse struct { - Response - Result WHOIS `json:"result,omitempty"` -} - -// IntelligenceWHOIS gets whois information for a domain. -// -// API Reference: https://api.cloudflare.com/#whois-record-get-whois-record -func (api *API) IntelligenceWHOIS(ctx context.Context, params WHOISParameters) (WHOIS, error) { - if params.AccountID == "" { - return WHOIS{}, ErrMissingAccountID - } - - if params.Domain == "" { - return WHOIS{}, ErrMissingDomain - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/intel/whois", params.AccountID), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WHOIS{}, err - } - - var whoisResponse WHOISResponse - if err := json.Unmarshal(res, &whoisResponse); err != nil { - return WHOIS{}, err - } - - return whoisResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/ip_address_management.go b/vendor/github.com/cloudflare/cloudflare-go/ip_address_management.go deleted file mode 100644 index 52b71e9..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/ip_address_management.go +++ /dev/null @@ -1,148 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// IPPrefix contains information about an IP prefix. -type IPPrefix struct { - ID string `json:"id"` - CreatedAt *time.Time `json:"created_at"` - ModifiedAt *time.Time `json:"modified_at"` - CIDR string `json:"cidr"` - AccountID string `json:"account_id"` - Description string `json:"description"` - Approved string `json:"approved"` - OnDemandEnabled bool `json:"on_demand_enabled"` - OnDemandLocked bool `json:"on_demand_locked"` - Advertised bool `json:"advertised"` - AdvertisedModifiedAt *time.Time `json:"advertised_modified_at"` -} - -// AdvertisementStatus contains information about the BGP status of an IP prefix. -type AdvertisementStatus struct { - Advertised bool `json:"advertised"` - AdvertisedModifiedAt *time.Time `json:"advertised_modified_at"` -} - -// ListIPPrefixResponse contains a slice of IP prefixes. -type ListIPPrefixResponse struct { - Response - Result []IPPrefix `json:"result"` -} - -// GetIPPrefixResponse contains a specific IP prefix's API Response. -type GetIPPrefixResponse struct { - Response - Result IPPrefix `json:"result"` -} - -// GetAdvertisementStatusResponse contains an API Response for the BGP status of the IP Prefix. -type GetAdvertisementStatusResponse struct { - Response - Result AdvertisementStatus `json:"result"` -} - -// IPPrefixUpdateRequest contains information about prefix updates. -type IPPrefixUpdateRequest struct { - Description string `json:"description"` -} - -// AdvertisementStatusUpdateRequest contains information about bgp status updates. -type AdvertisementStatusUpdateRequest struct { - Advertised bool `json:"advertised"` -} - -// ListPrefixes lists all IP prefixes for a given account -// -// API reference: https://api.cloudflare.com/#ip-address-management-prefixes-list-prefixes -func (api *API) ListPrefixes(ctx context.Context, accountID string) ([]IPPrefix, error) { - uri := fmt.Sprintf("/accounts/%s/addressing/prefixes", accountID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []IPPrefix{}, err - } - - result := ListIPPrefixResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []IPPrefix{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetPrefix returns a specific IP prefix -// -// API reference: https://api.cloudflare.com/#ip-address-management-prefixes-prefix-details -func (api *API) GetPrefix(ctx context.Context, accountID, ID string) (IPPrefix, error) { - uri := fmt.Sprintf("/accounts/%s/addressing/prefixes/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return IPPrefix{}, err - } - - result := GetIPPrefixResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPPrefix{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// UpdatePrefixDescription edits the description of the IP prefix -// -// API reference: https://api.cloudflare.com/#ip-address-management-prefixes-update-prefix-description -func (api *API) UpdatePrefixDescription(ctx context.Context, accountID, ID string, description string) (IPPrefix, error) { - uri := fmt.Sprintf("/accounts/%s/addressing/prefixes/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, IPPrefixUpdateRequest{Description: description}) - if err != nil { - return IPPrefix{}, err - } - - result := GetIPPrefixResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPPrefix{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetAdvertisementStatus returns the BGP status of the IP prefix -// -// API reference: https://api.cloudflare.com/#ip-address-management-prefixes-update-prefix-description -func (api *API) GetAdvertisementStatus(ctx context.Context, accountID, ID string) (AdvertisementStatus, error) { - uri := fmt.Sprintf("/accounts/%s/addressing/prefixes/%s/bgp/status", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return AdvertisementStatus{}, err - } - - result := GetAdvertisementStatusResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return AdvertisementStatus{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// UpdateAdvertisementStatus changes the BGP status of an IP prefix -// -// API reference: https://api.cloudflare.com/#ip-address-management-prefixes-update-prefix-description -func (api *API) UpdateAdvertisementStatus(ctx context.Context, accountID, ID string, advertised bool) (AdvertisementStatus, error) { - uri := fmt.Sprintf("/accounts/%s/addressing/prefixes/%s/bgp/status", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, AdvertisementStatusUpdateRequest{Advertised: advertised}) - if err != nil { - return AdvertisementStatus{}, err - } - - result := GetAdvertisementStatusResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return AdvertisementStatus{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/ip_list.go b/vendor/github.com/cloudflare/cloudflare-go/ip_list.go deleted file mode 100644 index d2f6a92..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/ip_list.go +++ /dev/null @@ -1,506 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// The definitions in this file are deprecated and should be removed after -// enough time is given for users to migrate. Use the more general `List` -// methods instead. - -const ( - // IPListTypeIP specifies a list containing IP addresses. - IPListTypeIP = "ip" -) - -// IPListBulkOperation contains information about a Bulk Operation. -type IPListBulkOperation struct { - ID string `json:"id"` - Status string `json:"status"` - Error string `json:"error"` - Completed *time.Time `json:"completed"` -} - -// IPList contains information about an IP List. -type IPList struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Kind string `json:"kind"` - NumItems int `json:"num_items"` - NumReferencingFilters int `json:"num_referencing_filters"` - CreatedOn *time.Time `json:"created_on"` - ModifiedOn *time.Time `json:"modified_on"` -} - -// IPListItem contains information about a single IP List Item. -type IPListItem struct { - ID string `json:"id"` - IP string `json:"ip"` - Comment string `json:"comment"` - CreatedOn *time.Time `json:"created_on"` - ModifiedOn *time.Time `json:"modified_on"` -} - -// IPListCreateRequest contains data for a new IP List. -type IPListCreateRequest struct { - Name string `json:"name"` - Description string `json:"description"` - Kind string `json:"kind"` -} - -// IPListItemCreateRequest contains data for a new IP List Item. -type IPListItemCreateRequest struct { - IP string `json:"ip"` - Comment string `json:"comment"` -} - -// IPListItemDeleteRequest wraps IP List Items that shall be deleted. -type IPListItemDeleteRequest struct { - Items []IPListItemDeleteItemRequest `json:"items"` -} - -// IPListItemDeleteItemRequest contains single IP List Items that shall be deleted. -type IPListItemDeleteItemRequest struct { - ID string `json:"id"` -} - -// IPListUpdateRequest contains data for an IP List update. -type IPListUpdateRequest struct { - Description string `json:"description"` -} - -// IPListResponse contains a single IP List. -type IPListResponse struct { - Response - Result IPList `json:"result"` -} - -// IPListItemCreateResponse contains information about the creation of an IP List Item. -type IPListItemCreateResponse struct { - Response - Result struct { - OperationID string `json:"operation_id"` - } `json:"result"` -} - -// IPListListResponse contains a slice of IP Lists. -type IPListListResponse struct { - Response - Result []IPList `json:"result"` -} - -// IPListBulkOperationResponse contains information about a Bulk Operation. -type IPListBulkOperationResponse struct { - Response - Result IPListBulkOperation `json:"result"` -} - -// IPListDeleteResponse contains information about the deletion of an IP List. -type IPListDeleteResponse struct { - Response - Result struct { - ID string `json:"id"` - } `json:"result"` -} - -// IPListItemsListResponse contains information about IP List Items. -type IPListItemsListResponse struct { - Response - ResultInfo `json:"result_info"` - Result []IPListItem `json:"result"` -} - -// IPListItemDeleteResponse contains information about the deletion of an IP List Item. -type IPListItemDeleteResponse struct { - Response - Result struct { - OperationID string `json:"operation_id"` - } `json:"result"` -} - -// IPListItemsGetResponse contains information about a single IP List Item. -type IPListItemsGetResponse struct { - Response - Result IPListItem `json:"result"` -} - -// ListIPLists lists all IP Lists. -// -// API reference: https://api.cloudflare.com/#rules-lists-list-lists -// -// Deprecated: Use `ListLists` instead. -func (api *API) ListIPLists(ctx context.Context, accountID string) ([]IPList, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists", accountID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []IPList{}, err - } - - result := IPListListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// CreateIPList creates a new IP List. -// -// API reference: https://api.cloudflare.com/#rules-lists-create-list -// -// Deprecated: Use `CreateList` instead. -func (api *API) CreateIPList(ctx context.Context, accountID, name, description, kind string) (IPList, - error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists", accountID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, - IPListCreateRequest{Name: name, Description: description, Kind: kind}) - if err != nil { - return IPList{}, err - } - - result := IPListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetIPList returns a single IP List -// -// API reference: https://api.cloudflare.com/#rules-lists-get-list -// -// Deprecated: Use `GetList` instead. -func (api *API) GetIPList(ctx context.Context, accountID, ID string) (IPList, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return IPList{}, err - } - - result := IPListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// UpdateIPList updates the description of an existing IP List. -// -// API reference: https://api.cloudflare.com/#rules-lists-update-list -// -// Deprecated: Use `UpdateList` instead. -func (api *API) UpdateIPList(ctx context.Context, accountID, ID, description string) (IPList, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, IPListUpdateRequest{Description: description}) - if err != nil { - return IPList{}, err - } - - result := IPListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// DeleteIPList deletes an IP List. -// -// API reference: https://api.cloudflare.com/#rules-lists-delete-list -// -// Deprecated: Use `DeleteList` instead. -func (api *API) DeleteIPList(ctx context.Context, accountID, ID string) (IPListDeleteResponse, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return IPListDeleteResponse{}, err - } - - result := IPListDeleteResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPListDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// ListIPListItems returns a list with all items in an IP List. -// -// API reference: https://api.cloudflare.com/#rules-lists-list-list-items -// -// Deprecated: Use `ListListItems` instead. -func (api *API) ListIPListItems(ctx context.Context, accountID, ID string) ([]IPListItem, error) { - var list []IPListItem - var cursor string - var cursorQuery string - - for { - if len(cursor) > 0 { - cursorQuery = fmt.Sprintf("?cursor=%s", cursor) - } - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items%s", accountID, ID, cursorQuery) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []IPListItem{}, err - } - - result := IPListItemsListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []IPListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - list = append(list, result.Result...) - if cursor = result.ResultInfo.Cursors.After; cursor == "" { - break - } - } - - return list, nil -} - -// CreateIPListItemAsync creates a new IP List Item asynchronously. Users have -// to poll the operation status by using the operation_id returned by this -// function. -// -// API reference: https://api.cloudflare.com/#rules-lists-create-list-items -// -// Deprecated: Use `CreateListItemAsync` instead. -func (api *API) CreateIPListItemAsync(ctx context.Context, accountID, ID, ip, comment string) (IPListItemCreateResponse, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, []IPListItemCreateRequest{{IP: ip, Comment: comment}}) - if err != nil { - return IPListItemCreateResponse{}, err - } - - result := IPListItemCreateResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// CreateIPListItem creates a new IP List Item synchronously and returns the -// current set of IP List Items. -// -// Deprecated: Use `CreateListItem` instead. -func (api *API) CreateIPListItem(ctx context.Context, accountID, ID, ip, comment string) ([]IPListItem, error) { - result, err := api.CreateIPListItemAsync(ctx, accountID, ID, ip, comment) - - if err != nil { - return []IPListItem{}, err - } - - err = api.pollIPListBulkOperation(ctx, accountID, result.Result.OperationID) - if err != nil { - return []IPListItem{}, err - } - - return api.ListIPListItems(ctx, accountID, ID) -} - -// CreateIPListItemsAsync bulk creates many IP List Items asynchronously. Users -// have to poll the operation status by using the operation_id returned by this -// function. -// -// API reference: https://api.cloudflare.com/#rules-lists-create-list-items -// -// Deprecated: Use `CreateListItemsAsync` instead. -func (api *API) CreateIPListItemsAsync(ctx context.Context, accountID, ID string, items []IPListItemCreateRequest) ( - IPListItemCreateResponse, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, items) - if err != nil { - return IPListItemCreateResponse{}, err - } - - result := IPListItemCreateResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// CreateIPListItems bulk creates many IP List Items synchronously and returns -// the current set of IP List Items. -// -// Deprecated: Use `CreateListItems` instead. -func (api *API) CreateIPListItems(ctx context.Context, accountID, ID string, items []IPListItemCreateRequest) ( - []IPListItem, error) { - result, err := api.CreateIPListItemsAsync(ctx, accountID, ID, items) - if err != nil { - return []IPListItem{}, err - } - - err = api.pollIPListBulkOperation(ctx, accountID, result.Result.OperationID) - if err != nil { - return []IPListItem{}, err - } - - return api.ListIPListItems(ctx, accountID, ID) -} - -// ReplaceIPListItemsAsync replaces all IP List Items asynchronously. Users have -// to poll the operation status by using the operation_id returned by this -// function. -// -// API reference: https://api.cloudflare.com/#rules-lists-replace-list-items -// -// Deprecated: Use `ReplaceListItemsAsync` instead. -func (api *API) ReplaceIPListItemsAsync(ctx context.Context, accountID, ID string, items []IPListItemCreateRequest) ( - IPListItemCreateResponse, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, items) - if err != nil { - return IPListItemCreateResponse{}, err - } - - result := IPListItemCreateResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// ReplaceIPListItems replaces all IP List Items synchronously and returns the -// current set of IP List Items. -// -// Deprecated: Use `ReplaceListItems` instead. -func (api *API) ReplaceIPListItems(ctx context.Context, accountID, ID string, items []IPListItemCreateRequest) ( - []IPListItem, error) { - result, err := api.ReplaceIPListItemsAsync(ctx, accountID, ID, items) - if err != nil { - return []IPListItem{}, err - } - - err = api.pollIPListBulkOperation(ctx, accountID, result.Result.OperationID) - if err != nil { - return []IPListItem{}, err - } - - return api.ListIPListItems(ctx, accountID, ID) -} - -// DeleteIPListItemsAsync removes specific Items of an IP List by their ID -// asynchronously. Users have to poll the operation status by using the -// operation_id returned by this function. -// -// API reference: https://api.cloudflare.com/#rules-lists-delete-list-items -// -// Deprecated: Use `DeleteListItemsAsync` instead. -func (api *API) DeleteIPListItemsAsync(ctx context.Context, accountID, ID string, items IPListItemDeleteRequest) ( - IPListItemDeleteResponse, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, items) - if err != nil { - return IPListItemDeleteResponse{}, err - } - - result := IPListItemDeleteResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPListItemDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// DeleteIPListItems removes specific Items of an IP List by their ID -// synchronously and returns the current set of IP List Items. -// -// Deprecated: Use `DeleteListItems` instead. -func (api *API) DeleteIPListItems(ctx context.Context, accountID, ID string, items IPListItemDeleteRequest) ( - []IPListItem, error) { - result, err := api.DeleteIPListItemsAsync(ctx, accountID, ID, items) - if err != nil { - return []IPListItem{}, err - } - - err = api.pollIPListBulkOperation(ctx, accountID, result.Result.OperationID) - if err != nil { - return []IPListItem{}, err - } - - return api.ListIPListItems(ctx, accountID, ID) -} - -// GetIPListItem returns a single IP List Item. -// -// API reference: https://api.cloudflare.com/#rules-lists-get-list-item -// -// Deprecated: Use `GetListItem` instead. -func (api *API) GetIPListItem(ctx context.Context, accountID, listID, id string) (IPListItem, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items/%s", accountID, listID, id) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return IPListItem{}, err - } - - result := IPListItemsGetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetIPListBulkOperation returns the status of a bulk operation. -// -// API reference: https://api.cloudflare.com/#rules-lists-get-bulk-operation -// -// Deprecated: Use `GetListBulkOperation` instead. -func (api *API) GetIPListBulkOperation(ctx context.Context, accountID, ID string) (IPListBulkOperation, error) { - uri := fmt.Sprintf("/accounts/%s/rules/lists/bulk_operations/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return IPListBulkOperation{}, err - } - - result := IPListBulkOperationResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return IPListBulkOperation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// pollIPListBulkOperation implements synchronous behaviour for some -// asynchronous endpoints. bulk-operation status can be either pending, running, -// failed or completed. -func (api *API) pollIPListBulkOperation(ctx context.Context, accountID, ID string) error { - for i := uint8(0); i < 16; i++ { - sleepDuration := 1 << (i / 2) * time.Second - select { - case <-time.After(sleepDuration): - case <-ctx.Done(): - return fmt.Errorf("operation aborted during backoff: %w", ctx.Err()) - } - - bulkResult, err := api.GetIPListBulkOperation(ctx, accountID, ID) - if err != nil { - return err - } - - switch bulkResult.Status { - case "failed": - return errors.New(bulkResult.Error) - case "pending", "running": - continue - case "completed": - return nil - default: - return fmt.Errorf("%s: %s", errOperationUnexpectedStatus, bulkResult.Status) - } - } - - return errors.New(errOperationStillRunning) -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/ips.go b/vendor/github.com/cloudflare/cloudflare-go/ips.go deleted file mode 100644 index 85d1c5b..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/ips.go +++ /dev/null @@ -1,67 +0,0 @@ -package cloudflare - -import ( - "encoding/json" - "fmt" - "io" - "net/http" - "strings" -) - -// IPRangesResponse contains the structure for the API response, not modified. -type IPRangesResponse struct { - IPv4CIDRs []string `json:"ipv4_cidrs"` - IPv6CIDRs []string `json:"ipv6_cidrs"` - ChinaColos []string `json:"china_colos"` -} - -// IPRanges contains lists of IPv4 and IPv6 CIDRs. -type IPRanges struct { - IPv4CIDRs []string `json:"ipv4_cidrs"` - IPv6CIDRs []string `json:"ipv6_cidrs"` - ChinaIPv4CIDRs []string `json:"china_ipv4_cidrs"` - ChinaIPv6CIDRs []string `json:"china_ipv6_cidrs"` -} - -// IPsResponse is the API response containing a list of IPs. -type IPsResponse struct { - Response - Result IPRangesResponse `json:"result"` -} - -// IPs gets a list of Cloudflare's IP ranges. -// -// This does not require logging in to the API. -// -// API reference: https://api.cloudflare.com/#cloudflare-ips -func IPs() (IPRanges, error) { - uri := fmt.Sprintf("%s/ips?china_colo=1", apiURL) - resp, err := http.Get(uri) //nolint:gosec - if err != nil { - return IPRanges{}, fmt.Errorf("HTTP request failed: %w", err) - } - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - return IPRanges{}, fmt.Errorf("Response body could not be read: %w", err) - } - var r IPsResponse - err = json.Unmarshal(body, &r) - if err != nil { - return IPRanges{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - var ips IPRanges - ips.IPv4CIDRs = r.Result.IPv4CIDRs - ips.IPv6CIDRs = r.Result.IPv6CIDRs - - for _, ip := range r.Result.ChinaColos { - if strings.Contains(ip, ":") { - ips.ChinaIPv6CIDRs = append(ips.ChinaIPv6CIDRs, ip) - } else { - ips.ChinaIPv4CIDRs = append(ips.ChinaIPv4CIDRs, ip) - } - } - - return ips, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/keyless.go b/vendor/github.com/cloudflare/cloudflare-go/keyless.go deleted file mode 100644 index 2171d4a..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/keyless.go +++ /dev/null @@ -1,145 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// KeylessSSL represents Keyless SSL configuration. -type KeylessSSL struct { - ID string `json:"id"` - Name string `json:"name"` - Host string `json:"host"` - Port int `json:"port"` - Status string `json:"status"` - Enabled bool `json:"enabled"` - Permissions []string `json:"permissions"` - CreatedOn time.Time `json:"created_on"` - ModifiedOn time.Time `json:"modified_on"` -} - -// KeylessSSLCreateRequest represents the request format made for creating KeylessSSL. -type KeylessSSLCreateRequest struct { - Host string `json:"host"` - Port int `json:"port"` - Certificate string `json:"certificate"` - Name string `json:"name,omitempty"` - BundleMethod string `json:"bundle_method,omitempty"` -} - -// KeylessSSLDetailResponse is the API response, containing a single Keyless SSL. -type KeylessSSLDetailResponse struct { - Response - Result KeylessSSL `json:"result"` -} - -// KeylessSSLListResponse represents the response from the Keyless SSL list endpoint. -type KeylessSSLListResponse struct { - Response - Result []KeylessSSL `json:"result"` -} - -// KeylessSSLUpdateRequest represents the request for updating KeylessSSL. -type KeylessSSLUpdateRequest struct { - Host string `json:"host,omitempty"` - Name string `json:"name,omitempty"` - Port int `json:"port,omitempty"` - Enabled *bool `json:"enabled,omitempty"` -} - -// CreateKeylessSSL creates a new Keyless SSL configuration for the zone. -// -// API reference: https://api.cloudflare.com/#keyless-ssl-for-a-zone-create-keyless-ssl-configuration -func (api *API) CreateKeylessSSL(ctx context.Context, zoneID string, keylessSSL KeylessSSLCreateRequest) (KeylessSSL, error) { - uri := fmt.Sprintf("/zones/%s/keyless_certificates", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, keylessSSL) - if err != nil { - return KeylessSSL{}, err - } - - var keylessSSLDetailResponse KeylessSSLDetailResponse - err = json.Unmarshal(res, &keylessSSLDetailResponse) - if err != nil { - return KeylessSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return keylessSSLDetailResponse.Result, nil -} - -// ListKeylessSSL lists Keyless SSL configurations for a zone. -// -// API reference: https://api.cloudflare.com/#keyless-ssl-for-a-zone-list-keyless-ssl-configurations -func (api *API) ListKeylessSSL(ctx context.Context, zoneID string) ([]KeylessSSL, error) { - uri := fmt.Sprintf("/zones/%s/keyless_certificates", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - var keylessSSLListResponse KeylessSSLListResponse - err = json.Unmarshal(res, &keylessSSLListResponse) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return keylessSSLListResponse.Result, nil -} - -// KeylessSSL provides the configuration for a given Keyless SSL identifier. -// -// API reference: https://api.cloudflare.com/#keyless-ssl-for-a-zone-keyless-ssl-details -func (api *API) KeylessSSL(ctx context.Context, zoneID, keylessSSLID string) (KeylessSSL, error) { - uri := fmt.Sprintf("/zones/%s/keyless_certificates/%s", zoneID, keylessSSLID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return KeylessSSL{}, err - } - - var keylessResponse KeylessSSLDetailResponse - err = json.Unmarshal(res, &keylessResponse) - if err != nil { - return KeylessSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return keylessResponse.Result, nil -} - -// UpdateKeylessSSL updates an existing Keyless SSL configuration. -// -// API reference: https://api.cloudflare.com/#keyless-ssl-for-a-zone-edit-keyless-ssl-configuration -func (api *API) UpdateKeylessSSL(ctx context.Context, zoneID, kelessSSLID string, keylessSSL KeylessSSLUpdateRequest) (KeylessSSL, error) { - uri := fmt.Sprintf("/zones/%s/keyless_certificates/%s", zoneID, kelessSSLID) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, keylessSSL) - if err != nil { - return KeylessSSL{}, err - } - - var keylessSSLDetailResponse KeylessSSLDetailResponse - err = json.Unmarshal(res, &keylessSSLDetailResponse) - if err != nil { - return KeylessSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return keylessSSLDetailResponse.Result, nil -} - -// DeleteKeylessSSL deletes an existing Keyless SSL configuration. -// -// API reference: https://api.cloudflare.com/#keyless-ssl-for-a-zone-delete-keyless-ssl-configuration -func (api *API) DeleteKeylessSSL(ctx context.Context, zoneID, keylessSSLID string) error { - uri := fmt.Sprintf("/zones/%s/keyless_certificates/%s", zoneID, keylessSSLID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/list.go b/vendor/github.com/cloudflare/cloudflare-go/list.go deleted file mode 100644 index 75e802f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/list.go +++ /dev/null @@ -1,615 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -const ( - // ListTypeIP specifies a list containing IP addresses. - ListTypeIP = "ip" - // ListTypeRedirect specifies a list containing redirects. - ListTypeRedirect = "redirect" -) - -// ListBulkOperation contains information about a Bulk Operation. -type ListBulkOperation struct { - ID string `json:"id"` - Status string `json:"status"` - Error string `json:"error"` - Completed *time.Time `json:"completed"` -} - -// List contains information about a List. -type List struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Kind string `json:"kind"` - NumItems int `json:"num_items"` - NumReferencingFilters int `json:"num_referencing_filters"` - CreatedOn *time.Time `json:"created_on"` - ModifiedOn *time.Time `json:"modified_on"` -} - -// Redirect represents a redirect item in a List. -type Redirect struct { - SourceUrl string `json:"source_url"` - IncludeSubdomains *bool `json:"include_subdomains,omitempty"` - TargetUrl string `json:"target_url"` - StatusCode *int `json:"status_code,omitempty"` - PreserveQueryString *bool `json:"preserve_query_string,omitempty"` - SubpathMatching *bool `json:"subpath_matching,omitempty"` - PreservePathSuffix *bool `json:"preserve_path_suffix,omitempty"` -} - -// ListItem contains information about a single List Item. -type ListItem struct { - ID string `json:"id"` - IP *string `json:"ip,omitempty"` - Redirect *Redirect `json:"redirect,omitempty"` - Comment string `json:"comment"` - CreatedOn *time.Time `json:"created_on"` - ModifiedOn *time.Time `json:"modified_on"` -} - -// ListCreateRequest contains data for a new List. -type ListCreateRequest struct { - Name string `json:"name"` - Description string `json:"description"` - Kind string `json:"kind"` -} - -// ListItemCreateRequest contains data for a new List Item. -type ListItemCreateRequest struct { - IP *string `json:"ip,omitempty"` - Redirect *Redirect `json:"redirect,omitempty"` - Comment string `json:"comment"` -} - -// ListItemDeleteRequest wraps List Items that shall be deleted. -type ListItemDeleteRequest struct { - Items []ListItemDeleteItemRequest `json:"items"` -} - -// ListItemDeleteItemRequest contains single List Items that shall be deleted. -type ListItemDeleteItemRequest struct { - ID string `json:"id"` -} - -// ListUpdateRequest contains data for a List update. -type ListUpdateRequest struct { - Description string `json:"description"` -} - -// ListResponse contains a single List. -type ListResponse struct { - Response - Result List `json:"result"` -} - -// ListItemCreateResponse contains information about the creation of a List Item. -type ListItemCreateResponse struct { - Response - Result struct { - OperationID string `json:"operation_id"` - } `json:"result"` -} - -// ListListResponse contains a slice of Lists. -type ListListResponse struct { - Response - Result []List `json:"result"` -} - -// ListBulkOperationResponse contains information about a Bulk Operation. -type ListBulkOperationResponse struct { - Response - Result ListBulkOperation `json:"result"` -} - -// ListDeleteResponse contains information about the deletion of a List. -type ListDeleteResponse struct { - Response - Result struct { - ID string `json:"id"` - } `json:"result"` -} - -// ListItemsListResponse contains information about List Items. -type ListItemsListResponse struct { - Response - ResultInfo `json:"result_info"` - Result []ListItem `json:"result"` -} - -// ListItemDeleteResponse contains information about the deletion of a List Item. -type ListItemDeleteResponse struct { - Response - Result struct { - OperationID string `json:"operation_id"` - } `json:"result"` -} - -// ListItemsGetResponse contains information about a single List Item. -type ListItemsGetResponse struct { - Response - Result ListItem `json:"result"` -} - -type ListListsParams struct { -} - -type ListCreateParams struct { - Name string - Description string - Kind string -} - -type ListGetParams struct { - ID string -} - -type ListUpdateParams struct { - ID string - Description string -} - -type ListDeleteParams struct { - ID string -} - -type ListListItemsParams struct { - ID string -} - -type ListCreateItemsParams struct { - ID string - Items []ListItemCreateRequest -} - -type ListCreateItemParams struct { - ID string - Item ListItemCreateRequest -} - -type ListReplaceItemsParams struct { - ID string - Items []ListItemCreateRequest -} - -type ListDeleteItemsParams struct { - ID string - Items ListItemDeleteRequest -} - -type ListGetItemParams struct { - ListID string - ID string -} - -type ListGetBulkOperationParams struct { - ID string -} - -// ListLists lists all Lists. -// -// API reference: https://api.cloudflare.com/#rules-lists-list-lists -func (api *API) ListLists(ctx context.Context, rc *ResourceContainer, params ListListsParams) ([]List, error) { - if rc.Identifier == "" { - return []List{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []List{}, err - } - - result := ListListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// CreateList creates a new List. -// -// API reference: https://api.cloudflare.com/#rules-lists-create-list -func (api *API) CreateList(ctx context.Context, rc *ResourceContainer, params ListCreateParams) (List, error) { - if rc.Identifier == "" { - return List{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, ListCreateRequest{Name: params.Name, Description: params.Description, Kind: params.Kind}) - if err != nil { - return List{}, err - } - - result := ListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetList returns a single List. -// -// API reference: https://api.cloudflare.com/#rules-lists-get-list -func (api *API) GetList(ctx context.Context, rc *ResourceContainer, listID string) (List, error) { - if rc.Identifier == "" { - return List{}, ErrMissingAccountID - } - - if listID == "" { - return List{}, ErrMissingListID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s", rc.Identifier, listID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return List{}, err - } - - result := ListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// UpdateList updates the description of an existing List. -// -// API reference: https://api.cloudflare.com/#rules-lists-update-list -func (api *API) UpdateList(ctx context.Context, rc *ResourceContainer, params ListUpdateParams) (List, error) { - if rc.Identifier == "" { - return List{}, ErrMissingAccountID - } - - if params.ID == "" { - return List{}, ErrMissingListID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, ListUpdateRequest{Description: params.Description}) - if err != nil { - return List{}, err - } - - result := ListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// DeleteList deletes a List. -// -// API reference: https://api.cloudflare.com/#rules-lists-delete-list -func (api *API) DeleteList(ctx context.Context, rc *ResourceContainer, listID string) (ListDeleteResponse, error) { - if rc.Identifier == "" { - return ListDeleteResponse{}, ErrMissingAccountID - } - - if listID == "" { - return ListDeleteResponse{}, ErrMissingListID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s", rc.Identifier, listID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return ListDeleteResponse{}, err - } - - result := ListDeleteResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ListDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// ListListItems returns a list with all items in a List. -// -// API reference: https://api.cloudflare.com/#rules-lists-list-list-items -func (api *API) ListListItems(ctx context.Context, rc *ResourceContainer, params ListListItemsParams) ([]ListItem, error) { - var list []ListItem - var cursor string - var cursorQuery string - - for { - if len(cursor) > 0 { - cursorQuery = fmt.Sprintf("?cursor=%s", cursor) - } - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items%s", rc.Identifier, params.ID, cursorQuery) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []ListItem{}, err - } - - result := ListItemsListResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []ListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - list = append(list, result.Result...) - if cursor = result.ResultInfo.Cursors.After; cursor == "" { - break - } - } - - return list, nil -} - -// CreateListItemAsync creates a new List Item asynchronously. Users have to poll the operation status by -// using the operation_id returned by this function. -// -// API reference: https://api.cloudflare.com/#rules-lists-create-list-items -func (api *API) CreateListItemAsync(ctx context.Context, rc *ResourceContainer, params ListCreateItemParams) (ListItemCreateResponse, error) { - if rc.Identifier == "" { - return ListItemCreateResponse{}, ErrMissingAccountID - } - - if params.ID == "" { - return ListItemCreateResponse{}, ErrMissingListID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, []ListItemCreateRequest{params.Item}) - if err != nil { - return ListItemCreateResponse{}, err - } - - result := ListItemCreateResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// CreateListItem creates a new List Item synchronously and returns the current set of List Items. -func (api *API) CreateListItem(ctx context.Context, rc *ResourceContainer, params ListCreateItemParams) ([]ListItem, error) { - result, err := api.CreateListItemAsync(ctx, rc, params) - - if err != nil { - return []ListItem{}, err - } - - err = api.pollListBulkOperation(ctx, rc, result.Result.OperationID) - if err != nil { - return []ListItem{}, err - } - - return api.ListListItems(ctx, rc, ListListItemsParams{ID: params.ID}) -} - -// CreateListItemsAsync bulk creates multiple List Items asynchronously. Users -// have to poll the operation status by using the operation_id returned by this -// function. -// -// API reference: https://api.cloudflare.com/#rules-lists-create-list-items -func (api *API) CreateListItemsAsync(ctx context.Context, rc *ResourceContainer, params ListCreateItemsParams) (ListItemCreateResponse, error) { - if rc.Identifier == "" { - return ListItemCreateResponse{}, ErrMissingAccountID - } - - if params.ID == "" { - return ListItemCreateResponse{}, ErrMissingListID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params.Items) - if err != nil { - return ListItemCreateResponse{}, err - } - - result := ListItemCreateResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// CreateListItems bulk creates multiple List Items synchronously and returns -// the current set of List Items. -func (api *API) CreateListItems(ctx context.Context, rc *ResourceContainer, params ListCreateItemsParams) ([]ListItem, error) { - result, err := api.CreateListItemsAsync(ctx, rc, params) - if err != nil { - return []ListItem{}, err - } - - err = api.pollListBulkOperation(ctx, rc, result.Result.OperationID) - if err != nil { - return []ListItem{}, err - } - - return api.ListListItems(ctx, rc, ListListItemsParams{ID: params.ID}) -} - -// ReplaceListItemsAsync replaces all List Items asynchronously. Users have to -// poll the operation status by using the operation_id returned by this -// function. -// -// API reference: https://api.cloudflare.com/#rules-lists-replace-list-items -func (api *API) ReplaceListItemsAsync(ctx context.Context, rc *ResourceContainer, params ListReplaceItemsParams) (ListItemCreateResponse, error) { - if rc.Identifier == "" { - return ListItemCreateResponse{}, ErrMissingAccountID - } - - if params.ID == "" { - return ListItemCreateResponse{}, ErrMissingListID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.Items) - if err != nil { - return ListItemCreateResponse{}, err - } - - result := ListItemCreateResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// ReplaceListItems replaces all List Items synchronously and returns the -// current set of List Items. -func (api *API) ReplaceListItems(ctx context.Context, rc *ResourceContainer, params ListReplaceItemsParams) ( - []ListItem, error) { - result, err := api.ReplaceListItemsAsync(ctx, rc, params) - if err != nil { - return []ListItem{}, err - } - - err = api.pollListBulkOperation(ctx, rc, result.Result.OperationID) - if err != nil { - return []ListItem{}, err - } - - return api.ListListItems(ctx, rc, ListListItemsParams{ID: params.ID}) -} - -// DeleteListItemsAsync removes specific Items of a List by their ID -// asynchronously. Users have to poll the operation status by using the -// operation_id returned by this function. -// -// API reference: https://api.cloudflare.com/#rules-lists-delete-list-items -func (api *API) DeleteListItemsAsync(ctx context.Context, rc *ResourceContainer, params ListDeleteItemsParams) (ListItemDeleteResponse, error) { - if rc.Identifier == "" { - return ListItemDeleteResponse{}, ErrMissingAccountID - } - - if params.ID == "" { - return ListItemDeleteResponse{}, ErrMissingListID - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, params.Items) - if err != nil { - return ListItemDeleteResponse{}, err - } - - result := ListItemDeleteResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ListItemDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, nil -} - -// DeleteListItems removes specific Items of a List by their ID synchronously -// and returns the current set of List Items. -func (api *API) DeleteListItems(ctx context.Context, rc *ResourceContainer, params ListDeleteItemsParams) ([]ListItem, error) { - result, err := api.DeleteListItemsAsync(ctx, rc, params) - if err != nil { - return []ListItem{}, err - } - - err = api.pollListBulkOperation(ctx, rc, result.Result.OperationID) - if err != nil { - return []ListItem{}, err - } - - return api.ListListItems(ctx, AccountIdentifier(rc.Identifier), ListListItemsParams{ID: params.ID}) -} - -// GetListItem returns a single List Item. -// -// API reference: https://api.cloudflare.com/#rules-lists-get-list-item -func (api *API) GetListItem(ctx context.Context, rc *ResourceContainer, listID, itemID string) (ListItem, error) { - if rc.Identifier == "" { - return ListItem{}, ErrMissingAccountID - } - - if listID == "" { - return ListItem{}, ErrMissingListID - } - - if itemID == "" { - return ListItem{}, ErrMissingResourceIdentifier - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/%s/items/%s", rc.Identifier, listID, itemID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ListItem{}, err - } - - result := ListItemsGetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetListBulkOperation returns the status of a bulk operation. -// -// API reference: https://api.cloudflare.com/#rules-lists-get-bulk-operation -func (api *API) GetListBulkOperation(ctx context.Context, rc *ResourceContainer, ID string) (ListBulkOperation, error) { - if rc.Identifier == "" { - return ListBulkOperation{}, ErrMissingAccountID - } - - if ID == "" { - return ListBulkOperation{}, ErrMissingResourceIdentifier - } - - uri := fmt.Sprintf("/accounts/%s/rules/lists/bulk_operations/%s", rc.Identifier, ID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ListBulkOperation{}, err - } - - result := ListBulkOperationResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ListBulkOperation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// pollListBulkOperation implements synchronous behaviour for some asynchronous -// endpoints. bulk-operation status can be either pending, running, failed or -// completed. -func (api *API) pollListBulkOperation(ctx context.Context, rc *ResourceContainer, ID string) error { - for i := uint8(0); i < 16; i++ { - sleepDuration := 1 << (i / 2) * time.Second - select { - case <-time.After(sleepDuration): - case <-ctx.Done(): - return fmt.Errorf("operation aborted during backoff: %w", ctx.Err()) - } - - bulkResult, err := api.GetListBulkOperation(ctx, rc, ID) - if err != nil { - return err - } - - switch bulkResult.Status { - case "failed": - return errors.New(bulkResult.Error) - case "pending", "running": - continue - case "completed": - return nil - default: - return fmt.Errorf("%s: %s", errOperationUnexpectedStatus, bulkResult.Status) - } - } - - return errors.New(errOperationStillRunning) -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go b/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go deleted file mode 100644 index 5b01ff5..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go +++ /dev/null @@ -1,772 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// LoadBalancerPool represents a load balancer pool's properties. -type LoadBalancerPool struct { - ID string `json:"id,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - Description string `json:"description"` - Name string `json:"name"` - Enabled bool `json:"enabled"` - MinimumOrigins int `json:"minimum_origins,omitempty"` - Monitor string `json:"monitor,omitempty"` - Origins []LoadBalancerOrigin `json:"origins"` - NotificationEmail string `json:"notification_email,omitempty"` - Latitude *float32 `json:"latitude,omitempty"` - Longitude *float32 `json:"longitude,omitempty"` - LoadShedding *LoadBalancerLoadShedding `json:"load_shedding,omitempty"` - OriginSteering *LoadBalancerOriginSteering `json:"origin_steering,omitempty"` - - // CheckRegions defines the geographic region(s) from where to run health-checks from - e.g. "WNAM", "WEU", "SAF", "SAM". - // Providing a null/empty value means "all regions", which may not be available to all plan types. - CheckRegions []string `json:"check_regions"` -} - -// LoadBalancerOrigin represents a Load Balancer origin's properties. -type LoadBalancerOrigin struct { - Name string `json:"name"` - Address string `json:"address"` - Enabled bool `json:"enabled"` - Weight float64 `json:"weight"` - Header map[string][]string `json:"header"` -} - -// LoadBalancerOriginSteering controls origin selection for new sessions and traffic without session affinity. -type LoadBalancerOriginSteering struct { - // Policy defaults to "random" (weighted) when empty or unspecified. - Policy string `json:"policy,omitempty"` -} - -// LoadBalancerMonitor represents a load balancer monitor's properties. -type LoadBalancerMonitor struct { - ID string `json:"id,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - Type string `json:"type"` - Description string `json:"description"` - Method string `json:"method"` - Path string `json:"path"` - Header map[string][]string `json:"header"` - Timeout int `json:"timeout"` - Retries int `json:"retries"` - Interval int `json:"interval"` - Port uint16 `json:"port,omitempty"` - ExpectedBody string `json:"expected_body"` - ExpectedCodes string `json:"expected_codes"` - FollowRedirects bool `json:"follow_redirects"` - AllowInsecure bool `json:"allow_insecure"` - ProbeZone string `json:"probe_zone"` -} - -// LoadBalancer represents a load balancer's properties. -type LoadBalancer struct { - ID string `json:"id,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - Description string `json:"description"` - Name string `json:"name"` - TTL int `json:"ttl,omitempty"` - FallbackPool string `json:"fallback_pool"` - DefaultPools []string `json:"default_pools"` - RegionPools map[string][]string `json:"region_pools"` - PopPools map[string][]string `json:"pop_pools"` - CountryPools map[string][]string `json:"country_pools"` - Proxied bool `json:"proxied"` - Enabled *bool `json:"enabled,omitempty"` - Persistence string `json:"session_affinity,omitempty"` - PersistenceTTL int `json:"session_affinity_ttl,omitempty"` - SessionAffinityAttributes *SessionAffinityAttributes `json:"session_affinity_attributes,omitempty"` - Rules []*LoadBalancerRule `json:"rules,omitempty"` - RandomSteering *RandomSteering `json:"random_steering,omitempty"` - AdaptiveRouting *AdaptiveRouting `json:"adaptive_routing,omitempty"` - LocationStrategy *LocationStrategy `json:"location_strategy,omitempty"` - - // SteeringPolicy controls pool selection logic. - // - // "off": Select pools in DefaultPools order. - // - // "geo": Select pools based on RegionPools/PopPools/CountryPools. - // For non-proxied requests, the country for CountryPools is determined by LocationStrategy. - // - // "dynamic_latency": Select pools based on RTT (requires health checks). - // - // "random": Selects pools in a random order. - // - // "proximity": Use the pools' latitude and longitude to select the closest pool using - // the Cloudflare PoP location for proxied requests or the location determined by - // LocationStrategy for non-proxied requests. - // - // "": Maps to "geo" if RegionPools or PopPools or CountryPools have entries otherwise "off". - SteeringPolicy string `json:"steering_policy,omitempty"` -} - -// LoadBalancerLoadShedding contains the settings for controlling load shedding. -type LoadBalancerLoadShedding struct { - DefaultPercent float32 `json:"default_percent,omitempty"` - DefaultPolicy string `json:"default_policy,omitempty"` - SessionPercent float32 `json:"session_percent,omitempty"` - SessionPolicy string `json:"session_policy,omitempty"` -} - -// LoadBalancerRule represents a single rule entry for a Load Balancer. Each rules -// is run one after the other in priority order. Disabled rules are skipped. -type LoadBalancerRule struct { - Overrides LoadBalancerRuleOverrides `json:"overrides"` - - // Name is required but is only used for human readability - Name string `json:"name"` - - Condition string `json:"condition"` - - // Priority controls the order of rule execution the lowest value will be invoked first - Priority int `json:"priority"` - - // FixedResponse if set and the condition is true we will not run - // routing logic but rather directly respond with the provided fields. - // FixedResponse implies terminates. - FixedResponse *LoadBalancerFixedResponseData `json:"fixed_response,omitempty"` - - Disabled bool `json:"disabled"` - - // Terminates flag this rule as 'terminating'. No further rules will - // be executed after this one. - Terminates bool `json:"terminates,omitempty"` -} - -// LoadBalancerFixedResponseData contains all the data needed to generate -// a fixed response from a Load Balancer. This behavior can be enabled via Rules. -type LoadBalancerFixedResponseData struct { - // MessageBody data to write into the http body - MessageBody string `json:"message_body,omitempty"` - // StatusCode the http status code to response with - StatusCode int `json:"status_code,omitempty"` - // ContentType value of the http 'content-type' header - ContentType string `json:"content_type,omitempty"` - // Location value of the http 'location' header - Location string `json:"location,omitempty"` -} - -// LoadBalancerRuleOverrides are the set of field overridable by the rules system. -type LoadBalancerRuleOverrides struct { - // session affinity - Persistence string `json:"session_affinity,omitempty"` - PersistenceTTL *uint `json:"session_affinity_ttl,omitempty"` - - SessionAffinityAttrs *LoadBalancerRuleOverridesSessionAffinityAttrs `json:"session_affinity_attributes,omitempty"` - - TTL uint `json:"ttl,omitempty"` - - SteeringPolicy string `json:"steering_policy,omitempty"` - FallbackPool string `json:"fallback_pool,omitempty"` - - DefaultPools []string `json:"default_pools,omitempty"` - PoPPools map[string][]string `json:"pop_pools,omitempty"` - RegionPools map[string][]string `json:"region_pools,omitempty"` - CountryPools map[string][]string `json:"country_pools,omitempty"` - - RandomSteering *RandomSteering `json:"random_steering,omitempty"` - AdaptiveRouting *AdaptiveRouting `json:"adaptive_routing,omitempty"` - LocationStrategy *LocationStrategy `json:"location_strategy,omitempty"` -} - -// RandomSteering represents fields used to set pool weights on a load balancer -// with "random" steering policy. -type RandomSteering struct { - DefaultWeight float64 `json:"default_weight,omitempty"` - PoolWeights map[string]float64 `json:"pool_weights,omitempty"` -} - -// AdaptiveRouting controls features that modify the routing of requests -// to pools and origins in response to dynamic conditions, such as during -// the interval between active health monitoring requests. -// For example, zero-downtime failover occurs immediately when an origin -// becomes unavailable due to HTTP 521, 522, or 523 response codes. -// If there is another healthy origin in the same pool, the request is -// retried once against this alternate origin. -type AdaptiveRouting struct { - // FailoverAcrossPools extends zero-downtime failover of requests to healthy origins - // from alternate pools, when no healthy alternate exists in the same pool, according - // to the failover order defined by traffic and origin steering. - // When set false (the default) zero-downtime failover will only occur between origins - // within the same pool. See SessionAffinityAttributes for control over when sessions - // are broken or reassigned. - FailoverAcrossPools *bool `json:"failover_across_pools,omitempty"` -} - -// LocationStrategy controls location-based steering for non-proxied requests. -// See SteeringPolicy to learn how steering is affected. -type LocationStrategy struct { - // PreferECS determines whether the EDNS Client Subnet (ECS) GeoIP should - // be preferred as the authoritative location. - // - // "always": Always prefer ECS. - // - // "never": Never prefer ECS. - // - // "proximity": (default) Prefer ECS only when SteeringPolicy="proximity". - // - // "geo": Prefer ECS only when SteeringPolicy="geo". - PreferECS string `json:"prefer_ecs,omitempty"` - // Mode determines the authoritative location when ECS is not preferred, - // does not exist in the request, or its GeoIP lookup is unsuccessful. - // - // "pop": (default) Use the Cloudflare PoP location. - // - // "resolver_ip": Use the DNS resolver GeoIP location. - // If the GeoIP lookup is unsuccessful, use the Cloudflare PoP location. - Mode string `json:"mode,omitempty"` -} - -// LoadBalancerRuleOverridesSessionAffinityAttrs mimics SessionAffinityAttributes without the -// DrainDuration field as that field can not be overwritten via rules. -type LoadBalancerRuleOverridesSessionAffinityAttrs struct { - SameSite string `json:"samesite,omitempty"` - Secure string `json:"secure,omitempty"` - ZeroDowntimeFailover string `json:"zero_downtime_failover,omitempty"` -} - -// SessionAffinityAttributes represents the fields used to set attributes in a load balancer session affinity cookie. -type SessionAffinityAttributes struct { - SameSite string `json:"samesite,omitempty"` - Secure string `json:"secure,omitempty"` - DrainDuration int `json:"drain_duration,omitempty"` - ZeroDowntimeFailover string `json:"zero_downtime_failover,omitempty"` -} - -// LoadBalancerOriginHealth represents the health of the origin. -type LoadBalancerOriginHealth struct { - Healthy bool `json:"healthy,omitempty"` - RTT Duration `json:"rtt,omitempty"` - FailureReason string `json:"failure_reason,omitempty"` - ResponseCode int `json:"response_code,omitempty"` -} - -// LoadBalancerPoolPopHealth represents the health of the pool for given PoP. -type LoadBalancerPoolPopHealth struct { - Healthy bool `json:"healthy,omitempty"` - Origins []map[string]LoadBalancerOriginHealth `json:"origins,omitempty"` -} - -// LoadBalancerPoolHealth represents the healthchecks from different PoPs for a pool. -type LoadBalancerPoolHealth struct { - ID string `json:"pool_id,omitempty"` - PopHealth map[string]LoadBalancerPoolPopHealth `json:"pop_health,omitempty"` -} - -// loadBalancerPoolResponse represents the response from the load balancer pool endpoints. -type loadBalancerPoolResponse struct { - Response - Result LoadBalancerPool `json:"result"` -} - -// loadBalancerPoolListResponse represents the response from the List Pools endpoint. -type loadBalancerPoolListResponse struct { - Response - Result []LoadBalancerPool `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// loadBalancerMonitorResponse represents the response from the load balancer monitor endpoints. -type loadBalancerMonitorResponse struct { - Response - Result LoadBalancerMonitor `json:"result"` -} - -// loadBalancerMonitorListResponse represents the response from the List Monitors endpoint. -type loadBalancerMonitorListResponse struct { - Response - Result []LoadBalancerMonitor `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// loadBalancerResponse represents the response from the load balancer endpoints. -type loadBalancerResponse struct { - Response - Result LoadBalancer `json:"result"` -} - -// loadBalancerListResponse represents the response from the List Load Balancers endpoint. -type loadBalancerListResponse struct { - Response - Result []LoadBalancer `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// loadBalancerPoolHealthResponse represents the response from the Pool Health Details endpoint. -type loadBalancerPoolHealthResponse struct { - Response - Result LoadBalancerPoolHealth `json:"result"` -} - -type CreateLoadBalancerPoolParams struct { - LoadBalancerPool LoadBalancerPool -} - -type ListLoadBalancerPoolParams struct { - PaginationOptions -} - -type UpdateLoadBalancerPoolParams struct { - LoadBalancer LoadBalancerPool -} - -type CreateLoadBalancerMonitorParams struct { - LoadBalancerMonitor LoadBalancerMonitor -} - -type ListLoadBalancerMonitorParams struct { - PaginationOptions -} - -type UpdateLoadBalancerMonitorParams struct { - LoadBalancerMonitor LoadBalancerMonitor -} - -type CreateLoadBalancerParams struct { - LoadBalancer LoadBalancer -} - -type ListLoadBalancerParams struct { - PaginationOptions -} - -type UpdateLoadBalancerParams struct { - LoadBalancer LoadBalancer -} - -var ( - ErrMissingPoolID = errors.New("missing required pool ID") - ErrMissingMonitorID = errors.New("missing required monitor ID") - ErrMissingLoadBalancerID = errors.New("missing required load balancer ID") -) - -// CreateLoadBalancerPool creates a new load balancer pool. -// -// API reference: https://api.cloudflare.com/#load-balancer-pools-create-pool -func (api *API) CreateLoadBalancerPool(ctx context.Context, rc *ResourceContainer, params CreateLoadBalancerPoolParams) (LoadBalancerPool, error) { - if rc.Level == ZoneRouteLevel { - return LoadBalancerPool{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - var uri string - if rc.Level == UserRouteLevel { - uri = "/user/load_balancers/pools" - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/pools", rc.Identifier) - } - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params.LoadBalancerPool) - if err != nil { - return LoadBalancerPool{}, err - } - var r loadBalancerPoolResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPool{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListLoadBalancerPools lists load balancer pools connected to an account. -// -// API reference: https://api.cloudflare.com/#load-balancer-pools-list-pools -func (api *API) ListLoadBalancerPools(ctx context.Context, rc *ResourceContainer, params ListLoadBalancerPoolParams) ([]LoadBalancerPool, error) { - if rc.Level == ZoneRouteLevel { - return []LoadBalancerPool{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - var uri string - if rc.Level == UserRouteLevel { - uri = "/user/load_balancers/pools" - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/pools", rc.Identifier) - } - - uri = buildURI(uri, params.PaginationOptions) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r loadBalancerPoolListResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetLoadBalancerPool returns the details for a load balancer pool. -// -// API reference: https://api.cloudflare.com/#load-balancer-pools-pool-details -func (api *API) GetLoadBalancerPool(ctx context.Context, rc *ResourceContainer, poolID string) (LoadBalancerPool, error) { - if rc.Level == ZoneRouteLevel { - return LoadBalancerPool{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if poolID == "" { - return LoadBalancerPool{}, ErrMissingPoolID - } - - var uri string - if rc.Level == UserRouteLevel { - uri = fmt.Sprintf("/user/load_balancers/pools/%s", poolID) - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/pools/%s", rc.Identifier, poolID) - } - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return LoadBalancerPool{}, err - } - var r loadBalancerPoolResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPool{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteLoadBalancerPool disables and deletes a load balancer pool. -// -// API reference: https://api.cloudflare.com/#load-balancer-pools-delete-pool -func (api *API) DeleteLoadBalancerPool(ctx context.Context, rc *ResourceContainer, poolID string) error { - if rc.Level == ZoneRouteLevel { - return fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if poolID == "" { - return ErrMissingPoolID - } - - var uri string - if rc.Level == UserRouteLevel { - uri = fmt.Sprintf("/user/load_balancers/pools/%s", poolID) - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/pools/%s", rc.Identifier, poolID) - } - - if _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil); err != nil { - return err - } - - return nil -} - -// UpdateLoadBalancerPool modifies a configured load balancer pool. -// -// API reference: https://api.cloudflare.com/#load-balancer-pools-update-pool -func (api *API) UpdateLoadBalancerPool(ctx context.Context, rc *ResourceContainer, params UpdateLoadBalancerPoolParams) (LoadBalancerPool, error) { - if rc.Level == ZoneRouteLevel { - return LoadBalancerPool{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if params.LoadBalancer.ID == "" { - return LoadBalancerPool{}, ErrMissingPoolID - } - - var uri string - if rc.Level == UserRouteLevel { - uri = fmt.Sprintf("/user/load_balancers/pools/%s", params.LoadBalancer.ID) - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/pools/%s", rc.Identifier, params.LoadBalancer.ID) - } - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.LoadBalancer) - if err != nil { - return LoadBalancerPool{}, err - } - var r loadBalancerPoolResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPool{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateLoadBalancerMonitor creates a new load balancer monitor. -// -// API reference: https://api.cloudflare.com/#load-balancer-monitors-create-monitor -func (api *API) CreateLoadBalancerMonitor(ctx context.Context, rc *ResourceContainer, params CreateLoadBalancerMonitorParams) (LoadBalancerMonitor, error) { - if rc.Level == ZoneRouteLevel { - return LoadBalancerMonitor{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - var uri string - if rc.Level == UserRouteLevel { - uri = "/user/load_balancers/monitors" - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/monitors", rc.Identifier) - } - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params.LoadBalancerMonitor) - if err != nil { - return LoadBalancerMonitor{}, err - } - var r loadBalancerMonitorResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerMonitor{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListLoadBalancerMonitors lists load balancer monitors connected to an account. -// -// API reference: https://api.cloudflare.com/#load-balancer-monitors-list-monitors -func (api *API) ListLoadBalancerMonitors(ctx context.Context, rc *ResourceContainer, params ListLoadBalancerMonitorParams) ([]LoadBalancerMonitor, error) { - if rc.Level == ZoneRouteLevel { - return []LoadBalancerMonitor{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - var uri string - if rc.Level == UserRouteLevel { - uri = "/user/load_balancers/monitors" - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/monitors", rc.Identifier) - } - - uri = buildURI(uri, params.PaginationOptions) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r loadBalancerMonitorListResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetLoadBalancerMonitor returns the details for a load balancer monitor. -// -// API reference: https://api.cloudflare.com/#load-balancer-monitors-monitor-details -func (api *API) GetLoadBalancerMonitor(ctx context.Context, rc *ResourceContainer, monitorID string) (LoadBalancerMonitor, error) { - if rc.Level == ZoneRouteLevel { - return LoadBalancerMonitor{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if monitorID == "" { - return LoadBalancerMonitor{}, ErrMissingMonitorID - } - - var uri string - if rc.Level == UserRouteLevel { - uri = fmt.Sprintf("/user/load_balancers/monitors/%s", monitorID) - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/monitors/%s", rc.Identifier, monitorID) - } - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return LoadBalancerMonitor{}, err - } - var r loadBalancerMonitorResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerMonitor{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteLoadBalancerMonitor disables and deletes a load balancer monitor. -// -// API reference: https://api.cloudflare.com/#load-balancer-monitors-delete-monitor -func (api *API) DeleteLoadBalancerMonitor(ctx context.Context, rc *ResourceContainer, monitorID string) error { - if rc.Level == ZoneRouteLevel { - return fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if monitorID == "" { - return ErrMissingMonitorID - } - - var uri string - if rc.Level == UserRouteLevel { - uri = fmt.Sprintf("/user/load_balancers/monitors/%s", monitorID) - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/monitors/%s", rc.Identifier, monitorID) - } - - if _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil); err != nil { - return err - } - return nil -} - -// UpdateLoadBalancerMonitor modifies a configured load balancer monitor. -// -// API reference: https://api.cloudflare.com/#load-balancer-monitors-update-monitor -func (api *API) UpdateLoadBalancerMonitor(ctx context.Context, rc *ResourceContainer, params UpdateLoadBalancerMonitorParams) (LoadBalancerMonitor, error) { - if rc.Level == ZoneRouteLevel { - return LoadBalancerMonitor{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if params.LoadBalancerMonitor.ID == "" { - return LoadBalancerMonitor{}, ErrMissingMonitorID - } - - var uri string - if rc.Level == UserRouteLevel { - uri = fmt.Sprintf("/user/load_balancers/monitors/%s", params.LoadBalancerMonitor.ID) - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/monitors/%s", rc.Identifier, params.LoadBalancerMonitor.ID) - } - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.LoadBalancerMonitor) - if err != nil { - return LoadBalancerMonitor{}, err - } - var r loadBalancerMonitorResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerMonitor{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateLoadBalancer creates a new load balancer. -// -// API reference: https://api.cloudflare.com/#load-balancers-create-load-balancer -func (api *API) CreateLoadBalancer(ctx context.Context, rc *ResourceContainer, params CreateLoadBalancerParams) (LoadBalancer, error) { - if rc.Level != ZoneRouteLevel { - return LoadBalancer{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - uri := fmt.Sprintf("/zones/%s/load_balancers", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params.LoadBalancer) - if err != nil { - return LoadBalancer{}, err - } - var r loadBalancerResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListLoadBalancers lists load balancers configured on a zone. -// -// API reference: https://api.cloudflare.com/#load-balancers-list-load-balancers -func (api *API) ListLoadBalancers(ctx context.Context, rc *ResourceContainer, params ListLoadBalancerParams) ([]LoadBalancer, error) { - if rc.Level != ZoneRouteLevel { - return []LoadBalancer{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - uri := buildURI(fmt.Sprintf("/zones/%s/load_balancers", rc.Identifier), params.PaginationOptions) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r loadBalancerListResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetLoadBalancer returns the details for a load balancer. -// -// API reference: https://api.cloudflare.com/#load-balancers-load-balancer-details -func (api *API) GetLoadBalancer(ctx context.Context, rc *ResourceContainer, loadbalancerID string) (LoadBalancer, error) { - if rc.Level != ZoneRouteLevel { - return LoadBalancer{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if loadbalancerID == "" { - return LoadBalancer{}, ErrMissingLoadBalancerID - } - - uri := fmt.Sprintf("/zones/%s/load_balancers/%s", rc.Identifier, loadbalancerID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return LoadBalancer{}, err - } - var r loadBalancerResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteLoadBalancer disables and deletes a load balancer. -// -// API reference: https://api.cloudflare.com/#load-balancers-delete-load-balancer -func (api *API) DeleteLoadBalancer(ctx context.Context, rc *ResourceContainer, loadbalancerID string) error { - if rc.Level != ZoneRouteLevel { - return fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if loadbalancerID == "" { - return ErrMissingLoadBalancerID - } - - uri := fmt.Sprintf("/zones/%s/load_balancers/%s", rc.Identifier, loadbalancerID) - - if _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil); err != nil { - return err - } - return nil -} - -// UpdateLoadBalancer modifies a configured load balancer. -// -// API reference: https://api.cloudflare.com/#load-balancers-update-load-balancer -func (api *API) UpdateLoadBalancer(ctx context.Context, rc *ResourceContainer, params UpdateLoadBalancerParams) (LoadBalancer, error) { - if rc.Level != ZoneRouteLevel { - return LoadBalancer{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if params.LoadBalancer.ID == "" { - return LoadBalancer{}, ErrMissingLoadBalancerID - } - - uri := fmt.Sprintf("/zones/%s/load_balancers/%s", rc.Identifier, params.LoadBalancer.ID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.LoadBalancer) - if err != nil { - return LoadBalancer{}, err - } - var r loadBalancerResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetLoadBalancerPoolHealth fetches the latest healtcheck details for a single -// pool. -// -// API reference: https://api.cloudflare.com/#load-balancer-pools-pool-health-details -func (api *API) GetLoadBalancerPoolHealth(ctx context.Context, rc *ResourceContainer, poolID string) (LoadBalancerPoolHealth, error) { - if rc.Level == ZoneRouteLevel { - return LoadBalancerPoolHealth{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if poolID == "" { - return LoadBalancerPoolHealth{}, ErrMissingPoolID - } - - var uri string - if rc.Level == UserRouteLevel { - uri = fmt.Sprintf("/user/load_balancers/pools/%s/health", poolID) - } else { - uri = fmt.Sprintf("/accounts/%s/load_balancers/pools/%s/health", rc.Identifier, poolID) - } - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return LoadBalancerPoolHealth{}, err - } - var r loadBalancerPoolHealthResponse - if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPoolHealth{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/lockdown.go b/vendor/github.com/cloudflare/cloudflare-go/lockdown.go deleted file mode 100644 index a946e5a..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/lockdown.go +++ /dev/null @@ -1,191 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// ZoneLockdown represents a Zone Lockdown rule. A rule only permits access to -// the provided URL pattern(s) from the given IP address(es) or subnet(s). -type ZoneLockdown struct { - ID string `json:"id"` - Description string `json:"description"` - URLs []string `json:"urls"` - Configurations []ZoneLockdownConfig `json:"configurations"` - Paused bool `json:"paused"` - Priority int `json:"priority,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` -} - -// ZoneLockdownConfig represents a Zone Lockdown config, which comprises -// a Target ("ip" or "ip_range") and a Value (an IP address or IP+mask, -// respectively.) -type ZoneLockdownConfig struct { - Target string `json:"target"` - Value string `json:"value"` -} - -// ZoneLockdownResponse represents a response from the Zone Lockdown endpoint. -type ZoneLockdownResponse struct { - Result ZoneLockdown `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// ZoneLockdownListResponse represents a response from the List Zone Lockdown -// endpoint. -type ZoneLockdownListResponse struct { - Result []ZoneLockdown `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// ZoneLockdownCreateParams contains required and optional params -// for creating a zone lockdown. -type ZoneLockdownCreateParams struct { - Description string `json:"description"` - URLs []string `json:"urls"` - Configurations []ZoneLockdownConfig `json:"configurations"` - Paused bool `json:"paused"` - Priority int `json:"priority,omitempty"` -} - -// ZoneLockdownUpdateParams contains required and optional params -// for updating a zone lockdown. -type ZoneLockdownUpdateParams struct { - ID string `json:"id"` - Description string `json:"description"` - URLs []string `json:"urls"` - Configurations []ZoneLockdownConfig `json:"configurations"` - Paused bool `json:"paused"` - Priority int `json:"priority,omitempty"` -} - -type LockdownListParams struct { - ResultInfo -} - -// CreateZoneLockdown creates a Zone ZoneLockdown rule for the given zone ID. -// -// API reference: https://api.cloudflare.com/#zone-ZoneLockdown-create-a-ZoneLockdown-rule -func (api *API) CreateZoneLockdown(ctx context.Context, rc *ResourceContainer, params ZoneLockdownCreateParams) (ZoneLockdown, error) { - uri := fmt.Sprintf("/zones/%s/firewall/lockdowns", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return ZoneLockdown{}, err - } - - response := &ZoneLockdownResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return ZoneLockdown{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// UpdateZoneLockdown updates a Zone ZoneLockdown rule (based on the ID) for the given zone ID. -// -// API reference: https://api.cloudflare.com/#zone-ZoneLockdown-update-ZoneLockdown-rule -func (api *API) UpdateZoneLockdown(ctx context.Context, rc *ResourceContainer, params ZoneLockdownUpdateParams) (ZoneLockdown, error) { - uri := fmt.Sprintf("/zones/%s/firewall/lockdowns/%s", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return ZoneLockdown{}, err - } - - response := &ZoneLockdownResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return ZoneLockdown{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// DeleteZoneLockdown deletes a Zone ZoneLockdown rule (based on the ID) for the given zone ID. -// -// API reference: https://api.cloudflare.com/#zone-ZoneLockdown-delete-ZoneLockdown-rule -func (api *API) DeleteZoneLockdown(ctx context.Context, rc *ResourceContainer, id string) (ZoneLockdown, error) { - uri := fmt.Sprintf("/zones/%s/firewall/lockdowns/%s", rc.Identifier, id) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return ZoneLockdown{}, err - } - - response := &ZoneLockdownResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return ZoneLockdown{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// ZoneLockdown retrieves a Zone ZoneLockdown rule (based on the ID) for the given zone ID. -// -// API reference: https://api.cloudflare.com/#zone-ZoneLockdown-ZoneLockdown-rule-details -func (api *API) ZoneLockdown(ctx context.Context, rc *ResourceContainer, id string) (ZoneLockdown, error) { - uri := fmt.Sprintf("/zones/%s/firewall/lockdowns/%s", rc.Identifier, id) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ZoneLockdown{}, err - } - - response := &ZoneLockdownResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return ZoneLockdown{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// ListZoneLockdowns retrieves every Zone ZoneLockdown rules for a given zone ID. -// -// Automatically paginates all results unless `params.PerPage` and `params.Page` -// is set. -// -// API reference: https://api.cloudflare.com/#zone-ZoneLockdown-list-ZoneLockdown-rules -func (api *API) ListZoneLockdowns(ctx context.Context, rc *ResourceContainer, params LockdownListParams) ([]ZoneLockdown, *ResultInfo, error) { - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - if params.PerPage < 1 { - params.PerPage = 50 - } - if params.Page < 1 { - params.Page = 1 - } - - var zoneLockdowns []ZoneLockdown - var zResponse ZoneLockdownListResponse - for { - zResponse = ZoneLockdownListResponse{} - uri := buildURI(fmt.Sprintf("/zones/%s/firewall/lockdowns", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []ZoneLockdown{}, &ResultInfo{}, err - } - - err = json.Unmarshal(res, &zResponse) - if err != nil { - return []ZoneLockdown{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal filters JSON data: %w", err) - } - - zoneLockdowns = append(zoneLockdowns, zResponse.Result...) - params.ResultInfo = zResponse.ResultInfo.Next() - - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return zoneLockdowns, &zResponse.ResultInfo, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/logger.go b/vendor/github.com/cloudflare/cloudflare-go/logger.go deleted file mode 100644 index b1bd9b4..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/logger.go +++ /dev/null @@ -1,130 +0,0 @@ -package cloudflare - -import ( - "fmt" - "io" - "log" - "os" -) - -// silentRetryLogger is the logger provided with retryable client to stop it -// displaying the retry attempts. -var silentRetryLogger = log.New(io.Discard, "", log.LstdFlags) - -const ( - // LevelNull sets a logger to show no messages at all. - LevelNull Level = 0 - - // LevelError sets a logger to show error messages only. - LevelError Level = 1 - - // LevelWarn sets a logger to show warning messages or anything more - // severe. - LevelWarn Level = 2 - - // LevelInfo sets a logger to show informational messages or anything more - // severe. - LevelInfo Level = 3 - - // LevelDebug sets a logger to show informational messages or anything more - // severe. - LevelDebug Level = 4 -) - -// DefaultLeveledLogger is the default logger that the library will use to log -// errors, warnings, and informational messages. -var DefaultLeveledLogger LeveledLoggerInterface = &LeveledLogger{ - Level: LevelError, -} - -// SilentLeveledLogger is a logger for disregarding all logs written. -var SilentLeveledLogger LeveledLoggerInterface = &LeveledLogger{ - Level: LevelNull, -} - -// Level represents a logging level. -type Level uint32 - -// LeveledLogger is a leveled logger implementation. -// -// It prints warnings and errors to `os.Stderr` and other messages to -// `os.Stdout`. -type LeveledLogger struct { - // Level is the minimum logging level that will be emitted by this logger. - // - // For example, a Level set to LevelWarn will emit warnings and errors, but - // not informational or debug messages. - // - // Always set this with a constant like LevelWarn because the individual - // values are not guaranteed to be stable. - Level Level - - // Internal testing use only. - stderrOverride io.Writer - stdoutOverride io.Writer -} - -// Debugf logs a debug message using Printf conventions. -func (l *LeveledLogger) Debugf(format string, v ...interface{}) { - if l.Level >= LevelDebug { - fmt.Fprintf(l.stdout(), "[debug] "+format, v...) - } -} - -// Errorf logs a warning message using Printf conventions. -func (l *LeveledLogger) Errorf(format string, v ...interface{}) { - // Infof logs a debug message using Printf conventions. - if l.Level >= LevelError { - fmt.Fprintf(l.stderr(), "[error] "+format, v...) - } -} - -// Infof logs an informational message using Printf conventions. -func (l *LeveledLogger) Infof(format string, v ...interface{}) { - if l.Level >= LevelInfo { - fmt.Fprintf(l.stdout(), "[info] "+format, v...) - } -} - -// Warnf logs a warning message using Printf conventions. -func (l *LeveledLogger) Warnf(format string, v ...interface{}) { - if l.Level >= LevelWarn { - fmt.Fprintf(l.stderr(), "[warn] "+format, v...) - } -} - -func (l *LeveledLogger) stderr() io.Writer { - if l.stderrOverride != nil { - return l.stderrOverride - } - - return os.Stderr -} - -func (l *LeveledLogger) stdout() io.Writer { - if l.stdoutOverride != nil { - return l.stdoutOverride - } - - return os.Stdout -} - -// LeveledLoggerInterface provides a basic leveled logging interface for -// printing debug, informational, warning, and error messages. -// -// It's implemented by LeveledLogger and also provides out-of-the-box -// compatibility with a Logrus Logger, but may require a thin shim for use with -// other logging libraries that you use less standard conventions like Zap. -type LeveledLoggerInterface interface { - // Debugf logs a debug message using Printf conventions. - Debugf(format string, v ...interface{}) - - // Errorf logs a warning message using Printf conventions. - Errorf(format string, v ...interface{}) - - // Infof logs an informational message using Printf conventions. - Infof(format string, v ...interface{}) - - // Warnf logs a warning message using Printf conventions. - Warnf(format string, v ...interface{}) -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/logpull.go b/vendor/github.com/cloudflare/cloudflare-go/logpull.go deleted file mode 100644 index b458ac8..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/logpull.go +++ /dev/null @@ -1,57 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// LogpullRetentionConfiguration describes a the structure of a Logpull Retention -// payload. -type LogpullRetentionConfiguration struct { - Flag bool `json:"flag"` -} - -// LogpullRetentionConfigurationResponse is the API response, containing the -// Logpull retention result. -type LogpullRetentionConfigurationResponse struct { - Response - Result LogpullRetentionConfiguration `json:"result"` -} - -// GetLogpullRetentionFlag gets the current setting flag. -// -// API reference: https://developers.cloudflare.com/logs/logpull-api/enabling-log-retention/ -func (api *API) GetLogpullRetentionFlag(ctx context.Context, zoneID string) (*LogpullRetentionConfiguration, error) { - uri := fmt.Sprintf("/zones/%s/logs/control/retention/flag", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return &LogpullRetentionConfiguration{}, err - } - var r LogpullRetentionConfigurationResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return &r.Result, nil -} - -// SetLogpullRetentionFlag updates the retention flag to the defined boolean. -// -// API reference: https://developers.cloudflare.com/logs/logpull-api/enabling-log-retention/ -func (api *API) SetLogpullRetentionFlag(ctx context.Context, zoneID string, enabled bool) (*LogpullRetentionConfiguration, error) { - uri := fmt.Sprintf("/zones/%s/logs/control/retention/flag", zoneID) - flagPayload := LogpullRetentionConfiguration{Flag: enabled} - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, flagPayload) - if err != nil { - return &LogpullRetentionConfiguration{}, err - } - var r LogpullRetentionConfigurationResponse - err = json.Unmarshal(res, &r) - if err != nil { - return &LogpullRetentionConfiguration{}, err - } - return &r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/logpush.go b/vendor/github.com/cloudflare/cloudflare-go/logpush.go deleted file mode 100644 index fbb5354..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/logpush.go +++ /dev/null @@ -1,619 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// LogpushJob describes a Logpush job. -type LogpushJob struct { - ID int `json:"id,omitempty"` - Dataset string `json:"dataset"` - Enabled bool `json:"enabled"` - Kind string `json:"kind,omitempty"` - Name string `json:"name"` - LogpullOptions string `json:"logpull_options"` - DestinationConf string `json:"destination_conf"` - OwnershipChallenge string `json:"ownership_challenge,omitempty"` - LastComplete *time.Time `json:"last_complete,omitempty"` - LastError *time.Time `json:"last_error,omitempty"` - ErrorMessage string `json:"error_message,omitempty"` - Frequency string `json:"frequency,omitempty"` - Filter *LogpushJobFilters `json:"filter,omitempty"` -} - -type LogpushJobFilters struct { - Where LogpushJobFilter `json:"where"` -} - -type Operator string - -const ( - Equal Operator = "eq" - NotEqual Operator = "!eq" - LessThan Operator = "lt" - LessThanOrEqual Operator = "leq" - GreaterThan Operator = "gt" - GreaterThanOrEqual Operator = "geq" - StartsWith Operator = "startsWith" - EndsWith Operator = "endsWith" - NotStartsWith Operator = "!startsWith" - NotEndsWith Operator = "!endsWith" - Contains Operator = "contains" - NotContains Operator = "!contains" - ValueIsIn Operator = "in" - ValueIsNotIn Operator = "!in" -) - -type LogpushJobFilter struct { - // either this - And []LogpushJobFilter `json:"and,omitempty"` - Or []LogpushJobFilter `json:"or,omitempty"` - // or this - Key string `json:"key,omitempty"` - Operator Operator `json:"operator,omitempty"` - Value interface{} `json:"value,omitempty"` -} - -// LogpushJobsResponse is the API response, containing an array of Logpush Jobs. -type LogpushJobsResponse struct { - Response - Result []LogpushJob `json:"result"` -} - -// LogpushJobDetailsResponse is the API response, containing a single Logpush Job. -type LogpushJobDetailsResponse struct { - Response - Result LogpushJob `json:"result"` -} - -// LogpushFieldsResponse is the API response for a datasets fields. -type LogpushFieldsResponse struct { - Response - Result LogpushFields `json:"result"` -} - -// LogpushFields is a map of available Logpush field names & descriptions. -type LogpushFields map[string]string - -// LogpushGetOwnershipChallenge describes a ownership validation. -type LogpushGetOwnershipChallenge struct { - Filename string `json:"filename"` - Valid bool `json:"valid"` - Message string `json:"message"` -} - -// LogpushGetOwnershipChallengeResponse is the API response, containing a ownership challenge. -type LogpushGetOwnershipChallengeResponse struct { - Response - Result LogpushGetOwnershipChallenge `json:"result"` -} - -// LogpushGetOwnershipChallengeRequest is the API request for get ownership challenge. -type LogpushGetOwnershipChallengeRequest struct { - DestinationConf string `json:"destination_conf"` -} - -// LogpushOwnershipChallengeValidationResponse is the API response, -// containing a ownership challenge validation result. -type LogpushOwnershipChallengeValidationResponse struct { - Response - Result struct { - Valid bool `json:"valid"` - } -} - -// LogpushValidateOwnershipChallengeRequest is the API request for validate ownership challenge. -type LogpushValidateOwnershipChallengeRequest struct { - DestinationConf string `json:"destination_conf"` - OwnershipChallenge string `json:"ownership_challenge"` -} - -// LogpushDestinationExistsResponse is the API response, -// containing a destination exists check result. -type LogpushDestinationExistsResponse struct { - Response - Result struct { - Exists bool `json:"exists"` - } -} - -// LogpushDestinationExistsRequest is the API request for check destination exists. -type LogpushDestinationExistsRequest struct { - DestinationConf string `json:"destination_conf"` -} - -// Custom Marshaller for LogpushJob filter key. -func (f LogpushJob) MarshalJSON() ([]byte, error) { - type Alias LogpushJob - - var filter string - - if f.Filter != nil { - b, err := json.Marshal(f.Filter) - - if err != nil { - return nil, err - } - - filter = string(b) - } - - return json.Marshal(&struct { - Filter string `json:"filter,omitempty"` - Alias - }{ - Filter: filter, - Alias: (Alias)(f), - }) -} - -// Custom Unmarshaller for LogpushJob filter key. -func (f *LogpushJob) UnmarshalJSON(data []byte) error { - type Alias LogpushJob - aux := &struct { - Filter string `json:"filter,omitempty"` - *Alias - }{ - Alias: (*Alias)(f), - } - if err := json.Unmarshal(data, &aux); err != nil { - return err - } - - if aux != nil && aux.Filter != "" { - var filter LogpushJobFilters - if err := json.Unmarshal([]byte(aux.Filter), &filter); err != nil { - return err - } - if err := filter.Where.Validate(); err != nil { - return err - } - f.Filter = &filter - } - return nil -} - -func (filter *LogpushJobFilter) Validate() error { - if filter.And != nil { - if filter.Or != nil || filter.Key != "" || filter.Operator != "" || filter.Value != nil { - return errors.New("And can't be set with Or, Key, Operator or Value") - } - for i, element := range filter.And { - err := element.Validate() - if err != nil { - return fmt.Errorf("element %v in And is invalid: %w", i, err) - } - } - return nil - } - if filter.Or != nil { - if filter.And != nil || filter.Key != "" || filter.Operator != "" || filter.Value != nil { - return errors.New("Or can't be set with And, Key, Operator or Value") - } - for i, element := range filter.Or { - err := element.Validate() - if err != nil { - return fmt.Errorf("element %v in Or is invalid: %w", i, err) - } - } - return nil - } - if filter.Key == "" { - return errors.New("Key is missing") - } - - if filter.Operator == "" { - return errors.New("Operator is missing") - } - - if filter.Value == nil { - return errors.New("Value is missing") - } - - return nil -} - -// CreateAccountLogpushJob creates a new account-level Logpush Job. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-create-logpush-job -func (api *API) CreateAccountLogpushJob(ctx context.Context, accountID string, job LogpushJob) (*LogpushJob, error) { - return api.createLogpushJob(ctx, AccountRouteRoot, accountID, job) -} - -// CreateZoneLogpushJob creates a new zone-level Logpush Job. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-create-logpush-job -func (api *API) CreateZoneLogpushJob(ctx context.Context, zoneID string, job LogpushJob) (*LogpushJob, error) { - return api.createLogpushJob(ctx, ZoneRouteRoot, zoneID, job) -} - -// CreateLogpushJob creates a new zone-level Logpush Job. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-create-logpush-job -// -// Deprecated: Use `CreateZoneLogpushJob` or `CreateAccountLogpushJob` depending -// on the desired resource to target. -func (api *API) CreateLogpushJob(ctx context.Context, zoneID string, job LogpushJob) (*LogpushJob, error) { - return api.createLogpushJob(ctx, ZoneRouteRoot, zoneID, job) -} - -func (api *API) createLogpushJob(ctx context.Context, identifierType RouteRoot, identifier string, job LogpushJob) (*LogpushJob, error) { - uri := fmt.Sprintf("/%s/%s/logpush/jobs", identifierType, identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, job) - if err != nil { - return nil, err - } - var r LogpushJobDetailsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return &r.Result, nil -} - -// ListAccountLogpushJobs returns all account-level Logpush Jobs for all datasets. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs -func (api *API) ListAccountLogpushJobs(ctx context.Context, accountID string) ([]LogpushJob, error) { - return api.listLogpushJobs(ctx, AccountRouteRoot, accountID) -} - -// ListZoneLogpushJobs returns all zone-level Logpush Jobs for all datasets. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs -func (api *API) ListZoneLogpushJobs(ctx context.Context, zoneID string) ([]LogpushJob, error) { - return api.listLogpushJobs(ctx, ZoneRouteRoot, zoneID) -} - -// LogpushJobs returns all zone-level Logpush Jobs for all datasets. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs -// -// Deprecated: Use `ListZoneLogpushJobs` or `ListAccountLogpushJobs` -// depending on the desired resource to target. -func (api *API) LogpushJobs(ctx context.Context, zoneID string) ([]LogpushJob, error) { - return api.listLogpushJobs(ctx, ZoneRouteRoot, zoneID) -} - -func (api *API) listLogpushJobs(ctx context.Context, identifierType RouteRoot, identifier string) ([]LogpushJob, error) { - uri := fmt.Sprintf("/%s/%s/logpush/jobs", identifierType, identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []LogpushJob{}, err - } - var r LogpushJobsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []LogpushJob{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListAccountLogpushJobsForDataset returns all account-level Logpush Jobs for a dataset. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs-for-a-dataset -func (api *API) ListAccountLogpushJobsForDataset(ctx context.Context, accountID, dataset string) ([]LogpushJob, error) { - return api.listLogpushJobsForDataset(ctx, AccountRouteRoot, accountID, dataset) -} - -// ListZoneLogpushJobsForDataset returns all zone-level Logpush Jobs for a dataset. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs-for-a-dataset -func (api *API) ListZoneLogpushJobsForDataset(ctx context.Context, zoneID, dataset string) ([]LogpushJob, error) { - return api.listLogpushJobsForDataset(ctx, ZoneRouteRoot, zoneID, dataset) -} - -// LogpushJobsForDataset returns all zone-level Logpush Jobs for a dataset. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs-for-a-dataset -// -// Deprecated: Use `ListZoneLogpushJobsForDataset` or -// `ListAccountLogpushJobsForDataset` depending on the desired resource -// to target. -func (api *API) LogpushJobsForDataset(ctx context.Context, zoneID, dataset string) ([]LogpushJob, error) { - return api.listLogpushJobsForDataset(ctx, ZoneRouteRoot, zoneID, dataset) -} - -func (api *API) listLogpushJobsForDataset(ctx context.Context, identifierType RouteRoot, identifier, dataset string) ([]LogpushJob, error) { - uri := fmt.Sprintf("/%s/%s/logpush/datasets/%s/jobs", identifierType, identifier, dataset) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []LogpushJob{}, err - } - var r LogpushJobsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []LogpushJob{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetAccountLogpushFields returns fields for a given account-level dataset. -// -// Account fields documentation: https://developers.cloudflare.com/logs/reference/log-fields/account -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs -func (api *API) GetAccountLogpushFields(ctx context.Context, accountID, dataset string) (LogpushFields, error) { - return api.getLogpushFields(ctx, AccountRouteRoot, accountID, dataset) -} - -// GetZoneLogpushFields returns fields for a given zone-level dataset. -// -// Zone fields documentation: https://developers.cloudflare.com/logs/reference/log-fields/zone -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs -func (api *API) GetZoneLogpushFields(ctx context.Context, zoneID, dataset string) (LogpushFields, error) { - return api.getLogpushFields(ctx, ZoneRouteRoot, zoneID, dataset) -} - -// LogpushFields returns fields for a given dataset. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-list-logpush-jobs -// -// Deprecated: Use `GetZoneLogpushFields` or `GetAccountLogpushFields` -// depending on the desired resource to target. -func (api *API) LogpushFields(ctx context.Context, zoneID, dataset string) (LogpushFields, error) { - return api.getLogpushFields(ctx, ZoneRouteRoot, zoneID, dataset) -} - -func (api *API) getLogpushFields(ctx context.Context, identifierType RouteRoot, identifier, dataset string) (LogpushFields, error) { - uri := fmt.Sprintf("/%s/%s/logpush/datasets/%s/fields", identifierType, identifier, dataset) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return LogpushFields{}, err - } - var r LogpushFieldsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return LogpushFields{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetAccountLogpushJob fetches detail about one account-level Logpush Job. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-logpush-job-details -func (api *API) GetAccountLogpushJob(ctx context.Context, accountID string, jobID int) (LogpushJob, error) { - return api.getLogpushJob(ctx, AccountRouteRoot, accountID, jobID) -} - -// GetZoneLogpushJob fetches detail about one Logpush Job for a zone. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-logpush-job-details -func (api *API) GetZoneLogpushJob(ctx context.Context, zoneID string, jobID int) (LogpushJob, error) { - return api.getLogpushJob(ctx, ZoneRouteRoot, zoneID, jobID) -} - -// LogpushJob fetches detail about one Logpush Job for a zone. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-logpush-job-details -// -// Deprecated: Use `GetZoneLogpushJob` or `GetAccountLogpushJob` -// depending on the desired resource to target. -func (api *API) LogpushJob(ctx context.Context, zoneID string, jobID int) (LogpushJob, error) { - return api.getLogpushJob(ctx, ZoneRouteRoot, zoneID, jobID) -} - -func (api *API) getLogpushJob(ctx context.Context, identifierType RouteRoot, identifier string, jobID int) (LogpushJob, error) { - uri := fmt.Sprintf("/%s/%s/logpush/jobs/%d", identifierType, identifier, jobID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return LogpushJob{}, err - } - var r LogpushJobDetailsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return LogpushJob{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateAccountLogpushJob lets you update an account-level Logpush Job. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-update-logpush-job -func (api *API) UpdateAccountLogpushJob(ctx context.Context, accountID string, jobID int, job LogpushJob) error { - return api.updateLogpushJob(ctx, AccountRouteRoot, accountID, jobID, job) -} - -// UpdateZoneLogpushJob lets you update a Logpush Job for a zone. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-update-logpush-job -func (api *API) UpdateZoneLogpushJob(ctx context.Context, zoneID string, jobID int, job LogpushJob) error { - return api.updateLogpushJob(ctx, ZoneRouteRoot, zoneID, jobID, job) -} - -// UpdateLogpushJob lets you update a Logpush Job. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-update-logpush-job -// -// Deprecated: Use `UpdateZoneLogpushJob` or `UpdateAccountLogpushJob` -// depending on the desired resource to target. -func (api *API) UpdateLogpushJob(ctx context.Context, zoneID string, jobID int, job LogpushJob) error { - return api.updateLogpushJob(ctx, ZoneRouteRoot, zoneID, jobID, job) -} - -func (api *API) updateLogpushJob(ctx context.Context, identifierType RouteRoot, identifier string, jobID int, job LogpushJob) error { - uri := fmt.Sprintf("/%s/%s/logpush/jobs/%d", identifierType, identifier, jobID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, job) - if err != nil { - return err - } - var r LogpushJobDetailsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// DeleteAccountLogpushJob deletes an account-level Logpush Job. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-delete-logpush-job -func (api *API) DeleteAccountLogpushJob(ctx context.Context, accountID string, jobID int) error { - return api.deleteLogpushJob(ctx, AccountRouteRoot, accountID, jobID) -} - -// DeleteZoneLogpushJob deletes a Logpush Job for a zone. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-delete-logpush-job -func (api *API) DeleteZoneLogpushJob(ctx context.Context, zoneID string, jobID int) error { - return api.deleteLogpushJob(ctx, ZoneRouteRoot, zoneID, jobID) -} - -// DeleteLogpushJob deletes a Logpush Job for a zone. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-delete-logpush-job -// -// Deprecated: Use `DeleteZoneLogpushJob` or `DeleteAccountLogpushJob` -// depending on the desired resource to target. -func (api *API) DeleteLogpushJob(ctx context.Context, zoneID string, jobID int) error { - return api.deleteLogpushJob(ctx, ZoneRouteRoot, zoneID, jobID) -} - -func (api *API) deleteLogpushJob(ctx context.Context, identifierType RouteRoot, identifier string, jobID int) error { - uri := fmt.Sprintf("/%s/%s/logpush/jobs/%d", identifierType, identifier, jobID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r LogpushJobDetailsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// GetAccountLogpushOwnershipChallenge returns ownership challenge. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-get-ownership-challenge -func (api *API) GetAccountLogpushOwnershipChallenge(ctx context.Context, accountID, destinationConf string) (*LogpushGetOwnershipChallenge, error) { - return api.getLogpushOwnershipChallenge(ctx, AccountRouteRoot, accountID, destinationConf) -} - -// GetZoneLogpushOwnershipChallenge returns ownership challenge. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-get-ownership-challenge -func (api *API) GetZoneLogpushOwnershipChallenge(ctx context.Context, zoneID, destinationConf string) (*LogpushGetOwnershipChallenge, error) { - return api.getLogpushOwnershipChallenge(ctx, ZoneRouteRoot, zoneID, destinationConf) -} - -// GetLogpushOwnershipChallenge returns ownership challenge. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-get-ownership-challenge -// -// Deprecated: Use `GetZoneLogpushOwnershipChallenge` or -// `GetAccountLogpushOwnershipChallenge` depending on the -// desired resource to target. -func (api *API) GetLogpushOwnershipChallenge(ctx context.Context, zoneID, destinationConf string) (*LogpushGetOwnershipChallenge, error) { - return api.getLogpushOwnershipChallenge(ctx, ZoneRouteRoot, zoneID, destinationConf) -} - -func (api *API) getLogpushOwnershipChallenge(ctx context.Context, identifierType RouteRoot, identifier, destinationConf string) (*LogpushGetOwnershipChallenge, error) { - uri := fmt.Sprintf("/%s/%s/logpush/ownership", identifierType, identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, LogpushGetOwnershipChallengeRequest{ - DestinationConf: destinationConf, - }) - if err != nil { - return nil, err - } - var r LogpushGetOwnershipChallengeResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !r.Result.Valid { - return nil, errors.New(r.Result.Message) - } - - return &r.Result, nil -} - -// ValidateAccountLogpushOwnershipChallenge returns account-level ownership challenge validation result. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-validate-ownership-challenge -func (api *API) ValidateAccountLogpushOwnershipChallenge(ctx context.Context, accountID, destinationConf, ownershipChallenge string) (bool, error) { - return api.validateLogpushOwnershipChallenge(ctx, AccountRouteRoot, accountID, destinationConf, ownershipChallenge) -} - -// ValidateZoneLogpushOwnershipChallenge returns zone-level ownership challenge validation result. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-validate-ownership-challenge -func (api *API) ValidateZoneLogpushOwnershipChallenge(ctx context.Context, zoneID, destinationConf, ownershipChallenge string) (bool, error) { - return api.validateLogpushOwnershipChallenge(ctx, ZoneRouteRoot, zoneID, destinationConf, ownershipChallenge) -} - -// ValidateLogpushOwnershipChallenge returns zone-level ownership challenge validation result. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-validate-ownership-challenge -// -// Deprecated: Use `ValidateZoneLogpushOwnershipChallenge` or -// `ValidateAccountLogpushOwnershipChallenge` depending on the -// desired resource to target. -func (api *API) ValidateLogpushOwnershipChallenge(ctx context.Context, zoneID, destinationConf, ownershipChallenge string) (bool, error) { - return api.validateLogpushOwnershipChallenge(ctx, ZoneRouteRoot, zoneID, destinationConf, ownershipChallenge) -} - -func (api *API) validateLogpushOwnershipChallenge(ctx context.Context, identifierType RouteRoot, identifier, destinationConf, ownershipChallenge string) (bool, error) { - uri := fmt.Sprintf("/%s/%s/logpush/ownership/validate", identifierType, identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, LogpushValidateOwnershipChallengeRequest{ - DestinationConf: destinationConf, - OwnershipChallenge: ownershipChallenge, - }) - if err != nil { - return false, err - } - var r LogpushGetOwnershipChallengeResponse - err = json.Unmarshal(res, &r) - if err != nil { - return false, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result.Valid, nil -} - -// CheckAccountLogpushDestinationExists returns account-level destination exists check result. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-check-destination-exists -func (api *API) CheckAccountLogpushDestinationExists(ctx context.Context, accountID, destinationConf string) (bool, error) { - return api.checkLogpushDestinationExists(ctx, AccountRouteRoot, accountID, destinationConf) -} - -// CheckZoneLogpushDestinationExists returns zone-level destination exists check result. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-check-destination-exists -func (api *API) CheckZoneLogpushDestinationExists(ctx context.Context, zoneID, destinationConf string) (bool, error) { - return api.checkLogpushDestinationExists(ctx, ZoneRouteRoot, zoneID, destinationConf) -} - -// CheckLogpushDestinationExists returns zone-level destination exists check result. -// -// API reference: https://api.cloudflare.com/#logpush-jobs-check-destination-exists -// -// Deprecated: Use `CheckZoneLogpushDestinationExists` or -// `CheckAccountLogpushDestinationExists` depending -// on the desired resource to target. -func (api *API) CheckLogpushDestinationExists(ctx context.Context, zoneID, destinationConf string) (bool, error) { - return api.checkLogpushDestinationExists(ctx, ZoneRouteRoot, zoneID, destinationConf) -} - -func (api *API) checkLogpushDestinationExists(ctx context.Context, identifierType RouteRoot, identifier, destinationConf string) (bool, error) { - uri := fmt.Sprintf("/%s/%s/logpush/validate/destination/exists", identifierType, identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, LogpushDestinationExistsRequest{ - DestinationConf: destinationConf, - }) - if err != nil { - return false, err - } - var r LogpushDestinationExistsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return false, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result.Exists, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/magic_firewall_rulesets.go b/vendor/github.com/cloudflare/cloudflare-go/magic_firewall_rulesets.go deleted file mode 100644 index 791f397..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/magic_firewall_rulesets.go +++ /dev/null @@ -1,205 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -const ( - // MagicFirewallRulesetKindRoot specifies a root Ruleset. - MagicFirewallRulesetKindRoot = "root" - - // MagicFirewallRulesetPhaseMagicTransit specifies the Magic Transit Ruleset phase. - MagicFirewallRulesetPhaseMagicTransit = "magic_transit" - - // MagicFirewallRulesetRuleActionSkip specifies a skip (allow) action. - MagicFirewallRulesetRuleActionSkip MagicFirewallRulesetRuleAction = "skip" - - // MagicFirewallRulesetRuleActionBlock specifies a block action. - MagicFirewallRulesetRuleActionBlock MagicFirewallRulesetRuleAction = "block" -) - -// MagicFirewallRulesetRuleAction specifies the action for a Firewall rule. -type MagicFirewallRulesetRuleAction string - -// MagicFirewallRuleset contains information about a Firewall Ruleset. -type MagicFirewallRuleset struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Kind string `json:"kind"` - Version string `json:"version,omitempty"` - LastUpdated *time.Time `json:"last_updated,omitempty"` - Phase string `json:"phase"` - Rules []MagicFirewallRulesetRule `json:"rules"` -} - -// MagicFirewallRulesetRuleActionParameters specifies the action parameters for a Firewall rule. -type MagicFirewallRulesetRuleActionParameters struct { - Ruleset string `json:"ruleset,omitempty"` -} - -// MagicFirewallRulesetRule contains information about a single Magic Firewall rule. -type MagicFirewallRulesetRule struct { - ID string `json:"id,omitempty"` - Version string `json:"version,omitempty"` - Action MagicFirewallRulesetRuleAction `json:"action"` - ActionParameters *MagicFirewallRulesetRuleActionParameters `json:"action_parameters,omitempty"` - Expression string `json:"expression"` - Description string `json:"description"` - LastUpdated *time.Time `json:"last_updated,omitempty"` - Ref string `json:"ref,omitempty"` - Enabled bool `json:"enabled"` -} - -// CreateMagicFirewallRulesetRequest contains data for a new Firewall ruleset. -type CreateMagicFirewallRulesetRequest struct { - Name string `json:"name"` - Description string `json:"description"` - Kind string `json:"kind"` - Phase string `json:"phase"` - Rules []MagicFirewallRulesetRule `json:"rules"` -} - -// UpdateMagicFirewallRulesetRequest contains data for a Magic Firewall ruleset update. -type UpdateMagicFirewallRulesetRequest struct { - Description string `json:"description"` - Rules []MagicFirewallRulesetRule `json:"rules"` -} - -// ListMagicFirewallRulesetResponse contains a list of Magic Firewall rulesets. -type ListMagicFirewallRulesetResponse struct { - Response - Result []MagicFirewallRuleset `json:"result"` -} - -// GetMagicFirewallRulesetResponse contains a single Magic Firewall Ruleset. -type GetMagicFirewallRulesetResponse struct { - Response - Result MagicFirewallRuleset `json:"result"` -} - -// CreateMagicFirewallRulesetResponse contains response data when creating a new Magic Firewall ruleset. -type CreateMagicFirewallRulesetResponse struct { - Response - Result MagicFirewallRuleset `json:"result"` -} - -// UpdateMagicFirewallRulesetResponse contains response data when updating an existing Magic Firewall ruleset. -type UpdateMagicFirewallRulesetResponse struct { - Response - Result MagicFirewallRuleset `json:"result"` -} - -// ListMagicFirewallRulesets lists all Rulesets for a given account -// -// API reference: https://api.cloudflare.com/#rulesets-list-rulesets -// -// Deprecated: Use `ListZoneRuleset` or `ListAccountRuleset` instead. -func (api *API) ListMagicFirewallRulesets(ctx context.Context, accountID string) ([]MagicFirewallRuleset, error) { - uri := fmt.Sprintf("/accounts/%s/rulesets", accountID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []MagicFirewallRuleset{}, err - } - - result := ListMagicFirewallRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetMagicFirewallRuleset returns a specific Magic Firewall Ruleset -// -// API reference: https://api.cloudflare.com/#rulesets-get-a-ruleset -// -// Deprecated: Use `GetZoneRuleset` or `GetAccountRuleset` instead. -func (api *API) GetMagicFirewallRuleset(ctx context.Context, accountID, ID string) (MagicFirewallRuleset, error) { - uri := fmt.Sprintf("/accounts/%s/rulesets/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return MagicFirewallRuleset{}, err - } - - result := GetMagicFirewallRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// CreateMagicFirewallRuleset creates a Magic Firewall ruleset -// -// API reference: https://api.cloudflare.com/#rulesets-list-rulesets -// -// Deprecated: Use `CreateZoneRuleset` or `CreateAccountRuleset` instead. -func (api *API) CreateMagicFirewallRuleset(ctx context.Context, accountID, name, description string, rules []MagicFirewallRulesetRule) (MagicFirewallRuleset, error) { - uri := fmt.Sprintf("/accounts/%s/rulesets", accountID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, - CreateMagicFirewallRulesetRequest{ - Name: name, - Description: description, - Kind: MagicFirewallRulesetKindRoot, - Phase: MagicFirewallRulesetPhaseMagicTransit, - Rules: rules}) - if err != nil { - return MagicFirewallRuleset{}, err - } - - result := CreateMagicFirewallRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// DeleteMagicFirewallRuleset deletes a Magic Firewall ruleset -// -// API reference: https://api.cloudflare.com/#rulesets-delete-ruleset -// -// Deprecated: Use `DeleteZoneRuleset` or `DeleteAccountRuleset` instead. -func (api *API) DeleteMagicFirewallRuleset(ctx context.Context, accountID, ID string) error { - uri := fmt.Sprintf("/accounts/%s/rulesets/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return err - } - - // Firewall API is not implementing the standard response blob but returns an empty response (204) in case - // of a success. So we are checking for the response body size here - if len(res) > 0 { - return fmt.Errorf(errMakeRequestError+": %w", errors.New(string(res))) - } - - return nil -} - -// UpdateMagicFirewallRuleset updates a Magic Firewall ruleset -// -// API reference: https://api.cloudflare.com/#rulesets-update-ruleset -// -// Deprecated: Use `UpdateZoneRuleset` or `UpdateAccountRuleset` instead. -func (api *API) UpdateMagicFirewallRuleset(ctx context.Context, accountID, ID string, description string, rules []MagicFirewallRulesetRule) (MagicFirewallRuleset, error) { - uri := fmt.Sprintf("/accounts/%s/rulesets/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, - UpdateMagicFirewallRulesetRequest{Description: description, Rules: rules}) - if err != nil { - return MagicFirewallRuleset{}, err - } - - result := UpdateMagicFirewallRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_gre_tunnel.go b/vendor/github.com/cloudflare/cloudflare-go/magic_transit_gre_tunnel.go deleted file mode 100644 index fcab192..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_gre_tunnel.go +++ /dev/null @@ -1,180 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// Magic Transit GRE Tunnel Error messages. -const ( - errMagicTransitGRETunnelNotModified = "When trying to modify GRE tunnel, API returned modified: false" - errMagicTransitGRETunnelNotDeleted = "When trying to delete GRE tunnel, API returned deleted: false" -) - -// MagicTransitGRETunnel contains information about a GRE tunnel. -type MagicTransitGRETunnel struct { - ID string `json:"id,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - Name string `json:"name"` - CustomerGREEndpoint string `json:"customer_gre_endpoint"` - CloudflareGREEndpoint string `json:"cloudflare_gre_endpoint"` - InterfaceAddress string `json:"interface_address"` - Description string `json:"description,omitempty"` - TTL uint8 `json:"ttl,omitempty"` - MTU uint16 `json:"mtu,omitempty"` - HealthCheck *MagicTransitGRETunnelHealthcheck `json:"health_check,omitempty"` -} - -// MagicTransitGRETunnelHealthcheck contains information about a GRE tunnel health check. -type MagicTransitGRETunnelHealthcheck struct { - Enabled bool `json:"enabled"` - Target string `json:"target,omitempty"` - Type string `json:"type,omitempty"` -} - -// ListMagicTransitGRETunnelsResponse contains a response including GRE tunnels. -type ListMagicTransitGRETunnelsResponse struct { - Response - Result struct { - GRETunnels []MagicTransitGRETunnel `json:"gre_tunnels"` - } `json:"result"` -} - -// GetMagicTransitGRETunnelResponse contains a response including zero or one GRE tunnels. -type GetMagicTransitGRETunnelResponse struct { - Response - Result struct { - GRETunnel MagicTransitGRETunnel `json:"gre_tunnel"` - } `json:"result"` -} - -// CreateMagicTransitGRETunnelsRequest is an array of GRE tunnels to create. -type CreateMagicTransitGRETunnelsRequest struct { - GRETunnels []MagicTransitGRETunnel `json:"gre_tunnels"` -} - -// UpdateMagicTransitGRETunnelResponse contains a response after updating a GRE Tunnel. -type UpdateMagicTransitGRETunnelResponse struct { - Response - Result struct { - Modified bool `json:"modified"` - ModifiedGRETunnel MagicTransitGRETunnel `json:"modified_gre_tunnel"` - } `json:"result"` -} - -// DeleteMagicTransitGRETunnelResponse contains a response after deleting a GRE Tunnel. -type DeleteMagicTransitGRETunnelResponse struct { - Response - Result struct { - Deleted bool `json:"deleted"` - DeletedGRETunnel MagicTransitGRETunnel `json:"deleted_gre_tunnel"` - } `json:"result"` -} - -// ListMagicTransitGRETunnels lists all GRE tunnels for a given account. -// -// API reference: https://api.cloudflare.com/#magic-gre-tunnels-list-gre-tunnels -func (api *API) ListMagicTransitGRETunnels(ctx context.Context, accountID string) ([]MagicTransitGRETunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/gre_tunnels", accountID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []MagicTransitGRETunnel{}, err - } - - result := ListMagicTransitGRETunnelsResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.GRETunnels, nil -} - -// GetMagicTransitGRETunnel returns zero or one GRE tunnel. -// -// API reference: https://api.cloudflare.com/#magic-gre-tunnels-gre-tunnel-details -func (api *API) GetMagicTransitGRETunnel(ctx context.Context, accountID string, id string) (MagicTransitGRETunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/gre_tunnels/%s", accountID, id) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return MagicTransitGRETunnel{}, err - } - - result := GetMagicTransitGRETunnelResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.GRETunnel, nil -} - -// CreateMagicTransitGRETunnels creates one or more GRE tunnels. -// -// API reference: https://api.cloudflare.com/#magic-gre-tunnels-create-gre-tunnels -func (api *API) CreateMagicTransitGRETunnels(ctx context.Context, accountID string, tunnels []MagicTransitGRETunnel) ([]MagicTransitGRETunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/gre_tunnels", accountID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, CreateMagicTransitGRETunnelsRequest{ - GRETunnels: tunnels, - }) - - if err != nil { - return []MagicTransitGRETunnel{}, err - } - - result := ListMagicTransitGRETunnelsResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.GRETunnels, nil -} - -// UpdateMagicTransitGRETunnel updates a GRE tunnel. -// -// API reference: https://api.cloudflare.com/#magic-gre-tunnels-update-gre-tunnel -func (api *API) UpdateMagicTransitGRETunnel(ctx context.Context, accountID string, id string, tunnel MagicTransitGRETunnel) (MagicTransitGRETunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/gre_tunnels/%s", accountID, id) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, tunnel) - - if err != nil { - return MagicTransitGRETunnel{}, err - } - - result := UpdateMagicTransitGRETunnelResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !result.Result.Modified { - return MagicTransitGRETunnel{}, errors.New(errMagicTransitGRETunnelNotModified) - } - - return result.Result.ModifiedGRETunnel, nil -} - -// DeleteMagicTransitGRETunnel deletes a GRE tunnel. -// -// API reference: https://api.cloudflare.com/#magic-gre-tunnels-delete-gre-tunnel -func (api *API) DeleteMagicTransitGRETunnel(ctx context.Context, accountID string, id string) (MagicTransitGRETunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/gre_tunnels/%s", accountID, id) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return MagicTransitGRETunnel{}, err - } - - result := DeleteMagicTransitGRETunnelResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !result.Result.Deleted { - return MagicTransitGRETunnel{}, errors.New(errMagicTransitGRETunnelNotDeleted) - } - - return result.Result.DeletedGRETunnel, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_ipsec_tunnel.go b/vendor/github.com/cloudflare/cloudflare-go/magic_transit_ipsec_tunnel.go deleted file mode 100644 index 6ac5f22..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_ipsec_tunnel.go +++ /dev/null @@ -1,214 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// Magic Transit IPsec Tunnel Error messages. -const ( - errMagicTransitIPsecTunnelNotModified = "When trying to modify IPsec tunnel, API returned modified: false" - errMagicTransitIPsecTunnelNotDeleted = "When trying to delete IPsec tunnel, API returned deleted: false" -) - -type RemoteIdentities struct { - HexID string `json:"hex_id"` - FQDNID string `json:"fqdn_id"` - UserID string `json:"user_id"` -} - -// MagicTransitIPsecTunnelPskMetadata contains metadata associated with PSK. -type MagicTransitIPsecTunnelPskMetadata struct { - LastGeneratedOn *time.Time `json:"last_generated_on,omitempty"` -} - -// MagicTransitIPsecTunnel contains information about an IPsec tunnel. -type MagicTransitIPsecTunnel struct { - ID string `json:"id,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - Name string `json:"name"` - CustomerEndpoint string `json:"customer_endpoint,omitempty"` - CloudflareEndpoint string `json:"cloudflare_endpoint"` - InterfaceAddress string `json:"interface_address"` - Description string `json:"description,omitempty"` - HealthCheck *MagicTransitTunnelHealthcheck `json:"health_check,omitempty"` - Psk string `json:"psk,omitempty"` - PskMetadata *MagicTransitIPsecTunnelPskMetadata `json:"psk_metadata,omitempty"` - RemoteIdentities *RemoteIdentities `json:"remote_identities,omitempty"` - AllowNullCipher bool `json:"allow_null_cipher"` -} - -// ListMagicTransitIPsecTunnelsResponse contains a response including IPsec tunnels. -type ListMagicTransitIPsecTunnelsResponse struct { - Response - Result struct { - IPsecTunnels []MagicTransitIPsecTunnel `json:"ipsec_tunnels"` - } `json:"result"` -} - -// GetMagicTransitIPsecTunnelResponse contains a response including zero or one IPsec tunnels. -type GetMagicTransitIPsecTunnelResponse struct { - Response - Result struct { - IPsecTunnel MagicTransitIPsecTunnel `json:"ipsec_tunnel"` - } `json:"result"` -} - -// CreateMagicTransitIPsecTunnelsRequest is an array of IPsec tunnels to create. -type CreateMagicTransitIPsecTunnelsRequest struct { - IPsecTunnels []MagicTransitIPsecTunnel `json:"ipsec_tunnels"` -} - -// UpdateMagicTransitIPsecTunnelResponse contains a response after updating an IPsec Tunnel. -type UpdateMagicTransitIPsecTunnelResponse struct { - Response - Result struct { - Modified bool `json:"modified"` - ModifiedIPsecTunnel MagicTransitIPsecTunnel `json:"modified_ipsec_tunnel"` - } `json:"result"` -} - -// DeleteMagicTransitIPsecTunnelResponse contains a response after deleting an IPsec Tunnel. -type DeleteMagicTransitIPsecTunnelResponse struct { - Response - Result struct { - Deleted bool `json:"deleted"` - DeletedIPsecTunnel MagicTransitIPsecTunnel `json:"deleted_ipsec_tunnel"` - } `json:"result"` -} - -// GenerateMagicTransitIPsecTunnelPSKResponse contains a response after generating IPsec Tunnel. -type GenerateMagicTransitIPsecTunnelPSKResponse struct { - Response - Result struct { - Psk string `json:"psk"` - PskMetadata *MagicTransitIPsecTunnelPskMetadata `json:"psk_metadata"` - } `json:"result"` -} - -// ListMagicTransitIPsecTunnels lists all IPsec tunnels for a given account -// -// API reference: https://api.cloudflare.com/#magic-ipsec-tunnels-list-ipsec-tunnels -func (api *API) ListMagicTransitIPsecTunnels(ctx context.Context, accountID string) ([]MagicTransitIPsecTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/ipsec_tunnels", accountID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []MagicTransitIPsecTunnel{}, err - } - - result := ListMagicTransitIPsecTunnelsResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.IPsecTunnels, nil -} - -// GetMagicTransitIPsecTunnel returns zero or one IPsec tunnel -// -// API reference: https://api.cloudflare.com/#magic-ipsec-tunnels-ipsec-tunnel-details -func (api *API) GetMagicTransitIPsecTunnel(ctx context.Context, accountID string, id string) (MagicTransitIPsecTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/ipsec_tunnels/%s", accountID, id) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return MagicTransitIPsecTunnel{}, err - } - - result := GetMagicTransitIPsecTunnelResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.IPsecTunnel, nil -} - -// CreateMagicTransitIPsecTunnels creates one or more IPsec tunnels -// -// API reference: https://api.cloudflare.com/#magic-ipsec-tunnels-create-ipsec-tunnels -func (api *API) CreateMagicTransitIPsecTunnels(ctx context.Context, accountID string, tunnels []MagicTransitIPsecTunnel) ([]MagicTransitIPsecTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/ipsec_tunnels", accountID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, CreateMagicTransitIPsecTunnelsRequest{ - IPsecTunnels: tunnels, - }) - - if err != nil { - return []MagicTransitIPsecTunnel{}, err - } - - result := ListMagicTransitIPsecTunnelsResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.IPsecTunnels, nil -} - -// UpdateMagicTransitIPsecTunnel updates an IPsec tunnel -// -// API reference: https://api.cloudflare.com/#magic-ipsec-tunnels-update-ipsec-tunnel -func (api *API) UpdateMagicTransitIPsecTunnel(ctx context.Context, accountID string, id string, tunnel MagicTransitIPsecTunnel) (MagicTransitIPsecTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/ipsec_tunnels/%s", accountID, id) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, tunnel) - - if err != nil { - return MagicTransitIPsecTunnel{}, err - } - - result := UpdateMagicTransitIPsecTunnelResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !result.Result.Modified { - return MagicTransitIPsecTunnel{}, errors.New(errMagicTransitIPsecTunnelNotModified) - } - - return result.Result.ModifiedIPsecTunnel, nil -} - -// DeleteMagicTransitIPsecTunnel deletes an IPsec Tunnel -// -// API reference: https://api.cloudflare.com/#magic-ipsec-tunnels-delete-ipsec-tunnel -func (api *API) DeleteMagicTransitIPsecTunnel(ctx context.Context, accountID string, id string) (MagicTransitIPsecTunnel, error) { - uri := fmt.Sprintf("/accounts/%s/magic/ipsec_tunnels/%s", accountID, id) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return MagicTransitIPsecTunnel{}, err - } - - result := DeleteMagicTransitIPsecTunnelResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !result.Result.Deleted { - return MagicTransitIPsecTunnel{}, errors.New(errMagicTransitIPsecTunnelNotDeleted) - } - - return result.Result.DeletedIPsecTunnel, nil -} - -// GenerateMagicTransitIPsecTunnelPSK generates a pre shared key (psk) for an IPsec tunnel -// -// API reference: https://api.cloudflare.com/#magic-ipsec-tunnels-generate-pre-shared-key-psk-for-ipsec-tunnels -func (api *API) GenerateMagicTransitIPsecTunnelPSK(ctx context.Context, accountID string, id string) (string, *MagicTransitIPsecTunnelPskMetadata, error) { - uri := fmt.Sprintf("/accounts/%s/magic/ipsec_tunnels/%s/psk_generate", accountID, id) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - - if err != nil { - return "", nil, err - } - - result := GenerateMagicTransitIPsecTunnelPSKResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return "", nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.Psk, result.Result.PskMetadata, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_static_routes.go b/vendor/github.com/cloudflare/cloudflare-go/magic_transit_static_routes.go deleted file mode 100644 index 1cce6cc..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_static_routes.go +++ /dev/null @@ -1,179 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// Magic Transit Static Routes Error messages. -const ( - errMagicTransitStaticRouteNotModified = "When trying to modify static route, API returned modified: false" - errMagicTransitStaticRouteNotDeleted = "When trying to delete static route, API returned deleted: false" -) - -// MagicTransitStaticRouteScope contains information about a static route's scope. -type MagicTransitStaticRouteScope struct { - ColoRegions []string `json:"colo_regions,omitempty"` - ColoNames []string `json:"colo_names,omitempty"` -} - -// MagicTransitStaticRoute contains information about a static route. -type MagicTransitStaticRoute struct { - ID string `json:"id,omitempty"` - Prefix string `json:"prefix"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - Nexthop string `json:"nexthop"` - Priority int `json:"priority,omitempty"` - Description string `json:"description,omitempty"` - Weight int `json:"weight,omitempty"` - Scope MagicTransitStaticRouteScope `json:"scope,omitempty"` -} - -// ListMagicTransitStaticRoutesResponse contains a response including Magic Transit static routes. -type ListMagicTransitStaticRoutesResponse struct { - Response - Result struct { - Routes []MagicTransitStaticRoute `json:"routes"` - } `json:"result"` -} - -// GetMagicTransitStaticRouteResponse contains a response including exactly one static route. -type GetMagicTransitStaticRouteResponse struct { - Response - Result struct { - Route MagicTransitStaticRoute `json:"route"` - } `json:"result"` -} - -// UpdateMagicTransitStaticRouteResponse contains a static route update response. -type UpdateMagicTransitStaticRouteResponse struct { - Response - Result struct { - Modified bool `json:"modified"` - ModifiedRoute MagicTransitStaticRoute `json:"modified_route"` - } `json:"result"` -} - -// DeleteMagicTransitStaticRouteResponse contains a static route deletion response. -type DeleteMagicTransitStaticRouteResponse struct { - Response - Result struct { - Deleted bool `json:"deleted"` - DeletedRoute MagicTransitStaticRoute `json:"deleted_route"` - } `json:"result"` -} - -// CreateMagicTransitStaticRoutesRequest is an array of static routes to create. -type CreateMagicTransitStaticRoutesRequest struct { - Routes []MagicTransitStaticRoute `json:"routes"` -} - -// ListMagicTransitStaticRoutes lists all static routes for a given account -// -// API reference: https://api.cloudflare.com/#magic-transit-static-routes-list-routes -func (api *API) ListMagicTransitStaticRoutes(ctx context.Context, accountID string) ([]MagicTransitStaticRoute, error) { - uri := fmt.Sprintf("/accounts/%s/magic/routes", accountID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []MagicTransitStaticRoute{}, err - } - - result := ListMagicTransitStaticRoutesResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.Routes, nil -} - -// GetMagicTransitStaticRoute returns exactly one static route -// -// API reference: https://api.cloudflare.com/#magic-transit-static-routes-route-details -func (api *API) GetMagicTransitStaticRoute(ctx context.Context, accountID, ID string) (MagicTransitStaticRoute, error) { - uri := fmt.Sprintf("/accounts/%s/magic/routes/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return MagicTransitStaticRoute{}, err - } - - result := GetMagicTransitStaticRouteResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.Route, nil -} - -// CreateMagicTransitStaticRoute creates a new static route -// -// API reference: https://api.cloudflare.com/#magic-transit-static-routes-create-routes -func (api *API) CreateMagicTransitStaticRoute(ctx context.Context, accountID string, route MagicTransitStaticRoute) ([]MagicTransitStaticRoute, error) { - uri := fmt.Sprintf("/accounts/%s/magic/routes", accountID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, CreateMagicTransitStaticRoutesRequest{ - Routes: []MagicTransitStaticRoute{ - route, - }, - }) - - if err != nil { - return []MagicTransitStaticRoute{}, err - } - - result := ListMagicTransitStaticRoutesResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.Routes, nil -} - -// UpdateMagicTransitStaticRoute updates a static route -// -// API reference: https://api.cloudflare.com/#magic-transit-static-routes-update-route -func (api *API) UpdateMagicTransitStaticRoute(ctx context.Context, accountID, ID string, route MagicTransitStaticRoute) (MagicTransitStaticRoute, error) { - uri := fmt.Sprintf("/accounts/%s/magic/routes/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, route) - - if err != nil { - return MagicTransitStaticRoute{}, err - } - - result := UpdateMagicTransitStaticRouteResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !result.Result.Modified { - return MagicTransitStaticRoute{}, errors.New(errMagicTransitStaticRouteNotModified) - } - - return result.Result.ModifiedRoute, nil -} - -// DeleteMagicTransitStaticRoute deletes a static route -// -// API reference: https://api.cloudflare.com/#magic-transit-static-routes-delete-route -func (api *API) DeleteMagicTransitStaticRoute(ctx context.Context, accountID, ID string) (MagicTransitStaticRoute, error) { - uri := fmt.Sprintf("/accounts/%s/magic/routes/%s", accountID, ID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return MagicTransitStaticRoute{}, err - } - - result := DeleteMagicTransitStaticRouteResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !result.Result.Deleted { - return MagicTransitStaticRoute{}, errors.New(errMagicTransitStaticRouteNotDeleted) - } - - return result.Result.DeletedRoute, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_tunnel_healthcheck.go b/vendor/github.com/cloudflare/cloudflare-go/magic_transit_tunnel_healthcheck.go deleted file mode 100644 index f79761e..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/magic_transit_tunnel_healthcheck.go +++ /dev/null @@ -1,8 +0,0 @@ -package cloudflare - -// MagicTransitTunnelHealthcheck contains information about a tunnel health check. -type MagicTransitTunnelHealthcheck struct { - Enabled bool `json:"enabled"` - Target string `json:"target,omitempty"` - Type string `json:"type,omitempty"` -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/managed_headers.go b/vendor/github.com/cloudflare/cloudflare-go/managed_headers.go deleted file mode 100644 index 11b2941..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/managed_headers.go +++ /dev/null @@ -1,77 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type ListManagedHeadersResponse struct { - Response - Result ManagedHeaders `json:"result"` -} - -type UpdateManagedHeadersParams struct { - ManagedHeaders -} - -type ManagedHeaders struct { - ManagedRequestHeaders []ManagedHeader `json:"managed_request_headers"` - ManagedResponseHeaders []ManagedHeader `json:"managed_response_headers"` -} - -type ManagedHeader struct { - ID string `json:"id"` - Enabled bool `json:"enabled"` - HasCoflict bool `json:"has_conflict,omitempty"` - ConflictsWith []string `json:"conflicts_with,omitempty"` -} - -type ListManagedHeadersParams struct { - Status string `url:"status,omitempty"` -} - -func (api *API) ListZoneManagedHeaders(ctx context.Context, rc *ResourceContainer, params ListManagedHeadersParams) (ManagedHeaders, error) { - if rc.Identifier == "" { - return ManagedHeaders{}, ErrMissingZoneID - } - - uri := buildURI(fmt.Sprintf("/zones/%s/managed_headers", rc.Identifier), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ManagedHeaders{}, err - } - - result := ListManagedHeadersResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ManagedHeaders{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -func (api *API) UpdateZoneManagedHeaders(ctx context.Context, rc *ResourceContainer, params UpdateManagedHeadersParams) (ManagedHeaders, error) { - if rc.Identifier == "" { - return ManagedHeaders{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/managed_headers", rc.Identifier) - - payload, err := json.Marshal(params.ManagedHeaders) - if err != nil { - return ManagedHeaders{}, err - } - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, payload) - if err != nil { - return ManagedHeaders{}, err - } - - result := ListManagedHeadersResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return ManagedHeaders{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/miscategorization.go b/vendor/github.com/cloudflare/cloudflare-go/miscategorization.go deleted file mode 100644 index 5164c53..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/miscategorization.go +++ /dev/null @@ -1,50 +0,0 @@ -package cloudflare - -import ( - "context" - "errors" - "fmt" - "net/http" -) - -var ( - // ErrMissingIP is for when ipv4 or ipv6 indicator was given but ip is missing. - ErrMissingIP = errors.New("ip is required when using 'ipv4' or 'ipv6' indicator type and is missing") - // ErrMissingURL is for when url or domain indicator was given but url is missing. - ErrMissingURL = errors.New("url is required when using 'domain' or 'url' indicator type and is missing") -) - -// MisCategorizationParameters represents the parameters for a miscategorization request. -type MisCategorizationParameters struct { - AccountID string - IndicatorType string `json:"indicator_type,omitempty"` - IP string `json:"ip,omitempty"` - URL string `json:"url,omitempty"` - ContentAdds []int `json:"content_adds,omitempty"` - ContentRemoves []int `json:"content_removes,omitempty"` - SecurityAdds []int `json:"security_adds,omitempty"` - SecurityRemoves []int `json:"security_removes,omitempty"` -} - -// CreateMiscategorization creates a miscatergorization. -// -// API Reference: https://api.cloudflare.com/#miscategorization-create-miscategorization -func (api *API) CreateMiscategorization(ctx context.Context, params MisCategorizationParameters) error { - if params.AccountID == "" { - return ErrMissingAccountID - } - if (params.IndicatorType == "ipv6" || params.IndicatorType == "ipv4") && params.IP == "" { - return ErrMissingIP - } - if (params.IndicatorType == "domain" || params.IndicatorType == "url") && params.URL == "" { - return ErrMissingURL - } - - uri := fmt.Sprintf("/accounts/%s/intel/miscategorization", params.AccountID) - _, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/mtls_certificates.go b/vendor/github.com/cloudflare/cloudflare-go/mtls_certificates.go deleted file mode 100644 index 5d92bd2..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/mtls_certificates.go +++ /dev/null @@ -1,214 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// MTLSAssociation represents the metadata for an existing association -// between a user-uploaded mTLS certificate and a Cloudflare service. -type MTLSAssociation struct { - Service string `json:"service"` - Status string `json:"status"` -} - -// MTLSAssociationResponse represents the response from the retrieval endpoint -// for mTLS certificate associations. -type MTLSAssociationResponse struct { - Response - Result []MTLSAssociation `json:"result"` -} - -// MTLSCertificate represents the metadata for a user-uploaded mTLS -// certificate. -type MTLSCertificate struct { - ID string `json:"id"` - Name string `json:"name"` - Issuer string `json:"issuer"` - Signature string `json:"signature"` - SerialNumber string `json:"serial_number"` - Certificates string `json:"certificates"` - CA bool `json:"ca"` - UploadedOn time.Time `json:"uploaded_on"` - UpdatedAt time.Time `json:"updated_at"` - ExpiresOn time.Time `json:"expires_on"` -} - -// MTLSCertificateResponse represents the response from endpoints relating to -// retrieving, creating, and deleting an mTLS certificate. -type MTLSCertificateResponse struct { - Response - Result MTLSCertificate `json:"result"` -} - -// MTLSCertificatesResponse represents the response from the mTLS certificate -// list endpoint. -type MTLSCertificatesResponse struct { - Response - Result []MTLSCertificate `json:"result"` - ResultInfo `json:"result_info"` -} - -// MTLSCertificateParams represents the data related to the mTLS certificate -// being uploaded. Name is an optional field. -type CreateMTLSCertificateParams struct { - Name string `json:"name"` - Certificates string `json:"certificates"` - PrivateKey string `json:"private_key"` - CA bool `json:"ca"` -} - -type ListMTLSCertificatesParams struct { - PaginationOptions - Limit int `url:"limit,omitempty"` - Offset int `url:"offset,omitempty"` - Name string `url:"name,omitempty"` - CA bool `url:"ca,omitempty"` -} - -type ListMTLSCertificateAssociationsParams struct { - CertificateID string -} - -var ( - ErrMissingCertificateID = errors.New("missing required certificate ID") -) - -// ListMTLSCertificates returns a list of all user-uploaded mTLS certificates. -// -// API reference: https://api.cloudflare.com/#mtls-certificate-management-list-mtls-certificates -func (api *API) ListMTLSCertificates(ctx context.Context, rc *ResourceContainer, params ListMTLSCertificatesParams) ([]MTLSCertificate, ResultInfo, error) { - if rc.Level != AccountRouteLevel { - return []MTLSCertificate{}, ResultInfo{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return []MTLSCertificate{}, ResultInfo{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/mtls_certificates", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, params) - if err != nil { - return []MTLSCertificate{}, ResultInfo{}, err - } - var r MTLSCertificatesResponse - if err := json.Unmarshal(res, &r); err != nil { - return []MTLSCertificate{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, r.ResultInfo, err -} - -// GetMTLSCertificate returns the metadata associated with a user-uploaded mTLS -// certificate. -// -// API reference: https://api.cloudflare.com/#mtls-certificate-management-get-mtls-certificate -func (api *API) GetMTLSCertificate(ctx context.Context, rc *ResourceContainer, certificateID string) (MTLSCertificate, error) { - if rc.Level != AccountRouteLevel { - return MTLSCertificate{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return MTLSCertificate{}, ErrMissingAccountID - } - - if certificateID == "" { - return MTLSCertificate{}, ErrMissingCertificateID - } - - uri := fmt.Sprintf("/accounts/%s/mtls_certificates/%s", rc.Identifier, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return MTLSCertificate{}, err - } - var r MTLSCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return MTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListMTLSCertificateAssociations returns a list of all existing associations -// between the mTLS certificate and Cloudflare services. -// -// API reference: https://api.cloudflare.com/#mtls-certificate-management-list-mtls-certificate-associations -func (api *API) ListMTLSCertificateAssociations(ctx context.Context, rc *ResourceContainer, params ListMTLSCertificateAssociationsParams) ([]MTLSAssociation, error) { - if rc.Level != AccountRouteLevel { - return []MTLSAssociation{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return []MTLSAssociation{}, ErrMissingAccountID - } - - if params.CertificateID == "" { - return []MTLSAssociation{}, ErrMissingCertificateID - } - - uri := fmt.Sprintf("/accounts/%s/mtls_certificates/%s/associations", rc.Identifier, params.CertificateID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []MTLSAssociation{}, err - } - var r MTLSAssociationResponse - if err := json.Unmarshal(res, &r); err != nil { - return []MTLSAssociation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateMTLSCertificate will create the provided certificate for use with mTLS -// enabled Cloudflare services. -// -// API reference: https://api.cloudflare.com/#mtls-certificate-management-upload-mtls-certificate -func (api *API) CreateMTLSCertificate(ctx context.Context, rc *ResourceContainer, params CreateMTLSCertificateParams) (MTLSCertificate, error) { - if rc.Level != AccountRouteLevel { - return MTLSCertificate{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return MTLSCertificate{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/mtls_certificates", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return MTLSCertificate{}, err - } - var r MTLSCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return MTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteMTLSCertificate will delete the specified mTLS certificate. -// -// API reference: https://api.cloudflare.com/#mtls-certificate-management-delete-mtls-certificate -func (api *API) DeleteMTLSCertificate(ctx context.Context, rc *ResourceContainer, certificateID string) (MTLSCertificate, error) { - if rc.Level != AccountRouteLevel { - return MTLSCertificate{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return MTLSCertificate{}, ErrMissingAccountID - } - - if certificateID == "" { - return MTLSCertificate{}, ErrMissingCertificateID - } - - uri := fmt.Sprintf("/accounts/%s/mtls_certificates/%s", rc.Identifier, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return MTLSCertificate{}, err - } - var r MTLSCertificateResponse - if err := json.Unmarshal(res, &r); err != nil { - return MTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/notifications.go b/vendor/github.com/cloudflare/cloudflare-go/notifications.go deleted file mode 100644 index 6d449c3..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/notifications.go +++ /dev/null @@ -1,446 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// NotificationMechanismData holds a single public facing mechanism data -// integation. -type NotificationMechanismData struct { - Name string `json:"name"` - ID string `json:"id"` -} - -// NotificationMechanismIntegrations is a list of all the integrations of a -// certain mechanism type e.g. all email integrations. -type NotificationMechanismIntegrations []NotificationMechanismData - -// NotificationPolicy represents the notification policy created along with -// the destinations. -type NotificationPolicy struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Enabled bool `json:"enabled"` - AlertType string `json:"alert_type"` - Mechanisms map[string]NotificationMechanismIntegrations `json:"mechanisms"` - Created time.Time `json:"created"` - Modified time.Time `json:"modified"` - Conditions map[string]interface{} `json:"conditions"` - Filters map[string][]string `json:"filters"` -} - -// NotificationPoliciesResponse holds the response for listing all -// notification policies for an account. -type NotificationPoliciesResponse struct { - Response - ResultInfo - Result []NotificationPolicy -} - -// NotificationPolicyResponse holds the response type when a single policy -// is retrieved. -type NotificationPolicyResponse struct { - Response - Result NotificationPolicy -} - -// NotificationWebhookIntegration describes the webhook information along -// with its status. -type NotificationWebhookIntegration struct { - ID string `json:"id"` - Name string `json:"name"` - Type string `json:"type"` - URL string `json:"url"` - CreatedAt time.Time `json:"created_at"` - LastSuccess *time.Time `json:"last_success"` - LastFailure *time.Time `json:"last_failure"` -} - -// NotificationWebhookResponse describes a single webhook retrieved. -type NotificationWebhookResponse struct { - Response - ResultInfo - Result NotificationWebhookIntegration -} - -// NotificationWebhooksResponse describes a list of webhooks retrieved. -type NotificationWebhooksResponse struct { - Response - ResultInfo - Result []NotificationWebhookIntegration -} - -// NotificationUpsertWebhooks describes a valid webhook request. -type NotificationUpsertWebhooks struct { - Name string `json:"name"` - URL string `json:"url"` - Secret string `json:"secret"` -} - -// NotificationPagerDutyResource describes a PagerDuty integration. -type NotificationPagerDutyResource struct { - ID string `json:"id"` - Name string `json:"name"` -} - -// NotificationPagerDutyResponse describes the PagerDuty integration -// retrieved. -type NotificationPagerDutyResponse struct { - Response - ResultInfo - Result NotificationPagerDutyResource -} - -// NotificationResource describes the id of an inserted/updated/deleted -// resource. -type NotificationResource struct { - ID string -} - -// SaveResponse is returned when a resource is inserted/updated/deleted. -type SaveResponse struct { - Response - Result NotificationResource -} - -// NotificationMechanismMetaData represents the state of the delivery -// mechanism. -type NotificationMechanismMetaData struct { - Eligible bool `json:"eligible"` - Ready bool `json:"ready"` - Type string `json:"type"` -} - -// NotificationMechanisms are the different possible delivery mechanisms. -type NotificationMechanisms struct { - Email NotificationMechanismMetaData `json:"email"` - PagerDuty NotificationMechanismMetaData `json:"pagerduty"` - Webhooks NotificationMechanismMetaData `json:"webhooks,omitempty"` -} - -// NotificationEligibilityResponse describes the eligible mechanisms that -// can be configured for a notification. -type NotificationEligibilityResponse struct { - Response - Result NotificationMechanisms -} - -// NotificationsGroupedByProduct are grouped by products. -type NotificationsGroupedByProduct map[string][]NotificationAlertWithDescription - -// NotificationAlertWithDescription represents the alert/notification -// available. -type NotificationAlertWithDescription struct { - DisplayName string `json:"display_name"` - Type string `json:"type"` - Description string `json:"description"` -} - -// NotificationAvailableAlertsResponse describes the available -// alerts/notifications grouped by products. -type NotificationAvailableAlertsResponse struct { - Response - Result NotificationsGroupedByProduct -} - -// NotificationHistory describes the history -// of notifications sent for an account. -type NotificationHistory struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - AlertBody string `json:"alert_body"` - AlertType string `json:"alert_type"` - Mechanism string `json:"mechanism"` - MechanismType string `json:"mechanism_type"` - Sent time.Time `json:"sent"` -} - -// NotificationHistoryResponse describes the notification history -// response for an account for a specific time period. -type NotificationHistoryResponse struct { - Response - ResultInfo `json:"result_info"` - Result []NotificationHistory -} - -// ListNotificationPolicies will return the notification policies -// created by a user for a specific account. -// -// API Reference: https://api.cloudflare.com/#notification-policies-properties -func (api *API) ListNotificationPolicies(ctx context.Context, accountID string) (NotificationPoliciesResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/policies", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, baseURL, nil) - if err != nil { - return NotificationPoliciesResponse{}, err - } - var r NotificationPoliciesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} - -// GetNotificationPolicy returns a specific created by a user, given the account -// id and the policy id. -// -// API Reference: https://api.cloudflare.com/#notification-policies-properties -func (api *API) GetNotificationPolicy(ctx context.Context, accountID, policyID string) (NotificationPolicyResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/policies/%s", accountID, policyID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, baseURL, nil) - if err != nil { - return NotificationPolicyResponse{}, err - } - var r NotificationPolicyResponse - err = json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} - -// CreateNotificationPolicy creates a notification policy for an account. -// -// API Reference: https://api.cloudflare.com/#notification-policies-create-notification-policy -func (api *API) CreateNotificationPolicy(ctx context.Context, accountID string, policy NotificationPolicy) (SaveResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/policies", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, baseURL, policy) - if err != nil { - return SaveResponse{}, err - } - return unmarshalNotificationSaveResponse(res) -} - -// UpdateNotificationPolicy updates a notification policy, given the -// account id and the policy id and returns the policy id. -// -// API Reference: https://api.cloudflare.com/#notification-policies-update-notification-policy -func (api *API) UpdateNotificationPolicy(ctx context.Context, accountID string, policy *NotificationPolicy) (SaveResponse, error) { - if policy == nil { - return SaveResponse{}, fmt.Errorf("policy cannot be nil") - } - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/policies/%s", accountID, policy.ID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, baseURL, policy) - if err != nil { - return SaveResponse{}, err - } - return unmarshalNotificationSaveResponse(res) -} - -// DeleteNotificationPolicy deletes a notification policy for an account. -// -// API Reference: https://api.cloudflare.com/#notification-policies-delete-notification-policy -func (api *API) DeleteNotificationPolicy(ctx context.Context, accountID, policyID string) (SaveResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/policies/%s", accountID, policyID) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, baseURL, nil) - if err != nil { - return SaveResponse{}, err - } - return unmarshalNotificationSaveResponse(res) -} - -// ListNotificationWebhooks will return the webhook destinations configured -// for an account. -// -// API Reference: https://api.cloudflare.com/#notification-webhooks-list-webhooks -func (api *API) ListNotificationWebhooks(ctx context.Context, accountID string) (NotificationWebhooksResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/destinations/webhooks", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, baseURL, nil) - if err != nil { - return NotificationWebhooksResponse{}, err - } - var r NotificationWebhooksResponse - err = json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} - -// CreateNotificationWebhooks will help connect a webhooks destination. -// A test message will be sent to the webhooks endpoint during creation. -// If added successfully, the webhooks can be setup as a destination mechanism -// while creating policies. -// -// Notifications will be posted to this URL. -// -// API Reference: https://api.cloudflare.com/#notification-webhooks-create-webhook -func (api *API) CreateNotificationWebhooks(ctx context.Context, accountID string, webhooks *NotificationUpsertWebhooks) (SaveResponse, error) { - if webhooks == nil { - return SaveResponse{}, fmt.Errorf("webhooks cannot be nil") - } - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/destinations/webhooks", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, baseURL, webhooks) - if err != nil { - return SaveResponse{}, err - } - - return unmarshalNotificationSaveResponse(res) -} - -// GetNotificationWebhooks will return a specific webhook destination, -// given the account and webhooks ids. -// -// API Reference: https://api.cloudflare.com/#notification-webhooks-get-webhook -func (api *API) GetNotificationWebhooks(ctx context.Context, accountID, webhookID string) (NotificationWebhookResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/destinations/webhooks/%s", accountID, webhookID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, baseURL, nil) - if err != nil { - return NotificationWebhookResponse{}, err - } - var r NotificationWebhookResponse - err = json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} - -// UpdateNotificationWebhooks will update a particular webhook's name, -// given the account and webhooks ids. -// -// The webhook url and secret cannot be updated. -// -// API Reference: https://api.cloudflare.com/#notification-webhooks-update-webhook -func (api *API) UpdateNotificationWebhooks(ctx context.Context, accountID, webhookID string, webhooks *NotificationUpsertWebhooks) (SaveResponse, error) { - if webhooks == nil { - return SaveResponse{}, fmt.Errorf("webhooks cannot be nil") - } - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/destinations/webhooks/%s", accountID, webhookID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, baseURL, webhooks) - if err != nil { - return SaveResponse{}, err - } - - return unmarshalNotificationSaveResponse(res) -} - -// DeleteNotificationWebhooks will delete a webhook, given the account and -// webhooks ids. Deleting the webhooks will remove it from any connected -// notification policies. -// -// API Reference: https://api.cloudflare.com/#notification-webhooks-delete-webhook -func (api *API) DeleteNotificationWebhooks(ctx context.Context, accountID, webhookID string) (SaveResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/destinations/webhooks/%s", accountID, webhookID) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, baseURL, nil) - if err != nil { - return SaveResponse{}, err - } - - return unmarshalNotificationSaveResponse(res) -} - -// ListPagerDutyNotificationDestinations will return the pagerduty -// destinations configured for an account. -// -// API Reference: https://api.cloudflare.com/#notification-destinations-with-pagerduty-list-pagerduty-services -func (api *API) ListPagerDutyNotificationDestinations(ctx context.Context, accountID string) (NotificationPagerDutyResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/destinations/pagerduty", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, baseURL, nil) - if err != nil { - return NotificationPagerDutyResponse{}, err - } - var r NotificationPagerDutyResponse - err = json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} - -// GetEligibleNotificationDestinations will return the types of -// destinations an account is eligible to configure. -// -// API Reference: https://api.cloudflare.com/#notification-mechanism-eligibility-properties -func (api *API) GetEligibleNotificationDestinations(ctx context.Context, accountID string) (NotificationEligibilityResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/destinations/eligible", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, baseURL, nil) - if err != nil { - return NotificationEligibilityResponse{}, err - } - var r NotificationEligibilityResponse - err = json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} - -// GetAvailableNotificationTypes will return the alert types available for -// a given account. -// -// API Reference: https://api.cloudflare.com/#notification-mechanism-eligibility-properties -func (api *API) GetAvailableNotificationTypes(ctx context.Context, accountID string) (NotificationAvailableAlertsResponse, error) { - baseURL := fmt.Sprintf("/accounts/%s/alerting/v3/available_alerts", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, baseURL, nil) - if err != nil { - return NotificationAvailableAlertsResponse{}, err - } - var r NotificationAvailableAlertsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} - -// TimeRange is an object for filtering the alert history based on timestamp. -type TimeRange struct { - Since string `json:"since,omitempty" url:"since,omitempty"` - Before string `json:"before,omitempty" url:"before,omitempty"` -} - -// AlertHistoryFilter is an object for filtering the alert history response from the api. -type AlertHistoryFilter struct { - TimeRange - PaginationOptions -} - -// ListNotificationHistory will return the history of alerts sent for -// a given account. The time period varies based on zone plan. -// Free, Biz, Pro = 30 days -// Ent = 90 days -// -// API Reference: https://api.cloudflare.com/#notification-history-list-history -func (api *API) ListNotificationHistory(ctx context.Context, accountID string, alertHistoryFilter AlertHistoryFilter) ([]NotificationHistory, ResultInfo, error) { - uri := buildURI(fmt.Sprintf("/accounts/%s/alerting/v3/history", accountID), alertHistoryFilter) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []NotificationHistory{}, ResultInfo{}, err - } - var r NotificationHistoryResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []NotificationHistory{}, ResultInfo{}, err - } - return r.Result, r.ResultInfo, nil -} - -// unmarshal will unmarshal bytes and return a SaveResponse. -func unmarshalNotificationSaveResponse(res []byte) (SaveResponse, error) { - var r SaveResponse - err := json.Unmarshal(res, &r) - if err != nil { - return r, err - } - return r, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/options.go b/vendor/github.com/cloudflare/cloudflare-go/options.go deleted file mode 100644 index 1ed8919..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/options.go +++ /dev/null @@ -1,118 +0,0 @@ -package cloudflare - -import ( - "net/http" - - "time" - - "golang.org/x/time/rate" -) - -// Option is a functional option for configuring the API client. -type Option func(*API) error - -// HTTPClient accepts a custom *http.Client for making API calls. -func HTTPClient(client *http.Client) Option { - return func(api *API) error { - api.httpClient = client - return nil - } -} - -// Headers allows you to set custom HTTP headers when making API calls (e.g. for -// satisfying HTTP proxies, or for debugging). -func Headers(headers http.Header) Option { - return func(api *API) error { - api.headers = headers - return nil - } -} - -// UsingAccount allows you to apply account-level changes (Load Balancing, -// Railguns) to an account instead. -// -// Deprecated: Resources should define the `AccountID` parameter explicitly. -func UsingAccount(accountID string) Option { - return func(api *API) error { - api.AccountID = accountID - return nil - } -} - -// UsingRateLimit applies a non-default rate limit to client API requests -// If not specified the default of 4rps will be applied. -func UsingRateLimit(rps float64) Option { - return func(api *API) error { - // because ratelimiter doesnt do any windowing - // setting burst makes it difficult to enforce a fixed rate - // so setting it equal to 1 this effectively disables bursting - // this doesn't check for sensible values, ultimately the api will enforce that the value is ok - api.rateLimiter = rate.NewLimiter(rate.Limit(rps), 1) - return nil - } -} - -// UsingRetryPolicy applies a non-default number of retries and min/max retry delays -// This will be used when the client exponentially backs off after errored requests. -func UsingRetryPolicy(maxRetries int, minRetryDelaySecs int, maxRetryDelaySecs int) Option { - // seconds is very granular for a minimum delay - but this is only in case of failure - return func(api *API) error { - api.retryPolicy = RetryPolicy{ - MaxRetries: maxRetries, - MinRetryDelay: time.Duration(minRetryDelaySecs) * time.Second, - MaxRetryDelay: time.Duration(maxRetryDelaySecs) * time.Second, - } - return nil - } -} - -// UsingLogger can be set if you want to get log output from this API instance -// By default no log output is emitted. -func UsingLogger(logger Logger) Option { - return func(api *API) error { - api.logger = logger - return nil - } -} - -// UserAgent can be set if you want to send a software name and version for HTTP access logs. -// It is recommended to set it in order to help future Customer Support diagnostics -// and prevent collateral damage by sharing generic User-Agent string with abusive users. -// E.g. "my-software/1.2.3". By default generic Go User-Agent is used. -func UserAgent(userAgent string) Option { - return func(api *API) error { - api.UserAgent = userAgent - return nil - } -} - -// BaseURL allows you to override the default HTTP base URL used for API calls. -func BaseURL(baseURL string) Option { - return func(api *API) error { - api.BaseURL = baseURL - return nil - } -} - -func Debug(debug bool) Option { - return func(api *API) error { - api.Debug = debug - return nil - } -} - -// parseOptions parses the supplied options functions and returns a configured -// *API instance. -func (api *API) parseOptions(opts ...Option) error { - // Range over each options function and apply it to our API type to - // configure it. Options functions are applied in order, with any - // conflicting options overriding earlier calls. - for _, option := range opts { - err := option(api) - if err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/origin_ca.go b/vendor/github.com/cloudflare/cloudflare-go/origin_ca.go deleted file mode 100644 index 45c8951..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/origin_ca.go +++ /dev/null @@ -1,232 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io" - "net/http" - "time" -) - -// OriginCACertificate represents a Cloudflare-issued certificate. -// -// API reference: https://api.cloudflare.com/#cloudflare-ca -type OriginCACertificate struct { - ID string `json:"id"` - Certificate string `json:"certificate"` - Hostnames []string `json:"hostnames"` - ExpiresOn time.Time `json:"expires_on"` - RequestType string `json:"request_type"` - RequestValidity int `json:"requested_validity"` - RevokedAt time.Time `json:"revoked_at,omitempty"` - CSR string `json:"csr"` -} - -type CreateOriginCertificateParams struct { - ID string `json:"id"` - Certificate string `json:"certificate"` - Hostnames []string `json:"hostnames"` - ExpiresOn time.Time `json:"expires_on"` - RequestType string `json:"request_type"` - RequestValidity int `json:"requested_validity"` - RevokedAt time.Time `json:"revoked_at,omitempty"` - CSR string `json:"csr"` -} - -// UnmarshalJSON handles custom parsing from an API response to an OriginCACertificate -// http://choly.ca/post/go-json-marshalling/ -func (c *OriginCACertificate) UnmarshalJSON(data []byte) error { - type alias OriginCACertificate - - aux := &struct { - ExpiresOn string `json:"expires_on"` - *alias - }{ - alias: (*alias)(c), - } - - var err error - - if err = json.Unmarshal(data, &aux); err != nil { - return err - } - - // This format comes from time.Time.String() source - c.ExpiresOn, err = time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", aux.ExpiresOn) - - if err != nil { - c.ExpiresOn, err = time.Parse(time.RFC3339, aux.ExpiresOn) - } - - if err != nil { - return err - } - - return nil -} - -// ListOriginCertificatesParams represents the parameters used to list -// Cloudflare-issued certificates. -type ListOriginCertificatesParams struct { - ZoneID string `url:"zone_id,omitempty"` -} - -// OriginCACertificateID represents the ID of the revoked certificate from the Revoke Certificate endpoint. -type OriginCACertificateID struct { - ID string `json:"id"` -} - -// originCACertificateResponse represents the response from the Create Certificate and the Certificate Details endpoints. -type originCACertificateResponse struct { - Response - Result OriginCACertificate `json:"result"` -} - -// originCACertificateResponseList represents the response from the List Certificates endpoint. -type originCACertificateResponseList struct { - Response - Result []OriginCACertificate `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// originCACertificateResponseRevoke represents the response from the Revoke Certificate endpoint. -type originCACertificateResponseRevoke struct { - Response - Result OriginCACertificateID `json:"result"` -} - -// CreateOriginCACertificate creates a Cloudflare-signed certificate. -// -// API reference: https://api.cloudflare.com/#cloudflare-ca-create-certificate -func (api *API) CreateOriginCACertificate(ctx context.Context, params CreateOriginCertificateParams) (*OriginCACertificate, error) { - res, err := api.makeRequestContext(ctx, http.MethodPost, "/certificates", params) - if err != nil { - return &OriginCACertificate{}, err - } - - var originResponse *originCACertificateResponse - - err = json.Unmarshal(res, &originResponse) - - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !originResponse.Success { - return nil, errors.New(errRequestNotSuccessful) - } - - return &originResponse.Result, nil -} - -// ListOriginCACertificates lists all Cloudflare-issued certificates. -// -// API reference: https://api.cloudflare.com/#cloudflare-ca-list-certificates -func (api *API) ListOriginCACertificates(ctx context.Context, params ListOriginCertificatesParams) ([]OriginCACertificate, error) { - uri := buildURI("/certificates", params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - - if err != nil { - return nil, err - } - - var originResponse *originCACertificateResponseList - - err = json.Unmarshal(res, &originResponse) - - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !originResponse.Success { - return nil, errors.New(errRequestNotSuccessful) - } - - return originResponse.Result, nil -} - -// GetOriginCACertificate returns the details for a Cloudflare-issued -// certificate. -// -// API reference: https://api.cloudflare.com/#cloudflare-ca-certificate-details -func (api *API) GetOriginCACertificate(ctx context.Context, certificateID string) (*OriginCACertificate, error) { - uri := fmt.Sprintf("/certificates/%s", certificateID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - - if err != nil { - return nil, err - } - - var originResponse *originCACertificateResponse - - err = json.Unmarshal(res, &originResponse) - - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !originResponse.Success { - return nil, errors.New(errRequestNotSuccessful) - } - - return &originResponse.Result, nil -} - -// RevokeOriginCACertificate revokes a created certificate for a zone. -// -// API reference: https://api.cloudflare.com/#cloudflare-ca-revoke-certificate -func (api *API) RevokeOriginCACertificate(ctx context.Context, certificateID string) (*OriginCACertificateID, error) { - uri := fmt.Sprintf("/certificates/%s", certificateID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return nil, err - } - - var originResponse *originCACertificateResponseRevoke - - err = json.Unmarshal(res, &originResponse) - - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !originResponse.Success { - return nil, errors.New(errRequestNotSuccessful) - } - - return &originResponse.Result, nil -} - -// Gets the Cloudflare Origin CA Root Certificate for a given algorithm in PEM format. -// Algorithm must be one of ['ecc', 'rsa']. -func GetOriginCARootCertificate(algorithm string) ([]byte, error) { - var url string - switch algorithm { - case "ecc": - url = originCARootCertEccURL - case "rsa": - url = originCARootCertRsaURL - default: - return nil, fmt.Errorf("invalid algorithm: must be one of ['ecc', 'rsa']") - } - - resp, err := http.Get(url) //nolint:gosec - if err != nil { - return nil, fmt.Errorf("HTTP request failed: %w", err) - } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return nil, errors.New(errRequestNotSuccessful) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("Response body could not be read: %w", err) - } - - return body, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/page_rules.go b/vendor/github.com/cloudflare/cloudflare-go/page_rules.go deleted file mode 100644 index 033bd7f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/page_rules.go +++ /dev/null @@ -1,239 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// PageRuleTarget is the target to evaluate on a request. -// -// Currently Target must always be "url" and Operator must be "matches". Value -// is the URL pattern to match against. -type PageRuleTarget struct { - Target string `json:"target"` - Constraint struct { - Operator string `json:"operator"` - Value string `json:"value"` - } `json:"constraint"` -} - -/* -PageRuleAction is the action to take when the target is matched. - -Valid IDs are: - - always_online - always_use_https - automatic_https_rewrites - browser_cache_ttl - browser_check - bypass_cache_on_cookie - cache_by_device_type - cache_deception_armor - cache_level - cache_key_fields - cache_on_cookie - disable_apps - disable_performance - disable_railgun - disable_security - edge_cache_ttl - email_obfuscation - explicit_cache_control - forwarding_url - host_header_override - ip_geolocation - minify - mirage - opportunistic_encryption - origin_error_page_pass_thru - polish - resolve_override - respect_strong_etag - response_buffering - rocket_loader - security_level - server_side_exclude - sort_query_string_for_cache - ssl - true_client_ip_header - waf -*/ -type PageRuleAction struct { - ID string `json:"id"` - Value interface{} `json:"value"` -} - -// PageRuleActions maps API action IDs to human-readable strings. -var PageRuleActions = map[string]string{ - "always_online": "Always Online", // Value of type string - "always_use_https": "Always Use HTTPS", // Value of type interface{} - "automatic_https_rewrites": "Automatic HTTPS Rewrites", // Value of type string - "browser_cache_ttl": "Browser Cache TTL", // Value of type int - "browser_check": "Browser Integrity Check", // Value of type string - "bypass_cache_on_cookie": "Bypass Cache on Cookie", // Value of type string - "cache_by_device_type": "Cache By Device Type", // Value of type string - "cache_deception_armor": "Cache Deception Armor", // Value of type string - "cache_level": "Cache Level", // Value of type string - "cache_key_fields": "Custom Cache Key", // Value of type map[string]interface - "cache_on_cookie": "Cache On Cookie", // Value of type string - "disable_apps": "Disable Apps", // Value of type interface{} - "disable_performance": "Disable Performance", // Value of type interface{} - "disable_railgun": "Disable Railgun", // Value of type string - "disable_security": "Disable Security", // Value of type interface{} - "edge_cache_ttl": "Edge Cache TTL", // Value of type int - "email_obfuscation": "Email Obfuscation", // Value of type string - "explicit_cache_control": "Origin Cache Control", // Value of type string - "forwarding_url": "Forwarding URL", // Value of type map[string]interface - "host_header_override": "Host Header Override", // Value of type string - "ip_geolocation": "IP Geolocation Header", // Value of type string - "minify": "Minify", // Value of type map[string]interface - "mirage": "Mirage", // Value of type string - "opportunistic_encryption": "Opportunistic Encryption", // Value of type string - "origin_error_page_pass_thru": "Origin Error Page Pass-thru", // Value of type string - "polish": "Polish", // Value of type string - "resolve_override": "Resolve Override", // Value of type string - "respect_strong_etag": "Respect Strong ETags", // Value of type string - "response_buffering": "Response Buffering", // Value of type string - "rocket_loader": "Rocker Loader", // Value of type string - "security_level": "Security Level", // Value of type string - "server_side_exclude": "Server Side Excludes", // Value of type string - "sort_query_string_for_cache": "Query String Sort", // Value of type string - "ssl": "SSL", // Value of type string - "true_client_ip_header": "True Client IP Header", // Value of type string - "waf": "Web Application Firewall", // Value of type string -} - -// PageRule describes a Page Rule. -type PageRule struct { - ID string `json:"id,omitempty"` - Targets []PageRuleTarget `json:"targets"` - Actions []PageRuleAction `json:"actions"` - Priority int `json:"priority"` - Status string `json:"status"` - ModifiedOn time.Time `json:"modified_on,omitempty"` - CreatedOn time.Time `json:"created_on,omitempty"` -} - -// PageRuleDetailResponse is the API response, containing a single PageRule. -type PageRuleDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result PageRule `json:"result"` -} - -// PageRulesResponse is the API response, containing an array of PageRules. -type PageRulesResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result []PageRule `json:"result"` -} - -// CreatePageRule creates a new Page Rule for a zone. -// -// API reference: https://api.cloudflare.com/#page-rules-for-a-zone-create-a-page-rule -func (api *API) CreatePageRule(ctx context.Context, zoneID string, rule PageRule) (*PageRule, error) { - uri := fmt.Sprintf("/zones/%s/pagerules", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, rule) - if err != nil { - return nil, err - } - var r PageRuleDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return &r.Result, nil -} - -// ListPageRules returns all Page Rules for a zone. -// -// API reference: https://api.cloudflare.com/#page-rules-for-a-zone-list-page-rules -func (api *API) ListPageRules(ctx context.Context, zoneID string) ([]PageRule, error) { - uri := fmt.Sprintf("/zones/%s/pagerules", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []PageRule{}, err - } - var r PageRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []PageRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// PageRule fetches detail about one Page Rule for a zone. -// -// API reference: https://api.cloudflare.com/#page-rules-for-a-zone-page-rule-details -func (api *API) PageRule(ctx context.Context, zoneID, ruleID string) (PageRule, error) { - uri := fmt.Sprintf("/zones/%s/pagerules/%s", zoneID, ruleID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PageRule{}, err - } - var r PageRuleDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PageRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ChangePageRule lets you change individual settings for a Page Rule. This is -// in contrast to UpdatePageRule which replaces the entire Page Rule. -// -// API reference: https://api.cloudflare.com/#page-rules-for-a-zone-change-a-page-rule -func (api *API) ChangePageRule(ctx context.Context, zoneID, ruleID string, rule PageRule) error { - uri := fmt.Sprintf("/zones/%s/pagerules/%s", zoneID, ruleID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, rule) - if err != nil { - return err - } - var r PageRuleDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// UpdatePageRule lets you replace a Page Rule. This is in contrast to -// ChangePageRule which lets you change individual settings. -// -// API reference: https://api.cloudflare.com/#page-rules-for-a-zone-update-a-page-rule -func (api *API) UpdatePageRule(ctx context.Context, zoneID, ruleID string, rule PageRule) error { - uri := fmt.Sprintf("/zones/%s/pagerules/%s", zoneID, ruleID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, rule) - if err != nil { - return err - } - var r PageRuleDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// DeletePageRule deletes a Page Rule for a zone. -// -// API reference: https://api.cloudflare.com/#page-rules-for-a-zone-delete-a-page-rule -func (api *API) DeletePageRule(ctx context.Context, zoneID, ruleID string) error { - uri := fmt.Sprintf("/zones/%s/pagerules/%s", zoneID, ruleID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r PageRuleDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/pages_deployment.go b/vendor/github.com/cloudflare/cloudflare-go/pages_deployment.go deleted file mode 100644 index 4eb5c8f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/pages_deployment.go +++ /dev/null @@ -1,326 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// SizeOptions can be passed to a list request to configure size and cursor location. -// These values will be defaulted if omitted. -// -// This should be swapped to ResultInfoCursors once the types are corrected. -type SizeOptions struct { - Size int `json:"size,omitempty" url:"size,omitempty"` - Before *int `json:"before,omitempty" url:"before,omitempty"` - After *int `json:"after,omitempty" url:"after,omitempty"` -} - -// PagesDeploymentStageLogs represents the logs for a Pages deployment stage. -type PagesDeploymentStageLogs struct { - Name string `json:"name"` - StartedOn *time.Time `json:"started_on"` - EndedOn *time.Time `json:"ended_on"` - Status string `json:"status"` - Start int `json:"start"` - End int `json:"end"` - Total int `json:"total"` - Data []PagesDeploymentStageLogEntry `json:"data"` -} - -// PagesDeploymentStageLogEntry represents a single log entry in a Pages deployment stage. -type PagesDeploymentStageLogEntry struct { - ID int `json:"id"` - Timestamp *time.Time `json:"timestamp"` - Message string `json:"message"` -} - -// PagesDeploymentLogs represents the logs for a Pages deployment. -type PagesDeploymentLogs struct { - Total int `json:"total"` - IncludesContainerLogs bool `json:"includes_container_logs"` - Data []PagesDeploymentLogEntry `json:"data"` -} - -// PagesDeploymentLogEntry represents a single log entry in a Pages deployment. -type PagesDeploymentLogEntry struct { - Timestamp *time.Time `json:"ts"` - Line string `json:"line"` -} - -type pagesDeploymentListResponse struct { - Response - Result []PagesProjectDeployment `json:"result"` - ResultInfo `json:"result_info"` -} - -type pagesDeploymentResponse struct { - Response - Result PagesProjectDeployment `json:"result"` -} - -type pagesDeploymentStageLogsResponse struct { - Response - Result PagesDeploymentStageLogs `json:"result"` - ResultInfo `json:"result_info"` -} - -type pagesDeploymentLogsResponse struct { - Response - Result PagesDeploymentLogs `json:"result"` - ResultInfo `json:"result_info"` -} - -type ListPagesDeploymentsParams struct { - ProjectName string - - PaginationOptions -} - -type GetPagesDeploymentInfoParams struct { - ProjectName string - DeploymentID string -} - -type GetPagesDeploymentStageLogsParams struct { - ProjectName string - DeploymentID string - StageName string - - SizeOptions -} - -type GetPagesDeploymentLogsParams struct { - ProjectName string - DeploymentID string - - SizeOptions -} - -type DeletePagesDeploymentParams struct { - ProjectName string - DeploymentID string -} - -type CreatePagesDeploymentParams struct { - ProjectName string -} - -type RetryPagesDeploymentParams struct { - ProjectName string - DeploymentID string -} - -type RollbackPagesDeploymentParams struct { - ProjectName string - DeploymentID string -} - -var ( - ErrMissingProjectName = errors.New("required missing project name") - ErrMissingDeploymentID = errors.New("required missing deployment ID") - ErrMissingStageName = errors.New("required missing stage name") -) - -// ListPagesDeployments returns all deployments for a Pages project. -// -// API reference: https://api.cloudflare.com/#pages-deployment-get-deployments -func (api *API) ListPagesDeployments(ctx context.Context, rc *ResourceContainer, params ListPagesDeploymentsParams) ([]PagesProjectDeployment, ResultInfo, error) { - if rc.Identifier == "" { - return []PagesProjectDeployment{}, ResultInfo{}, ErrMissingAccountID - } - - if params.ProjectName == "" { - return []PagesProjectDeployment{}, ResultInfo{}, ErrMissingProjectName - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments", rc.Identifier, params.ProjectName), params.PaginationOptions) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []PagesProjectDeployment{}, ResultInfo{}, err - } - var r pagesDeploymentListResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []PagesProjectDeployment{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, r.ResultInfo, nil -} - -// GetPagesDeploymentInfo returns a deployment for a Pages project. -// -// API reference: https://api.cloudflare.com/#pages-deployment-get-deployment-info -func (api *API) GetPagesDeploymentInfo(ctx context.Context, rc *ResourceContainer, projectName, deploymentID string) (PagesProjectDeployment, error) { - if rc.Identifier == "" { - return PagesProjectDeployment{}, ErrMissingAccountID - } - - if projectName == "" { - return PagesProjectDeployment{}, ErrMissingProjectName - } - - if deploymentID == "" { - return PagesProjectDeployment{}, ErrMissingDeploymentID - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments/%s", rc.Identifier, projectName, deploymentID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PagesProjectDeployment{}, err - } - var r pagesDeploymentResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// GetPagesDeploymentLogs returns the logs for a Pages deployment. -// -// API reference: https://api.cloudflare.com/#pages-deployment-get-deployment-logs -func (api *API) GetPagesDeploymentLogs(ctx context.Context, rc *ResourceContainer, params GetPagesDeploymentLogsParams) (PagesDeploymentLogs, error) { - if rc.Identifier == "" { - return PagesDeploymentLogs{}, ErrMissingAccountID - } - - if params.ProjectName == "" { - return PagesDeploymentLogs{}, ErrMissingProjectName - } - - if params.DeploymentID == "" { - return PagesDeploymentLogs{}, ErrMissingDeploymentID - } - - uri := buildURI( - fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments/%s/history/logs", rc.Identifier, params.ProjectName, params.DeploymentID), - params.SizeOptions, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PagesDeploymentLogs{}, err - } - var r pagesDeploymentLogsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesDeploymentLogs{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeletePagesDeployment deletes a Pages deployment. -// -// API reference: https://api.cloudflare.com/#pages-deployment-delete-deployment -func (api *API) DeletePagesDeployment(ctx context.Context, rc *ResourceContainer, projectName, deploymentID string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - if projectName == "" { - return ErrMissingProjectName - } - - if deploymentID == "" { - return ErrMissingDeploymentID - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments/%s", rc.Identifier, projectName, deploymentID) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - return nil -} - -// CreatePagesDeployment creates a Pages production deployment. -// -// API reference: https://api.cloudflare.com/#pages-deployment-create-deployment -func (api *API) CreatePagesDeployment(ctx context.Context, rc *ResourceContainer, params CreatePagesDeploymentParams) (PagesProjectDeployment, error) { - if rc.Identifier == "" { - return PagesProjectDeployment{}, ErrMissingAccountID - } - - if params.ProjectName == "" { - return PagesProjectDeployment{}, ErrMissingProjectName - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments", rc.Identifier, params.ProjectName) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return PagesProjectDeployment{}, err - } - var r pagesDeploymentResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// RetryPagesDeployment retries a specific Pages deployment. -// -// API reference: https://api.cloudflare.com/#pages-deployment-retry-deployment -func (api *API) RetryPagesDeployment(ctx context.Context, rc *ResourceContainer, projectName, deploymentID string) (PagesProjectDeployment, error) { - if rc.Identifier == "" { - return PagesProjectDeployment{}, ErrMissingAccountID - } - - if projectName == "" { - return PagesProjectDeployment{}, ErrMissingProjectName - } - - if deploymentID == "" { - return PagesProjectDeployment{}, ErrMissingDeploymentID - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments/%s/retry", rc.Identifier, projectName, deploymentID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return PagesProjectDeployment{}, err - } - var r pagesDeploymentResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// RollbackPagesDeployment rollbacks the Pages production deployment to a previous production deployment. -// -// API reference: https://api.cloudflare.com/#pages-deployment-rollback-deployment -func (api *API) RollbackPagesDeployment(ctx context.Context, rc *ResourceContainer, projectName, deploymentID string) (PagesProjectDeployment, error) { - if rc.Identifier == "" { - return PagesProjectDeployment{}, ErrMissingAccountID - } - - if projectName == "" { - return PagesProjectDeployment{}, ErrMissingProjectName - } - - if deploymentID == "" { - return PagesProjectDeployment{}, ErrMissingDeploymentID - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/deployments/%s/rollback", rc.Identifier, projectName, deploymentID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return PagesProjectDeployment{}, err - } - var r pagesDeploymentResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/pages_domain.go b/vendor/github.com/cloudflare/cloudflare-go/pages_domain.go deleted file mode 100644 index 7d80d6e..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/pages_domain.go +++ /dev/null @@ -1,193 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// PagesDomain represents a pages domain. -type PagesDomain struct { - ID string `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - VerificationData VerificationData `json:"verification_data"` - ValidationData ValidationData `json:"validation_data"` - ZoneTag string `json:"zone_tag"` - CreatedOn *time.Time `json:"created_on"` -} - -// VerificationData represents verification data for a domain. -type VerificationData struct { - Status string `json:"status"` -} - -// ValidationData represents validation data for a domain. -type ValidationData struct { - Status string `json:"status"` - Method string `json:"method"` -} - -// PagesDomainsParameters represents parameters for a pages domains request. -type PagesDomainsParameters struct { - AccountID string - ProjectName string -} - -// PagesDomainsResponse represents an API response for a pages domains request. -type PagesDomainsResponse struct { - Response - Result []PagesDomain `json:"result,omitempty"` -} - -// PagesDomainParameters represents parameters for a pages domain request. -type PagesDomainParameters struct { - AccountID string `json:"-"` - ProjectName string `json:"-"` - DomainName string `json:"name,omitempty"` -} - -// PagesDomainResponse represents an API response for a pages domain request. -type PagesDomainResponse struct { - Response - Result PagesDomain `json:"result,omitempty"` -} - -// GetPagesDomains gets all domains for a pages project. -// -// API Reference: https://api.cloudflare.com/#pages-domains-get-domains -func (api *API) GetPagesDomains(ctx context.Context, params PagesDomainsParameters) ([]PagesDomain, error) { - if params.AccountID == "" { - return []PagesDomain{}, ErrMissingAccountID - } - - if params.ProjectName == "" { - return []PagesDomain{}, ErrMissingProjectName - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/domains", params.AccountID, params.ProjectName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []PagesDomain{}, err - } - - var pageDomainResponse PagesDomainsResponse - if err := json.Unmarshal(res, &pageDomainResponse); err != nil { - return []PagesDomain{}, err - } - return pageDomainResponse.Result, nil -} - -// GetPagesDomain gets a single domain. -// -// API Reference: https://api.cloudflare.com/#pages-domains-get-domains -func (api *API) GetPagesDomain(ctx context.Context, params PagesDomainParameters) (PagesDomain, error) { - if params.AccountID == "" { - return PagesDomain{}, ErrMissingAccountID - } - - if params.ProjectName == "" { - return PagesDomain{}, ErrMissingProjectName - } - - if params.DomainName == "" { - return PagesDomain{}, ErrMissingDomain - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/domains/%s", params.AccountID, params.ProjectName, params.DomainName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PagesDomain{}, err - } - - var pagesDomainResponse PagesDomainResponse - if err := json.Unmarshal(res, &pagesDomainResponse); err != nil { - return PagesDomain{}, err - } - return pagesDomainResponse.Result, nil -} - -// PagesPatchDomain retries the validation status of a single domain. -// -// API Reference: https://api.cloudflare.com/#pages-domains-patch-domain -func (api *API) PagesPatchDomain(ctx context.Context, params PagesDomainParameters) (PagesDomain, error) { - if params.AccountID == "" { - return PagesDomain{}, ErrMissingAccountID - } - - if params.ProjectName == "" { - return PagesDomain{}, ErrMissingProjectName - } - - if params.DomainName == "" { - return PagesDomain{}, ErrMissingDomain - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/domains/%s", params.AccountID, params.ProjectName, params.DomainName) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, nil) - if err != nil { - return PagesDomain{}, err - } - - var pagesDomainResponse PagesDomainResponse - if err := json.Unmarshal(res, &pagesDomainResponse); err != nil { - return PagesDomain{}, err - } - return pagesDomainResponse.Result, nil -} - -// PagesAddDomain adds a domain to a pages project. -// -// API Reference: https://api.cloudflare.com/#pages-domains-add-domain -func (api *API) PagesAddDomain(ctx context.Context, params PagesDomainParameters) (PagesDomain, error) { - if params.AccountID == "" { - return PagesDomain{}, ErrMissingAccountID - } - - if params.ProjectName == "" { - return PagesDomain{}, ErrMissingProjectName - } - - if params.DomainName == "" { - return PagesDomain{}, ErrMissingDomain - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/domains", params.AccountID, params.ProjectName) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return PagesDomain{}, err - } - - var pagesDomainResponse PagesDomainResponse - if err := json.Unmarshal(res, &pagesDomainResponse); err != nil { - return PagesDomain{}, err - } - return pagesDomainResponse.Result, nil -} - -// PagesDeleteDomain removes a domain from a pages project. -// -// API Reference: https://api.cloudflare.com/#pages-domains-delete-domain -func (api *API) PagesDeleteDomain(ctx context.Context, params PagesDomainParameters) error { - if params.AccountID == "" { - return ErrMissingAccountID - } - - if params.ProjectName == "" { - return ErrMissingProjectName - } - - if params.DomainName == "" { - return ErrMissingDomain - } - - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s/domains/%s", params.AccountID, params.ProjectName, params.DomainName) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, params) - if err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/pages_project.go b/vendor/github.com/cloudflare/cloudflare-go/pages_project.go deleted file mode 100644 index 3177a8e..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/pages_project.go +++ /dev/null @@ -1,275 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type PagesPreviewDeploymentSetting string - -const ( - PagesPreviewAllBranches PagesPreviewDeploymentSetting = "all" - PagesPreviewNoBranches PagesPreviewDeploymentSetting = "none" - PagesPreviewCustomBranches PagesPreviewDeploymentSetting = "custom" -) - -// PagesProject represents a Pages project. -type PagesProject struct { - Name string `json:"name,omitempty"` - ID string `json:"id"` - CreatedOn *time.Time `json:"created_on"` - SubDomain string `json:"subdomain"` - Domains []string `json:"domains,omitempty"` - Source *PagesProjectSource `json:"source,omitempty"` - BuildConfig PagesProjectBuildConfig `json:"build_config"` - DeploymentConfigs PagesProjectDeploymentConfigs `json:"deployment_configs"` - LatestDeployment PagesProjectDeployment `json:"latest_deployment"` - CanonicalDeployment PagesProjectDeployment `json:"canonical_deployment"` - ProductionBranch string `json:"production_branch,omitempty"` -} - -// PagesProjectSource represents the configuration of a Pages project source. -type PagesProjectSource struct { - Type string `json:"type"` - Config *PagesProjectSourceConfig `json:"config"` -} - -// PagesProjectSourceConfig represents the properties use to configure a Pages project source. -type PagesProjectSourceConfig struct { - Owner string `json:"owner"` - RepoName string `json:"repo_name"` - ProductionBranch string `json:"production_branch"` - PRCommentsEnabled bool `json:"pr_comments_enabled"` - DeploymentsEnabled bool `json:"deployments_enabled"` - ProductionDeploymentsEnabled bool `json:"production_deployments_enabled"` - PreviewDeploymentSetting PagesPreviewDeploymentSetting `json:"preview_deployment_setting"` - PreviewBranchIncludes []string `json:"preview_branch_includes"` - PreviewBranchExcludes []string `json:"preview_branch_excludes"` -} - -// PagesProjectBuildConfig represents the configuration of a Pages project build process. -type PagesProjectBuildConfig struct { - BuildCommand string `json:"build_command"` - DestinationDir string `json:"destination_dir"` - RootDir string `json:"root_dir"` - WebAnalyticsTag string `json:"web_analytics_tag"` - WebAnalyticsToken string `json:"web_analytics_token"` -} - -// PagesProjectDeploymentConfigs represents the configuration for deployments in a Pages project. -type PagesProjectDeploymentConfigs struct { - Preview PagesProjectDeploymentConfigEnvironment `json:"preview"` - Production PagesProjectDeploymentConfigEnvironment `json:"production"` -} - -// PagesProjectDeploymentConfigEnvironment represents the configuration for preview or production deploys. -type PagesProjectDeploymentConfigEnvironment struct { - EnvVars EnvironmentVariableMap `json:"env_vars,omitempty"` - KvNamespaces NamespaceBindingMap `json:"kv_namespaces,omitempty"` - DoNamespaces NamespaceBindingMap `json:"durable_object_namespaces,omitempty"` - D1Databases D1BindingMap `json:"d1_databases,omitempty"` - R2Bindings R2BindingMap `json:"r2_buckets,omitempty"` - ServiceBindings ServiceBindingMap `json:"services,omitempty"` - CompatibilityDate string `json:"compatibility_date,omitempty"` - CompatibilityFlags []string `json:"compatibility_flags,omitempty"` - FailOpen bool `json:"fail_open"` - AlwaysUseLatestCompatibilityDate bool `json:"always_use_latest_compatibility_date"` - UsageModel UsageModel `json:"usage_model,omitempty"` -} - -// PagesProjectDeployment represents a deployment to a Pages project. -type PagesProjectDeployment struct { - ID string `json:"id"` - ShortID string `json:"short_id"` - ProjectID string `json:"project_id"` - ProjectName string `json:"project_name"` - Environment string `json:"environment"` - URL string `json:"url"` - CreatedOn *time.Time `json:"created_on"` - ModifiedOn *time.Time `json:"modified_on"` - Aliases []string `json:"aliases,omitempty"` - LatestStage PagesProjectDeploymentStage `json:"latest_stage"` - EnvVars EnvironmentVariableMap `json:"env_vars"` - KvNamespaces NamespaceBindingMap `json:"kv_namespaces,omitempty"` - DoNamespaces NamespaceBindingMap `json:"durable_object_namespaces,omitempty"` - D1Databases D1BindingMap `json:"d1_databases,omitempty"` - R2Bindings R2BindingMap `json:"r2_buckets,omitempty"` - ServiceBindings ServiceBindingMap `json:"services,omitempty"` - DeploymentTrigger PagesProjectDeploymentTrigger `json:"deployment_trigger"` - Stages []PagesProjectDeploymentStage `json:"stages"` - BuildConfig PagesProjectBuildConfig `json:"build_config"` - Source PagesProjectSource `json:"source"` - CompatibilityDate string `json:"compatibility_date,omitempty"` - CompatibilityFlags []string `json:"compatibility_flags,omitempty"` - UsageModel UsageModel `json:"usage_model,omitempty"` - IsSkipped bool `json:"is_skipped"` - ProductionBranch string `json:"production_branch,omitempty"` -} - -// PagesProjectDeploymentStage represents an individual stage in a Pages project deployment. -type PagesProjectDeploymentStage struct { - Name string `json:"name"` - StartedOn *time.Time `json:"started_on,omitempty"` - EndedOn *time.Time `json:"ended_on,omitempty"` - Status string `json:"status"` -} - -// PagesProjectDeploymentTrigger represents information about what caused a deployment. -type PagesProjectDeploymentTrigger struct { - Type string `json:"type"` - Metadata *PagesProjectDeploymentTriggerMetadata `json:"metadata"` -} - -// PagesProjectDeploymentTriggerMetadata represents additional information about the cause of a deployment. -type PagesProjectDeploymentTriggerMetadata struct { - Branch string `json:"branch"` - CommitHash string `json:"commit_hash"` - CommitMessage string `json:"commit_message"` -} - -type pagesProjectResponse struct { - Response - Result PagesProject `json:"result"` -} - -type pagesProjectListResponse struct { - Response - Result []PagesProject `json:"result"` - ResultInfo `json:"result_info"` -} - -type EnvironmentVariableMap map[string]*EnvironmentVariable - -// PagesProjectDeploymentVar represents a deployment environment variable. -type EnvironmentVariable struct { - Value string `json:"value"` - Type EnvVarType `json:"type"` -} - -type EnvVarType string - -const ( - PlainText EnvVarType = "plain_text" - SecretText EnvVarType = "secret_text" -) - -type NamespaceBindingMap map[string]*NamespaceBindingValue - -type NamespaceBindingValue struct { - Value string `json:"namespace_id"` -} - -type R2BindingMap map[string]*R2BindingValue - -type R2BindingValue struct { - Name string `json:"name"` -} - -type D1BindingMap map[string]*D1Binding - -type D1Binding struct { - ID string `json:"id"` -} - -type ServiceBindingMap map[string]*ServiceBinding - -type ServiceBinding struct { - Service string `json:"service"` - Environment string `json:"environment"` -} - -type UsageModel string - -const ( - Bundled UsageModel = "bundled" - Unbound UsageModel = "unbound" -) - -// ListPagesProjects returns all Pages projects for an account. -// -// API reference: https://api.cloudflare.com/#pages-project-get-projects -func (api *API) ListPagesProjects(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]PagesProject, ResultInfo, error) { - uri := buildURI(fmt.Sprintf("/accounts/%s/pages/projects", accountID), pageOpts) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []PagesProject{}, ResultInfo{}, err - } - var r pagesProjectListResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []PagesProject{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, r.ResultInfo, nil -} - -// PagesProject returns a single Pages project by name. -// -// API reference: https://api.cloudflare.com/#pages-project-get-project -func (api *API) PagesProject(ctx context.Context, accountID, projectName string) (PagesProject, error) { - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", accountID, projectName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PagesProject{}, err - } - var r pagesProjectResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesProject{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreatePagesProject creates a new Pages project in an account. -// -// API reference: https://api.cloudflare.com/#pages-project-create-project -func (api *API) CreatePagesProject(ctx context.Context, accountID string, pagesProject PagesProject) (PagesProject, error) { - uri := fmt.Sprintf("/accounts/%s/pages/projects", accountID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, pagesProject) - if err != nil { - return PagesProject{}, err - } - var r pagesProjectResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesProject{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdatePagesProject updates an existing Pages project. -// -// API reference: https://api.cloudflare.com/#pages-project-update-project -func (api *API) UpdatePagesProject(ctx context.Context, accountID, projectName string, pagesProject PagesProject) (PagesProject, error) { - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", accountID, projectName) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, pagesProject) - if err != nil { - return PagesProject{}, err - } - var r pagesProjectResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PagesProject{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeletePagesProject deletes a Pages project by name. -// -// API reference: https://api.cloudflare.com/#pages-project-delete-project -func (api *API) DeletePagesProject(ctx context.Context, accountID, projectName string) error { - uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", accountID, projectName) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r pagesProjectResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/pagination.go b/vendor/github.com/cloudflare/cloudflare-go/pagination.go deleted file mode 100644 index 07d75ed..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/pagination.go +++ /dev/null @@ -1,19 +0,0 @@ -package cloudflare - -// Done returns true for the last page and false otherwise. -func (p ResultInfo) Done() bool { - return p.Page > 1 && p.Page > p.TotalPages -} - -// Next advances the page of a paginated API response, but does not fetch the -// next page of results. -func (p ResultInfo) Next() ResultInfo { - p.Page++ - return p -} - -// HasMorePages returns whether there is another page of results after the -// current one. -func (p ResultInfo) HasMorePages() bool { - return p.Page > 1 && p.Page < p.TotalPages -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/permission_group.go b/vendor/github.com/cloudflare/cloudflare-go/permission_group.go deleted file mode 100644 index c6468d0..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/permission_group.go +++ /dev/null @@ -1,98 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -type PermissionGroup struct { - ID string `json:"id"` - Name string `json:"name"` - Meta map[string]string `json:"meta"` - Permissions []Permission `json:"permissions"` -} - -type Permission struct { - ID string `json:"id"` - Key string `json:"key"` - Attributes map[string]string `json:"attributes,omitempty"` // same as Meta in other structs -} - -type PermissionGroupListResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result []PermissionGroup `json:"result"` -} - -type PermissionGroupDetailResponse struct { - Success bool `json:"success"` - Errors []string `json:"errors"` - Messages []string `json:"messages"` - Result PermissionGroup `json:"result"` -} - -type ListPermissionGroupParams struct { - Depth int `url:"depth,omitempty"` - RoleName string `url:"name,omitempty"` -} - -const errMissingPermissionGroupID = "missing required permission group ID" - -var ErrMissingPermissionGroupID = errors.New(errMissingPermissionGroupID) - -// GetPermissionGroup returns a specific permission group from the API given -// the account ID and permission group ID. -func (api *API) GetPermissionGroup(ctx context.Context, rc *ResourceContainer, permissionGroupId string) (PermissionGroup, error) { - if rc.Level != AccountRouteLevel { - return PermissionGroup{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if rc.Identifier == "" { - return PermissionGroup{}, ErrMissingAccountID - } - - if permissionGroupId == "" { - return PermissionGroup{}, ErrMissingPermissionGroupID - } - - uri := fmt.Sprintf("/accounts/%s/iam/permission_groups/%s?depth=2", rc.Identifier, permissionGroupId) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return PermissionGroup{}, err - } - - var permissionGroupResponse PermissionGroupDetailResponse - err = json.Unmarshal(res, &permissionGroupResponse) - if err != nil { - return PermissionGroup{}, err - } - - return permissionGroupResponse.Result, nil -} - -// ListPermissionGroups returns all valid permission groups for the provided -// parameters. -func (api *API) ListPermissionGroups(ctx context.Context, rc *ResourceContainer, params ListPermissionGroupParams) ([]PermissionGroup, error) { - if rc.Level != AccountRouteLevel { - return []PermissionGroup{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - params.Depth = 2 - uri := buildURI(fmt.Sprintf("/accounts/%s/iam/permission_groups", rc.Identifier), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []PermissionGroup{}, err - } - - var permissionGroupResponse PermissionGroupListResponse - err = json.Unmarshal(res, &permissionGroupResponse) - if err != nil { - return []PermissionGroup{}, err - } - - return permissionGroupResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/policy.go b/vendor/github.com/cloudflare/cloudflare-go/policy.go deleted file mode 100644 index 8077241..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/policy.go +++ /dev/null @@ -1,8 +0,0 @@ -package cloudflare - -type Policy struct { - ID string `json:"id"` - PermissionGroups []PermissionGroup `json:"permission_groups"` - ResourceGroups []ResourceGroup `json:"resource_groups"` - Access string `json:"access"` -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/queue.go b/vendor/github.com/cloudflare/cloudflare-go/queue.go deleted file mode 100644 index 771a1f1..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/queue.go +++ /dev/null @@ -1,377 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -var ( - ErrMissingQueueName = errors.New("required queue name is missing") - ErrMissingQueueConsumerName = errors.New("required queue consumer name is missing") -) - -type Queue struct { - ID string `json:"queue_id,omitempty"` - Name string `json:"queue_name,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - ProducersTotalCount int `json:"producers_total_count,omitempty"` - Producers []QueueProducer `json:"producers,omitempty"` - ConsumersTotalCount int `json:"consumers_total_count,omitempty"` - Consumers []QueueConsumer `json:"consumers,omitempty"` -} - -type QueueProducer struct { - Service string `json:"service,omitempty"` - Environment string `json:"environment,omitempty"` -} - -type QueueConsumer struct { - Name string `json:"-"` - Service string `json:"service,omitempty"` - ScriptName string `json:"script_name,omitempty"` - Environment string `json:"environment,omitempty"` - Settings QueueConsumerSettings `json:"settings,omitempty"` - QueueName string `json:"queue_name,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - DeadLetterQueue string `json:"dead_letter_queue,omitempty"` -} - -type QueueConsumerSettings struct { - BatchSize int `json:"batch_size,omitempty"` - MaxRetires int `json:"max_retries,omitempty"` - MaxWaitTime int `json:"max_wait_time_ms,omitempty"` -} - -type QueueListResponse struct { - Response - ResultInfo `json:"result_info"` - Result []Queue `json:"result"` -} - -type CreateQueueParams struct { - Name string `json:"queue_name"` -} - -type QueueResponse struct { - Response - Result Queue `json:"result"` -} - -type ListQueueConsumersResponse struct { - Response - ResultInfo `json:"result_info"` - Result []QueueConsumer `json:"result"` -} - -type ListQueuesParams struct { - ResultInfo -} - -type QueueConsumerResponse struct { - Response - Result QueueConsumer `json:"result"` -} - -type UpdateQueueParams struct { - Name string `json:"-"` - UpdatedName string `json:"queue_name,omitempty"` -} - -type ListQueueConsumersParams struct { - QueueName string `url:"-"` - ResultInfo -} - -type CreateQueueConsumerParams struct { - QueueName string `json:"-"` - Consumer QueueConsumer -} - -type UpdateQueueConsumerParams struct { - QueueName string `json:"-"` - Consumer QueueConsumer -} - -type DeleteQueueConsumerParams struct { - QueueName, ConsumerName string -} - -// ListQueues returns the queues owned by an account. -// -// API reference: https://api.cloudflare.com/#queue-list-queues -func (api *API) ListQueues(ctx context.Context, rc *ResourceContainer, params ListQueuesParams) ([]Queue, *ResultInfo, error) { - if rc.Identifier == "" { - return []Queue{}, &ResultInfo{}, ErrMissingAccountID - } - - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - if params.PerPage < 1 { - params.PerPage = 50 - } - if params.Page < 1 { - params.Page = 1 - } - - var queues []Queue - var qResponse QueueListResponse - for { - qResponse = QueueListResponse{} - uri := buildURI(fmt.Sprintf("/accounts/%s/workers/queues", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Queue{}, &ResultInfo{}, err - } - - err = json.Unmarshal(res, &qResponse) - if err != nil { - return []Queue{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal filters JSON data: %w", err) - } - - queues = append(queues, qResponse.Result...) - params.ResultInfo = qResponse.ResultInfo.Next() - - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return queues, &qResponse.ResultInfo, nil -} - -// CreateQueue creates a new queue. -// -// API reference: https://api.cloudflare.com/#queue-create-queue -func (api *API) CreateQueue(ctx context.Context, rc *ResourceContainer, queue CreateQueueParams) (Queue, error) { - if rc.Identifier == "" { - return Queue{}, ErrMissingAccountID - } - - if queue.Name == "" { - return Queue{}, ErrMissingQueueName - } - - uri := fmt.Sprintf("/accounts/%s/workers/queues", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, queue) - if err != nil { - return Queue{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r QueueResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Queue{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteQueue deletes a queue. -// -// API reference: https://api.cloudflare.com/#queue-delete-queue -func (api *API) DeleteQueue(ctx context.Context, rc *ResourceContainer, queueName string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - if queueName == "" { - return ErrMissingQueueName - } - - uri := fmt.Sprintf("/accounts/%s/workers/queues/%s", rc.Identifier, queueName) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return fmt.Errorf("%s: %w", errMakeRequestError, err) - } - return nil -} - -// GetQueue returns a single queue based on the name. -// -// API reference: https://api.cloudflare.com/#queue-get-queue -func (api *API) GetQueue(ctx context.Context, rc *ResourceContainer, queueName string) (Queue, error) { - if rc.Identifier == "" { - return Queue{}, ErrMissingAccountID - } - - if queueName == "" { - return Queue{}, ErrMissingQueueName - } - - uri := fmt.Sprintf("/accounts/%s/workers/queues/%s", rc.Identifier, queueName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Queue{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r QueueResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Queue{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateQueue updates a queue. -// -// API reference: https://api.cloudflare.com/#queue-update-queue -func (api *API) UpdateQueue(ctx context.Context, rc *ResourceContainer, params UpdateQueueParams) (Queue, error) { - if rc.Identifier == "" { - return Queue{}, ErrMissingAccountID - } - - if params.Name == "" || params.UpdatedName == "" { - return Queue{}, ErrMissingQueueName - } - - uri := fmt.Sprintf("/accounts/%s/workers/queues/%s", rc.Identifier, params.Name) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return Queue{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r QueueResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Queue{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListQueueConsumers returns the consumers of a queue. -// -// API reference: https://api.cloudflare.com/#queue-list-queue-consumers -func (api *API) ListQueueConsumers(ctx context.Context, rc *ResourceContainer, params ListQueueConsumersParams) ([]QueueConsumer, *ResultInfo, error) { - if rc.Identifier == "" { - return []QueueConsumer{}, &ResultInfo{}, ErrMissingAccountID - } - - if params.QueueName == "" { - return []QueueConsumer{}, &ResultInfo{}, ErrMissingQueueName - } - - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - if params.PerPage < 1 { - params.PerPage = 50 - } - if params.Page < 1 { - params.Page = 1 - } - - var queuesConsumers []QueueConsumer - var qResponse ListQueueConsumersResponse - for { - qResponse = ListQueueConsumersResponse{} - uri := buildURI(fmt.Sprintf("/accounts/%s/workers/queues/%s/consumers", rc.Identifier, params.QueueName), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []QueueConsumer{}, &ResultInfo{}, err - } - - err = json.Unmarshal(res, &qResponse) - if err != nil { - return []QueueConsumer{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal filters JSON data: %w", err) - } - - queuesConsumers = append(queuesConsumers, qResponse.Result...) - params.ResultInfo = qResponse.ResultInfo.Next() - - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return queuesConsumers, &qResponse.ResultInfo, nil -} - -// CreateQueueConsumer creates a new consumer for a queue. -// -// API reference: https://api.cloudflare.com/#queue-create-queue-consumer -func (api *API) CreateQueueConsumer(ctx context.Context, rc *ResourceContainer, params CreateQueueConsumerParams) (QueueConsumer, error) { - if rc.Identifier == "" { - return QueueConsumer{}, ErrMissingAccountID - } - - if params.QueueName == "" { - return QueueConsumer{}, ErrMissingQueueName - } - - uri := fmt.Sprintf("/accounts/%s/workers/queues/%s/consumers", rc.Identifier, params.QueueName) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params.Consumer) - if err != nil { - return QueueConsumer{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r QueueConsumerResponse - err = json.Unmarshal(res, &r) - if err != nil { - return QueueConsumer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteQueueConsumer deletes the consumer for a queue.. -// -// API reference: https://api.cloudflare.com/#queue-delete-queue-consumer -func (api *API) DeleteQueueConsumer(ctx context.Context, rc *ResourceContainer, params DeleteQueueConsumerParams) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - if params.QueueName == "" { - return ErrMissingQueueName - } - - if params.ConsumerName == "" { - return ErrMissingQueueConsumerName - } - - uri := fmt.Sprintf("/accounts/%s/workers/queues/%s/consumers/%s", rc.Identifier, params.QueueName, params.ConsumerName) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - return nil -} - -// UpdateQueueConsumer updates the consumer for a queue, or creates one if it does not exist.. -// -// API reference: https://api.cloudflare.com/#queue-update-queue-consumer -func (api *API) UpdateQueueConsumer(ctx context.Context, rc *ResourceContainer, params UpdateQueueConsumerParams) (QueueConsumer, error) { - if rc.Identifier == "" { - return QueueConsumer{}, ErrMissingAccountID - } - - if params.QueueName == "" { - return QueueConsumer{}, ErrMissingQueueName - } - - if params.Consumer.Name == "" { - return QueueConsumer{}, ErrMissingQueueConsumerName - } - - uri := fmt.Sprintf("/accounts/%s/workers/queues/%s/consumers/%s", rc.Identifier, params.QueueName, params.Consumer.Name) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.Consumer) - if err != nil { - return QueueConsumer{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r QueueConsumerResponse - err = json.Unmarshal(res, &r) - if err != nil { - return QueueConsumer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/r2_bucket.go b/vendor/github.com/cloudflare/cloudflare-go/r2_bucket.go deleted file mode 100644 index 08de630..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/r2_bucket.go +++ /dev/null @@ -1,102 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -var ( - ErrMissingBucketName = errors.New("require bucket name missing") -) - -// R2Bucket defines a container for objects stored in R2 Storage. -type R2Bucket struct { - Name string `json:"name"` - CreationDate string `json:"creation_date,omitempty"` -} - -// R2Buckets represents the map of buckets response from -// the R2 buckets endpoint. -type R2Buckets struct { - Buckets []R2Bucket `json:"buckets"` -} - -// R2BucketListResponse represents the response from the list -// R2 buckets endpoint. -type R2BucketListResponse struct { - Result R2Buckets `json:"result"` - Response -} - -type ListR2BucketsParams struct { - Name string `url:"name_contains,omitempty"` - StartAfter string `url:"start_after,omitempty"` - PerPage int64 `url:"per_page,omitempty"` - Order string `url:"order,omitempty"` - Direction string `url:"direction,omitempty"` - Cursor string `url:"cursor,omitempty"` -} - -// ListR2Buckets Lists R2 buckets. -func (api *API) ListR2Buckets(ctx context.Context, rc *ResourceContainer, params ListR2BucketsParams) ([]R2Bucket, error) { - if rc.Identifier == "" { - return []R2Bucket{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/r2/buckets", rc.Identifier), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []R2Bucket{}, err - } - - var r2BucketListResponse R2BucketListResponse - err = json.Unmarshal(res, &r2BucketListResponse) - if err != nil { - return []R2Bucket{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r2BucketListResponse.Result.Buckets, nil -} - -type CreateR2BucketParameters struct { - Name string `json:"name,omitempty"` -} - -// CreateR2Bucket Creates a new R2 bucket. -// -// API reference: https://api.cloudflare.com/#r2-bucket-create-bucket -func (api *API) CreateR2Bucket(ctx context.Context, rc *ResourceContainer, params CreateR2BucketParameters) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - if params.Name == "" { - return ErrMissingBucketName - } - - uri := fmt.Sprintf("/accounts/%s/r2/buckets", rc.Identifier) - _, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - - return err -} - -// DeleteR2Bucket Deletes an existing R2 bucket. -// -// API reference: https://api.cloudflare.com/#r2-bucket-delete-bucket -func (api *API) DeleteR2Bucket(ctx context.Context, rc *ResourceContainer, bucketName string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - if bucketName == "" { - return ErrMissingBucketName - } - - uri := fmt.Sprintf("/accounts/%s/r2/buckets/%s", rc.Identifier, bucketName) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - return err -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/railgun.go b/vendor/github.com/cloudflare/cloudflare-go/railgun.go deleted file mode 100644 index e189124..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/railgun.go +++ /dev/null @@ -1,298 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "time" -) - -// Railgun represents a Railgun's properties. -type Railgun struct { - ID string `json:"id"` - Name string `json:"name"` - Status string `json:"status"` - Enabled bool `json:"enabled"` - ZonesConnected int `json:"zones_connected"` - Build string `json:"build"` - Version string `json:"version"` - Revision string `json:"revision"` - ActivationKey string `json:"activation_key"` - ActivatedOn time.Time `json:"activated_on"` - CreatedOn time.Time `json:"created_on"` - ModifiedOn time.Time `json:"modified_on"` - UpgradeInfo struct { - LatestVersion string `json:"latest_version"` - DownloadLink string `json:"download_link"` - } `json:"upgrade_info"` -} - -// RailgunListOptions represents the parameters used to list railguns. -type RailgunListOptions struct { - Direction string -} - -// railgunResponse represents the response from the Create Railgun and the Railgun Details endpoints. -type railgunResponse struct { - Response - Result Railgun `json:"result"` -} - -// railgunsResponse represents the response from the List Railguns endpoint. -type railgunsResponse struct { - Response - Result []Railgun `json:"result"` -} - -// CreateRailgun creates a new Railgun. -// -// API reference: https://api.cloudflare.com/#railgun-create-railgun -func (api *API) CreateRailgun(ctx context.Context, name string) (Railgun, error) { - uri := fmt.Sprintf("%s/railguns", api.userBaseURL("")) - params := struct { - Name string `json:"name"` - }{ - Name: name, - } - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return Railgun{}, err - } - var r railgunResponse - if err := json.Unmarshal(res, &r); err != nil { - return Railgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListRailguns lists Railguns connected to an account. -// -// API reference: https://api.cloudflare.com/#railgun-list-railguns -func (api *API) ListRailguns(ctx context.Context, options RailgunListOptions) ([]Railgun, error) { - v := url.Values{} - if options.Direction != "" { - v.Set("direction", options.Direction) - } - uri := fmt.Sprintf("%s/railguns?%s", api.userBaseURL(""), v.Encode()) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r railgunsResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// RailgunDetails returns the details for a Railgun. -// -// API reference: https://api.cloudflare.com/#railgun-railgun-details -func (api *API) RailgunDetails(ctx context.Context, railgunID string) (Railgun, error) { - uri := fmt.Sprintf("%s/railguns/%s", api.userBaseURL(""), railgunID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Railgun{}, err - } - var r railgunResponse - if err := json.Unmarshal(res, &r); err != nil { - return Railgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// RailgunZones returns the zones that are currently using a Railgun. -// -// API reference: https://api.cloudflare.com/#railgun-get-zones-connected-to-a-railgun -func (api *API) RailgunZones(ctx context.Context, railgunID string) ([]Zone, error) { - uri := fmt.Sprintf("%s/railguns/%s/zones", api.userBaseURL(""), railgunID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r ZonesResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// enableRailgun enables (true) or disables (false) a Railgun for all zones connected to it. -// -// API reference: https://api.cloudflare.com/#railgun-enable-or-disable-a-railgun -func (api *API) enableRailgun(ctx context.Context, railgunID string, enable bool) (Railgun, error) { - uri := fmt.Sprintf("%s/railguns/%s", api.userBaseURL(""), railgunID) - params := struct { - Enabled bool `json:"enabled"` - }{ - Enabled: enable, - } - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) - if err != nil { - return Railgun{}, err - } - var r railgunResponse - if err := json.Unmarshal(res, &r); err != nil { - return Railgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// EnableRailgun enables a Railgun for all zones connected to it. -// -// API reference: https://api.cloudflare.com/#railgun-enable-or-disable-a-railgun -func (api *API) EnableRailgun(ctx context.Context, railgunID string) (Railgun, error) { - return api.enableRailgun(ctx, railgunID, true) -} - -// DisableRailgun enables a Railgun for all zones connected to it. -// -// API reference: https://api.cloudflare.com/#railgun-enable-or-disable-a-railgun -func (api *API) DisableRailgun(ctx context.Context, railgunID string) (Railgun, error) { - return api.enableRailgun(ctx, railgunID, false) -} - -// DeleteRailgun disables and deletes a Railgun. -// -// API reference: https://api.cloudflare.com/#railgun-delete-railgun -func (api *API) DeleteRailgun(ctx context.Context, railgunID string) error { - uri := fmt.Sprintf("%s/railguns/%s", api.userBaseURL(""), railgunID) - if _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil); err != nil { - return err - } - return nil -} - -// ZoneRailgun represents the status of a Railgun on a zone. -type ZoneRailgun struct { - ID string `json:"id"` - Name string `json:"name"` - Enabled bool `json:"enabled"` - Connected bool `json:"connected"` -} - -// zoneRailgunResponse represents the response from the Zone Railgun Details endpoint. -type zoneRailgunResponse struct { - Response - Result ZoneRailgun `json:"result"` -} - -// zoneRailgunsResponse represents the response from the Zone Railgun endpoint. -type zoneRailgunsResponse struct { - Response - Result []ZoneRailgun `json:"result"` -} - -// RailgunDiagnosis represents the test results from testing railgun connections -// to a zone. -type RailgunDiagnosis struct { - Method string `json:"method"` - HostName string `json:"host_name"` - HTTPStatus int `json:"http_status"` - Railgun string `json:"railgun"` - URL string `json:"url"` - ResponseStatus string `json:"response_status"` - Protocol string `json:"protocol"` - ElapsedTime string `json:"elapsed_time"` - BodySize string `json:"body_size"` - BodyHash string `json:"body_hash"` - MissingHeaders string `json:"missing_headers"` - ConnectionClose bool `json:"connection_close"` - Cloudflare string `json:"cloudflare"` - CFRay string `json:"cf-ray"` - // NOTE: Cloudflare's online API documentation does not yet have definitions - // for the following fields. See: https://api.cloudflare.com/#railgun-connections-for-a-zone-test-railgun-connection/ - CFWANError string `json:"cf-wan-error"` - CFCacheStatus string `json:"cf-cache-status"` -} - -// railgunDiagnosisResponse represents the response from the Test Railgun Connection endpoint. -type railgunDiagnosisResponse struct { - Response - Result RailgunDiagnosis `json:"result"` -} - -// ZoneRailguns returns the available Railguns for a zone. -// -// API reference: https://api.cloudflare.com/#railguns-for-a-zone-get-available-railguns -func (api *API) ZoneRailguns(ctx context.Context, zoneID string) ([]ZoneRailgun, error) { - uri := fmt.Sprintf("/zones/%s/railguns", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r zoneRailgunsResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ZoneRailgunDetails returns the configuration for a given Railgun. -// -// API reference: https://api.cloudflare.com/#railguns-for-a-zone-get-railgun-details -func (api *API) ZoneRailgunDetails(ctx context.Context, zoneID, railgunID string) (ZoneRailgun, error) { - uri := fmt.Sprintf("/zones/%s/railguns/%s", zoneID, railgunID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ZoneRailgun{}, err - } - var r zoneRailgunResponse - if err := json.Unmarshal(res, &r); err != nil { - return ZoneRailgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// TestRailgunConnection tests a Railgun connection for a given zone. -// -// API reference: https://api.cloudflare.com/#railgun-connections-for-a-zone-test-railgun-connection -func (api *API) TestRailgunConnection(ctx context.Context, zoneID, railgunID string) (RailgunDiagnosis, error) { - uri := fmt.Sprintf("/zones/%s/railguns/%s/diagnose", zoneID, railgunID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return RailgunDiagnosis{}, err - } - var r railgunDiagnosisResponse - if err := json.Unmarshal(res, &r); err != nil { - return RailgunDiagnosis{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// connectZoneRailgun connects (true) or disconnects (false) a Railgun for a given zone. -// -// API reference: https://api.cloudflare.com/#railguns-for-a-zone-connect-or-disconnect-a-railgun -func (api *API) connectZoneRailgun(ctx context.Context, zoneID, railgunID string, connect bool) (ZoneRailgun, error) { - uri := fmt.Sprintf("/zones/%s/railguns/%s", zoneID, railgunID) - params := struct { - Connected bool `json:"connected"` - }{ - Connected: connect, - } - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) - if err != nil { - return ZoneRailgun{}, err - } - var r zoneRailgunResponse - if err := json.Unmarshal(res, &r); err != nil { - return ZoneRailgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ConnectZoneRailgun connects a Railgun for a given zone. -// -// API reference: https://api.cloudflare.com/#railguns-for-a-zone-connect-or-disconnect-a-railgun -func (api *API) ConnectZoneRailgun(ctx context.Context, zoneID, railgunID string) (ZoneRailgun, error) { - return api.connectZoneRailgun(ctx, zoneID, railgunID, true) -} - -// DisconnectZoneRailgun disconnects a Railgun for a given zone. -// -// API reference: https://api.cloudflare.com/#railguns-for-a-zone-connect-or-disconnect-a-railgun -func (api *API) DisconnectZoneRailgun(ctx context.Context, zoneID, railgunID string) (ZoneRailgun, error) { - return api.connectZoneRailgun(ctx, zoneID, railgunID, false) -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/rate_limiting.go b/vendor/github.com/cloudflare/cloudflare-go/rate_limiting.go deleted file mode 100644 index d40ae73..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/rate_limiting.go +++ /dev/null @@ -1,198 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// RateLimit is a policy than can be applied to limit traffic within a customer domain. -type RateLimit struct { - ID string `json:"id,omitempty"` - Disabled bool `json:"disabled,omitempty"` - Description string `json:"description,omitempty"` - Match RateLimitTrafficMatcher `json:"match"` - Bypass []RateLimitKeyValue `json:"bypass,omitempty"` - Threshold int `json:"threshold"` - Period int `json:"period"` - Action RateLimitAction `json:"action"` - Correlate *RateLimitCorrelate `json:"correlate,omitempty"` -} - -// RateLimitTrafficMatcher contains the rules that will be used to apply a rate limit to traffic. -type RateLimitTrafficMatcher struct { - Request RateLimitRequestMatcher `json:"request"` - Response RateLimitResponseMatcher `json:"response"` -} - -// RateLimitRequestMatcher contains the matching rules pertaining to requests. -type RateLimitRequestMatcher struct { - Methods []string `json:"methods,omitempty"` - Schemes []string `json:"schemes,omitempty"` - URLPattern string `json:"url,omitempty"` -} - -// RateLimitResponseMatcher contains the matching rules pertaining to responses. -type RateLimitResponseMatcher struct { - Statuses []int `json:"status,omitempty"` - OriginTraffic *bool `json:"origin_traffic,omitempty"` // api defaults to true so we need an explicit empty value - Headers []RateLimitResponseMatcherHeader `json:"headers,omitempty"` -} - -// RateLimitResponseMatcherHeader contains the structure of the origin -// HTTP headers used in request matcher checks. -type RateLimitResponseMatcherHeader struct { - Name string `json:"name"` - Op string `json:"op"` - Value string `json:"value"` -} - -// RateLimitKeyValue is k-v formatted as expected in the rate limit description. -type RateLimitKeyValue struct { - Name string `json:"name"` - Value string `json:"value"` -} - -// RateLimitAction is the action that will be taken when the rate limit threshold is reached. -type RateLimitAction struct { - Mode string `json:"mode"` - Timeout int `json:"timeout"` - Response *RateLimitActionResponse `json:"response"` -} - -// RateLimitActionResponse is the response that will be returned when rate limit action is triggered. -type RateLimitActionResponse struct { - ContentType string `json:"content_type"` - Body string `json:"body"` -} - -// RateLimitCorrelate pertainings to NAT support. -type RateLimitCorrelate struct { - By string `json:"by"` -} - -type rateLimitResponse struct { - Response - Result RateLimit `json:"result"` -} - -type rateLimitListResponse struct { - Response - Result []RateLimit `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// CreateRateLimit creates a new rate limit for a zone. -// -// API reference: https://api.cloudflare.com/#rate-limits-for-a-zone-create-a-ratelimit -func (api *API) CreateRateLimit(ctx context.Context, zoneID string, limit RateLimit) (RateLimit, error) { - uri := fmt.Sprintf("/zones/%s/rate_limits", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, limit) - if err != nil { - return RateLimit{}, err - } - var r rateLimitResponse - if err := json.Unmarshal(res, &r); err != nil { - return RateLimit{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListRateLimits returns Rate Limits for a zone, paginated according to the provided options -// -// API reference: https://api.cloudflare.com/#rate-limits-for-a-zone-list-rate-limits -func (api *API) ListRateLimits(ctx context.Context, zoneID string, pageOpts PaginationOptions) ([]RateLimit, ResultInfo, error) { - uri := buildURI(fmt.Sprintf("/zones/%s/rate_limits", zoneID), pageOpts) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []RateLimit{}, ResultInfo{}, err - } - - var r rateLimitListResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []RateLimit{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, r.ResultInfo, nil -} - -// ListAllRateLimits returns all Rate Limits for a zone. -// -// API reference: https://api.cloudflare.com/#rate-limits-for-a-zone-list-rate-limits -func (api *API) ListAllRateLimits(ctx context.Context, zoneID string) ([]RateLimit, error) { - pageOpts := PaginationOptions{ - PerPage: 100, // this is the max page size allowed - Page: 1, - } - - allRateLimits := make([]RateLimit, 0) - for { - rateLimits, resultInfo, err := api.ListRateLimits(ctx, zoneID, pageOpts) - if err != nil { - return []RateLimit{}, err - } - allRateLimits = append(allRateLimits, rateLimits...) - // total pages is not returned on this call - // if number of records is less than the max, this must be the last page - // in case TotalCount % PerPage = 0, the last request will return an empty list - if resultInfo.Count < resultInfo.PerPage { - break - } - // continue with the next page - pageOpts.Page = pageOpts.Page + 1 - } - - return allRateLimits, nil -} - -// RateLimit fetches detail about one Rate Limit for a zone. -// -// API reference: https://api.cloudflare.com/#rate-limits-for-a-zone-rate-limit-details -func (api *API) RateLimit(ctx context.Context, zoneID, limitID string) (RateLimit, error) { - uri := fmt.Sprintf("/zones/%s/rate_limits/%s", zoneID, limitID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return RateLimit{}, err - } - var r rateLimitResponse - err = json.Unmarshal(res, &r) - if err != nil { - return RateLimit{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateRateLimit lets you replace a Rate Limit for a zone. -// -// API reference: https://api.cloudflare.com/#rate-limits-for-a-zone-update-rate-limit -func (api *API) UpdateRateLimit(ctx context.Context, zoneID, limitID string, limit RateLimit) (RateLimit, error) { - uri := fmt.Sprintf("/zones/%s/rate_limits/%s", zoneID, limitID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, limit) - if err != nil { - return RateLimit{}, err - } - var r rateLimitResponse - if err := json.Unmarshal(res, &r); err != nil { - return RateLimit{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteRateLimit deletes a Rate Limit for a zone. -// -// API reference: https://api.cloudflare.com/#rate-limits-for-a-zone-delete-rate-limit -func (api *API) DeleteRateLimit(ctx context.Context, zoneID, limitID string) error { - uri := fmt.Sprintf("/zones/%s/rate_limits/%s", zoneID, limitID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r rateLimitResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/registrar.go b/vendor/github.com/cloudflare/cloudflare-go/registrar.go deleted file mode 100644 index e0a210f..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/registrar.go +++ /dev/null @@ -1,175 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// RegistrarDomain is the structure of the API response for a new -// Cloudflare Registrar domain. -type RegistrarDomain struct { - ID string `json:"id"` - Available bool `json:"available"` - SupportedTLD bool `json:"supported_tld"` - CanRegister bool `json:"can_register"` - TransferIn RegistrarTransferIn `json:"transfer_in"` - CurrentRegistrar string `json:"current_registrar"` - ExpiresAt time.Time `json:"expires_at"` - RegistryStatuses string `json:"registry_statuses"` - Locked bool `json:"locked"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - RegistrantContact RegistrantContact `json:"registrant_contact"` -} - -// RegistrarTransferIn contains the structure for a domain transfer in -// request. -type RegistrarTransferIn struct { - UnlockDomain string `json:"unlock_domain"` - DisablePrivacy string `json:"disable_privacy"` - EnterAuthCode string `json:"enter_auth_code"` - ApproveTransfer string `json:"approve_transfer"` - AcceptFoa string `json:"accept_foa"` - CanCancelTransfer bool `json:"can_cancel_transfer"` -} - -// RegistrantContact is the contact details for the domain registration. -type RegistrantContact struct { - ID string `json:"id"` - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - Organization string `json:"organization"` - Address string `json:"address"` - Address2 string `json:"address2"` - City string `json:"city"` - State string `json:"state"` - Zip string `json:"zip"` - Country string `json:"country"` - Phone string `json:"phone"` - Email string `json:"email"` - Fax string `json:"fax"` -} - -// RegistrarDomainConfiguration is the structure for making updates to -// and existing domain. -type RegistrarDomainConfiguration struct { - NameServers []string `json:"name_servers"` - Privacy bool `json:"privacy"` - Locked bool `json:"locked"` - AutoRenew bool `json:"auto_renew"` -} - -// RegistrarDomainDetailResponse is the structure of the detailed -// response from the API for a single domain. -type RegistrarDomainDetailResponse struct { - Response - Result RegistrarDomain `json:"result"` -} - -// RegistrarDomainsDetailResponse is the structure of the detailed -// response from the API. -type RegistrarDomainsDetailResponse struct { - Response - Result []RegistrarDomain `json:"result"` -} - -// RegistrarDomain returns a single domain based on the account ID and -// domain name. -// -// API reference: https://api.cloudflare.com/#registrar-domains-get-domain -func (api *API) RegistrarDomain(ctx context.Context, accountID, domainName string) (RegistrarDomain, error) { - uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s", accountID, domainName) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return RegistrarDomain{}, err - } - - var r RegistrarDomainDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// RegistrarDomains returns all registrar domains based on the account -// ID. -// -// API reference: https://api.cloudflare.com/#registrar-domains-list-domains -func (api *API) RegistrarDomains(ctx context.Context, accountID string) ([]RegistrarDomain, error) { - uri := fmt.Sprintf("/accounts/%s/registrar/domains", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return []RegistrarDomain{}, err - } - - var r RegistrarDomainsDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// TransferRegistrarDomain initiates the transfer from another registrar -// to Cloudflare Registrar. -// -// API reference: https://api.cloudflare.com/#registrar-domains-transfer-domain -func (api *API) TransferRegistrarDomain(ctx context.Context, accountID, domainName string) ([]RegistrarDomain, error) { - uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s/transfer", accountID, domainName) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return []RegistrarDomain{}, err - } - - var r RegistrarDomainsDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CancelRegistrarDomainTransfer cancels a pending domain transfer. -// -// API reference: https://api.cloudflare.com/#registrar-domains-cancel-transfer -func (api *API) CancelRegistrarDomainTransfer(ctx context.Context, accountID, domainName string) ([]RegistrarDomain, error) { - uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s/cancel_transfer", accountID, domainName) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return []RegistrarDomain{}, err - } - - var r RegistrarDomainsDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateRegistrarDomain updates an existing Registrar Domain configuration. -// -// API reference: https://api.cloudflare.com/#registrar-domains-update-domain -func (api *API) UpdateRegistrarDomain(ctx context.Context, accountID, domainName string, domainConfiguration RegistrarDomainConfiguration) (RegistrarDomain, error) { - uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s", accountID, domainName) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, domainConfiguration) - if err != nil { - return RegistrarDomain{}, err - } - - var r RegistrarDomainDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/resource.go b/vendor/github.com/cloudflare/cloudflare-go/resource.go deleted file mode 100644 index cf0a9cf..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/resource.go +++ /dev/null @@ -1,49 +0,0 @@ -package cloudflare - -// RouteLevel holds the "level" where the resource resides. -type RouteLevel string - -const ( - AccountRouteLevel RouteLevel = "accounts" - ZoneRouteLevel RouteLevel = "zones" - UserRouteLevel RouteLevel = "user" -) - -// ResourceContainer defines an API resource you wish to target. Should not be -// used directly, use `UserIdentifier`, `ZoneIdentifier` and `AccountIdentifier` -// instead. -type ResourceContainer struct { - Level RouteLevel - Identifier string -} - -// ResourceIdentifier returns a generic *ResourceContainer. -func ResourceIdentifier(id string) *ResourceContainer { - return &ResourceContainer{ - Identifier: id, - } -} - -// UserIdentifier returns a user level *ResourceContainer. -func UserIdentifier(id string) *ResourceContainer { - return &ResourceContainer{ - Level: UserRouteLevel, - Identifier: id, - } -} - -// ZoneIdentifier returns a zone level *ResourceContainer. -func ZoneIdentifier(id string) *ResourceContainer { - return &ResourceContainer{ - Level: ZoneRouteLevel, - Identifier: id, - } -} - -// AccountIdentifier returns an account level *ResourceContainer. -func AccountIdentifier(id string) *ResourceContainer { - return &ResourceContainer{ - Level: AccountRouteLevel, - Identifier: id, - } -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/resource_group.go b/vendor/github.com/cloudflare/cloudflare-go/resource_group.go deleted file mode 100644 index 6d25ffb..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/resource_group.go +++ /dev/null @@ -1,53 +0,0 @@ -package cloudflare - -import "fmt" - -type ResourceGroup struct { - ID string `json:"id"` - Name string `json:"name"` - Meta map[string]string `json:"meta"` - Scope Scope `json:"scope"` -} - -type Scope struct { - Key string `json:"key"` - ScopeObjects []ScopeObject `json:"objects"` -} - -type ScopeObject struct { - Key string `json:"key"` -} - -// NewResourceGroupForZone takes an existing zone and provides a resource group -// to be used within a Policy that allows access to that zone. -func NewResourceGroupForZone(zone Zone) ResourceGroup { - return NewResourceGroup(fmt.Sprintf("com.cloudflare.api.account.zone.%s", zone.ID)) -} - -// NewResourceGroupForAccount takes an existing zone and provides a resource group -// to be used within a Policy that allows access to that account. -func NewResourceGroupForAccount(account Account) ResourceGroup { - return NewResourceGroup(fmt.Sprintf("com.cloudflare.api.account.%s", account.ID)) -} - -// NewResourceGroup takes a Cloudflare-formatted key (e.g. 'com.cloudflare.api.%s') and -// returns a resource group to be used within a Policy to allow access to that resource. -func NewResourceGroup(key string) ResourceGroup { - scope := Scope{ - Key: key, - ScopeObjects: []ScopeObject{ - { - Key: "*", - }, - }, - } - resourceGroup := ResourceGroup{ - ID: "", - Name: key, - Meta: map[string]string{ - "editable": "false", - }, - Scope: scope, - } - return resourceGroup -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/rulesets.go b/vendor/github.com/cloudflare/cloudflare-go/rulesets.go deleted file mode 100644 index 27521b0..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/rulesets.go +++ /dev/null @@ -1,914 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "strings" - "time" -) - -const ( - RulesetKindCustom RulesetKind = "custom" - RulesetKindManaged RulesetKind = "managed" - RulesetKindRoot RulesetKind = "root" - RulesetKindSchema RulesetKind = "schema" - RulesetKindZone RulesetKind = "zone" - - RulesetPhaseDDoSL4 RulesetPhase = "ddos_l4" - RulesetPhaseDDoSL7 RulesetPhase = "ddos_l7" - RulesetPhaseHTTPCustomErrors RulesetPhase = "http_custom_errors" - RulesetPhaseHTTPLogCustomFields RulesetPhase = "http_log_custom_fields" - RulesetPhaseHTTPRequestCacheSettings RulesetPhase = "http_request_cache_settings" - RulesetPhaseHTTPRequestFirewallCustom RulesetPhase = "http_request_firewall_custom" - RulesetPhaseHTTPRequestFirewallManaged RulesetPhase = "http_request_firewall_managed" - RulesetPhaseHTTPRequestLateTransform RulesetPhase = "http_request_late_transform" - RulesetPhaseHTTPRequestLateTransformManaged RulesetPhase = "http_request_late_transform_managed" - RulesetPhaseHTTPRequestMain RulesetPhase = "http_request_main" - RulesetPhaseHTTPRequestOrigin RulesetPhase = "http_request_origin" - RulesetPhaseHTTPRequestDynamicRedirect RulesetPhase = "http_request_dynamic_redirect" //nolint:gosec - RulesetPhaseHTTPRequestRedirect RulesetPhase = "http_request_redirect" - RulesetPhaseHTTPRequestSanitize RulesetPhase = "http_request_sanitize" - RulesetPhaseHTTPRequestTransform RulesetPhase = "http_request_transform" - RulesetPhaseHTTPResponseFirewallManaged RulesetPhase = "http_response_firewall_managed" - RulesetPhaseHTTPResponseHeadersTransform RulesetPhase = "http_response_headers_transform" - RulesetPhaseHTTPResponseHeadersTransformManaged RulesetPhase = "http_response_headers_transform_managed" - RulesetPhaseMagicTransit RulesetPhase = "magic_transit" - RulesetPhaseRateLimit RulesetPhase = "http_ratelimit" - RulesetPhaseSuperBotFightMode RulesetPhase = "http_request_sbfm" - RulesetPhaseHTTPConfigSettings RulesetPhase = "http_config_settings" - - RulesetRuleActionBlock RulesetRuleAction = "block" - RulesetRuleActionChallenge RulesetRuleAction = "challenge" - RulesetRuleActionDDoSDynamic RulesetRuleAction = "ddos_dynamic" - RulesetRuleActionExecute RulesetRuleAction = "execute" - RulesetRuleActionForceConnectionClose RulesetRuleAction = "force_connection_close" - RulesetRuleActionJSChallenge RulesetRuleAction = "js_challenge" - RulesetRuleActionLog RulesetRuleAction = "log" - RulesetRuleActionLogCustomField RulesetRuleAction = "log_custom_field" - RulesetRuleActionManagedChallenge RulesetRuleAction = "managed_challenge" - RulesetRuleActionRedirect RulesetRuleAction = "redirect" - RulesetRuleActionRewrite RulesetRuleAction = "rewrite" - RulesetRuleActionRoute RulesetRuleAction = "route" - RulesetRuleActionScore RulesetRuleAction = "score" - RulesetRuleActionSetCacheSettings RulesetRuleAction = "set_cache_settings" - RulesetRuleActionSetConfig RulesetRuleAction = "set_config" - RulesetRuleActionServeError RulesetRuleAction = "serve_error" - RulesetRuleActionSkip RulesetRuleAction = "skip" - - RulesetActionParameterProductBIC RulesetActionParameterProduct = "bic" - RulesetActionParameterProductHOT RulesetActionParameterProduct = "hot" - RulesetActionParameterProductRateLimit RulesetActionParameterProduct = "ratelimit" - RulesetActionParameterProductSecurityLevel RulesetActionParameterProduct = "securityLevel" - RulesetActionParameterProductUABlock RulesetActionParameterProduct = "uablock" - RulesetActionParameterProductWAF RulesetActionParameterProduct = "waf" - RulesetActionParameterProductZoneLockdown RulesetActionParameterProduct = "zonelockdown" - - RulesetRuleActionParametersHTTPHeaderOperationRemove RulesetRuleActionParametersHTTPHeaderOperation = "remove" - RulesetRuleActionParametersHTTPHeaderOperationSet RulesetRuleActionParametersHTTPHeaderOperation = "set" -) - -// RulesetKindValues exposes all the available `RulesetKind` values as a slice -// of strings. -func RulesetKindValues() []string { - return []string{ - string(RulesetKindCustom), - string(RulesetKindManaged), - string(RulesetKindRoot), - string(RulesetKindSchema), - string(RulesetKindZone), - } -} - -// RulesetPhaseValues exposes all the available `RulesetPhase` values as a slice -// of strings. -func RulesetPhaseValues() []string { - return []string{ - string(RulesetPhaseDDoSL4), - string(RulesetPhaseDDoSL7), - string(RulesetPhaseHTTPCustomErrors), - string(RulesetPhaseHTTPLogCustomFields), - string(RulesetPhaseHTTPRequestCacheSettings), - string(RulesetPhaseHTTPRequestFirewallCustom), - string(RulesetPhaseHTTPRequestFirewallManaged), - string(RulesetPhaseHTTPRequestLateTransform), - string(RulesetPhaseHTTPRequestLateTransformManaged), - string(RulesetPhaseHTTPRequestMain), - string(RulesetPhaseHTTPRequestOrigin), - string(RulesetPhaseHTTPRequestDynamicRedirect), - string(RulesetPhaseHTTPRequestRedirect), - string(RulesetPhaseHTTPRequestSanitize), - string(RulesetPhaseHTTPRequestTransform), - string(RulesetPhaseHTTPResponseFirewallManaged), - string(RulesetPhaseHTTPResponseHeadersTransform), - string(RulesetPhaseHTTPResponseHeadersTransformManaged), - string(RulesetPhaseMagicTransit), - string(RulesetPhaseRateLimit), - string(RulesetPhaseSuperBotFightMode), - string(RulesetPhaseHTTPConfigSettings), - } -} - -// RulesetRuleActionValues exposes all the available `RulesetRuleAction` values -// as a slice of strings. -func RulesetRuleActionValues() []string { - return []string{ - string(RulesetRuleActionBlock), - string(RulesetRuleActionChallenge), - string(RulesetRuleActionDDoSDynamic), - string(RulesetRuleActionExecute), - string(RulesetRuleActionForceConnectionClose), - string(RulesetRuleActionJSChallenge), - string(RulesetRuleActionLog), - string(RulesetRuleActionLogCustomField), - string(RulesetRuleActionManagedChallenge), - string(RulesetRuleActionRedirect), - string(RulesetRuleActionRewrite), - string(RulesetRuleActionRoute), - string(RulesetRuleActionScore), - string(RulesetRuleActionSetCacheSettings), - string(RulesetRuleActionSetConfig), - string(RulesetRuleActionServeError), - string(RulesetRuleActionSkip), - } -} - -// RulesetActionParameterProductValues exposes all the available -// `RulesetActionParameterProduct` values as a slice of strings. -func RulesetActionParameterProductValues() []string { - return []string{ - string(RulesetActionParameterProductBIC), - string(RulesetActionParameterProductHOT), - string(RulesetActionParameterProductRateLimit), - string(RulesetActionParameterProductSecurityLevel), - string(RulesetActionParameterProductUABlock), - string(RulesetActionParameterProductWAF), - string(RulesetActionParameterProductZoneLockdown), - } -} - -func RulesetRuleActionParametersHTTPHeaderOperationValues() []string { - return []string{ - string(RulesetRuleActionParametersHTTPHeaderOperationRemove), - string(RulesetRuleActionParametersHTTPHeaderOperationSet), - } -} - -// RulesetRuleAction defines a custom type that is used to express allowed -// values for the rule action. -type RulesetRuleAction string - -// RulesetKind is the custom type for allowed variances of rulesets. -type RulesetKind string - -// RulesetPhase is the custom type for defining at what point the ruleset will -// be applied in the request pipeline. -type RulesetPhase string - -// RulesetActionParameterProduct is the custom type for defining what products -// can be used within the action parameters of a ruleset. -type RulesetActionParameterProduct string - -// RulesetRuleActionParametersHTTPHeaderOperation defines available options for -// HTTP header operations in actions. -type RulesetRuleActionParametersHTTPHeaderOperation string - -// Ruleset contains the structure of a Ruleset. Using `string` for Kind and -// Phase is a developer nicety to support downstream clients like Terraform who -// don't really have a strong and expansive type system. As always, the -// recommendation is to use the types provided where possible to avoid -// surprises. -type Ruleset struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Kind string `json:"kind,omitempty"` - Version string `json:"version,omitempty"` - LastUpdated *time.Time `json:"last_updated,omitempty"` - Phase string `json:"phase,omitempty"` - Rules []RulesetRule `json:"rules"` - ShareableEntitlementName string `json:"shareable_entitlement_name,omitempty"` -} - -// RulesetActionParametersLogCustomField wraps an object that is part of -// request_fields, response_fields or cookie_fields. -type RulesetActionParametersLogCustomField struct { - Name string `json:"name,omitempty"` -} - -// RulesetRuleActionParameters specifies the action parameters for a Ruleset -// rule. -type RulesetRuleActionParameters struct { - ID string `json:"id,omitempty"` - Ruleset string `json:"ruleset,omitempty"` - Rulesets []string `json:"rulesets,omitempty"` - Rules map[string][]string `json:"rules,omitempty"` - Increment int `json:"increment,omitempty"` - URI *RulesetRuleActionParametersURI `json:"uri,omitempty"` - Headers map[string]RulesetRuleActionParametersHTTPHeader `json:"headers,omitempty"` - Products []string `json:"products,omitempty"` - Phases []string `json:"phases,omitempty"` - Overrides *RulesetRuleActionParametersOverrides `json:"overrides,omitempty"` - MatchedData *RulesetRuleActionParametersMatchedData `json:"matched_data,omitempty"` - Version string `json:"version,omitempty"` - Response *RulesetRuleActionParametersBlockResponse `json:"response,omitempty"` - HostHeader string `json:"host_header,omitempty"` - Origin *RulesetRuleActionParametersOrigin `json:"origin,omitempty"` - SNI *RulesetRuleActionParametersSni `json:"sni,omitempty"` - RequestFields []RulesetActionParametersLogCustomField `json:"request_fields,omitempty"` - ResponseFields []RulesetActionParametersLogCustomField `json:"response_fields,omitempty"` - CookieFields []RulesetActionParametersLogCustomField `json:"cookie_fields,omitempty"` - Cache *bool `json:"cache,omitempty"` - EdgeTTL *RulesetRuleActionParametersEdgeTTL `json:"edge_ttl,omitempty"` - BrowserTTL *RulesetRuleActionParametersBrowserTTL `json:"browser_ttl,omitempty"` - ServeStale *RulesetRuleActionParametersServeStale `json:"serve_stale,omitempty"` - Content string `json:"content,omitempty"` - ContentType string `json:"content_type,omitempty"` - StatusCode uint16 `json:"status_code,omitempty"` - RespectStrongETags *bool `json:"respect_strong_etags,omitempty"` - CacheKey *RulesetRuleActionParametersCacheKey `json:"cache_key,omitempty"` - OriginErrorPagePassthru *bool `json:"origin_error_page_passthru,omitempty"` - FromList *RulesetRuleActionParametersFromList `json:"from_list,omitempty"` - FromValue *RulesetRuleActionParametersFromValue `json:"from_value,omitempty"` - AutomaticHTTPSRewrites *bool `json:"automatic_https_rewrites,omitempty"` - AutoMinify *RulesetRuleActionParametersAutoMinify `json:"autominify,omitempty"` - BrowserIntegrityCheck *bool `json:"bic,omitempty"` - DisableApps *bool `json:"disable_apps,omitempty"` - DisableZaraz *bool `json:"disable_zaraz,omitempty"` - DisableRailgun *bool `json:"disable_railgun,omitempty"` - EmailObfuscation *bool `json:"email_obfuscation,omitempty"` - Mirage *bool `json:"mirage,omitempty"` - OpportunisticEncryption *bool `json:"opportunistic_encryption,omitempty"` - Polish *Polish `json:"polish,omitempty"` - RocketLoader *bool `json:"rocket_loader,omitempty"` - SecurityLevel *SecurityLevel `json:"security_level,omitempty"` - ServerSideExcludes *bool `json:"server_side_excludes,omitempty"` - SSL *SSL `json:"ssl,omitempty"` - SXG *bool `json:"sxg,omitempty"` - HotLinkProtection *bool `json:"hotlink_protection,omitempty"` -} - -// RulesetRuleActionParametersFromList holds the FromList struct for -// actions which pull data from a list. -type RulesetRuleActionParametersFromList struct { - Name string `json:"name"` - Key string `json:"key"` -} - -type RulesetRuleActionParametersAutoMinify struct { - HTML bool `json:"html"` - CSS bool `json:"css"` - JS bool `json:"js"` -} - -type RulesetRuleActionParametersFromValue struct { - StatusCode uint16 `json:"status_code,omitempty"` - TargetURL RulesetRuleActionParametersTargetURL `json:"target_url"` - PreserveQueryString bool `json:"preserve_query_string,omitempty"` -} - -type RulesetRuleActionParametersTargetURL struct { - Value string `json:"value,omitempty"` - Expression string `json:"expression,omitempty"` -} - -type RulesetRuleActionParametersEdgeTTL struct { - Mode string `json:"mode,omitempty"` - Default *uint `json:"default,omitempty"` - StatusCodeTTL []RulesetRuleActionParametersStatusCodeTTL `json:"status_code_ttl,omitempty"` -} - -type RulesetRuleActionParametersStatusCodeTTL struct { - StatusCodeRange *RulesetRuleActionParametersStatusCodeRange `json:"status_code_range,omitempty"` - StatusCodeValue *uint `json:"status_code,omitempty"` - Value *int `json:"value,omitempty"` -} - -type RulesetRuleActionParametersStatusCodeRange struct { - From *uint `json:"from,omitempty"` - To *uint `json:"to,omitempty"` -} - -type RulesetRuleActionParametersBrowserTTL struct { - Mode string `json:"mode"` - Default *uint `json:"default,omitempty"` -} - -type RulesetRuleActionParametersServeStale struct { - DisableStaleWhileUpdating *bool `json:"disable_stale_while_updating,omitempty"` -} - -type RulesetRuleActionParametersCacheKey struct { - CacheByDeviceType *bool `json:"cache_by_device_type,omitempty"` - IgnoreQueryStringsOrder *bool `json:"ignore_query_strings_order,omitempty"` - CacheDeceptionArmor *bool `json:"cache_deception_armor,omitempty"` - CustomKey *RulesetRuleActionParametersCustomKey `json:"custom_key,omitempty"` -} - -type RulesetRuleActionParametersCustomKey struct { - Query *RulesetRuleActionParametersCustomKeyQuery `json:"query_string,omitempty"` - Header *RulesetRuleActionParametersCustomKeyHeader `json:"header,omitempty"` - Cookie *RulesetRuleActionParametersCustomKeyCookie `json:"cookie,omitempty"` - User *RulesetRuleActionParametersCustomKeyUser `json:"user,omitempty"` - Host *RulesetRuleActionParametersCustomKeyHost `json:"host,omitempty"` -} - -type RulesetRuleActionParametersCustomKeyHeader struct { - RulesetRuleActionParametersCustomKeyFields - ExcludeOrigin *bool `json:"exclude_origin,omitempty"` -} - -type RulesetRuleActionParametersCustomKeyCookie RulesetRuleActionParametersCustomKeyFields - -type RulesetRuleActionParametersCustomKeyFields struct { - Include []string `json:"include,omitempty"` - CheckPresence []string `json:"check_presence,omitempty"` -} - -type RulesetRuleActionParametersCustomKeyQuery struct { - Include *RulesetRuleActionParametersCustomKeyList `json:"include,omitempty"` - Exclude *RulesetRuleActionParametersCustomKeyList `json:"exclude,omitempty"` - Ignore *bool `json:"ignore,omitempty"` -} - -type RulesetRuleActionParametersCustomKeyList struct { - List []string - All bool -} - -func (s *RulesetRuleActionParametersCustomKeyList) UnmarshalJSON(data []byte) error { - var all string - if err := json.Unmarshal(data, &all); err == nil { - s.All = all == "*" - return nil - } - var list []string - if err := json.Unmarshal(data, &list); err == nil { - s.List = list - } - - return nil -} - -func (s RulesetRuleActionParametersCustomKeyList) MarshalJSON() ([]byte, error) { - if s.All { - return json.Marshal("*") - } - return json.Marshal(s.List) -} - -type RulesetRuleActionParametersCustomKeyUser struct { - DeviceType *bool `json:"device_type,omitempty"` - Geo *bool `json:"geo,omitempty"` - Lang *bool `json:"lang,omitempty"` -} - -type RulesetRuleActionParametersCustomKeyHost struct { - Resolved *bool `json:"resolved,omitempty"` -} - -// RulesetRuleActionParametersBlockResponse holds the BlockResponse struct -// for an action parameter. -type RulesetRuleActionParametersBlockResponse struct { - StatusCode uint16 `json:"status_code"` - ContentType string `json:"content_type"` - Content string `json:"content"` -} - -// RulesetRuleActionParametersURI holds the URI struct for an action parameter. -type RulesetRuleActionParametersURI struct { - Path *RulesetRuleActionParametersURIPath `json:"path,omitempty"` - Query *RulesetRuleActionParametersURIQuery `json:"query,omitempty"` - Origin bool `json:"origin,omitempty"` -} - -// RulesetRuleActionParametersURIPath holds the path specific portion of a URI -// action parameter. -type RulesetRuleActionParametersURIPath struct { - Value string `json:"value,omitempty"` - Expression string `json:"expression,omitempty"` -} - -// RulesetRuleActionParametersURIQuery holds the query specific portion of a URI -// action parameter. -type RulesetRuleActionParametersURIQuery struct { - Value string `json:"value,omitempty"` - Expression string `json:"expression,omitempty"` -} - -// RulesetRuleActionParametersHTTPHeader is the definition for define action -// parameters that involve HTTP headers. -type RulesetRuleActionParametersHTTPHeader struct { - Operation string `json:"operation,omitempty"` - Value string `json:"value,omitempty"` - Expression string `json:"expression,omitempty"` -} - -type RulesetRuleActionParametersOverrides struct { - Enabled *bool `json:"enabled,omitempty"` - Action string `json:"action,omitempty"` - SensitivityLevel string `json:"sensitivity_level,omitempty"` - Categories []RulesetRuleActionParametersCategories `json:"categories,omitempty"` - Rules []RulesetRuleActionParametersRules `json:"rules,omitempty"` -} - -type RulesetRuleActionParametersCategories struct { - Category string `json:"category"` - Action string `json:"action,omitempty"` - Enabled *bool `json:"enabled,omitempty"` -} - -type RulesetRuleActionParametersRules struct { - ID string `json:"id"` - Action string `json:"action,omitempty"` - Enabled *bool `json:"enabled,omitempty"` - ScoreThreshold int `json:"score_threshold,omitempty"` - SensitivityLevel string `json:"sensitivity_level,omitempty"` -} - -// RulesetRuleActionParametersMatchedData holds the structure for WAF based -// payload logging. -type RulesetRuleActionParametersMatchedData struct { - PublicKey string `json:"public_key,omitempty"` -} - -// RulesetRuleActionParametersOrigin is the definition for route action -// parameters that involve origin overrides. -type RulesetRuleActionParametersOrigin struct { - Host string `json:"host,omitempty"` - Port uint16 `json:"port,omitempty"` -} - -// RulesetRuleActionParametersSni is the definition for the route action -// parameters that involve SNI overrides. -type RulesetRuleActionParametersSni struct { - Value string `json:"value"` -} - -type Polish int - -const ( - _ Polish = iota - PolishOff - PolishLossless - PolishLossy -) - -func (p Polish) MarshalJSON() ([]byte, error) { - return json.Marshal(p.String()) -} - -func (p Polish) String() string { - return [...]string{"off", "lossless", "lossy"}[p-1] -} - -func (p *Polish) UnmarshalJSON(data []byte) error { - var ( - s string - err error - ) - err = json.Unmarshal(data, &s) - if err != nil { - return err - } - v, err := PolishFromString(s) - if err != nil { - return err - } - *p = *v - return nil -} - -func PolishFromString(s string) (*Polish, error) { - s = strings.ToLower(s) - var v Polish - switch s { - case "off": - v = PolishOff - case "lossless": - v = PolishLossless - case "lossy": - v = PolishLossy - default: - return nil, fmt.Errorf("unknown variant for polish: %s", s) - } - return &v, nil -} - -func (p Polish) IntoRef() *Polish { - return &p -} - -type SecurityLevel int - -const ( - _ SecurityLevel = iota - SecurityLevelOff - SecurityLevelEssentiallyOff - SecurityLevelLow - SecurityLevelMedium - SecurityLevelHigh - SecurityLevelHelp -) - -func (p SecurityLevel) MarshalJSON() ([]byte, error) { - return json.Marshal(p.String()) -} - -func (p SecurityLevel) String() string { - return [...]string{"off", "essentially_off", "low", "medium", "high", "under_attack"}[p-1] -} - -func (p *SecurityLevel) UnmarshalJSON(data []byte) error { - var ( - s string - err error - ) - err = json.Unmarshal(data, &s) - if err != nil { - return err - } - v, err := SecurityLevelFromString(s) - if err != nil { - return err - } - *p = *v - return nil -} - -func SecurityLevelFromString(s string) (*SecurityLevel, error) { - s = strings.ToLower(s) - var v SecurityLevel - switch s { - case "off": - v = SecurityLevelOff - case "essentially_off": - v = SecurityLevelEssentiallyOff - case "low": - v = SecurityLevelLow - case "medium": - v = SecurityLevelMedium - case "high": - v = SecurityLevelHigh - case "under_attack": - v = SecurityLevelHelp - default: - return nil, fmt.Errorf("unknown variant for security_level: %s", s) - } - return &v, nil -} - -func (p SecurityLevel) IntoRef() *SecurityLevel { - return &p -} - -type SSL int - -const ( - _ SSL = iota - SSLOff - SSLFlexible - SSLFull - SSLStrict - SSLOriginPull -) - -func (p SSL) MarshalJSON() ([]byte, error) { - return json.Marshal(p.String()) -} - -func (p SSL) String() string { - return [...]string{"off", "flexible", "full", "strict", "origin_pull"}[p-1] -} - -func (p *SSL) UnmarshalJSON(data []byte) error { - var ( - s string - err error - ) - err = json.Unmarshal(data, &s) - if err != nil { - return err - } - v, err := SSLFromString(s) - if err != nil { - return err - } - *p = *v - return nil -} - -func SSLFromString(s string) (*SSL, error) { - s = strings.ToLower(s) - var v SSL - switch s { - case "off": - v = SSLOff - case "flexible": - v = SSLFlexible - case "full": - v = SSLFull - case "strict": - v = SSLStrict - case "origin_pull": - v = SSLOriginPull - default: - return nil, fmt.Errorf("unknown variant for ssl: %s", s) - } - return &v, nil -} - -func (p SSL) IntoRef() *SSL { - return &p -} - -// RulesetRule contains information about a single Ruleset Rule. -type RulesetRule struct { - ID string `json:"id,omitempty"` - Version string `json:"version,omitempty"` - Action string `json:"action"` - ActionParameters *RulesetRuleActionParameters `json:"action_parameters,omitempty"` - Expression string `json:"expression"` - Description string `json:"description"` - LastUpdated *time.Time `json:"last_updated,omitempty"` - Ref string `json:"ref,omitempty"` - Enabled bool `json:"enabled"` - ScoreThreshold int `json:"score_threshold,omitempty"` - RateLimit *RulesetRuleRateLimit `json:"ratelimit,omitempty"` - ExposedCredentialCheck *RulesetRuleExposedCredentialCheck `json:"exposed_credential_check,omitempty"` - Logging *RulesetRuleLogging `json:"logging,omitempty"` -} - -// RulesetRuleRateLimit contains the structure of a HTTP rate limit Ruleset Rule. -type RulesetRuleRateLimit struct { - Characteristics []string `json:"characteristics,omitempty"` - RequestsPerPeriod int `json:"requests_per_period,omitempty"` - ScorePerPeriod int `json:"score_per_period,omitempty"` - ScoreResponseHeaderName string `json:"score_response_header_name,omitempty"` - Period int `json:"period,omitempty"` - MitigationTimeout int `json:"mitigation_timeout,omitempty"` - CountingExpression string `json:"counting_expression,omitempty"` - RequestsToOrigin bool `json:"requests_to_origin,omitempty"` -} - -// RulesetRuleExposedCredentialCheck contains the structure of an exposed -// credential check Ruleset Rule. -type RulesetRuleExposedCredentialCheck struct { - UsernameExpression string `json:"username_expression,omitempty"` - PasswordExpression string `json:"password_expression,omitempty"` -} - -// RulesetRuleLogging contains the logging configuration for the rule. -type RulesetRuleLogging struct { - Enabled *bool `json:"enabled,omitempty"` -} - -// UpdateRulesetRequest is the representation of a Ruleset update. -type UpdateRulesetRequest struct { - Description string `json:"description"` - Rules []RulesetRule `json:"rules"` -} - -// ListRulesetResponse contains all Rulesets. -type ListRulesetResponse struct { - Response - Result []Ruleset `json:"result"` -} - -// GetRulesetResponse contains a single Ruleset. -type GetRulesetResponse struct { - Response - Result Ruleset `json:"result"` -} - -// CreateRulesetResponse contains response data when creating a new Ruleset. -type CreateRulesetResponse struct { - Response - Result Ruleset `json:"result"` -} - -// UpdateRulesetResponse contains response data when updating an existing -// Ruleset. -type UpdateRulesetResponse struct { - Response - Result Ruleset `json:"result"` -} - -// ListZoneRulesets fetches all rulesets for a zone. -// -// API reference: https://api.cloudflare.com/#zone-rulesets-list-zone-rulesets -func (api *API) ListZoneRulesets(ctx context.Context, zoneID string) ([]Ruleset, error) { - return api.listRulesets(ctx, ZoneRouteRoot, zoneID) -} - -// ListAccountRulesets fetches all rulesets for an account. -// -// API reference: https://api.cloudflare.com/#account-rulesets-list-account-rulesets -func (api *API) ListAccountRulesets(ctx context.Context, accountID string) ([]Ruleset, error) { - return api.listRulesets(ctx, AccountRouteRoot, accountID) -} - -// listRulesets lists all Rulesets for a given zone or account depending on the -// identifier type provided. -func (api *API) listRulesets(ctx context.Context, identifierType RouteRoot, identifier string) ([]Ruleset, error) { - uri := fmt.Sprintf("/%s/%s/rulesets", identifierType, identifier) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Ruleset{}, err - } - - result := ListRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetZoneRuleset fetches a single ruleset for a zone. -// -// API reference: https://api.cloudflare.com/#zone-rulesets-get-a-zone-ruleset -func (api *API) GetZoneRuleset(ctx context.Context, zoneID, rulesetID string) (Ruleset, error) { - return api.getRuleset(ctx, ZoneRouteRoot, zoneID, rulesetID) -} - -// GetAccountRuleset fetches a single ruleset for an account. -// -// API reference: https://api.cloudflare.com/#account-rulesets-get-an-account-ruleset -func (api *API) GetAccountRuleset(ctx context.Context, accountID, rulesetID string) (Ruleset, error) { - return api.getRuleset(ctx, AccountRouteRoot, accountID, rulesetID) -} - -// getRuleset fetches a single ruleset based on the zone or account, the -// identifier and the ruleset ID. -func (api *API) getRuleset(ctx context.Context, identifierType RouteRoot, identifier, rulesetID string) (Ruleset, error) { - uri := fmt.Sprintf("/%s/%s/rulesets/%s", identifierType, identifier, rulesetID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Ruleset{}, err - } - - result := GetRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// CreateZoneRuleset creates a new ruleset for a zone. -// -// API reference: https://api.cloudflare.com/#zone-rulesets-create-zone-ruleset -func (api *API) CreateZoneRuleset(ctx context.Context, zoneID string, ruleset Ruleset) (Ruleset, error) { - return api.createRuleset(ctx, ZoneRouteRoot, zoneID, ruleset) -} - -// CreateAccountRuleset creates a new ruleset for an account. -// -// API reference: https://api.cloudflare.com/#account-rulesets-create-account-ruleset -func (api *API) CreateAccountRuleset(ctx context.Context, accountID string, ruleset Ruleset) (Ruleset, error) { - return api.createRuleset(ctx, AccountRouteRoot, accountID, ruleset) -} - -func (api *API) createRuleset(ctx context.Context, identifierType RouteRoot, identifier string, ruleset Ruleset) (Ruleset, error) { - uri := fmt.Sprintf("/%s/%s/rulesets", identifierType, identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, ruleset) - if err != nil { - return Ruleset{}, err - } - - result := CreateRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// DeleteZoneRuleset deletes a single ruleset for a zone. -// -// API reference: https://api.cloudflare.com/#zone-rulesets-delete-zone-ruleset -func (api *API) DeleteZoneRuleset(ctx context.Context, zoneID, rulesetID string) error { - return api.deleteRuleset(ctx, ZoneRouteRoot, zoneID, rulesetID) -} - -// DeleteAccountRuleset deletes a single ruleset for an account. -// -// API reference: https://api.cloudflare.com/#account-rulesets-delete-account-ruleset -func (api *API) DeleteAccountRuleset(ctx context.Context, accountID, rulesetID string) error { - return api.deleteRuleset(ctx, AccountRouteRoot, accountID, rulesetID) -} - -// deleteRuleset removes a ruleset based on the ruleset ID. -func (api *API) deleteRuleset(ctx context.Context, identifierType RouteRoot, identifier, rulesetID string) error { - uri := fmt.Sprintf("/%s/%s/rulesets/%s", identifierType, identifier, rulesetID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - // The API is not implementing the standard response blob but returns an - // empty response (204) in case of a success. So we are checking for the - // response body size here. - if len(res) > 0 { - return fmt.Errorf(errMakeRequestError+": %w", errors.New(string(res))) - } - - return nil -} - -// UpdateZoneRuleset updates a single ruleset for a zone. -// -// API reference: https://api.cloudflare.com/#zone-rulesets-update-a-zone-ruleset -func (api *API) UpdateZoneRuleset(ctx context.Context, zoneID, rulesetID, description string, rules []RulesetRule) (Ruleset, error) { - return api.updateRuleset(ctx, ZoneRouteRoot, zoneID, rulesetID, description, rules) -} - -// UpdateAccountRuleset updates a single ruleset for an account. -// -// API reference: https://api.cloudflare.com/#account-rulesets-update-account-ruleset -func (api *API) UpdateAccountRuleset(ctx context.Context, accountID, rulesetID, description string, rules []RulesetRule) (Ruleset, error) { - return api.updateRuleset(ctx, AccountRouteRoot, accountID, rulesetID, description, rules) -} - -// updateRuleset updates a ruleset based on the ruleset ID. -func (api *API) updateRuleset(ctx context.Context, identifierType RouteRoot, identifier, rulesetID, description string, rules []RulesetRule) (Ruleset, error) { - uri := fmt.Sprintf("/%s/%s/rulesets/%s", identifierType, identifier, rulesetID) - payload := UpdateRulesetRequest{Description: description, Rules: rules} - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, payload) - if err != nil { - return Ruleset{}, err - } - - result := UpdateRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// GetZoneRulesetPhase returns a ruleset phase for a zone. -// -// API reference: TBA. -func (api *API) GetZoneRulesetPhase(ctx context.Context, zoneID, rulesetPhase string) (Ruleset, error) { - return api.getRulesetPhase(ctx, ZoneRouteRoot, zoneID, rulesetPhase) -} - -// GetAccountRulesetPhase returns a ruleset phase for an account. -// -// API reference: TBA. -func (api *API) GetAccountRulesetPhase(ctx context.Context, accountID, rulesetPhase string) (Ruleset, error) { - return api.getRulesetPhase(ctx, AccountRouteRoot, accountID, rulesetPhase) -} - -// getRulesetPhase returns a ruleset phase based on the zone or account and the -// identifier. -func (api *API) getRulesetPhase(ctx context.Context, identifierType RouteRoot, identifier, rulesetPhase string) (Ruleset, error) { - uri := fmt.Sprintf("/%s/%s/rulesets/phases/%s/entrypoint", identifierType, identifier, rulesetPhase) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Ruleset{}, err - } - - result := GetRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// UpdateZoneRulesetPhase updates a ruleset phase for a zone. -// -// API reference: TBA. -func (api *API) UpdateZoneRulesetPhase(ctx context.Context, zoneID, rulesetPhase string, ruleset Ruleset) (Ruleset, error) { - return api.updateRulesetPhase(ctx, ZoneRouteRoot, zoneID, rulesetPhase, ruleset) -} - -// UpdateAccountRulesetPhase updates a ruleset phase for an account. -// -// API reference: TBA. -func (api *API) UpdateAccountRulesetPhase(ctx context.Context, accountID, rulesetPhase string, ruleset Ruleset) (Ruleset, error) { - return api.updateRulesetPhase(ctx, AccountRouteRoot, accountID, rulesetPhase, ruleset) -} - -// updateRulesetPhase updates a ruleset phase based on the zone or account, the -// identifier and the rules. -func (api *API) updateRulesetPhase(ctx context.Context, identifierType RouteRoot, identifier, rulesetPhase string, ruleset Ruleset) (Ruleset, error) { - uri := fmt.Sprintf("/%s/%s/rulesets/phases/%s/entrypoint", identifierType, identifier, rulesetPhase) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, ruleset) - if err != nil { - return Ruleset{}, err - } - - result := GetRulesetResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_primaries.go b/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_primaries.go deleted file mode 100644 index 4aa623c..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_primaries.go +++ /dev/null @@ -1,164 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -const ( - errSecondaryDNSInvalidPrimaryID = "secondary DNS primary ID is required" - errSecondaryDNSInvalidPrimaryIP = "secondary DNS primary IP invalid" - errSecondaryDNSInvalidPrimaryPort = "secondary DNS primary port invalid" -) - -// SecondaryDNSPrimary is the representation of the DNS Primary. -type SecondaryDNSPrimary struct { - ID string `json:"id,omitempty"` - IP string `json:"ip"` - Port int `json:"port"` - IxfrEnable bool `json:"ixfr_enable"` - TsigID string `json:"tsig_id"` - Name string `json:"name"` -} - -// SecondaryDNSPrimaryDetailResponse is the API representation of a single -// secondary DNS primary response. -type SecondaryDNSPrimaryDetailResponse struct { - Response - Result SecondaryDNSPrimary `json:"result"` -} - -// SecondaryDNSPrimaryListResponse is the API representation of all secondary DNS -// primaries. -type SecondaryDNSPrimaryListResponse struct { - Response - Result []SecondaryDNSPrimary `json:"result"` -} - -// GetSecondaryDNSPrimary returns a single secondary DNS primary. -// -// API reference: https://api.cloudflare.com/#secondary-dns-primary--primary-details -func (api *API) GetSecondaryDNSPrimary(ctx context.Context, accountID, primaryID string) (SecondaryDNSPrimary, error) { - uri := fmt.Sprintf("/accounts/%s/secondary_dns/primaries/%s", accountID, primaryID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return SecondaryDNSPrimary{}, err - } - - var r SecondaryDNSPrimaryDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListSecondaryDNSPrimaries returns all secondary DNS primaries for an account. -// -// API reference: https://api.cloudflare.com/#secondary-dns-primary--list-primaries -func (api *API) ListSecondaryDNSPrimaries(ctx context.Context, accountID string) ([]SecondaryDNSPrimary, error) { - uri := fmt.Sprintf("/accounts/%s/secondary_dns/primaries", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []SecondaryDNSPrimary{}, err - } - - var r SecondaryDNSPrimaryListResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateSecondaryDNSPrimary creates a secondary DNS primary. -// -// API reference: https://api.cloudflare.com/#secondary-dns-primary--create-primary -func (api *API) CreateSecondaryDNSPrimary(ctx context.Context, accountID string, primary SecondaryDNSPrimary) (SecondaryDNSPrimary, error) { - if err := validateRequiredSecondaryDNSPrimaries(primary); err != nil { - return SecondaryDNSPrimary{}, err - } - - uri := fmt.Sprintf("/accounts/%s/secondary_dns/primaries", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, SecondaryDNSPrimary{ - IP: primary.IP, - Port: primary.Port, - IxfrEnable: primary.IxfrEnable, - TsigID: primary.TsigID, - Name: primary.Name, - }) - if err != nil { - return SecondaryDNSPrimary{}, err - } - - var r SecondaryDNSPrimaryDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateSecondaryDNSPrimary creates a secondary DNS primary. -// -// API reference: https://api.cloudflare.com/#secondary-dns-primary--update-primary -func (api *API) UpdateSecondaryDNSPrimary(ctx context.Context, accountID string, primary SecondaryDNSPrimary) (SecondaryDNSPrimary, error) { - if primary.ID == "" { - return SecondaryDNSPrimary{}, errors.New(errSecondaryDNSInvalidPrimaryID) - } - - if err := validateRequiredSecondaryDNSPrimaries(primary); err != nil { - return SecondaryDNSPrimary{}, err - } - - uri := fmt.Sprintf("/accounts/%s/secondary_dns/primaries/%s", accountID, primary.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, SecondaryDNSPrimary{ - IP: primary.IP, - Port: primary.Port, - IxfrEnable: primary.IxfrEnable, - TsigID: primary.TsigID, - Name: primary.Name, - }) - if err != nil { - return SecondaryDNSPrimary{}, err - } - - var r SecondaryDNSPrimaryDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteSecondaryDNSPrimary deletes a secondary DNS primary. -// -// API reference: https://api.cloudflare.com/#secondary-dns-primary--delete-primary -func (api *API) DeleteSecondaryDNSPrimary(ctx context.Context, accountID, primaryID string) error { - uri := fmt.Sprintf("/zones/%s/secondary_dns/primaries/%s", accountID, primaryID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return err - } - - return nil -} - -func validateRequiredSecondaryDNSPrimaries(p SecondaryDNSPrimary) error { - if p.IP == "" { - return errors.New(errSecondaryDNSInvalidPrimaryIP) - } - - if p.Port == 0 { - return errors.New(errSecondaryDNSInvalidPrimaryPort) - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_tsig.go b/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_tsig.go deleted file mode 100644 index ed9a4bc..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_tsig.go +++ /dev/null @@ -1,131 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -const ( - errSecondaryDNSTSIGMissingID = "secondary DNS TSIG ID is required" -) - -// SecondaryDNSTSIG contains the structure for a secondary DNS TSIG. -type SecondaryDNSTSIG struct { - ID string `json:"id,omitempty"` - Name string `json:"name"` - Secret string `json:"secret"` - Algo string `json:"algo"` -} - -// SecondaryDNSTSIGDetailResponse is the API response for a single secondary -// DNS TSIG. -type SecondaryDNSTSIGDetailResponse struct { - Response - Result SecondaryDNSTSIG `json:"result"` -} - -// SecondaryDNSTSIGListResponse is the API response for all secondary DNS TSIGs. -type SecondaryDNSTSIGListResponse struct { - Response - Result []SecondaryDNSTSIG `json:"result"` -} - -// GetSecondaryDNSTSIG gets a single account level TSIG for a secondary DNS -// configuration. -// -// API reference: https://api.cloudflare.com/#secondary-dns-tsig--tsig-details -func (api *API) GetSecondaryDNSTSIG(ctx context.Context, accountID, tsigID string) (SecondaryDNSTSIG, error) { - uri := fmt.Sprintf("/accounts/%s/secondary_dns/tsigs/%s", accountID, tsigID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return SecondaryDNSTSIG{}, err - } - - var r SecondaryDNSTSIGDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListSecondaryDNSTSIGs gets all account level TSIG for a secondary DNS -// configuration. -// -// API reference: https://api.cloudflare.com/#secondary-dns-tsig--list-tsigs -func (api *API) ListSecondaryDNSTSIGs(ctx context.Context, accountID string) ([]SecondaryDNSTSIG, error) { - uri := fmt.Sprintf("/accounts/%s/secondary_dns/tsigs", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []SecondaryDNSTSIG{}, err - } - - var r SecondaryDNSTSIGListResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateSecondaryDNSTSIG creates a secondary DNS TSIG at the account level. -// -// API reference: https://api.cloudflare.com/#secondary-dns-tsig--create-tsig -func (api *API) CreateSecondaryDNSTSIG(ctx context.Context, accountID string, tsig SecondaryDNSTSIG) (SecondaryDNSTSIG, error) { - uri := fmt.Sprintf("/accounts/%s/secondary_dns/tsigs", accountID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, tsig) - - if err != nil { - return SecondaryDNSTSIG{}, err - } - - result := SecondaryDNSTSIGDetailResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// UpdateSecondaryDNSTSIG updates an existing secondary DNS TSIG at -// the account level. -// -// API reference: https://api.cloudflare.com/#secondary-dns-tsig--update-tsig -func (api *API) UpdateSecondaryDNSTSIG(ctx context.Context, accountID string, tsig SecondaryDNSTSIG) (SecondaryDNSTSIG, error) { - if tsig.ID == "" { - return SecondaryDNSTSIG{}, errors.New(errSecondaryDNSTSIGMissingID) - } - - uri := fmt.Sprintf("/accounts/%s/secondary_dns/tsigs/%s", accountID, tsig.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, tsig) - - if err != nil { - return SecondaryDNSTSIG{}, err - } - - result := SecondaryDNSTSIGDetailResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// DeleteSecondaryDNSTSIG deletes a secondary DNS TSIG. -// -// API reference: https://api.cloudflare.com/#secondary-dns-tsig--delete-tsig -func (api *API) DeleteSecondaryDNSTSIG(ctx context.Context, accountID, tsigID string) error { - uri := fmt.Sprintf("/accounts/%s/secondary_dns/tsigs/%s", accountID, tsigID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_zone.go b/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_zone.go deleted file mode 100644 index 662a2f2..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/secondary_dns_zone.go +++ /dev/null @@ -1,171 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -const ( - errSecondaryDNSInvalidAutoRefreshValue = "secondary DNS auto refresh value is invalid" - errSecondaryDNSInvalidZoneName = "secondary DNS zone name is invalid" - errSecondaryDNSInvalidPrimaries = "secondary DNS primaries value is invalid" -) - -// SecondaryDNSZone contains the high level structure of a secondary DNS zone. -type SecondaryDNSZone struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Primaries []string `json:"primaries,omitempty"` - AutoRefreshSeconds int `json:"auto_refresh_seconds,omitempty"` - SoaSerial int `json:"soa_serial,omitempty"` - CreatedTime time.Time `json:"created_time,omitempty"` - CheckedTime time.Time `json:"checked_time,omitempty"` - ModifiedTime time.Time `json:"modified_time,omitempty"` -} - -// SecondaryDNSZoneDetailResponse is the API response for a single secondary -// DNS zone. -type SecondaryDNSZoneDetailResponse struct { - Response - Result SecondaryDNSZone `json:"result"` -} - -// SecondaryDNSZoneAXFRResponse is the API response for a single secondary -// DNS AXFR response. -type SecondaryDNSZoneAXFRResponse struct { - Response - Result string `json:"result"` -} - -// GetSecondaryDNSZone returns the secondary DNS zone configuration for a -// single zone. -// -// API reference: https://api.cloudflare.com/#secondary-dns-secondary-zone-configuration-details -func (api *API) GetSecondaryDNSZone(ctx context.Context, zoneID string) (SecondaryDNSZone, error) { - uri := fmt.Sprintf("/zones/%s/secondary_dns", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return SecondaryDNSZone{}, err - } - - var r SecondaryDNSZoneDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return SecondaryDNSZone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateSecondaryDNSZone creates a secondary DNS zone. -// -// API reference: https://api.cloudflare.com/#secondary-dns-create-secondary-zone-configuration -func (api *API) CreateSecondaryDNSZone(ctx context.Context, zoneID string, zone SecondaryDNSZone) (SecondaryDNSZone, error) { - if err := validateRequiredSecondaryDNSZoneValues(zone); err != nil { - return SecondaryDNSZone{}, err - } - - uri := fmt.Sprintf("/zones/%s/secondary_dns", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, - SecondaryDNSZone{ - Name: zone.Name, - AutoRefreshSeconds: zone.AutoRefreshSeconds, - Primaries: zone.Primaries, - }, - ) - - if err != nil { - return SecondaryDNSZone{}, err - } - - result := SecondaryDNSZoneDetailResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSZone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// UpdateSecondaryDNSZone updates an existing secondary DNS zone. -// -// API reference: https://api.cloudflare.com/#secondary-dns-update-secondary-zone-configuration -func (api *API) UpdateSecondaryDNSZone(ctx context.Context, zoneID string, zone SecondaryDNSZone) (SecondaryDNSZone, error) { - if err := validateRequiredSecondaryDNSZoneValues(zone); err != nil { - return SecondaryDNSZone{}, err - } - - uri := fmt.Sprintf("/zones/%s/secondary_dns", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, - SecondaryDNSZone{ - Name: zone.Name, - AutoRefreshSeconds: zone.AutoRefreshSeconds, - Primaries: zone.Primaries, - }, - ) - - if err != nil { - return SecondaryDNSZone{}, err - } - - result := SecondaryDNSZoneDetailResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSZone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result, nil -} - -// DeleteSecondaryDNSZone deletes a secondary DNS zone. -// -// API reference: https://api.cloudflare.com/#secondary-dns-delete-secondary-zone-configuration -func (api *API) DeleteSecondaryDNSZone(ctx context.Context, zoneID string) error { - uri := fmt.Sprintf("/zones/%s/secondary_dns", zoneID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - if err != nil { - return err - } - - return nil -} - -// ForceSecondaryDNSZoneAXFR requests an immediate AXFR request. -// -// API reference: https://api.cloudflare.com/#secondary-dns-update-secondary-zone-configuration -func (api *API) ForceSecondaryDNSZoneAXFR(ctx context.Context, zoneID string) error { - uri := fmt.Sprintf("/zones/%s/secondary_dns/force_axfr", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - - if err != nil { - return err - } - - result := SecondaryDNSZoneAXFRResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// validateRequiredSecondaryDNSZoneValues ensures that the payload matches the -// API requirements for required fields. -func validateRequiredSecondaryDNSZoneValues(zone SecondaryDNSZone) error { - if zone.Name == "" { - return errors.New(errSecondaryDNSInvalidZoneName) - } - - if zone.AutoRefreshSeconds == 0 || zone.AutoRefreshSeconds < 0 { - return errors.New(errSecondaryDNSInvalidAutoRefreshValue) - } - - if len(zone.Primaries) == 0 { - return errors.New(errSecondaryDNSInvalidPrimaries) - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/spectrum.go b/vendor/github.com/cloudflare/cloudflare-go/spectrum.go deleted file mode 100644 index 8fe42b2..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/spectrum.go +++ /dev/null @@ -1,367 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net" - "net/http" - "strconv" - "strings" - "time" -) - -// ProxyProtocol implements json.Unmarshaler in order to support deserializing of the deprecated boolean -// value for `proxy_protocol`. -type ProxyProtocol string - -// UnmarshalJSON handles deserializing of both the deprecated boolean value and the current string value -// for the `proxy_protocol` field. -func (p *ProxyProtocol) UnmarshalJSON(data []byte) error { - var raw interface{} - if err := json.Unmarshal(data, &raw); err != nil { - return err - } - - switch pp := raw.(type) { - case string: - *p = ProxyProtocol(pp) - case bool: - if pp { - *p = "v1" - } else { - *p = "off" - } - default: - return fmt.Errorf("invalid type for proxy_protocol field: %T", pp) - } - return nil -} - -// SpectrumApplicationOriginPort defines a union of a single port or range of ports. -type SpectrumApplicationOriginPort struct { - Port, Start, End uint16 -} - -// ErrOriginPortInvalid is a common error for failing to parse a single port or port range. -var ErrOriginPortInvalid = errors.New("invalid origin port") - -func (p *SpectrumApplicationOriginPort) parse(s string) error { - switch split := strings.Split(s, "-"); len(split) { - case 1: - i, err := strconv.ParseUint(split[0], 10, 16) - if err != nil { - return err - } - p.Port = uint16(i) - case 2: - start, err := strconv.ParseUint(split[0], 10, 16) - if err != nil { - return err - } - end, err := strconv.ParseUint(split[1], 10, 16) - if err != nil { - return err - } - if start >= end { - return ErrOriginPortInvalid - } - p.Start = uint16(start) - p.End = uint16(end) - default: - return ErrOriginPortInvalid - } - return nil -} - -// UnmarshalJSON converts a byte slice into a single port or port range. -func (p *SpectrumApplicationOriginPort) UnmarshalJSON(b []byte) error { - var port interface{} - if err := json.Unmarshal(b, &port); err != nil { - return err - } - - switch i := port.(type) { - case float64: - p.Port = uint16(i) - case string: - if err := p.parse(i); err != nil { - return err - } - } - - return nil -} - -// MarshalJSON converts a single port or port range to a suitable byte slice. -func (p *SpectrumApplicationOriginPort) MarshalJSON() ([]byte, error) { - if p.End > 0 { - return json.Marshal(fmt.Sprintf("%d-%d", p.Start, p.End)) - } - return json.Marshal(p.Port) -} - -// SpectrumApplication defines a single Spectrum Application. -type SpectrumApplication struct { - DNS SpectrumApplicationDNS `json:"dns,omitempty"` - OriginDirect []string `json:"origin_direct,omitempty"` - ID string `json:"id,omitempty"` - Protocol string `json:"protocol,omitempty"` - TrafficType string `json:"traffic_type,omitempty"` - TLS string `json:"tls,omitempty"` - ProxyProtocol ProxyProtocol `json:"proxy_protocol,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - OriginDNS *SpectrumApplicationOriginDNS `json:"origin_dns,omitempty"` - OriginPort *SpectrumApplicationOriginPort `json:"origin_port,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - EdgeIPs *SpectrumApplicationEdgeIPs `json:"edge_ips,omitempty"` - ArgoSmartRouting bool `json:"argo_smart_routing,omitempty"` - IPv4 bool `json:"ipv4,omitempty"` - IPFirewall bool `json:"ip_firewall,omitempty"` -} - -// UnmarshalJSON handles setting the `ProxyProtocol` field based on the value of the deprecated `spp` field. -func (a *SpectrumApplication) UnmarshalJSON(data []byte) error { - var body map[string]interface{} - if err := json.Unmarshal(data, &body); err != nil { - return err - } - - var app spectrumApplicationRaw - if err := json.Unmarshal(data, &app); err != nil { - return err - } - - if spp, ok := body["spp"]; ok && spp.(bool) { - app.ProxyProtocol = "simple" - } - - *a = SpectrumApplication(app) - return nil -} - -// spectrumApplicationRaw is used to inspect an application body to support the deprecated boolean value for `spp`. -type spectrumApplicationRaw SpectrumApplication - -// SpectrumApplicationDNS holds the external DNS configuration for a Spectrum -// Application. -type SpectrumApplicationDNS struct { - Type string `json:"type"` - Name string `json:"name"` -} - -// SpectrumApplicationOriginDNS holds the origin DNS configuration for a Spectrum -// Application. -type SpectrumApplicationOriginDNS struct { - Name string `json:"name"` -} - -// SpectrumApplicationDetailResponse is the structure of the detailed response -// from the API. -type SpectrumApplicationDetailResponse struct { - Response - Result SpectrumApplication `json:"result"` -} - -// SpectrumApplicationsDetailResponse is the structure of the detailed response -// from the API. -type SpectrumApplicationsDetailResponse struct { - Response - Result []SpectrumApplication `json:"result"` -} - -// SpectrumApplicationEdgeIPs represents configuration for Bring-Your-Own-IP -// https://developers.cloudflare.com/spectrum/getting-started/byoip/ -type SpectrumApplicationEdgeIPs struct { - Type SpectrumApplicationEdgeType `json:"type"` - Connectivity *SpectrumApplicationConnectivity `json:"connectivity,omitempty"` - IPs []net.IP `json:"ips,omitempty"` -} - -// SpectrumApplicationEdgeType for possible Edge configurations. -type SpectrumApplicationEdgeType string - -const ( - // SpectrumEdgeTypeDynamic IP config. - SpectrumEdgeTypeDynamic SpectrumApplicationEdgeType = "dynamic" - // SpectrumEdgeTypeStatic IP config. - SpectrumEdgeTypeStatic SpectrumApplicationEdgeType = "static" -) - -// UnmarshalJSON function for SpectrumApplicationEdgeType enum. -func (t *SpectrumApplicationEdgeType) UnmarshalJSON(b []byte) error { - var s string - err := json.Unmarshal(b, &s) - if err != nil { - return err - } - - newEdgeType := SpectrumApplicationEdgeType(strings.ToLower(s)) - switch newEdgeType { - case SpectrumEdgeTypeDynamic, SpectrumEdgeTypeStatic: - *t = newEdgeType - return nil - } - - return errors.New(errUnmarshalError) -} - -func (t SpectrumApplicationEdgeType) String() string { - return string(t) -} - -// SpectrumApplicationConnectivity specifies IP address type on the edge configuration. -type SpectrumApplicationConnectivity string - -const ( - // SpectrumConnectivityAll specifies IPv4/6 edge IP. - SpectrumConnectivityAll SpectrumApplicationConnectivity = "all" - // SpectrumConnectivityIPv4 specifies IPv4 edge IP. - SpectrumConnectivityIPv4 SpectrumApplicationConnectivity = "ipv4" - // SpectrumConnectivityIPv6 specifies IPv6 edge IP. - SpectrumConnectivityIPv6 SpectrumApplicationConnectivity = "ipv6" - // SpectrumConnectivityStatic specifies static edge IP configuration. - SpectrumConnectivityStatic SpectrumApplicationConnectivity = "static" -) - -func (c SpectrumApplicationConnectivity) String() string { - return string(c) -} - -// UnmarshalJSON function for SpectrumApplicationConnectivity enum. -func (c *SpectrumApplicationConnectivity) UnmarshalJSON(b []byte) error { - var s string - err := json.Unmarshal(b, &s) - if err != nil { - return err - } - - newConnectivity := SpectrumApplicationConnectivity(strings.ToLower(s)) - if newConnectivity.Dynamic() { - *c = newConnectivity - return nil - } - - return errors.New(errUnmarshalError) -} - -// Dynamic checks if address family is specified as dynamic config. -func (c SpectrumApplicationConnectivity) Dynamic() bool { - switch c { - case SpectrumConnectivityAll, SpectrumConnectivityIPv4, SpectrumConnectivityIPv6: - return true - } - return false -} - -// Static checks if address family is specified as static config. -func (c SpectrumApplicationConnectivity) Static() bool { - return c == SpectrumConnectivityStatic -} - -// SpectrumApplications fetches all of the Spectrum applications for a zone. -// -// API reference: https://developers.cloudflare.com/spectrum/api-reference/#list-spectrum-applications -func (api *API) SpectrumApplications(ctx context.Context, zoneID string) ([]SpectrumApplication, error) { - uri := fmt.Sprintf("/zones/%s/spectrum/apps", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []SpectrumApplication{}, err - } - - var spectrumApplications SpectrumApplicationsDetailResponse - err = json.Unmarshal(res, &spectrumApplications) - if err != nil { - return []SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return spectrumApplications.Result, nil -} - -// SpectrumApplication fetches a single Spectrum application based on the ID. -// -// API reference: https://developers.cloudflare.com/spectrum/api-reference/#list-spectrum-applications -func (api *API) SpectrumApplication(ctx context.Context, zoneID string, applicationID string) (SpectrumApplication, error) { - uri := fmt.Sprintf( - "/zones/%s/spectrum/apps/%s", - zoneID, - applicationID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return SpectrumApplication{}, err - } - - var spectrumApplication SpectrumApplicationDetailResponse - err = json.Unmarshal(res, &spectrumApplication) - if err != nil { - return SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return spectrumApplication.Result, nil -} - -// CreateSpectrumApplication creates a new Spectrum application. -// -// API reference: https://developers.cloudflare.com/spectrum/api-reference/#create-a-spectrum-application -func (api *API) CreateSpectrumApplication(ctx context.Context, zoneID string, appDetails SpectrumApplication) (SpectrumApplication, error) { - uri := fmt.Sprintf("/zones/%s/spectrum/apps", zoneID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, appDetails) - if err != nil { - return SpectrumApplication{}, err - } - - var spectrumApplication SpectrumApplicationDetailResponse - err = json.Unmarshal(res, &spectrumApplication) - if err != nil { - return SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return spectrumApplication.Result, nil -} - -// UpdateSpectrumApplication updates an existing Spectrum application. -// -// API reference: https://developers.cloudflare.com/spectrum/api-reference/#update-a-spectrum-application -func (api *API) UpdateSpectrumApplication(ctx context.Context, zoneID, appID string, appDetails SpectrumApplication) (SpectrumApplication, error) { - uri := fmt.Sprintf( - "/zones/%s/spectrum/apps/%s", - zoneID, - appID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, appDetails) - if err != nil { - return SpectrumApplication{}, err - } - - var spectrumApplication SpectrumApplicationDetailResponse - err = json.Unmarshal(res, &spectrumApplication) - if err != nil { - return SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return spectrumApplication.Result, nil -} - -// DeleteSpectrumApplication removes a Spectrum application based on the ID. -// -// API reference: https://developers.cloudflare.com/spectrum/api-reference/#delete-a-spectrum-application -func (api *API) DeleteSpectrumApplication(ctx context.Context, zoneID string, applicationID string) error { - uri := fmt.Sprintf( - "/zones/%s/spectrum/apps/%s", - zoneID, - applicationID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/split_tunnel.go b/vendor/github.com/cloudflare/cloudflare-go/split_tunnel.go deleted file mode 100644 index 3855cae..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/split_tunnel.go +++ /dev/null @@ -1,106 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// SplitTunnelResponse represents the response from the get split -// tunnel endpoints. -type SplitTunnelResponse struct { - Response - Result []SplitTunnel `json:"result"` -} - -// SplitTunnel represents the individual tunnel struct. -type SplitTunnel struct { - Address string `json:"address,omitempty"` - Host string `json:"host,omitempty"` - Description string `json:"description,omitempty"` -} - -// ListSplitTunnel returns all include or exclude split tunnel within an account. -// -// API reference for include: https://api.cloudflare.com/#device-policy-get-split-tunnel-include-list -// API reference for exclude: https://api.cloudflare.com/#device-policy-get-split-tunnel-exclude-list -func (api *API) ListSplitTunnels(ctx context.Context, accountID string, mode string) ([]SplitTunnel, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, mode) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []SplitTunnel{}, err - } - - var splitTunnelResponse SplitTunnelResponse - err = json.Unmarshal(res, &splitTunnelResponse) - if err != nil { - return []SplitTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return splitTunnelResponse.Result, nil -} - -// UpdateSplitTunnel updates the existing split tunnel policy. -// -// API reference for include: https://api.cloudflare.com/#device-policy-set-split-tunnel-include-list -// API reference for exclude: https://api.cloudflare.com/#device-policy-set-split-tunnel-exclude-list -func (api *API) UpdateSplitTunnel(ctx context.Context, accountID string, mode string, tunnels []SplitTunnel) ([]SplitTunnel, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, mode) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, tunnels) - if err != nil { - return []SplitTunnel{}, err - } - - var splitTunnelResponse SplitTunnelResponse - err = json.Unmarshal(res, &splitTunnelResponse) - if err != nil { - return []SplitTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return splitTunnelResponse.Result, nil -} - -// ListSplitTunnelDeviceSettingsPolicy returns all include or exclude split tunnel within a device settings policy -// -// API reference for include: https://api.cloudflare.com/#device-policy-get-split-tunnel-include-list -// API reference for exclude: https://api.cloudflare.com/#device-policy-get-split-tunnel-exclude-list -func (api *API) ListSplitTunnelsDeviceSettingsPolicy(ctx context.Context, accountID, policyID string, mode string) ([]SplitTunnel, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s/%s", AccountRouteRoot, accountID, policyID, mode) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []SplitTunnel{}, err - } - - var splitTunnelResponse SplitTunnelResponse - err = json.Unmarshal(res, &splitTunnelResponse) - if err != nil { - return []SplitTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return splitTunnelResponse.Result, nil -} - -// UpdateSplitTunnelDeviceSettingsPolicy updates the existing split tunnel policy within a device settings policy -// -// API reference for include: https://api.cloudflare.com/#device-policy-set-split-tunnel-include-list -// API reference for exclude: https://api.cloudflare.com/#device-policy-set-split-tunnel-exclude-list -func (api *API) UpdateSplitTunnelDeviceSettingsPolicy(ctx context.Context, accountID, policyID string, mode string, tunnels []SplitTunnel) ([]SplitTunnel, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s/%s", AccountRouteRoot, accountID, policyID, mode) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, tunnels) - if err != nil { - return []SplitTunnel{}, err - } - - var splitTunnelResponse SplitTunnelResponse - err = json.Unmarshal(res, &splitTunnelResponse) - if err != nil { - return []SplitTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return splitTunnelResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/ssl.go b/vendor/github.com/cloudflare/cloudflare-go/ssl.go deleted file mode 100644 index 125ab02..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/ssl.go +++ /dev/null @@ -1,172 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// ZoneCustomSSL represents custom SSL certificate metadata. -type ZoneCustomSSL struct { - ID string `json:"id"` - Hosts []string `json:"hosts"` - Issuer string `json:"issuer"` - Signature string `json:"signature"` - Status string `json:"status"` - BundleMethod string `json:"bundle_method"` - GeoRestrictions ZoneCustomSSLGeoRestrictions `json:"geo_restrictions"` - ZoneID string `json:"zone_id"` - UploadedOn time.Time `json:"uploaded_on"` - ModifiedOn time.Time `json:"modified_on"` - ExpiresOn time.Time `json:"expires_on"` - Priority int `json:"priority"` - KeylessServer KeylessSSL `json:"keyless_server"` -} - -// ZoneCustomSSLGeoRestrictions represents the parameter to create or update -// geographic restrictions on a custom ssl certificate. -type ZoneCustomSSLGeoRestrictions struct { - Label string `json:"label"` -} - -// zoneCustomSSLResponse represents the response from the zone SSL details endpoint. -type zoneCustomSSLResponse struct { - Response - Result ZoneCustomSSL `json:"result"` -} - -// zoneCustomSSLsResponse represents the response from the zone SSL list endpoint. -type zoneCustomSSLsResponse struct { - Response - Result []ZoneCustomSSL `json:"result"` -} - -// ZoneCustomSSLOptions represents the parameters to create or update an existing -// custom SSL configuration. -type ZoneCustomSSLOptions struct { - Certificate string `json:"certificate"` - PrivateKey string `json:"private_key"` - BundleMethod string `json:"bundle_method,omitempty"` - GeoRestrictions *ZoneCustomSSLGeoRestrictions `json:"geo_restrictions,omitempty"` - Type string `json:"type,omitempty"` -} - -// ZoneCustomSSLPriority represents a certificate's ID and priority. It is a -// subset of ZoneCustomSSL used for patch requests. -type ZoneCustomSSLPriority struct { - ID string `json:"ID"` - Priority int `json:"priority"` -} - -// CreateSSL allows you to add a custom SSL certificate to the given zone. -// -// API reference: https://api.cloudflare.com/#custom-ssl-for-a-zone-create-ssl-configuration -func (api *API) CreateSSL(ctx context.Context, zoneID string, options ZoneCustomSSLOptions) (ZoneCustomSSL, error) { - uri := fmt.Sprintf("/zones/%s/custom_certificates", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, options) - if err != nil { - return ZoneCustomSSL{}, err - } - var r zoneCustomSSLResponse - if err := json.Unmarshal(res, &r); err != nil { - return ZoneCustomSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListSSL lists the custom certificates for the given zone. -// -// API reference: https://api.cloudflare.com/#custom-ssl-for-a-zone-list-ssl-configurations -func (api *API) ListSSL(ctx context.Context, zoneID string) ([]ZoneCustomSSL, error) { - uri := fmt.Sprintf("/zones/%s/custom_certificates", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r zoneCustomSSLsResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// SSLDetails returns the configuration details for a custom SSL certificate. -// -// API reference: https://api.cloudflare.com/#custom-ssl-for-a-zone-ssl-configuration-details -func (api *API) SSLDetails(ctx context.Context, zoneID, certificateID string) (ZoneCustomSSL, error) { - uri := fmt.Sprintf("/zones/%s/custom_certificates/%s", zoneID, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ZoneCustomSSL{}, err - } - var r zoneCustomSSLResponse - if err := json.Unmarshal(res, &r); err != nil { - return ZoneCustomSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateSSL updates (replaces) a custom SSL certificate. -// -// API reference: https://api.cloudflare.com/#custom-ssl-for-a-zone-update-ssl-configuration -func (api *API) UpdateSSL(ctx context.Context, zoneID, certificateID string, options ZoneCustomSSLOptions) (ZoneCustomSSL, error) { - uri := fmt.Sprintf("/zones/%s/custom_certificates/%s", zoneID, certificateID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, options) - if err != nil { - return ZoneCustomSSL{}, err - } - var r zoneCustomSSLResponse - if err := json.Unmarshal(res, &r); err != nil { - return ZoneCustomSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ReprioritizeSSL allows you to change the priority (which is served for a given -// request) of custom SSL certificates associated with the given zone. -// -// API reference: https://api.cloudflare.com/#custom-ssl-for-a-zone-re-prioritize-ssl-certificates -func (api *API) ReprioritizeSSL(ctx context.Context, zoneID string, p []ZoneCustomSSLPriority) ([]ZoneCustomSSL, error) { - uri := fmt.Sprintf("/zones/%s/custom_certificates/prioritize", zoneID) - params := struct { - Certificates []ZoneCustomSSLPriority `json:"certificates"` - }{ - Certificates: p, - } - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return nil, err - } - var r zoneCustomSSLsResponse - if err := json.Unmarshal(res, &r); err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteSSL deletes a custom SSL certificate from the given zone. -// -// API reference: https://api.cloudflare.com/#custom-ssl-for-a-zone-delete-an-ssl-certificate -func (api *API) DeleteSSL(ctx context.Context, zoneID, certificateID string) error { - uri := fmt.Sprintf("/zones/%s/custom_certificates/%s", zoneID, certificateID) - if _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil); err != nil { - return err - } - return nil -} - -// SSLValidationRecord displays Domain Control Validation tokens. -type SSLValidationRecord struct { - CnameTarget string `json:"cname_target,omitempty"` - CnameName string `json:"cname,omitempty"` - - TxtName string `json:"txt_name,omitempty"` - TxtValue string `json:"txt_value,omitempty"` - - HTTPUrl string `json:"http_url,omitempty"` - HTTPBody string `json:"http_body,omitempty"` - - Emails []string `json:"emails,omitempty"` -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/stream.go b/vendor/github.com/cloudflare/cloudflare-go/stream.go deleted file mode 100644 index 95edd6b..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/stream.go +++ /dev/null @@ -1,444 +0,0 @@ -package cloudflare - -import ( - "bytes" - "context" - "encoding/json" - "errors" - "fmt" - "io" - "mime/multipart" - "net/http" - "os" - "time" -) - -var ( - // ErrMissingUploadURL is for when a URL is required but missing. - ErrMissingUploadURL = errors.New("required url missing") - // ErrMissingMaxDuration is for when MaxDuration is required but missing. - ErrMissingMaxDuration = errors.New("required max duration missing") - // ErrMissingVideoID is for when VideoID is required but missing. - ErrMissingVideoID = errors.New("required video id missing") - // ErrMissingFilePath is for when FilePath is required but missing. - ErrMissingFilePath = errors.New("required file path missing") -) - -// StreamVideo represents a stream video. -type StreamVideo struct { - AllowedOrigins []string `json:"allowedOrigins,omitempty"` - Created *time.Time `json:"created,omitempty"` - Duration int `json:"duration,omitempty"` - Input StreamVideoInput `json:"input,omitempty"` - MaxDurationSeconds int `json:"maxDurationSeconds,omitempty"` - Meta map[string]interface{} `json:"meta,omitempty"` - Modified *time.Time `json:"modified,omitempty"` - UploadExpiry *time.Time `json:"uploadExpiry,omitempty"` - Playback StreamVideoPlayback `json:"playback,omitempty"` - Preview string `json:"preview,omitempty"` - ReadyToStream bool `json:"readyToStream,omitempty"` - RequireSignedURLs bool `json:"requireSignedURLs,omitempty"` - Size int `json:"size,omitempty"` - Status StreamVideoStatus `json:"status,omitempty"` - Thumbnail string `json:"thumbnail,omitempty"` - ThumbnailTimestampPct float64 `json:"thumbnailTimestampPct,omitempty"` - UID string `json:"uid,omitempty"` - Creator string `json:"creator,omitempty"` - LiveInput string `json:"liveInput,omitempty"` - Uploaded *time.Time `json:"uploaded,omitempty"` - Watermark StreamVideoWatermark `json:"watermark,omitempty"` - NFT StreamVideoNFTParameters `json:"nft,omitempty"` -} - -// StreamVideoInput represents the video input values of a stream video. -type StreamVideoInput struct { - Height int `json:"height,omitempty"` - Width int `json:"width,omitempty"` -} - -// StreamVideoPlayback represents the playback URLs for a video. -type StreamVideoPlayback struct { - HLS string `json:"hls,omitempty"` - Dash string `json:"dash,omitempty"` -} - -// StreamVideoStatus represents the status of a stream video. -type StreamVideoStatus struct { - State string `json:"state,omitempty"` - PctComplete string `json:"pctComplete,omitempty"` - ErrorReasonCode string `json:"errorReasonCode,omitempty"` - ErrorReasonText string `json:"errorReasonText,omitempty"` -} - -// StreamVideoWatermark represents a watermark for a stream video. -type StreamVideoWatermark struct { - UID string `json:"uid,omitempty"` - Size int `json:"size,omitempty"` - Height int `json:"height,omitempty"` - Width int `json:"width,omitempty"` - Created *time.Time `json:"created,omitempty"` - DownloadedFrom string `json:"downloadedFrom,omitempty"` - Name string `json:"name,omitempty"` - Opacity float64 `json:"opacity,omitempty"` - Padding float64 `json:"padding,omitempty"` - Scale float64 `json:"scale,omitempty"` - Position string `json:"position,omitempty"` -} - -// StreamVideoNFTParameters represents a NFT for a stream video. -type StreamVideoNFTParameters struct { - AccountID string - VideoID string - Contract string `json:"contract,omitempty"` - Token int `json:"token,omitempty"` -} - -// StreamUploadFromURLParameters are the parameters used when uploading a video from URL. -type StreamUploadFromURLParameters struct { - AccountID string - VideoID string - URL string `json:"url"` - Creator string `json:"creator,omitempty"` - ThumbnailTimestampPct float64 `json:"thumbnailTimestampPct,omitempty"` - AllowedOrigins []string `json:"allowedOrigins,omitempty"` - RequireSignedURLs bool `json:"requireSignedURLs,omitempty"` - Watermark UploadVideoURLWatermark `json:"watermark,omitempty"` -} - -// StreamCreateVideoParameters are parameters used when creating a video. -type StreamCreateVideoParameters struct { - AccountID string - MaxDurationSeconds int `json:"maxDurationSeconds,omitempty"` - Expiry *time.Time `json:"expiry,omitempty"` - Creator string `json:"creator,omitempty"` - ThumbnailTimestampPct float64 `json:"thumbnailTimestampPct,omitempty"` - AllowedOrigins []string `json:"allowedOrigins,omitempty"` - RequireSignedURLs bool `json:"requireSignedURLs,omitempty"` - Watermark UploadVideoURLWatermark `json:"watermark,omitempty"` -} - -// UploadVideoURLWatermark represents UID of an existing watermark. -type UploadVideoURLWatermark struct { - UID string `json:"uid,omitempty"` -} - -// StreamVideoCreate represents parameters returned after creating a video. -type StreamVideoCreate struct { - UploadURL string `json:"uploadURL,omitempty"` - UID string `json:"uid,omitempty"` - Watermark StreamVideoWatermark `json:"watermark,omitempty"` -} - -// StreamParameters are the basic parameters needed. -type StreamParameters struct { - AccountID string - VideoID string -} - -// StreamUploadFileParameters are parameters needed for file upload of a video. -type StreamUploadFileParameters struct { - AccountID string - VideoID string - FilePath string -} - -// StreamListParameters represents parameters used when listing stream videos. -type StreamListParameters struct { - AccountID string - VideoID string - After *time.Time `url:"after,omitempty"` - Before *time.Time `url:"before,omitempty"` - Creator string `url:"creator,omitempty"` - IncludeCounts bool `url:"include_counts,omitempty"` - Search string `url:"search,omitempty"` - Limit int `url:"limit,omitempty"` - Asc bool `url:"asc,omitempty"` - Status string `url:"status,omitempty"` -} - -// StreamSignedURLParameters represent parameters used when creating a signed URL. -type StreamSignedURLParameters struct { - AccountID string - VideoID string - ID string `json:"id,omitempty"` - PEM string `json:"pem,omitempty"` - EXP int `json:"exp,omitempty"` - NBF int `json:"nbf,omitempty"` - Downloadable bool `json:"downloadable,omitempty"` - AccessRules []StreamAccessRule `json:"accessRules,omitempty"` -} - -// StreamVideoResponse represents an API response of a stream video. -type StreamVideoResponse struct { - Response - Result StreamVideo `json:"result,omitempty"` -} - -// StreamVideoCreateResponse represents an API response of creating a stream video. -type StreamVideoCreateResponse struct { - Response - Result StreamVideoCreate `json:"result,omitempty"` -} - -// StreamListResponse represents the API response from a StreamListRequest. -type StreamListResponse struct { - Response - Result []StreamVideo `json:"result,omitempty"` - Total string `json:"total,omitempty"` - Range string `json:"range,omitempty"` -} - -// StreamSignedURLResponse represents an API response for a signed URL. -type StreamSignedURLResponse struct { - Response - Result struct { - Token string `json:"token,omitempty"` - } -} - -// StreamAccessRule represents the accessRules when creating a signed URL. -type StreamAccessRule struct { - Type string `json:"type"` - Country []string `json:"country,omitempty"` - Action string `json:"action"` - IP []string `json:"ip,omitempty"` -} - -// StreamUploadFromURL send a video URL to it will be downloaded and made available on Stream. -// -// API Reference: https://api.cloudflare.com/#stream-videos-upload-a-video-from-a-url -func (api *API) StreamUploadFromURL(ctx context.Context, params StreamUploadFromURLParameters) (StreamVideo, error) { - if params.AccountID == "" { - return StreamVideo{}, ErrMissingAccountID - } - - if params.URL == "" { - return StreamVideo{}, ErrMissingUploadURL - } - - uri := fmt.Sprintf("/accounts/%s/stream/copy", params.AccountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return StreamVideo{}, err - } - - var streamVideoResponse StreamVideoResponse - if err := json.Unmarshal(res, &streamVideoResponse); err != nil { - return StreamVideo{}, err - } - return streamVideoResponse.Result, nil -} - -// StreamUploadVideoFile uploads a video from a path to the file. -// -// API Reference: https://api.cloudflare.com/#stream-videos-upload-a-video-using-a-single-http-request -func (api *API) StreamUploadVideoFile(ctx context.Context, params StreamUploadFileParameters) (StreamVideo, error) { - if params.AccountID == "" { - return StreamVideo{}, ErrMissingAccountID - } - - if params.FilePath == "" { - return StreamVideo{}, ErrMissingFilePath - } - - uri := fmt.Sprintf("/accounts/%s/stream", params.AccountID) - - // Create new multipart writer - body := &bytes.Buffer{} - writer := multipart.NewWriter(body) - formFile, err := writer.CreateFormFile("file", params.FilePath) - if err != nil { - return StreamVideo{}, err - } - file, err := os.Open(params.FilePath) - if err != nil { - return StreamVideo{}, err - } - if _, err := io.Copy(formFile, file); err != nil { - return StreamVideo{}, err - } - if err := writer.Close(); err != nil { - return StreamVideo{}, err - } - - res, err := api.makeRequestContextWithHeaders(ctx, http.MethodPost, uri, body, http.Header{ - "Accept": []string{"application/json"}, - "Content-Type": []string{writer.FormDataContentType()}, - }) - if err != nil { - return StreamVideo{}, err - } - - var streamVideoResponse StreamVideoResponse - if err := json.Unmarshal(res, &streamVideoResponse); err != nil { - return StreamVideo{}, err - } - return streamVideoResponse.Result, nil -} - -// StreamCreateVideoDirectURL creates a video and returns an authenticated URL. -// -// API Reference: https://api.cloudflare.com/#stream-videos-create-a-video-and-get-authenticated-direct-upload-url -func (api *API) StreamCreateVideoDirectURL(ctx context.Context, params StreamCreateVideoParameters) (StreamVideoCreate, error) { - if params.AccountID == "" { - return StreamVideoCreate{}, ErrMissingAccountID - } - - if params.MaxDurationSeconds == 0 { - return StreamVideoCreate{}, ErrMissingMaxDuration - } - - uri := fmt.Sprintf("/accounts/%s/stream/direct_upload", params.AccountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return StreamVideoCreate{}, err - } - - var streamVideoCreateResponse StreamVideoCreateResponse - if err := json.Unmarshal(res, &streamVideoCreateResponse); err != nil { - return StreamVideoCreate{}, err - } - return streamVideoCreateResponse.Result, nil -} - -// StreamListVideos list videos currently in stream. -// -// API reference: https://api.cloudflare.com/#stream-videos-list-videos -func (api *API) StreamListVideos(ctx context.Context, params StreamListParameters) ([]StreamVideo, error) { - if params.AccountID == "" { - return []StreamVideo{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/stream", params.AccountID), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []StreamVideo{}, err - } - - var streamListResponse StreamListResponse - if err := json.Unmarshal(res, &streamListResponse); err != nil { - return []StreamVideo{}, err - } - return streamListResponse.Result, nil -} - -// Skipped: https://api.cloudflare.com/#stream-videos-initiate-a-video-upload-using-tus - -// StreamGetVideo gets the details for a specific video. -// -// API Reference: https://api.cloudflare.com/#stream-videos-video-details -func (api *API) StreamGetVideo(ctx context.Context, options StreamParameters) (StreamVideo, error) { - if options.AccountID == "" { - return StreamVideo{}, ErrMissingAccountID - } - - if options.VideoID == "" { - return StreamVideo{}, ErrMissingVideoID - } - - uri := fmt.Sprintf("/accounts/%s/stream/%s", options.AccountID, options.VideoID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return StreamVideo{}, err - } - var streamVideoResponse StreamVideoResponse - if err := json.Unmarshal(res, &streamVideoResponse); err != nil { - return StreamVideo{}, err - } - return streamVideoResponse.Result, nil -} - -// StreamEmbedHTML gets an HTML fragment to embed on a web page. -// -// API Reference: https://api.cloudflare.com/#stream-videos-embed-code-html -func (api *API) StreamEmbedHTML(ctx context.Context, options StreamParameters) (string, error) { - if options.AccountID == "" { - return "", ErrMissingAccountID - } - - if options.VideoID == "" { - return "", ErrMissingVideoID - } - - uri := fmt.Sprintf("/accounts/%s/stream/%s/embed", options.AccountID, options.VideoID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - - if err != nil { - return "", err - } - return string(res), nil -} - -// StreamDeleteVideo deletes a video. -// -// API Reference: https://api.cloudflare.com/#stream-videos-delete-video -func (api *API) StreamDeleteVideo(ctx context.Context, options StreamParameters) error { - if options.AccountID == "" { - return ErrMissingAccountID - } - - if options.VideoID == "" { - return ErrMissingVideoID - } - - uri := fmt.Sprintf("/accounts/%s/stream/%s", options.AccountID, options.VideoID) - if _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil); err != nil { - return err - } - return nil -} - -// StreamAssociateNFT associates a video to a token and contract address. -// -// API Reference: https://api.cloudflare.com/#stream-videos-associate-video-to-an-nft -func (api *API) StreamAssociateNFT(ctx context.Context, options StreamVideoNFTParameters) (StreamVideo, error) { - if options.AccountID == "" { - return StreamVideo{}, ErrMissingAccountID - } - - if options.VideoID == "" { - return StreamVideo{}, ErrMissingVideoID - } - - uri := fmt.Sprintf("/accounts/%s/stream/%s", options.AccountID, options.VideoID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, options) - if err != nil { - return StreamVideo{}, err - } - var streamVideoResponse StreamVideoResponse - if err := json.Unmarshal(res, &streamVideoResponse); err != nil { - return StreamVideo{}, err - } - return streamVideoResponse.Result, nil -} - -// StreamCreateSignedURL creates a signed URL token for a video. -// -// API Reference: https://api.cloudflare.com/#stream-videos-associate-video-to-an-nft -func (api *API) StreamCreateSignedURL(ctx context.Context, params StreamSignedURLParameters) (string, error) { - if params.AccountID == "" { - return "", ErrMissingAccountID - } - if params.VideoID == "" { - return "", ErrMissingVideoID - } - - uri := fmt.Sprintf("/accounts/%s/stream/%s/token", params.AccountID, params.VideoID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - - if err != nil { - return "", err - } - var streamSignedResponse StreamSignedURLResponse - if err := json.Unmarshal(res, &streamSignedResponse); err != nil { - return "", err - } - return streamSignedResponse.Result.Token, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/sts.go b/vendor/github.com/cloudflare/cloudflare-go/sts.go deleted file mode 100644 index 94b5666..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/sts.go +++ /dev/null @@ -1,100 +0,0 @@ -package cloudflare - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "net/http" - - "github.com/hashicorp/go-retryablehttp" -) - -var ( - ErrSTSFailure = errors.New("failed to fetch security token") - ErrSTSHTTPFailure = errors.New("failed making securtiy token issuer call") - ErrSTSHTTPResponseError = errors.New("security token request returned a failure") - ErrSTSMissingServiceSecret = errors.New("service secret missing but is required") - ErrSTSMissingServiceTag = errors.New("service tag missing but is required") - ErrSTSMissingIssuerHostname = errors.New("issuer hostname missing but is required") - ErrSTSMissingServicePath = errors.New("issuer path missing but is required") -) - -// IssuerConfiguration allows the configuration of the issuance provider. -type IssuerConfiguration struct { - Hostname string - Path string -} - -// SecurityTokenConfiguration holds the configuration for requesting a security -// token from the service. -type SecurityTokenConfiguration struct { - Issuer *IssuerConfiguration - ServiceTag string - Secret string -} - -type securityToken struct { - Token string `json:"json_web_token"` -} - -type securityTokenResponse struct { - Result securityToken `json:"result"` - Response -} - -// fetchSTSCredentials provides a way to authenticate with the security token -// service and issue a usable token for the system. -func fetchSTSCredentials(stsConfig *SecurityTokenConfiguration) (string, error) { - if stsConfig.Secret == "" { - return "", ErrSTSMissingServiceSecret - } - - if stsConfig.ServiceTag == "" { - return "", ErrSTSMissingServiceTag - } - - if stsConfig.Issuer.Hostname == "" { - return "", ErrSTSMissingIssuerHostname - } - - if stsConfig.Issuer.Path == "" { - return "", ErrSTSMissingServicePath - } - - retryableClient := retryablehttp.NewClient() - retryableClient.RetryMax = 3 - stsClient := retryableClient.StandardClient() - - uri := fmt.Sprintf("https://%s%s", stsConfig.Issuer.Hostname, stsConfig.Issuer.Path) - req, err := http.NewRequest(http.MethodGet, uri, nil) - if err != nil { - return "", fmt.Errorf("HTTP request creation failed: %w", err) - } - - req.Header.Set("Authorization", "Bearer "+stsConfig.ServiceTag+stsConfig.Secret) - - resp, err := stsClient.Do(req) - if err != nil { - return "", ErrSTSHTTPFailure - } - - var respBody []byte - respBody, err = io.ReadAll(resp.Body) - if err != nil { - return "", fmt.Errorf("failed to read response body: %w", err) - } - resp.Body.Close() - - var stsTokenResponse *securityTokenResponse - err = json.Unmarshal(respBody, &stsTokenResponse) - if err != nil { - return "", fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !stsTokenResponse.Success { - return "", ErrSTSHTTPResponseError - } - - return stsTokenResponse.Result.Token, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/teams_accounts.go b/vendor/github.com/cloudflare/cloudflare-go/teams_accounts.go deleted file mode 100644 index f907071..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/teams_accounts.go +++ /dev/null @@ -1,252 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type TeamsAccount struct { - GatewayTag string `json:"gateway_tag"` // Internal teams ID - ProviderName string `json:"provider_name"` // Auth provider - ID string `json:"id"` // cloudflare account ID -} - -// TeamsAccountResponse is the API response, containing information on teams -// account. -type TeamsAccountResponse struct { - Response - Result TeamsAccount `json:"result"` -} - -// TeamsConfigResponse is the API response, containing information on teams -// account config. -type TeamsConfigResponse struct { - Response - Result TeamsConfiguration `json:"result"` -} - -// TeamsConfiguration data model. -type TeamsConfiguration struct { - Settings TeamsAccountSettings `json:"settings"` - CreatedAt time.Time `json:"created_at,omitempty"` - UpdatedAt time.Time `json:"updated_at,omitempty"` -} - -type TeamsAccountSettings struct { - Antivirus *TeamsAntivirus `json:"antivirus,omitempty"` - TLSDecrypt *TeamsTLSDecrypt `json:"tls_decrypt,omitempty"` - ActivityLog *TeamsActivityLog `json:"activity_log,omitempty"` - BlockPage *TeamsBlockPage `json:"block_page,omitempty"` - BrowserIsolation *BrowserIsolation `json:"browser_isolation,omitempty"` - FIPS *TeamsFIPS `json:"fips,omitempty"` -} - -type BrowserIsolation struct { - UrlBrowserIsolationEnabled bool `json:"url_browser_isolation_enabled"` -} - -type TeamsAntivirus struct { - EnabledDownloadPhase bool `json:"enabled_download_phase"` - EnabledUploadPhase bool `json:"enabled_upload_phase"` - FailClosed bool `json:"fail_closed"` -} - -type TeamsFIPS struct { - TLS bool `json:"tls"` -} - -type TeamsTLSDecrypt struct { - Enabled bool `json:"enabled"` -} - -type TeamsActivityLog struct { - Enabled bool `json:"enabled"` -} - -type TeamsBlockPage struct { - Enabled *bool `json:"enabled,omitempty"` - FooterText string `json:"footer_text,omitempty"` - HeaderText string `json:"header_text,omitempty"` - LogoPath string `json:"logo_path,omitempty"` - BackgroundColor string `json:"background_color,omitempty"` - Name string `json:"name,omitempty"` - MailtoAddress string `json:"mailto_address,omitempty"` - MailtoSubject string `json:"mailto_subject,omitempty"` - SuppressFooter *bool `json:"suppress_footer,omitempty"` -} - -type TeamsRuleType = string - -const ( - TeamsHttpRuleType TeamsRuleType = "http" - TeamsDnsRuleType TeamsRuleType = "dns" - TeamsL4RuleType TeamsRuleType = "l4" -) - -type TeamsAccountLoggingConfiguration struct { - LogAll bool `json:"log_all"` - LogBlocks bool `json:"log_blocks"` -} - -type TeamsLoggingSettings struct { - LoggingSettingsByRuleType map[TeamsRuleType]TeamsAccountLoggingConfiguration `json:"settings_by_rule_type"` - RedactPii bool `json:"redact_pii,omitempty"` -} - -type TeamsDeviceSettings struct { - GatewayProxyEnabled bool `json:"gateway_proxy_enabled"` - GatewayProxyUDPEnabled bool `json:"gateway_udp_proxy_enabled"` -} - -type TeamsDeviceSettingsResponse struct { - Response - Result TeamsDeviceSettings `json:"result"` -} - -type TeamsLoggingSettingsResponse struct { - Response - Result TeamsLoggingSettings `json:"result"` -} - -// TeamsAccount returns teams account information with internal and external ID. -// -// API reference: TBA. -func (api *API) TeamsAccount(ctx context.Context, accountID string) (TeamsAccount, error) { - uri := fmt.Sprintf("/accounts/%s/gateway", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsAccount{}, err - } - - var teamsAccountResponse TeamsAccountResponse - err = json.Unmarshal(res, &teamsAccountResponse) - if err != nil { - return TeamsAccount{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsAccountResponse.Result, nil -} - -// TeamsAccountConfiguration returns teams account configuration. -// -// API reference: TBA. -func (api *API) TeamsAccountConfiguration(ctx context.Context, accountID string) (TeamsConfiguration, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/configuration", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsConfiguration{}, err - } - - var teamsConfigResponse TeamsConfigResponse - err = json.Unmarshal(res, &teamsConfigResponse) - if err != nil { - return TeamsConfiguration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsConfigResponse.Result, nil -} - -// TeamsAccountDeviceConfiguration returns teams account device configuration with udp status. -// -// API reference: TBA. -func (api *API) TeamsAccountDeviceConfiguration(ctx context.Context, accountID string) (TeamsDeviceSettings, error) { - uri := fmt.Sprintf("/accounts/%s/devices/settings", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsDeviceSettings{}, err - } - - var teamsDeviceResponse TeamsDeviceSettingsResponse - err = json.Unmarshal(res, &teamsDeviceResponse) - if err != nil { - return TeamsDeviceSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsDeviceResponse.Result, nil -} - -// TeamsAccountLoggingConfiguration returns teams account logging configuration. -// -// API reference: TBA. -func (api *API) TeamsAccountLoggingConfiguration(ctx context.Context, accountID string) (TeamsLoggingSettings, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsLoggingSettings{}, err - } - - var teamsConfigResponse TeamsLoggingSettingsResponse - err = json.Unmarshal(res, &teamsConfigResponse) - if err != nil { - return TeamsLoggingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsConfigResponse.Result, nil -} - -// TeamsAccountUpdateConfiguration updates a teams account configuration. -// -// API reference: TBA. -func (api *API) TeamsAccountUpdateConfiguration(ctx context.Context, accountID string, config TeamsConfiguration) (TeamsConfiguration, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/configuration", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, config) - if err != nil { - return TeamsConfiguration{}, err - } - - var teamsConfigResponse TeamsConfigResponse - err = json.Unmarshal(res, &teamsConfigResponse) - if err != nil { - return TeamsConfiguration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsConfigResponse.Result, nil -} - -// TeamsAccountUpdateLoggingConfiguration updates the log settings and returns new teams account logging configuration. -// -// API reference: TBA. -func (api *API) TeamsAccountUpdateLoggingConfiguration(ctx context.Context, accountID string, config TeamsLoggingSettings) (TeamsLoggingSettings, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, config) - if err != nil { - return TeamsLoggingSettings{}, err - } - - var teamsConfigResponse TeamsLoggingSettingsResponse - err = json.Unmarshal(res, &teamsConfigResponse) - if err != nil { - return TeamsLoggingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsConfigResponse.Result, nil -} - -// TeamsAccountDeviceUpdateConfiguration updates teams account device configuration including udp filtering status. -// -// API reference: TBA. -func (api *API) TeamsAccountDeviceUpdateConfiguration(ctx context.Context, accountID string, settings TeamsDeviceSettings) (TeamsDeviceSettings, error) { - uri := fmt.Sprintf("/accounts/%s/devices/settings", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, settings) - if err != nil { - return TeamsDeviceSettings{}, err - } - - var teamsDeviceResponse TeamsDeviceSettingsResponse - err = json.Unmarshal(res, &teamsDeviceResponse) - if err != nil { - return TeamsDeviceSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsDeviceResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/teams_devices.go b/vendor/github.com/cloudflare/cloudflare-go/teams_devices.go deleted file mode 100644 index 8836cbe..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/teams_devices.go +++ /dev/null @@ -1,105 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type TeamsDevicesList struct { - Response - Result []TeamsDeviceListItem `json:"result"` -} - -type TeamsDeviceDetail struct { - Response - Result TeamsDeviceListItem `json:"result"` -} - -type TeamsDeviceListItem struct { - User UserItem `json:"user,omitempty"` - ID string `json:"id,omitempty"` - Key string `json:"key,omitempty"` - DeviceType string `json:"device_type,omitempty"` - Name string `json:"name,omitempty"` - Model string `json:"model,omitempty"` - Manufacturer string `json:"manufacturer,omitempty"` - Deleted bool `json:"deleted,omitempty"` - Version string `json:"version,omitempty"` - SerialNumber string `json:"serial_number,omitempty"` - OSVersion string `json:"os_version,omitempty"` - OSDistroName string `json:"os_distro_name,omitempty"` - OsDistroRevision string `json:"os_distro_revision,omitempty"` - MacAddress string `json:"mac_address,omitempty"` - IP string `json:"ip,omitempty"` - Created string `json:"created,omitempty"` - Updated string `json:"updated,omitempty"` - LastSeen string `json:"last_seen,omitempty"` - RevokedAt string `json:"revoked_at,omitempty"` -} - -type UserItem struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Email string `json:"email,omitempty"` -} - -// ListTeamsDevice returns all devices for a given account. -// -// API reference : https://api.cloudflare.com/#devices-list-devices -func (api *API) ListTeamsDevices(ctx context.Context, accountID string) ([]TeamsDeviceListItem, error) { - uri := fmt.Sprintf("/%s/%s/devices", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []TeamsDeviceListItem{}, err - } - - var response TeamsDevicesList - err = json.Unmarshal(res, &response) - if err != nil { - return []TeamsDeviceListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// RevokeTeamsDevice revokes device with given identifiers. -// -// API reference : https://api.cloudflare.com/#devices-revoke-devices -func (api *API) RevokeTeamsDevices(ctx context.Context, accountID string, deviceIds []string) (Response, error) { - uri := fmt.Sprintf("/%s/%s/devices/revoke", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, deviceIds) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// GetTeamsDeviceDetails gets device details. -// -// API reference : https://api.cloudflare.com/#devices-device-details -func (api *API) GetTeamsDeviceDetails(ctx context.Context, accountID string, deviceID string) (TeamsDeviceListItem, error) { - uri := fmt.Sprintf("/%s/%s/devices/%s", AccountRouteRoot, accountID, deviceID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsDeviceListItem{}, err - } - - var response TeamsDeviceDetail - err = json.Unmarshal(res, &response) - if err != nil { - return TeamsDeviceListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/teams_list.go b/vendor/github.com/cloudflare/cloudflare-go/teams_list.go deleted file mode 100644 index 30c21d9..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/teams_list.go +++ /dev/null @@ -1,329 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -var ErrMissingListID = errors.New("required missing list ID") - -// TeamsList represents a Teams List. -type TeamsList struct { - ID string `json:"id,omitempty"` - Name string `json:"name"` - Type string `json:"type"` - Description string `json:"description,omitempty"` - Items []TeamsListItem `json:"items,omitempty"` - Count uint64 `json:"count,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -// TeamsListItem represents a single list item. -type TeamsListItem struct { - Value string `json:"value"` - CreatedAt *time.Time `json:"created_at,omitempty"` -} - -// PatchTeamsList represents a patch request for appending/removing list items. -type PatchTeamsList struct { - ID string `json:"id"` - Append []TeamsListItem `json:"append"` - Remove []string `json:"remove"` -} - -// TeamsListListResponse represents the response from the list -// teams lists endpoint. -type TeamsListListResponse struct { - Result []TeamsList `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// TeamsListItemsListResponse represents the response from the list -// teams list items endpoint. -type TeamsListItemsListResponse struct { - Result []TeamsListItem `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// TeamsListDetailResponse is the API response, containing a single -// teams list. -type TeamsListDetailResponse struct { - Response - Result TeamsList `json:"result"` -} - -type ListTeamsListItemsParams struct { - ListID string `url:"-"` - - ResultInfo -} - -type ListTeamListsParams struct{} - -type CreateTeamsListParams struct { - ID string `json:"id,omitempty"` - Name string `json:"name"` - Type string `json:"type"` - Description string `json:"description,omitempty"` - Items []TeamsListItem `json:"items,omitempty"` - Count uint64 `json:"count,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -type UpdateTeamsListParams struct { - ID string `json:"id,omitempty"` - Name string `json:"name"` - Type string `json:"type"` - Description string `json:"description,omitempty"` - Items []TeamsListItem `json:"items,omitempty"` - Count uint64 `json:"count,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -type PatchTeamsListParams struct { - ID string `json:"id"` - Append []TeamsListItem `json:"append"` - Remove []string `json:"remove"` -} - -// ListTeamsLists returns all lists within an account. -// -// API reference: https://api.cloudflare.com/#teams-lists-list-teams-lists -func (api *API) ListTeamsLists(ctx context.Context, rc *ResourceContainer, params ListTeamListsParams) ([]TeamsList, ResultInfo, error) { - uri := fmt.Sprintf("/%s/%s/gateway/lists", AccountRouteRoot, rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []TeamsList{}, ResultInfo{}, err - } - - var teamsListListResponse TeamsListListResponse - err = json.Unmarshal(res, &teamsListListResponse) - if err != nil { - return []TeamsList{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsListListResponse.Result, teamsListListResponse.ResultInfo, nil -} - -// GetTeamsList returns a single list based on the list ID. -// -// API reference: https://api.cloudflare.com/#teams-lists-teams-list-details -func (api *API) GetTeamsList(ctx context.Context, rc *ResourceContainer, listID string) (TeamsList, error) { - uri := fmt.Sprintf( - "/%s/%s/gateway/lists/%s", - rc.Level, - rc.Identifier, - listID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsList{}, err - } - - var teamsListDetailResponse TeamsListDetailResponse - err = json.Unmarshal(res, &teamsListDetailResponse) - if err != nil { - return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsListDetailResponse.Result, nil -} - -// ListTeamsListItems returns all list items for a list. -// -// API reference: https://api.cloudflare.com/#teams-lists-teams-list-items -func (api *API) ListTeamsListItems(ctx context.Context, rc *ResourceContainer, params ListTeamsListItemsParams) ([]TeamsListItem, ResultInfo, error) { - if rc.Level != AccountRouteLevel { - return []TeamsListItem{}, ResultInfo{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if rc.Identifier == "" { - return []TeamsListItem{}, ResultInfo{}, ErrMissingAccountID - } - - if params.ListID == "" { - return []TeamsListItem{}, ResultInfo{}, ErrMissingListID - } - - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - - if params.PerPage < 1 { - params.PerPage = 50 - } - - if params.Page < 1 { - params.Page = 1 - } - - var teamListItems []TeamsListItem - var lResponse TeamsListItemsListResponse - for { - lResponse = TeamsListItemsListResponse{} - uri := buildURI( - fmt.Sprintf("/%s/%s/gateway/lists/%s/items", rc.Level, rc.Identifier, params.ListID), - params, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []TeamsListItem{}, ResultInfo{}, err - } - - err = json.Unmarshal(res, &lResponse) - if err != nil { - return []TeamsListItem{}, ResultInfo{}, fmt.Errorf("failed to unmarshal teams list JSON data: %w", err) - } - - teamListItems = append(teamListItems, lResponse.Result...) - params.ResultInfo = lResponse.ResultInfo.Next() - - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return teamListItems, lResponse.ResultInfo, nil -} - -// CreateTeamsList creates a new teams list. -// -// API reference: https://api.cloudflare.com/#teams-lists-create-teams-list -func (api *API) CreateTeamsList(ctx context.Context, rc *ResourceContainer, params CreateTeamsListParams) (TeamsList, error) { - if rc.Level != AccountRouteLevel { - return TeamsList{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if rc.Identifier == "" { - return TeamsList{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/%s/%s/gateway/lists", rc.Level, rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return TeamsList{}, err - } - - var teamsListDetailResponse TeamsListDetailResponse - err = json.Unmarshal(res, &teamsListDetailResponse) - if err != nil { - return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsListDetailResponse.Result, nil -} - -// UpdateTeamsList updates an existing teams list. -// -// API reference: https://api.cloudflare.com/#teams-lists-update-teams-list -func (api *API) UpdateTeamsList(ctx context.Context, rc *ResourceContainer, params UpdateTeamsListParams) (TeamsList, error) { - if rc.Level != AccountRouteLevel { - return TeamsList{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if rc.Identifier == "" { - return TeamsList{}, ErrMissingAccountID - } - - if params.ID == "" { - return TeamsList{}, fmt.Errorf("teams list ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/gateway/lists/%s", - rc.Level, - rc.Identifier, - params.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return TeamsList{}, err - } - - var teamsListDetailResponse TeamsListDetailResponse - err = json.Unmarshal(res, &teamsListDetailResponse) - if err != nil { - return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsListDetailResponse.Result, nil -} - -// PatchTeamsList updates the items in an existing teams list. -// -// API reference: https://api.cloudflare.com/#teams-lists-patch-teams-list -func (api *API) PatchTeamsList(ctx context.Context, rc *ResourceContainer, listPatch PatchTeamsListParams) (TeamsList, error) { - if rc.Level != AccountRouteLevel { - return TeamsList{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if rc.Identifier == "" { - return TeamsList{}, ErrMissingAccountID - } - - if listPatch.ID == "" { - return TeamsList{}, fmt.Errorf("teams list ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/gateway/lists/%s", - AccountRouteRoot, - rc.Identifier, - listPatch.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, listPatch) - if err != nil { - return TeamsList{}, err - } - - var teamsListDetailResponse TeamsListDetailResponse - err = json.Unmarshal(res, &teamsListDetailResponse) - if err != nil { - return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsListDetailResponse.Result, nil -} - -// DeleteTeamsList deletes a teams list. -// -// API reference: https://api.cloudflare.com/#teams-lists-delete-teams-list -func (api *API) DeleteTeamsList(ctx context.Context, rc *ResourceContainer, teamsListID string) error { - if rc.Level != AccountRouteLevel { - return fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) - } - - if rc.Identifier == "" { - return ErrMissingAccountID - } - - uri := fmt.Sprintf( - "/%s/%s/gateway/lists/%s", - AccountRouteRoot, - rc.Identifier, - teamsListID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/teams_locations.go b/vendor/github.com/cloudflare/cloudflare-go/teams_locations.go deleted file mode 100644 index dab63b5..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/teams_locations.go +++ /dev/null @@ -1,153 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type TeamsLocationsListResponse struct { - Response - ResultInfo `json:"result_info"` - Result []TeamsLocation `json:"result"` -} - -type TeamsLocationDetailResponse struct { - Response - Result TeamsLocation `json:"result"` -} - -type TeamsLocationNetwork struct { - ID string `json:"id"` - Network string `json:"network"` -} - -type TeamsLocation struct { - ID string `json:"id"` - Name string `json:"name"` - Networks []TeamsLocationNetwork `json:"networks"` - PolicyIDs []string `json:"policy_ids"` - Ip string `json:"ip,omitempty"` - Subdomain string `json:"doh_subdomain"` - AnonymizedLogsEnabled bool `json:"anonymized_logs_enabled"` - IPv4Destination string `json:"ipv4_destination"` - ClientDefault bool `json:"client_default"` - - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -// TeamsLocations returns all locations within an account. -// -// API reference: https://api.cloudflare.com/#teams-locations-list-teams-locations -func (api *API) TeamsLocations(ctx context.Context, accountID string) ([]TeamsLocation, ResultInfo, error) { - uri := fmt.Sprintf("/%s/%s/gateway/locations", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []TeamsLocation{}, ResultInfo{}, err - } - - var teamsLocationsListResponse TeamsLocationsListResponse - err = json.Unmarshal(res, &teamsLocationsListResponse) - if err != nil { - return []TeamsLocation{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsLocationsListResponse.Result, teamsLocationsListResponse.ResultInfo, nil -} - -// TeamsLocation returns a single location based on the ID. -// -// API reference: https://api.cloudflare.com/#teams-locations-teams-location-details -func (api *API) TeamsLocation(ctx context.Context, accountID, locationID string) (TeamsLocation, error) { - uri := fmt.Sprintf( - "/%s/%s/gateway/locations/%s", - AccountRouteRoot, - accountID, - locationID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsLocation{}, err - } - - var teamsLocationDetailResponse TeamsLocationDetailResponse - err = json.Unmarshal(res, &teamsLocationDetailResponse) - if err != nil { - return TeamsLocation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsLocationDetailResponse.Result, nil -} - -// CreateTeamsLocation creates a new teams location. -// -// API reference: https://api.cloudflare.com/#teams-locations-create-teams-location -func (api *API) CreateTeamsLocation(ctx context.Context, accountID string, teamsLocation TeamsLocation) (TeamsLocation, error) { - uri := fmt.Sprintf("/%s/%s/gateway/locations", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, teamsLocation) - if err != nil { - return TeamsLocation{}, err - } - - var teamsLocationDetailResponse TeamsLocationDetailResponse - err = json.Unmarshal(res, &teamsLocationDetailResponse) - if err != nil { - return TeamsLocation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsLocationDetailResponse.Result, nil -} - -// UpdateTeamsLocation updates an existing teams location. -// -// API reference: https://api.cloudflare.com/#teams-locations-update-teams-location -func (api *API) UpdateTeamsLocation(ctx context.Context, accountID string, teamsLocation TeamsLocation) (TeamsLocation, error) { - if teamsLocation.ID == "" { - return TeamsLocation{}, fmt.Errorf("teams location ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/gateway/locations/%s", - AccountRouteRoot, - accountID, - teamsLocation.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, teamsLocation) - if err != nil { - return TeamsLocation{}, err - } - - var teamsLocationDetailResponse TeamsLocationDetailResponse - err = json.Unmarshal(res, &teamsLocationDetailResponse) - if err != nil { - return TeamsLocation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsLocationDetailResponse.Result, nil -} - -// DeleteTeamsLocation deletes a teams location. -// -// API reference: https://api.cloudflare.com/#teams-locations-delete-teams-location -func (api *API) DeleteTeamsLocation(ctx context.Context, accountID, teamsLocationID string) error { - uri := fmt.Sprintf( - "/%s/%s/gateway/locations/%s", - AccountRouteRoot, - accountID, - teamsLocationID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/teams_proxy_endpoints.go b/vendor/github.com/cloudflare/cloudflare-go/teams_proxy_endpoints.go deleted file mode 100644 index e11aecd..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/teams_proxy_endpoints.go +++ /dev/null @@ -1,136 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type TeamsProxyEndpointListResponse struct { - Response - ResultInfo `json:"result_info"` - Result []TeamsProxyEndpoint `json:"result"` -} -type TeamsProxyEndpointDetailResponse struct { - Response - Result TeamsProxyEndpoint `json:"result"` -} - -type TeamsProxyEndpoint struct { - ID string `json:"id"` - Name string `json:"name"` - IPs []string `json:"ips"` - Subdomain string `json:"subdomain"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` -} - -// TeamsProxyEndpoint returns a single proxy endpoints within an account. -// -// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-proxy-endpoint-details -func (api *API) TeamsProxyEndpoint(ctx context.Context, accountID, proxyEndpointID string) (TeamsProxyEndpoint, error) { - uri := fmt.Sprintf("/%s/%s/gateway/proxy_endpoints/%s", AccountRouteRoot, accountID, proxyEndpointID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsProxyEndpoint{}, err - } - - var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse - err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse) - if err != nil { - return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsProxyEndpointDetailResponse.Result, nil -} - -// TeamsProxyEndpoints returns all proxy endpoints within an account. -// -// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-list-proxy-endpoints -func (api *API) TeamsProxyEndpoints(ctx context.Context, accountID string) ([]TeamsProxyEndpoint, ResultInfo, error) { - uri := fmt.Sprintf("/%s/%s/gateway/proxy_endpoints", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []TeamsProxyEndpoint{}, ResultInfo{}, err - } - - var teamsProxyEndpointListResponse TeamsProxyEndpointListResponse - err = json.Unmarshal(res, &teamsProxyEndpointListResponse) - if err != nil { - return []TeamsProxyEndpoint{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsProxyEndpointListResponse.Result, teamsProxyEndpointListResponse.ResultInfo, nil -} - -// CreateTeamsProxyEndpoint creates a new proxy endpoint. -// -// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-create-proxy-endpoint -func (api *API) CreateTeamsProxyEndpoint(ctx context.Context, accountID string, proxyEndpoint TeamsProxyEndpoint) (TeamsProxyEndpoint, error) { - uri := fmt.Sprintf("/%s/%s/gateway/proxy_endpoints", AccountRouteRoot, accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, proxyEndpoint) - if err != nil { - return TeamsProxyEndpoint{}, err - } - - var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse - err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse) - if err != nil { - return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsProxyEndpointDetailResponse.Result, nil -} - -// UpdateTeamsProxyEndpoint updates an existing teams Proxy Endpoint. -// -// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-update-proxy-endpoint -func (api *API) UpdateTeamsProxyEndpoint(ctx context.Context, accountID string, proxyEndpoint TeamsProxyEndpoint) (TeamsProxyEndpoint, error) { - if proxyEndpoint.ID == "" { - return TeamsProxyEndpoint{}, fmt.Errorf("Proxy Endpoint ID cannot be empty") - } - - uri := fmt.Sprintf( - "/%s/%s/gateway/proxy_endpoints/%s", - AccountRouteRoot, - accountID, - proxyEndpoint.ID, - ) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, proxyEndpoint) - if err != nil { - return TeamsProxyEndpoint{}, err - } - - var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse - err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse) - if err != nil { - return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsProxyEndpointDetailResponse.Result, nil -} - -// DeleteTeamsProxyEndpoint deletes a teams Proxy Endpoint. -// -// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-delete-proxy-endpoint -func (api *API) DeleteTeamsProxyEndpoint(ctx context.Context, accountID, proxyEndpointID string) error { - uri := fmt.Sprintf( - "/%s/%s/gateway/proxy_endpoints/%s", - AccountRouteRoot, - accountID, - proxyEndpointID, - ) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/teams_rules.go b/vendor/github.com/cloudflare/cloudflare-go/teams_rules.go deleted file mode 100644 index 16c5134..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/teams_rules.go +++ /dev/null @@ -1,266 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type TeamsRuleSettings struct { - // list of ipv4 or ipv6 ips to override with, when action is set to dns override - OverrideIPs []string `json:"override_ips"` - - // show this string at block page caused by this rule - BlockReason string `json:"block_reason"` - - // host name to override with when action is set to dns override. Can not be used with OverrideIPs - OverrideHost string `json:"override_host"` - - // settings for browser isolation actions - BISOAdminControls *TeamsBISOAdminControlSettings `json:"biso_admin_controls"` - - // settings for l4(network) level overrides - L4Override *TeamsL4OverrideSettings `json:"l4override"` - - // settings for adding headers to http requests - AddHeaders http.Header `json:"add_headers"` - - // settings for session check in allow action - CheckSession *TeamsCheckSessionSettings `json:"check_session"` - - // Enable block page on rules with action block - BlockPageEnabled bool `json:"block_page_enabled"` - - // whether to disable dnssec validation for allow action - InsecureDisableDNSSECValidation bool `json:"insecure_disable_dnssec_validation"` - - EgressSettings *EgressSettings `json:"egress"` -} - -type EgressSettings struct { - Ipv6Range string `json:"ipv6"` - Ipv4 string `json:"ipv4"` - Ipv4Fallback string `json:"ipv4_fallback"` -} - -// TeamsL4OverrideSettings used in l4 filter type rule with action set to override. -type TeamsL4OverrideSettings struct { - IP string `json:"ip,omitempty"` - Port int `json:"port,omitempty"` -} - -type TeamsBISOAdminControlSettings struct { - DisablePrinting bool `json:"dp"` - DisableCopyPaste bool `json:"dcp"` - DisableDownload bool `json:"dd"` - DisableUpload bool `json:"du"` - DisableKeyboard bool `json:"dk"` -} - -type TeamsCheckSessionSettings struct { - Enforce bool `json:"enforce"` - Duration Duration `json:"duration"` -} - -type TeamsFilterType string - -type TeamsGatewayAction string - -const ( - HttpFilter TeamsFilterType = "http" - DnsFilter TeamsFilterType = "dns" - L4Filter TeamsFilterType = "l4" - EgressFilter TeamsFilterType = "egress" -) - -const ( - Allow TeamsGatewayAction = "allow" - Block TeamsGatewayAction = "block" - SafeSearch TeamsGatewayAction = "safesearch" - YTRestricted TeamsGatewayAction = "ytrestricted" - On TeamsGatewayAction = "on" - Off TeamsGatewayAction = "off" - Scan TeamsGatewayAction = "scan" - NoScan TeamsGatewayAction = "noscan" - Isolate TeamsGatewayAction = "isolate" - NoIsolate TeamsGatewayAction = "noisolate" - Override TeamsGatewayAction = "override" - L4Override TeamsGatewayAction = "l4_override" - Egress TeamsGatewayAction = "egress" -) - -func TeamsRulesActionValues() []string { - return []string{ - string(Allow), - string(Block), - string(SafeSearch), - string(YTRestricted), - string(On), - string(Off), - string(Scan), - string(NoScan), - string(Isolate), - string(NoIsolate), - string(Override), - string(L4Override), - string(Egress), - } -} - -// TeamsRule represents an Teams wirefilter rule. -type TeamsRule struct { - ID string `json:"id,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - UpdatedAt *time.Time `json:"updated_at,omitempty"` - DeletedAt *time.Time `json:"deleted_at,omitempty"` - Name string `json:"name"` - Description string `json:"description"` - Precedence uint64 `json:"precedence"` - Enabled bool `json:"enabled"` - Action TeamsGatewayAction `json:"action"` - Filters []TeamsFilterType `json:"filters"` - Traffic string `json:"traffic"` - Identity string `json:"identity"` - DevicePosture string `json:"device_posture"` - Version uint64 `json:"version"` - RuleSettings TeamsRuleSettings `json:"rule_settings,omitempty"` -} - -// TeamsRuleResponse is the API response, containing a single rule. -type TeamsRuleResponse struct { - Response - Result TeamsRule `json:"result"` -} - -// TeamsRuleResponse is the API response, containing an array of rules. -type TeamsRulesResponse struct { - Response - Result []TeamsRule `json:"result"` -} - -// TeamsRulePatchRequest is used to patch an existing rule. -type TeamsRulePatchRequest struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Precedence uint64 `json:"precedence"` - Enabled bool `json:"enabled"` - Action TeamsGatewayAction `json:"action"` - RuleSettings TeamsRuleSettings `json:"rule_settings,omitempty"` -} - -// TeamsRules returns all rules within an account. -// -// API reference: https://api.cloudflare.com/#teams-rules-properties -func (api *API) TeamsRules(ctx context.Context, accountID string) ([]TeamsRule, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/rules", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []TeamsRule{}, err - } - - var teamsRulesResponse TeamsRulesResponse - err = json.Unmarshal(res, &teamsRulesResponse) - if err != nil { - return []TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsRulesResponse.Result, nil -} - -// TeamsRule returns the rule with rule ID in the URL. -// -// API reference: https://api.cloudflare.com/#teams-rules-properties -func (api *API) TeamsRule(ctx context.Context, accountID string, ruleId string) (TeamsRule, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/rules/%s", accountID, ruleId) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TeamsRule{}, err - } - - var teamsRuleResponse TeamsRuleResponse - err = json.Unmarshal(res, &teamsRuleResponse) - if err != nil { - return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsRuleResponse.Result, nil -} - -// TeamsCreateRule creates a rule with wirefilter expression. -// -// API reference: https://api.cloudflare.com/#teams-rules-properties -func (api *API) TeamsCreateRule(ctx context.Context, accountID string, rule TeamsRule) (TeamsRule, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/rules", accountID) - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, rule) - if err != nil { - return TeamsRule{}, err - } - - var teamsRuleResponse TeamsRuleResponse - err = json.Unmarshal(res, &teamsRuleResponse) - if err != nil { - return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsRuleResponse.Result, nil -} - -// TeamsUpdateRule updates a rule with wirefilter expression. -// -// API reference: https://api.cloudflare.com/#teams-rules-properties -func (api *API) TeamsUpdateRule(ctx context.Context, accountID string, ruleId string, rule TeamsRule) (TeamsRule, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/rules/%s", accountID, ruleId) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, rule) - if err != nil { - return TeamsRule{}, err - } - - var teamsRuleResponse TeamsRuleResponse - err = json.Unmarshal(res, &teamsRuleResponse) - if err != nil { - return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsRuleResponse.Result, nil -} - -// TeamsPatchRule patches a rule associated values. -// -// API reference: https://api.cloudflare.com/#teams-rules-properties -func (api *API) TeamsPatchRule(ctx context.Context, accountID string, ruleId string, rule TeamsRulePatchRequest) (TeamsRule, error) { - uri := fmt.Sprintf("/accounts/%s/gateway/rules/%s", accountID, ruleId) - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, rule) - if err != nil { - return TeamsRule{}, err - } - - var teamsRuleResponse TeamsRuleResponse - err = json.Unmarshal(res, &teamsRuleResponse) - if err != nil { - return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return teamsRuleResponse.Result, nil -} - -// TeamsDeleteRule deletes a rule. -// -// API reference: https://api.cloudflare.com/#teams-rules-properties -func (api *API) TeamsDeleteRule(ctx context.Context, accountID string, ruleId string) error { - uri := fmt.Sprintf("/accounts/%s/gateway/rules/%s", accountID, ruleId) - - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/tiered_cache.go b/vendor/github.com/cloudflare/cloudflare-go/tiered_cache.go deleted file mode 100644 index 77b0ce5..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/tiered_cache.go +++ /dev/null @@ -1,316 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -type TieredCacheType int - -const ( - TieredCacheOff TieredCacheType = 0 - TieredCacheGeneric TieredCacheType = 1 - TieredCacheSmart TieredCacheType = 2 -) - -func (e TieredCacheType) String() string { - switch e { - case TieredCacheGeneric: - return "generic" - case TieredCacheSmart: - return "smart" - case TieredCacheOff: - return "off" - default: - return fmt.Sprintf("%d", int(e)) - } -} - -type TieredCache struct { - Type TieredCacheType - LastModified time.Time -} - -// GetTieredCache allows you to retrieve the current Tiered Cache Settings for a Zone. -// This function does not support custom topologies, only Generic and Smart Tiered Caching. -// -// API Reference: https://api.cloudflare.com/#smart-tiered-cache-get-smart-tiered-cache-setting -// API Reference: https://api.cloudflare.com/#tiered-cache-get-tiered-cache-setting -func (api *API) GetTieredCache(ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - var lastModified time.Time - - generic, err := getGenericTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - lastModified = generic.LastModified - - smart, err := getSmartTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - - if smart.LastModified.After(lastModified) { - lastModified = smart.LastModified - } - - if generic.Type == TieredCacheOff { - return TieredCache{Type: TieredCacheOff, LastModified: lastModified}, nil - } - - if smart.Type == TieredCacheOff { - return TieredCache{Type: TieredCacheGeneric, LastModified: lastModified}, nil - } - - return TieredCache{Type: TieredCacheSmart, LastModified: lastModified}, nil -} - -// SetTieredCache allows you to set a zone's tiered cache topology between the available types. -// Using the value of TieredCacheOff will disable Tiered Cache entirely. -// -// API Reference: https://api.cloudflare.com/#smart-tiered-cache-patch-smart-tiered-cache-setting -// API Reference: https://api.cloudflare.com/#tiered-cache-patch-tiered-cache-setting -func (api *API) SetTieredCache(ctx context.Context, rc *ResourceContainer, value TieredCacheType) (TieredCache, error) { - if value == TieredCacheOff { - return api.DeleteTieredCache(ctx, rc) - } - - var lastModified time.Time - - if value == TieredCacheGeneric { - result, err := deleteSmartTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - lastModified = result.LastModified - - result, err = enableGenericTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - - if result.LastModified.After(lastModified) { - lastModified = result.LastModified - } - return TieredCache{Type: TieredCacheGeneric, LastModified: lastModified}, nil - } - - result, err := enableGenericTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - lastModified = result.LastModified - - result, err = enableSmartTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - - if result.LastModified.After(lastModified) { - lastModified = result.LastModified - } - return TieredCache{Type: TieredCacheSmart, LastModified: lastModified}, nil -} - -// DeleteTieredCache allows you to delete the tiered cache settings for a zone. -// This is equivalent to using SetTieredCache with the value of TieredCacheOff. -// -// API Reference: https://api.cloudflare.com/#smart-tiered-cache-delete-smart-tiered-cache-setting -// API Reference: https://api.cloudflare.com/#tiered-cache-patch-tiered-cache-setting -func (api *API) DeleteTieredCache(ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - var lastModified time.Time - - result, err := deleteSmartTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - lastModified = result.LastModified - - result, err = disableGenericTieredCache(api, ctx, rc) - if err != nil { - return TieredCache{}, err - } - - if result.LastModified.After(lastModified) { - lastModified = result.LastModified - } - return TieredCache{Type: TieredCacheOff, LastModified: lastModified}, nil -} - -type tieredCacheResult struct { - ID string `json:"id"` - Value string `json:"value,omitempty"` - LastModified time.Time `json:"modified_on"` -} - -type tieredCacheResponse struct { - Result tieredCacheResult `json:"result"` - Response -} - -type tieredCacheSetting struct { - Value string `json:"value"` -} - -func getGenericTieredCache(api *API, ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - uri := fmt.Sprintf("/zones/%s/argo/tiered_caching", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - var response tieredCacheResponse - err = json.Unmarshal(res, &response) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - if !response.Success { - return TieredCache{Type: TieredCacheOff}, errors.New("request to retrieve generic tiered cache failed") - } - - if response.Result.Value == "off" { - return TieredCache{Type: TieredCacheOff, LastModified: response.Result.LastModified}, nil - } - - return TieredCache{Type: TieredCacheGeneric, LastModified: response.Result.LastModified}, nil -} - -func getSmartTieredCache(api *API, ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - uri := fmt.Sprintf("/zones/%s/cache/tiered_cache_smart_topology_enable", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - var notFoundError *NotFoundError - if errors.As(err, ¬FoundError) { - return TieredCache{Type: TieredCacheOff}, nil - } - return TieredCache{Type: TieredCacheOff}, err - } - - var response tieredCacheResponse - err = json.Unmarshal(res, &response) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - if !response.Success { - return TieredCache{Type: TieredCacheOff}, errors.New("request to retrieve smart tiered cache failed") - } - - if response.Result.Value == "off" { - return TieredCache{Type: TieredCacheOff, LastModified: response.Result.LastModified}, nil - } - return TieredCache{Type: TieredCacheSmart, LastModified: response.Result.LastModified}, nil -} - -func enableGenericTieredCache(api *API, ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - uri := fmt.Sprintf("/zones/%s/argo/tiered_caching", rc.Identifier) - setting := tieredCacheSetting{ - Value: "on", - } - body, err := json.Marshal(setting) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, body) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - var response tieredCacheResponse - err = json.Unmarshal(res, &response) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - if !response.Success { - return TieredCache{Type: TieredCacheOff}, errors.New("request to enable generic tiered cache failed") - } - - return TieredCache{Type: TieredCacheGeneric, LastModified: response.Result.LastModified}, nil -} - -func enableSmartTieredCache(api *API, ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - uri := fmt.Sprintf("/zones/%s/cache/tiered_cache_smart_topology_enable", rc.Identifier) - setting := tieredCacheSetting{ - Value: "on", - } - body, err := json.Marshal(setting) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, body) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - var response tieredCacheResponse - err = json.Unmarshal(res, &response) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - if !response.Success { - return TieredCache{Type: TieredCacheOff}, errors.New("request to enable smart tiered cache failed") - } - - return TieredCache{Type: TieredCacheSmart, LastModified: response.Result.LastModified}, nil -} - -func disableGenericTieredCache(api *API, ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - uri := fmt.Sprintf("/zones/%s/argo/tiered_caching", rc.Identifier) - setting := tieredCacheSetting{ - Value: "off", - } - body, err := json.Marshal(setting) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, body) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - var response tieredCacheResponse - err = json.Unmarshal(res, &response) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - if !response.Success { - return TieredCache{Type: TieredCacheOff}, errors.New("request to disable generic tiered cache failed") - } - - return TieredCache{Type: TieredCacheOff, LastModified: response.Result.LastModified}, nil -} - -func deleteSmartTieredCache(api *API, ctx context.Context, rc *ResourceContainer) (TieredCache, error) { - uri := fmt.Sprintf("/zones/%s/cache/tiered_cache_smart_topology_enable", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - var notFoundError *NotFoundError - if errors.As(err, ¬FoundError) { - return TieredCache{Type: TieredCacheOff}, nil - } - return TieredCache{Type: TieredCacheOff}, err - } - - var response tieredCacheResponse - err = json.Unmarshal(res, &response) - if err != nil { - return TieredCache{Type: TieredCacheOff}, err - } - - if !response.Success { - return TieredCache{Type: TieredCacheOff}, errors.New("request to disable smart tiered cache failed") - } - - return TieredCache{Type: TieredCacheOff, LastModified: response.Result.LastModified}, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/total_tls.go b/vendor/github.com/cloudflare/cloudflare-go/total_tls.go deleted file mode 100644 index 98772e8..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/total_tls.go +++ /dev/null @@ -1,63 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type TotalTLS struct { - Enabled *bool `json:"enabled,omitempty"` - CertificateAuthority string `json:"certificate_authority,omitempty"` - ValidityDays int `json:"validity_days,omitempty"` -} - -type TotalTLSResponse struct { - Response - Result TotalTLS `json:"result"` -} - -// GetTotalTLS Get Total TLS Settings for a Zone. -// -// API Reference: https://api.cloudflare.com/#total-tls-total-tls-settings-details -func (api *API) GetTotalTLS(ctx context.Context, rc *ResourceContainer) (TotalTLS, error) { - if rc.Identifier == "" { - return TotalTLS{}, ErrMissingZoneID - } - uri := fmt.Sprintf("/zones/%s/acm/total_tls", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TotalTLS{}, err - } - - var r TotalTLSResponse - err = json.Unmarshal(res, &r) - if err != nil { - return TotalTLS{}, err - } - - return r.Result, nil -} - -// SetTotalTLS Set Total TLS Settings or disable the feature for a Zone. -// -// API Reference: https://api.cloudflare.com/#total-tls-enable-or-disable-total-tls -func (api *API) SetTotalTLS(ctx context.Context, rc *ResourceContainer, params TotalTLS) (TotalTLS, error) { - if rc.Identifier == "" { - return TotalTLS{}, ErrMissingZoneID - } - uri := fmt.Sprintf("/zones/%s/acm/total_tls", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return TotalTLS{}, err - } - - var r TotalTLSResponse - err = json.Unmarshal(res, &r) - if err != nil { - return TotalTLS{}, err - } - - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/tunnel.go b/vendor/github.com/cloudflare/cloudflare-go/tunnel.go deleted file mode 100644 index d933eed..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/tunnel.go +++ /dev/null @@ -1,461 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -// ErrMissingTunnelID is for when a required tunnel ID is missing from the -// parameters. -var ErrMissingTunnelID = errors.New("required missing tunnel ID") - -// Tunnel is the struct definition of a tunnel. -type Tunnel struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Secret string `json:"tunnel_secret,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - DeletedAt *time.Time `json:"deleted_at,omitempty"` - Connections []TunnelConnection `json:"connections,omitempty"` - ConnsActiveAt *time.Time `json:"conns_active_at,omitempty"` - ConnInactiveAt *time.Time `json:"conns_inactive_at,omitempty"` -} - -// Connection is the struct definition of a connection. -type Connection struct { - ID string `json:"id,omitempty"` - Features []string `json:"features,omitempty"` - Version string `json:"version,omitempty"` - Arch string `json:"arch,omitempty"` - Connections []TunnelConnection `json:"conns,omitempty"` - RunAt *time.Time `json:"run_at,omitempty"` -} - -// TunnelConnection represents the connections associated with a tunnel. -type TunnelConnection struct { - ColoName string `json:"colo_name"` - ID string `json:"id"` - IsPendingReconnect bool `json:"is_pending_reconnect"` - ClientID string `json:"client_id"` - ClientVersion string `json:"client_version"` - OpenedAt string `json:"opened_at"` - OriginIP string `json:"origin_ip"` -} - -// TunnelsDetailResponse is used for representing the API response payload for -// multiple tunnels. -type TunnelsDetailResponse struct { - Result []Tunnel `json:"result"` - Response -} - -// TunnelDetailResponse is used for representing the API response payload for -// a single tunnel. -type TunnelDetailResponse struct { - Result Tunnel `json:"result"` - Response -} - -// TunnelConnectionResponse is used for representing the API response payload for -// connections of a single tunnel. -type TunnelConnectionResponse struct { - Result []Connection `json:"result"` - Response -} - -type TunnelConfigurationResult struct { - TunnelID string `json:"tunnel_id,omitempty"` - Config TunnelConfiguration `json:"config,omitempty"` - Version int `json:"version,omitempty"` -} - -// TunnelConfigurationResponse is used for representing the API response payload -// for a single tunnel. -type TunnelConfigurationResponse struct { - Result TunnelConfigurationResult `json:"result"` - Response -} - -// TunnelTokenResponse is the API response for a tunnel token. -type TunnelTokenResponse struct { - Result string `json:"result"` - Response -} - -type TunnelCreateParams struct { - Name string `json:"name,omitempty"` - Secret string `json:"tunnel_secret,omitempty"` -} - -type TunnelUpdateParams struct { - Name string `json:"name,omitempty"` - Secret string `json:"tunnel_secret,omitempty"` -} - -type UnvalidatedIngressRule struct { - Hostname string `json:"hostname,omitempty"` - Path string `json:"path,omitempty"` - Service string `json:"service,omitempty"` -} - -// OriginRequestConfig is a set of optional fields that users may set to -// customize how cloudflared sends requests to origin services. It is used to set -// up general config that apply to all rules, and also, specific per-rule -// config. -type OriginRequestConfig struct { - // HTTP proxy timeout for establishing a new connection - ConnectTimeout *time.Duration `json:"connectTimeout,omitempty"` - // HTTP proxy timeout for completing a TLS handshake - TLSTimeout *time.Duration `json:"tlsTimeout,omitempty"` - // HTTP proxy TCP keepalive duration - TCPKeepAlive *time.Duration `json:"tcpKeepAlive,omitempty"` - // HTTP proxy should disable "happy eyeballs" for IPv4/v6 fallback - NoHappyEyeballs *bool `json:"noHappyEyeballs,omitempty"` - // HTTP proxy maximum keepalive connection pool size - KeepAliveConnections *int `json:"keepAliveConnections,omitempty"` - // HTTP proxy timeout for closing an idle connection - KeepAliveTimeout *time.Duration `json:"keepAliveTimeout,omitempty"` - // Sets the HTTP Host header for the local webserver. - HTTPHostHeader *string `json:"httpHostHeader,omitempty"` - // Hostname on the origin server certificate. - OriginServerName *string `json:"originServerName,omitempty"` - // Path to the CA for the certificate of your origin. - // This option should be used only if your certificate is not signed by Cloudflare. - CAPool *string `json:"caPool,omitempty"` - // Disables TLS verification of the certificate presented by your origin. - // Will allow any certificate from the origin to be accepted. - // Note: The connection from your machine to Cloudflare's Edge is still encrypted. - NoTLSVerify *bool `json:"noTLSVerify,omitempty"` - // Disables chunked transfer encoding. - // Useful if you are running a WSGI server. - DisableChunkedEncoding *bool `json:"disableChunkedEncoding,omitempty"` - // Runs as jump host - BastionMode *bool `json:"bastionMode,omitempty"` - // Listen address for the proxy. - ProxyAddress *string `json:"proxyAddress,omitempty"` - // Listen port for the proxy. - ProxyPort *uint `json:"proxyPort,omitempty"` - // Valid options are 'socks' or empty. - ProxyType *string `json:"proxyType,omitempty"` - // IP rules for the proxy service - IPRules []IngressIPRule `json:"ipRules,omitempty"` -} - -type IngressIPRule struct { - Prefix *string `json:"prefix,omitempty"` - Ports []int `json:"ports,omitempty"` - Allow bool `json:"allow,omitempty"` -} - -type TunnelConfiguration struct { - Ingress []UnvalidatedIngressRule `json:"ingress,omitempty"` - WarpRouting *WarpRoutingConfig `json:"warp-routing,omitempty"` - OriginRequest OriginRequestConfig `json:"originRequest,omitempty"` -} - -type WarpRoutingConfig struct { - Enabled bool `json:"enabled,omitempty"` -} - -type TunnelConfigurationParams struct { - TunnelID string `json:"-"` - Config TunnelConfiguration `json:"config,omitempty"` -} - -type TunnelListParams struct { - Name string `url:"name,omitempty"` - UUID string `url:"uuid,omitempty"` // the tunnel ID - IsDeleted *bool `url:"is_deleted,omitempty"` - ExistedAt *time.Time `url:"existed_at,omitempty"` -} - -// Tunnels lists all tunnels. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-list-cloudflare-tunnels -func (api *API) Tunnels(ctx context.Context, rc *ResourceContainer, params TunnelListParams) ([]Tunnel, error) { - if rc.Identifier == "" { - return []Tunnel{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/cfd_tunnel", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Tunnel{}, err - } - - var argoDetailsResponse TunnelsDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return []Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// Tunnel returns a single Argo tunnel. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-get-cloudflare-tunnel -func (api *API) Tunnel(ctx context.Context, rc *ResourceContainer, tunnelID string) (Tunnel, error) { - if rc.Identifier == "" { - return Tunnel{}, ErrMissingAccountID - } - - if tunnelID == "" { - return Tunnel{}, errors.New("missing tunnel ID") - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s", rc.Identifier, tunnelID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Tunnel{}, err - } - - var argoDetailsResponse TunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// CreateTunnel creates a new tunnel for the account. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-create-cloudflare-tunnel -func (api *API) CreateTunnel(ctx context.Context, rc *ResourceContainer, params TunnelCreateParams) (Tunnel, error) { - if rc.Identifier == "" { - return Tunnel{}, ErrMissingAccountID - } - - if params.Name == "" { - return Tunnel{}, errors.New("missing tunnel name") - } - - if params.Secret == "" { - return Tunnel{}, errors.New("missing tunnel secret") - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel", rc.Identifier) - - tunnel := Tunnel{Name: params.Name, Secret: params.Secret} - - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, tunnel) - if err != nil { - return Tunnel{}, err - } - - var argoDetailsResponse TunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return argoDetailsResponse.Result, nil -} - -// UpdateTunnel updates an existing tunnel for the account. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-update-cloudflare-tunnel -func (api *API) UpdateTunnel(ctx context.Context, rc *ResourceContainer, params TunnelUpdateParams) (Tunnel, error) { - if rc.Identifier == "" { - return Tunnel{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel", rc.Identifier) - - var tunnel Tunnel - - if params.Name != "" { - tunnel.Name = params.Name - } - - if params.Secret != "" { - tunnel.Secret = params.Secret - } - - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, tunnel) - if err != nil { - return Tunnel{}, err - } - - var argoDetailsResponse TunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return argoDetailsResponse.Result, nil -} - -// UpdateTunnelConfiguration updates an existing tunnel for the account. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-configuration-properties -func (api *API) UpdateTunnelConfiguration(ctx context.Context, rc *ResourceContainer, params TunnelConfigurationParams) (TunnelConfigurationResult, error) { - if rc.Identifier == "" { - return TunnelConfigurationResult{}, ErrMissingAccountID - } - - if params.TunnelID == "" { - return TunnelConfigurationResult{}, ErrMissingTunnelID - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s/configurations", rc.Identifier, params.TunnelID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return TunnelConfigurationResult{}, err - } - - var tunnelDetailsResponse TunnelConfigurationResponse - err = json.Unmarshal(res, &tunnelDetailsResponse) - if err != nil { - return TunnelConfigurationResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - var tunnelDetails TunnelConfigurationResult - - tunnelDetails.Config = tunnelDetailsResponse.Result.Config - tunnelDetails.TunnelID = tunnelDetailsResponse.Result.TunnelID - tunnelDetails.Version = tunnelDetailsResponse.Result.Version - - return tunnelDetails, nil -} - -// GetTunnelConfiguration updates an existing tunnel for the account. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-configuration-properties -func (api *API) GetTunnelConfiguration(ctx context.Context, rc *ResourceContainer, tunnelID string) (TunnelConfigurationResult, error) { - if rc.Identifier == "" { - return TunnelConfigurationResult{}, ErrMissingAccountID - } - - if tunnelID == "" { - return TunnelConfigurationResult{}, ErrMissingTunnelID - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s/configurations", rc.Identifier, tunnelID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TunnelConfigurationResult{}, err - } - - var tunnelDetailsResponse TunnelConfigurationResponse - err = json.Unmarshal(res, &tunnelDetailsResponse) - if err != nil { - return TunnelConfigurationResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - var tunnelDetails TunnelConfigurationResult - - tunnelDetails.Config = tunnelDetailsResponse.Result.Config - tunnelDetails.TunnelID = tunnelDetailsResponse.Result.TunnelID - tunnelDetails.Version = tunnelDetailsResponse.Result.Version - - return tunnelDetails, nil -} - -// TunnelConnections gets all connections on a tunnel. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-list-cloudflare-tunnel-connections -func (api *API) TunnelConnections(ctx context.Context, rc *ResourceContainer, tunnelID string) ([]Connection, error) { - if rc.Identifier == "" { - return []Connection{}, ErrMissingAccountID - } - - if tunnelID == "" { - return []Connection{}, ErrMissingTunnelID - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s/connections", rc.Identifier, tunnelID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Connection{}, err - } - - var argoDetailsResponse TunnelConnectionResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return []Connection{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return argoDetailsResponse.Result, nil -} - -// DeleteTunnel removes a single Argo tunnel. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-delete-cloudflare-tunnel -func (api *API) DeleteTunnel(ctx context.Context, rc *ResourceContainer, tunnelID string) error { - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s", rc.Identifier, tunnelID) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - var argoDetailsResponse TunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// CleanupTunnelConnections deletes any inactive connections on a tunnel. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-clean-up-cloudflare-tunnel-connections -func (api *API) CleanupTunnelConnections(ctx context.Context, rc *ResourceContainer, tunnelID string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - if tunnelID == "" { - return errors.New("missing tunnel ID") - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s/connections", rc.Identifier, tunnelID) - - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - var argoDetailsResponse TunnelDetailResponse - err = json.Unmarshal(res, &argoDetailsResponse) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// TunnelToken that allows to run a tunnel. -// -// API reference: https://api.cloudflare.com/#cloudflare-tunnel-get-cloudflare-tunnel-token -func (api *API) TunnelToken(ctx context.Context, rc *ResourceContainer, tunnelID string) (string, error) { - if rc.Identifier == "" { - return "", ErrMissingAccountID - } - - if tunnelID == "" { - return "", errors.New("missing tunnel ID") - } - - uri := fmt.Sprintf("/accounts/%s/cfd_tunnel/%s/token", rc.Identifier, tunnelID) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return "", err - } - - var tunnelTokenResponse TunnelTokenResponse - err = json.Unmarshal(res, &tunnelTokenResponse) - if err != nil { - return "", fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return tunnelTokenResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/tunnel_routes.go b/vendor/github.com/cloudflare/cloudflare-go/tunnel_routes.go deleted file mode 100644 index 0fba4eb..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/tunnel_routes.go +++ /dev/null @@ -1,213 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" - "strings" - "time" -) - -var ( - ErrMissingNetwork = errors.New("missing required network parameter") - ErrInvalidNetworkValue = errors.New("invalid IP parameter. Cannot use CIDR ranges for this endpoint.") -) - -// TunnelRoute is the full record for a route. -type TunnelRoute struct { - Network string `json:"network"` - TunnelID string `json:"tunnel_id"` - TunnelName string `json:"tunnel_name"` - Comment string `json:"comment"` - CreatedAt *time.Time `json:"created_at"` - DeletedAt *time.Time `json:"deleted_at"` - VirtualNetworkID string `json:"virtual_network_id"` -} - -type TunnelRoutesListParams struct { - TunnelID string `url:"tunnel_id,omitempty"` - Comment string `url:"comment,omitempty"` - IsDeleted *bool `url:"is_deleted,omitempty"` - NetworkSubset string `url:"network_subset,omitempty"` - NetworkSuperset string `url:"network_superset,omitempty"` - ExistedAt *time.Time `url:"existed_at,omitempty"` - VirtualNetworkID string `url:"virtual_network_id,omitempty"` - PaginationOptions -} - -type TunnelRoutesCreateParams struct { - Network string `json:"-"` - TunnelID string `json:"tunnel_id"` - Comment string `json:"comment,omitempty"` - VirtualNetworkID string `json:"virtual_network_id,omitempty"` -} - -type TunnelRoutesUpdateParams struct { - Network string `json:"network"` - TunnelID string `json:"tunnel_id"` - Comment string `json:"comment,omitempty"` - VirtualNetworkID string `json:"virtual_network_id,omitempty"` -} - -type TunnelRoutesForIPParams struct { - Network string `url:"-"` - VirtualNetworkID string `url:"virtual_network_id,omitempty"` -} - -type TunnelRoutesDeleteParams struct { - Network string `url:"-"` - VirtualNetworkID string `url:"virtual_network_id,omitempty"` -} - -// tunnelRouteListResponse is the API response for listing tunnel routes. -type tunnelRouteListResponse struct { - Response - Result []TunnelRoute `json:"result"` -} - -type tunnelRouteResponse struct { - Response - Result TunnelRoute `json:"result"` -} - -// ListTunnelRoutes lists all defined routes for tunnels in the account. -// -// See: https://api.cloudflare.com/#tunnel-route-list-tunnel-routes -func (api *API) ListTunnelRoutes(ctx context.Context, rc *ResourceContainer, params TunnelRoutesListParams) ([]TunnelRoute, error) { - if rc.Identifier == "" { - return []TunnelRoute{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/%s/%s/teamnet/routes", AccountRouteRoot, rc.Identifier), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []TunnelRoute{}, err - } - - var resp tunnelRouteListResponse - err = json.Unmarshal(res, &resp) - if err != nil { - return []TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return resp.Result, nil -} - -// GetTunnelRouteForIP finds the Tunnel Route that encompasses the given IP. -// -// See: https://api.cloudflare.com/#tunnel-route-get-tunnel-route-by-ip -func (api *API) GetTunnelRouteForIP(ctx context.Context, rc *ResourceContainer, params TunnelRoutesForIPParams) (TunnelRoute, error) { - if rc.Identifier == "" { - return TunnelRoute{}, ErrMissingAccountID - } - - if params.Network == "" { - return TunnelRoute{}, ErrMissingNetwork - } - - if strings.Contains(params.Network, "/") { - return TunnelRoute{}, ErrInvalidNetworkValue - } - - uri := buildURI(fmt.Sprintf("/%s/%s/teamnet/routes/ip/%s", AccountRouteRoot, rc.Identifier, params.Network), params) - - responseBody, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return TunnelRoute{}, err - } - - var routeResponse tunnelRouteResponse - err = json.Unmarshal(responseBody, &routeResponse) - if err != nil { - return TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return routeResponse.Result, nil -} - -// CreateTunnelRoute add a new route to the account routing table for the given -// tunnel. -// -// See: https://api.cloudflare.com/#tunnel-route-create-route -func (api *API) CreateTunnelRoute(ctx context.Context, rc *ResourceContainer, params TunnelRoutesCreateParams) (TunnelRoute, error) { - if rc.Identifier == "" { - return TunnelRoute{}, ErrMissingAccountID - } - - if params.Network == "" { - return TunnelRoute{}, ErrMissingNetwork - } - - uri := fmt.Sprintf("/%s/%s/teamnet/routes/network/%s", AccountRouteRoot, rc.Identifier, url.PathEscape(params.Network)) - - responseBody, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return TunnelRoute{}, err - } - - var routeResponse tunnelRouteResponse - err = json.Unmarshal(responseBody, &routeResponse) - if err != nil { - return TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return routeResponse.Result, nil -} - -// DeleteTunnelRoute delete an existing route from the account routing table. -// -// See: https://api.cloudflare.com/#tunnel-route-delete-route -func (api *API) DeleteTunnelRoute(ctx context.Context, rc *ResourceContainer, params TunnelRoutesDeleteParams) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - if params.Network == "" { - return ErrMissingNetwork - } - - // Cannot fully utilize buildURI here because it tries to escape "%" sign - // from the already escaped "/" sign from Network field. - uri := fmt.Sprintf("/%s/%s/teamnet/routes/network/%s%s", AccountRouteRoot, rc.Identifier, url.PathEscape(params.Network), buildURI("", params)) - - responseBody, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - var routeResponse tunnelRouteResponse - err = json.Unmarshal(responseBody, &routeResponse) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// UpdateTunnelRoute updates an existing route in the account routing table for -// the given tunnel. -// -// See: https://api.cloudflare.com/#tunnel-route-update-route -func (api *API) UpdateTunnelRoute(ctx context.Context, rc *ResourceContainer, params TunnelRoutesUpdateParams) (TunnelRoute, error) { - if rc.Identifier == "" { - return TunnelRoute{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/%s/%s/teamnet/routes/network/%s", AccountRouteRoot, rc.Identifier, url.PathEscape(params.Network)) - - responseBody, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) - if err != nil { - return TunnelRoute{}, err - } - - var routeResponse tunnelRouteResponse - err = json.Unmarshal(responseBody, &routeResponse) - if err != nil { - return TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return routeResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/tunnel_virtual_networks.go b/vendor/github.com/cloudflare/cloudflare-go/tunnel_virtual_networks.go deleted file mode 100644 index a7ba6f4..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/tunnel_virtual_networks.go +++ /dev/null @@ -1,158 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -var ErrMissingVnetName = errors.New("required missing virtual network name") - -// TunnelVirtualNetwork is segregation of Tunnel IP Routes via Virtualized -// Networks to handle overlapping private IPs in your origins. -type TunnelVirtualNetwork struct { - ID string `json:"id"` - Name string `json:"name"` - IsDefaultNetwork bool `json:"is_default_network"` - Comment string `json:"comment"` - CreatedAt *time.Time `json:"created_at"` - DeletedAt *time.Time `json:"deleted_at"` -} - -type TunnelVirtualNetworksListParams struct { - ID string `url:"id,omitempty"` - Name string `url:"name,omitempty"` - IsDefault *bool `url:"is_default,omitempty"` - IsDeleted *bool `url:"is_deleted,omitempty"` - - PaginationOptions -} - -type TunnelVirtualNetworkCreateParams struct { - Name string `json:"name"` - Comment string `json:"comment"` - IsDefault bool `json:"is_default"` -} - -type TunnelVirtualNetworkUpdateParams struct { - VnetID string `json:"-"` - Name string `json:"name,omitempty"` - Comment string `json:"comment,omitempty"` - IsDefaultNetwork *bool `json:"is_default_network,omitempty"` -} - -// tunnelRouteListResponse is the API response for listing tunnel virtual -// networks. -type tunnelVirtualNetworkListResponse struct { - Response - Result []TunnelVirtualNetwork `json:"result"` -} - -type tunnelVirtualNetworkResponse struct { - Response - Result TunnelVirtualNetwork `json:"result"` -} - -// ListTunnelVirtualNetworks lists all defined virtual networks for tunnels in -// the account. -// -// API reference: https://api.cloudflare.com/#tunnel-virtual-network-list-virtual-networks -func (api *API) ListTunnelVirtualNetworks(ctx context.Context, rc *ResourceContainer, params TunnelVirtualNetworksListParams) ([]TunnelVirtualNetwork, error) { - if rc.Identifier == "" { - return []TunnelVirtualNetwork{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/%s/%s/teamnet/virtual_networks", AccountRouteRoot, rc.Identifier), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, params) - if err != nil { - return []TunnelVirtualNetwork{}, err - } - - var resp tunnelVirtualNetworkListResponse - err = json.Unmarshal(res, &resp) - if err != nil { - return []TunnelVirtualNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return resp.Result, nil -} - -// CreateTunnelVirtualNetwork adds a new virtual network to the account. -// -// API reference: https://api.cloudflare.com/#tunnel-virtual-network-create-virtual-network -func (api *API) CreateTunnelVirtualNetwork(ctx context.Context, rc *ResourceContainer, params TunnelVirtualNetworkCreateParams) (TunnelVirtualNetwork, error) { - if rc.Identifier == "" { - return TunnelVirtualNetwork{}, ErrMissingAccountID - } - - if params.Name == "" { - return TunnelVirtualNetwork{}, ErrMissingVnetName - } - - uri := fmt.Sprintf("/%s/%s/teamnet/virtual_networks", AccountRouteRoot, rc.Identifier) - - responseBody, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return TunnelVirtualNetwork{}, err - } - - var resp tunnelVirtualNetworkResponse - err = json.Unmarshal(responseBody, &resp) - if err != nil { - return TunnelVirtualNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return resp.Result, nil -} - -// DeleteTunnelVirtualNetwork deletes an existing virtual network from the -// account. -// -// API reference: https://api.cloudflare.com/#tunnel-virtual-network-delete-virtual-network -func (api *API) DeleteTunnelVirtualNetwork(ctx context.Context, rc *ResourceContainer, vnetID string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - uri := fmt.Sprintf("/%s/%s/teamnet/virtual_networks/%s", AccountRouteRoot, rc.Identifier, vnetID) - - responseBody, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - var resp tunnelVirtualNetworkResponse - err = json.Unmarshal(responseBody, &resp) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// UpdateTunnelRoute updates an existing virtual network in the account. -// -// API reference: https://api.cloudflare.com/#tunnel-virtual-network-update-virtual-network -func (api *API) UpdateTunnelVirtualNetwork(ctx context.Context, rc *ResourceContainer, params TunnelVirtualNetworkUpdateParams) (TunnelVirtualNetwork, error) { - if rc.Identifier == "" { - return TunnelVirtualNetwork{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/%s/%s/teamnet/virtual_networks/%s", AccountRouteRoot, rc.Identifier, params.VnetID) - - responseBody, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) - if err != nil { - return TunnelVirtualNetwork{}, err - } - - var resp tunnelVirtualNetworkResponse - err = json.Unmarshal(responseBody, &resp) - if err != nil { - return TunnelVirtualNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return resp.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/universal_ssl.go b/vendor/github.com/cloudflare/cloudflare-go/universal_ssl.go deleted file mode 100644 index fed72d8..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/universal_ssl.go +++ /dev/null @@ -1,107 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// UniversalSSLSetting represents a universal ssl setting's properties. -type UniversalSSLSetting struct { - Enabled bool `json:"enabled"` -} - -type universalSSLSettingResponse struct { - Response - Result UniversalSSLSetting `json:"result"` -} - -// UniversalSSLVerificationDetails represents a universal ssl verification's properties. -type UniversalSSLVerificationDetails struct { - CertificateStatus string `json:"certificate_status"` - VerificationType string `json:"verification_type"` - ValidationMethod string `json:"validation_method"` - CertPackUUID string `json:"cert_pack_uuid"` - VerificationStatus bool `json:"verification_status"` - BrandCheck bool `json:"brand_check"` - VerificationInfo []SSLValidationRecord `json:"verification_info"` -} - -type universalSSLVerificationResponse struct { - Response - Result []UniversalSSLVerificationDetails `json:"result"` -} - -type UniversalSSLCertificatePackValidationMethodSetting struct { - ValidationMethod string `json:"validation_method"` -} - -type universalSSLCertificatePackValidationMethodSettingResponse struct { - Response - Result UniversalSSLCertificatePackValidationMethodSetting `json:"result"` -} - -// UniversalSSLSettingDetails returns the details for a universal ssl setting -// -// API reference: https://api.cloudflare.com/#universal-ssl-settings-for-a-zone-universal-ssl-settings-details -func (api *API) UniversalSSLSettingDetails(ctx context.Context, zoneID string) (UniversalSSLSetting, error) { - uri := fmt.Sprintf("/zones/%s/ssl/universal/settings", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return UniversalSSLSetting{}, err - } - var r universalSSLSettingResponse - if err := json.Unmarshal(res, &r); err != nil { - return UniversalSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// EditUniversalSSLSetting edits the universal ssl setting for a zone -// -// API reference: https://api.cloudflare.com/#universal-ssl-settings-for-a-zone-edit-universal-ssl-settings -func (api *API) EditUniversalSSLSetting(ctx context.Context, zoneID string, setting UniversalSSLSetting) (UniversalSSLSetting, error) { - uri := fmt.Sprintf("/zones/%s/ssl/universal/settings", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, setting) - if err != nil { - return UniversalSSLSetting{}, err - } - var r universalSSLSettingResponse - if err := json.Unmarshal(res, &r); err != nil { - return UniversalSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UniversalSSLVerificationDetails returns the details for a universal ssl verification -// -// API reference: https://api.cloudflare.com/#ssl-verification-ssl-verification-details -func (api *API) UniversalSSLVerificationDetails(ctx context.Context, zoneID string) ([]UniversalSSLVerificationDetails, error) { - uri := fmt.Sprintf("/zones/%s/ssl/verification", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []UniversalSSLVerificationDetails{}, err - } - var r universalSSLVerificationResponse - if err := json.Unmarshal(res, &r); err != nil { - return []UniversalSSLVerificationDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateUniversalSSLCertificatePackValidationMethod changes the validation method for a certificate pack -// -// API reference: https://api.cloudflare.com/#ssl-verification-ssl-verification-details -func (api *API) UpdateUniversalSSLCertificatePackValidationMethod(ctx context.Context, zoneID string, certPackUUID string, setting UniversalSSLCertificatePackValidationMethodSetting) (UniversalSSLCertificatePackValidationMethodSetting, error) { - uri := fmt.Sprintf("/zones/%s/ssl/verification/%s", zoneID, certPackUUID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, setting) - if err != nil { - return UniversalSSLCertificatePackValidationMethodSetting{}, err - } - var r universalSSLCertificatePackValidationMethodSettingResponse - if err := json.Unmarshal(res, &r); err != nil { - return UniversalSSLCertificatePackValidationMethodSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/url_normalization_settings.go b/vendor/github.com/cloudflare/cloudflare-go/url_normalization_settings.go deleted file mode 100644 index c0247ce..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/url_normalization_settings.go +++ /dev/null @@ -1,59 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type URLNormalizationSettings struct { - Type string `json:"type"` - Scope string `json:"scope"` -} - -type URLNormalizationSettingsResponse struct { - Result URLNormalizationSettings `json:"result"` - Response -} - -type URLNormalizationSettingsUpdateParams struct { - Type string `json:"type"` - Scope string `json:"scope"` -} - -// URLNormalizationSettings API reference: https://api.cloudflare.com/#url-normalization-get-url-normalization-settings -func (api *API) URLNormalizationSettings(ctx context.Context, rc *ResourceContainer) (URLNormalizationSettings, error) { - uri := fmt.Sprintf("/zones/%s/url_normalization", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return URLNormalizationSettings{}, err - } - - var urlNormalizationSettingsResponse URLNormalizationSettingsResponse - err = json.Unmarshal(res, &urlNormalizationSettingsResponse) - if err != nil { - return URLNormalizationSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return urlNormalizationSettingsResponse.Result, nil -} - -// UpdateURLNormalizationSettings https://api.cloudflare.com/#url-normalization-update-url-normalization-settings -func (api *API) UpdateURLNormalizationSettings(ctx context.Context, rc *ResourceContainer, params URLNormalizationSettingsUpdateParams) (URLNormalizationSettings, error) { - uri := fmt.Sprintf("/zones/%s/url_normalization", rc.Identifier) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return URLNormalizationSettings{}, err - } - - var urlNormalizationSettingsResponse URLNormalizationSettingsResponse - err = json.Unmarshal(res, &urlNormalizationSettingsResponse) - if err != nil { - return URLNormalizationSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return urlNormalizationSettingsResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/user.go b/vendor/github.com/cloudflare/cloudflare-go/user.go deleted file mode 100644 index 08c2f07..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/user.go +++ /dev/null @@ -1,160 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// User describes a user account. -type User struct { - ID string `json:"id,omitempty"` - Email string `json:"email,omitempty"` - FirstName string `json:"first_name,omitempty"` - LastName string `json:"last_name,omitempty"` - Username string `json:"username,omitempty"` - Telephone string `json:"telephone,omitempty"` - Country string `json:"country,omitempty"` - Zipcode string `json:"zipcode,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` - APIKey string `json:"api_key,omitempty"` - TwoFA bool `json:"two_factor_authentication_enabled,omitempty"` - Betas []string `json:"betas,omitempty"` - Accounts []Account `json:"organizations,omitempty"` -} - -// UserResponse wraps a response containing User accounts. -type UserResponse struct { - Response - Result User `json:"result"` -} - -// userBillingProfileResponse wraps a response containing Billing Profile information. -type userBillingProfileResponse struct { - Response - Result UserBillingProfile -} - -// UserBillingProfile contains Billing Profile information. -type UserBillingProfile struct { - ID string `json:"id,omitempty"` - FirstName string `json:"first_name,omitempty"` - LastName string `json:"last_name,omitempty"` - Address string `json:"address,omitempty"` - Address2 string `json:"address2,omitempty"` - Company string `json:"company,omitempty"` - City string `json:"city,omitempty"` - State string `json:"state,omitempty"` - ZipCode string `json:"zipcode,omitempty"` - Country string `json:"country,omitempty"` - Telephone string `json:"telephone,omitempty"` - CardNumber string `json:"card_number,omitempty"` - CardExpiryYear int `json:"card_expiry_year,omitempty"` - CardExpiryMonth int `json:"card_expiry_month,omitempty"` - VAT string `json:"vat,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - EditedOn *time.Time `json:"edited_on,omitempty"` -} - -type UserBillingHistoryResponse struct { - Response - Result []UserBillingHistory `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -type UserBillingHistory struct { - ID string `json:"id,omitempty"` - Type string `json:"type,omitempty"` - Action string `json:"action,omitempty"` - Description string `json:"description,omitempty"` - OccurredAt *time.Time `json:"occurred_at,omitempty"` - Amount float32 `json:"amount,omitempty"` - Currency string `json:"currency,omitempty"` - Zone userBillingHistoryZone `json:"zone"` -} - -type userBillingHistoryZone struct { - Name string `json:"name,omitempty"` -} - -type UserBillingOptions struct { - PaginationOptions - Order string `url:"order,omitempty"` - Type string `url:"type,omitempty"` - OccurredAt *time.Time `url:"occurred_at,omitempty"` - Action string `url:"action,omitempty"` -} - -// UserDetails provides information about the logged-in user. -// -// API reference: https://api.cloudflare.com/#user-user-details -func (api *API) UserDetails(ctx context.Context) (User, error) { - var r UserResponse - res, err := api.makeRequestContext(ctx, http.MethodGet, "/user", nil) - if err != nil { - return User{}, err - } - - err = json.Unmarshal(res, &r) - if err != nil { - return User{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateUser updates the properties of the given user. -// -// API reference: https://api.cloudflare.com/#user-update-user -func (api *API) UpdateUser(ctx context.Context, user *User) (User, error) { - var r UserResponse - res, err := api.makeRequestContext(ctx, http.MethodPatch, "/user", user) - if err != nil { - return User{}, err - } - - err = json.Unmarshal(res, &r) - if err != nil { - return User{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UserBillingProfile returns the billing profile of the user. -// -// API reference: https://api.cloudflare.com/#user-billing-profile -func (api *API) UserBillingProfile(ctx context.Context) (UserBillingProfile, error) { - var r userBillingProfileResponse - res, err := api.makeRequestContext(ctx, http.MethodGet, "/user/billing/profile", nil) - if err != nil { - return UserBillingProfile{}, err - } - - err = json.Unmarshal(res, &r) - if err != nil { - return UserBillingProfile{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UserBillingHistory return the billing history of the user -// -// API reference: https://api.cloudflare.com/#user-billing-history-billing-history-details -func (api *API) UserBillingHistory(ctx context.Context, pageOpts UserBillingOptions) ([]UserBillingHistory, error) { - uri := buildURI("/user/billing/history", pageOpts) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []UserBillingHistory{}, err - } - var r UserBillingHistoryResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []UserBillingHistory{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/user_agent.go b/vendor/github.com/cloudflare/cloudflare-go/user_agent.go deleted file mode 100644 index 8c1a392..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/user_agent.go +++ /dev/null @@ -1,150 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" - "strconv" -) - -// UserAgentRule represents a User-Agent Block. These rules can be used to -// challenge, block or whitelist specific User-Agents for a given zone. -type UserAgentRule struct { - ID string `json:"id"` - Description string `json:"description"` - Mode string `json:"mode"` - Configuration UserAgentRuleConfig `json:"configuration"` - Paused bool `json:"paused"` -} - -// UserAgentRuleConfig represents a Zone Lockdown config, which comprises -// a Target ("ip" or "ip_range") and a Value (an IP address or IP+mask, -// respectively.) -type UserAgentRuleConfig ZoneLockdownConfig - -// UserAgentRuleResponse represents a response from the Zone Lockdown endpoint. -type UserAgentRuleResponse struct { - Result UserAgentRule `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// UserAgentRuleListResponse represents a response from the List Zone Lockdown endpoint. -type UserAgentRuleListResponse struct { - Result []UserAgentRule `json:"result"` - Response - ResultInfo `json:"result_info"` -} - -// CreateUserAgentRule creates a User-Agent Block rule for the given zone ID. -// -// API reference: https://api.cloudflare.com/#user-agent-blocking-rules-create-a-useragent-rule -func (api *API) CreateUserAgentRule(ctx context.Context, zoneID string, ld UserAgentRule) (*UserAgentRuleResponse, error) { - switch ld.Mode { - case "block", "challenge", "js_challenge", "managed_challenge": - break - default: - return nil, errors.New(`the User-Agent Block rule mode must be one of "block", "challenge", "js_challenge", "managed_challenge"`) - } - - uri := fmt.Sprintf("/zones/%s/firewall/ua_rules", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, ld) - if err != nil { - return nil, err - } - - response := &UserAgentRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// UpdateUserAgentRule updates a User-Agent Block rule (based on the ID) for the given zone ID. -// -// API reference: https://api.cloudflare.com/#user-agent-blocking-rules-update-useragent-rule -func (api *API) UpdateUserAgentRule(ctx context.Context, zoneID string, id string, ld UserAgentRule) (*UserAgentRuleResponse, error) { - uri := fmt.Sprintf("/zones/%s/firewall/ua_rules/%s", zoneID, id) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, ld) - if err != nil { - return nil, err - } - - response := &UserAgentRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// DeleteUserAgentRule deletes a User-Agent Block rule (based on the ID) for the given zone ID. -// -// API reference: https://api.cloudflare.com/#user-agent-blocking-rules-delete-useragent-rule -func (api *API) DeleteUserAgentRule(ctx context.Context, zoneID string, id string) (*UserAgentRuleResponse, error) { - uri := fmt.Sprintf("/zones/%s/firewall/ua_rules/%s", zoneID, id) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return nil, err - } - - response := &UserAgentRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// UserAgentRule retrieves a User-Agent Block rule (based on the ID) for the given zone ID. -// -// API reference: https://api.cloudflare.com/#user-agent-blocking-rules-useragent-rule-details -func (api *API) UserAgentRule(ctx context.Context, zoneID string, id string) (*UserAgentRuleResponse, error) { - uri := fmt.Sprintf("/zones/%s/firewall/ua_rules/%s", zoneID, id) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - response := &UserAgentRuleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// ListUserAgentRules retrieves a list of User-Agent Block rules for a given zone ID by page number. -// -// API reference: https://api.cloudflare.com/#user-agent-blocking-rules-list-useragent-rules -func (api *API) ListUserAgentRules(ctx context.Context, zoneID string, page int) (*UserAgentRuleListResponse, error) { - v := url.Values{} - if page <= 0 { - page = 1 - } - - v.Set("page", strconv.Itoa(page)) - v.Set("per_page", strconv.Itoa(100)) - - uri := fmt.Sprintf("/zones/%s/firewall/ua_rules?%s", zoneID, v.Encode()) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - response := &UserAgentRuleListResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/utils.go b/vendor/github.com/cloudflare/cloudflare-go/utils.go deleted file mode 100644 index bc2dc56..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/utils.go +++ /dev/null @@ -1,28 +0,0 @@ -package cloudflare - -import ( - "fmt" - "net/url" - "os" - "path/filepath" - - "github.com/google/go-querystring/query" -) - -// buildURI assembles the base path and queries. -func buildURI(path string, options interface{}) string { - v, _ := query.Values(options) - return (&url.URL{Path: path, RawQuery: v.Encode()}).String() -} - -// loadFixture takes a series of path components and returns the JSON fixture at -// that location associated. -func loadFixture(parts ...string) string { - paths := []string{"testdata", "fixtures"} - paths = append(paths, parts...) - b, err := os.ReadFile(filepath.Join(paths...) + ".json") - if err != nil { - fmt.Print(err) - } - return string(b) -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/virtualdns.go b/vendor/github.com/cloudflare/cloudflare-go/virtualdns.go deleted file mode 100644 index ad4ed02..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/virtualdns.go +++ /dev/null @@ -1,165 +0,0 @@ -package cloudflare - -import ( - "context" - "fmt" -) - -// NOTE: Everything in this file is deprecated. See `dns_firewall.go` instead. - -// VirtualDNS represents a Virtual DNS configuration. -// -// Deprecated: Use DNSFirewallCluster instead. -type VirtualDNS struct { - ID string `json:"id"` - Name string `json:"name"` - OriginIPs []string `json:"origin_ips"` - VirtualDNSIPs []string `json:"virtual_dns_ips"` - MinimumCacheTTL uint `json:"minimum_cache_ttl"` - MaximumCacheTTL uint `json:"maximum_cache_ttl"` - DeprecateAnyRequests bool `json:"deprecate_any_requests"` - ModifiedOn string `json:"modified_on"` -} - -// VirtualDNSAnalyticsMetrics represents a group of aggregated Virtual DNS metrics. -// -// Deprecated: Use DNSFirewallAnalyticsMetrics instead. -type VirtualDNSAnalyticsMetrics DNSFirewallAnalyticsMetrics - -// VirtualDNSAnalytics represents a set of aggregated Virtual DNS metrics. -// -// Deprecated: Use DNSFirewallAnalytics instead. -type VirtualDNSAnalytics struct { - Totals VirtualDNSAnalyticsMetrics `json:"totals"` - Min VirtualDNSAnalyticsMetrics `json:"min"` - Max VirtualDNSAnalyticsMetrics `json:"max"` -} - -// VirtualDNSUserAnalyticsOptions represents range and dimension selection on analytics endpoint -// -// Deprecated: Use DNSFirewallUserAnalyticsOptions instead. -type VirtualDNSUserAnalyticsOptions DNSFirewallUserAnalyticsOptions - -// VirtualDNSResponse represents a Virtual DNS response. -// -// Deprecated: This internal type will be removed in the future. -type VirtualDNSResponse struct { - Response - Result *VirtualDNS `json:"result"` -} - -// VirtualDNSListResponse represents an array of Virtual DNS responses. -// -// Deprecated: This internal type will be removed in the future. -type VirtualDNSListResponse struct { - Response - Result []*VirtualDNS `json:"result"` -} - -// VirtualDNSAnalyticsResponse represents a Virtual DNS analytics response. -// -// Deprecated: This internal type will be removed in the future. -type VirtualDNSAnalyticsResponse struct { - Response - Result VirtualDNSAnalytics `json:"result"` -} - -// CreateVirtualDNS creates a new Virtual DNS cluster. -// -// Deprecated: Use CreateDNSFirewallCluster instead. -func (api *API) CreateVirtualDNS(ctx context.Context, v *VirtualDNS) (*VirtualDNS, error) { - if v == nil { - return nil, fmt.Errorf("cluster must not be nil") - } - - res, err := api.CreateDNSFirewallCluster(ctx, v.vdnsUpgrade()) - return res.vdnsDowngrade(), err -} - -// VirtualDNS fetches a single virtual DNS cluster. -// -// Deprecated: Use DNSFirewallCluster instead. -func (api *API) VirtualDNS(ctx context.Context, virtualDNSID string) (*VirtualDNS, error) { - res, err := api.DNSFirewallCluster(ctx, virtualDNSID) - return res.vdnsDowngrade(), err -} - -// ListVirtualDNS lists the virtual DNS clusters associated with an account. -// -// Deprecated: Use ListDNSFirewallClusters instead. -func (api *API) ListVirtualDNS(ctx context.Context) ([]*VirtualDNS, error) { - res, err := api.ListDNSFirewallClusters(ctx) - if res == nil { - return nil, err - } - - clusters := make([]*VirtualDNS, 0, len(res)) - for _, cluster := range res { - clusters = append(clusters, cluster.vdnsDowngrade()) - } - - return clusters, err -} - -// UpdateVirtualDNS updates a Virtual DNS cluster. -// -// Deprecated: Use UpdateDNSFirewallCluster instead. -func (api *API) UpdateVirtualDNS(ctx context.Context, virtualDNSID string, vv VirtualDNS) error { - return api.UpdateDNSFirewallCluster(ctx, virtualDNSID, vv.vdnsUpgrade()) -} - -// DeleteVirtualDNS deletes a Virtual DNS cluster. Note that this cannot be -// undone, and will stop all traffic to that cluster. -// -// Deprecated: Use DeleteDNSFirewallCluster instead. -func (api *API) DeleteVirtualDNS(ctx context.Context, virtualDNSID string) error { - return api.DeleteDNSFirewallCluster(ctx, virtualDNSID) -} - -// VirtualDNSUserAnalytics retrieves analytics report for a specified dimension and time range -// -// Deprecated: Use DNSFirewallUserAnalytics instead. -func (api *API) VirtualDNSUserAnalytics(ctx context.Context, virtualDNSID string, o VirtualDNSUserAnalyticsOptions) (VirtualDNSAnalytics, error) { - res, err := api.DNSFirewallUserAnalytics(ctx, virtualDNSID, DNSFirewallUserAnalyticsOptions(o)) - return res.vdnsDowngrade(), err -} - -// --- Compatibility helper functions --- - -func (v VirtualDNS) vdnsUpgrade() DNSFirewallCluster { - return DNSFirewallCluster{ - ID: v.ID, - Name: v.Name, - OriginIPs: v.OriginIPs, - DNSFirewallIPs: v.VirtualDNSIPs, - MinimumCacheTTL: v.MinimumCacheTTL, - MaximumCacheTTL: v.MaximumCacheTTL, - DeprecateAnyRequests: v.DeprecateAnyRequests, - ModifiedOn: v.ModifiedOn, - } -} - -func (v *DNSFirewallCluster) vdnsDowngrade() *VirtualDNS { - if v == nil { - return nil - } - - return &VirtualDNS{ - ID: v.ID, - Name: v.Name, - OriginIPs: v.OriginIPs, - VirtualDNSIPs: v.DNSFirewallIPs, - MinimumCacheTTL: v.MinimumCacheTTL, - MaximumCacheTTL: v.MaximumCacheTTL, - DeprecateAnyRequests: v.DeprecateAnyRequests, - ModifiedOn: v.ModifiedOn, - } -} - -func (v DNSFirewallAnalytics) vdnsDowngrade() VirtualDNSAnalytics { - return VirtualDNSAnalytics{ - Totals: VirtualDNSAnalyticsMetrics(v.Totals), - Min: VirtualDNSAnalyticsMetrics(v.Min), - Max: VirtualDNSAnalyticsMetrics(v.Max), - } -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/waf.go b/vendor/github.com/cloudflare/cloudflare-go/waf.go deleted file mode 100644 index 7e81c64..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/waf.go +++ /dev/null @@ -1,351 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "strconv" -) - -// WAFPackage represents a WAF package configuration. -type WAFPackage struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - ZoneID string `json:"zone_id"` - DetectionMode string `json:"detection_mode"` - Sensitivity string `json:"sensitivity"` - ActionMode string `json:"action_mode"` -} - -// WAFPackagesResponse represents the response from the WAF packages endpoint. -type WAFPackagesResponse struct { - Response - Result []WAFPackage `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFPackageResponse represents the response from the WAF package endpoint. -type WAFPackageResponse struct { - Response - Result WAFPackage `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFPackageOptions represents options to edit a WAF package. -type WAFPackageOptions struct { - Sensitivity string `json:"sensitivity,omitempty"` - ActionMode string `json:"action_mode,omitempty"` -} - -// WAFGroup represents a WAF rule group. -type WAFGroup struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - RulesCount int `json:"rules_count"` - ModifiedRulesCount int `json:"modified_rules_count"` - PackageID string `json:"package_id"` - Mode string `json:"mode"` - AllowedModes []string `json:"allowed_modes"` -} - -// WAFGroupsResponse represents the response from the WAF groups endpoint. -type WAFGroupsResponse struct { - Response - Result []WAFGroup `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFGroupResponse represents the response from the WAF group endpoint. -type WAFGroupResponse struct { - Response - Result WAFGroup `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFRule represents a WAF rule. -type WAFRule struct { - ID string `json:"id"` - Description string `json:"description"` - Priority string `json:"priority"` - PackageID string `json:"package_id"` - Group struct { - ID string `json:"id"` - Name string `json:"name"` - } `json:"group"` - Mode string `json:"mode"` - DefaultMode string `json:"default_mode"` - AllowedModes []string `json:"allowed_modes"` -} - -// WAFRulesResponse represents the response from the WAF rules endpoint. -type WAFRulesResponse struct { - Response - Result []WAFRule `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFRuleResponse represents the response from the WAF rule endpoint. -type WAFRuleResponse struct { - Response - Result WAFRule `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFRuleOptions is a subset of WAFRule, for editable options. -type WAFRuleOptions struct { - Mode string `json:"mode"` -} - -// ListWAFPackages returns a slice of the WAF packages for the given zone. -// -// API Reference: https://api.cloudflare.com/#waf-rule-packages-list-firewall-packages -func (api *API) ListWAFPackages(ctx context.Context, zoneID string) ([]WAFPackage, error) { - // Construct a query string - v := url.Values{} - // Request as many WAF packages as possible per page - API max is 100 - v.Set("per_page", "100") - - var packages []WAFPackage - var res []byte - var err error - page := 1 - - // Loop over makeRequest until what we've fetched all records - for { - v.Set("page", strconv.Itoa(page)) - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages?%s", zoneID, v.Encode()) - res, err = api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WAFPackage{}, err - } - - var p WAFPackagesResponse - err = json.Unmarshal(res, &p) - if err != nil { - return []WAFPackage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !p.Success { - // TODO: Provide an actual error message instead of always returning nil - return []WAFPackage{}, err - } - - packages = append(packages, p.Result...) - if p.ResultInfo.Page >= p.ResultInfo.TotalPages { - break - } - - // Loop around and fetch the next page - page++ - } - - return packages, nil -} - -// WAFPackage returns a WAF package for the given zone. -// -// API Reference: https://api.cloudflare.com/#waf-rule-packages-firewall-package-details -func (api *API) WAFPackage(ctx context.Context, zoneID, packageID string) (WAFPackage, error) { - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s", zoneID, packageID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WAFPackage{}, err - } - - var r WAFPackageResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFPackage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateWAFPackage lets you update the a WAF Package. -// -// API Reference: https://api.cloudflare.com/#waf-rule-packages-edit-firewall-package -func (api *API) UpdateWAFPackage(ctx context.Context, zoneID, packageID string, opts WAFPackageOptions) (WAFPackage, error) { - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s", zoneID, packageID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, opts) - if err != nil { - return WAFPackage{}, err - } - - var r WAFPackageResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFPackage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListWAFGroups returns a slice of the WAF groups for the given WAF package. -// -// API Reference: https://api.cloudflare.com/#waf-rule-groups-list-rule-groups -func (api *API) ListWAFGroups(ctx context.Context, zoneID, packageID string) ([]WAFGroup, error) { - // Construct a query string - v := url.Values{} - // Request as many WAF groups as possible per page - API max is 100 - v.Set("per_page", "100") - - var groups []WAFGroup - var res []byte - var err error - page := 1 - - // Loop over makeRequest until what we've fetched all records - for { - v.Set("page", strconv.Itoa(page)) - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s/groups?%s", zoneID, packageID, v.Encode()) - res, err = api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WAFGroup{}, err - } - - var r WAFGroupsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []WAFGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !r.Success { - // TODO: Provide an actual error message instead of always returning nil - return []WAFGroup{}, err - } - - groups = append(groups, r.Result...) - if r.ResultInfo.Page >= r.ResultInfo.TotalPages { - break - } - - // Loop around and fetch the next page - page++ - } - return groups, nil -} - -// WAFGroup returns a WAF rule group from the given WAF package. -// -// API Reference: https://api.cloudflare.com/#waf-rule-groups-rule-group-details -func (api *API) WAFGroup(ctx context.Context, zoneID, packageID, groupID string) (WAFGroup, error) { - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s/groups/%s", zoneID, packageID, groupID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WAFGroup{}, err - } - - var r WAFGroupResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateWAFGroup lets you update the mode of a WAF Group. -// -// API Reference: https://api.cloudflare.com/#waf-rule-groups-edit-rule-group -func (api *API) UpdateWAFGroup(ctx context.Context, zoneID, packageID, groupID, mode string) (WAFGroup, error) { - opts := WAFRuleOptions{Mode: mode} - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s/groups/%s", zoneID, packageID, groupID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, opts) - if err != nil { - return WAFGroup{}, err - } - - var r WAFGroupResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ListWAFRules returns a slice of the WAF rules for the given WAF package. -// -// API Reference: https://api.cloudflare.com/#waf-rules-list-rules -func (api *API) ListWAFRules(ctx context.Context, zoneID, packageID string) ([]WAFRule, error) { - // Construct a query string - v := url.Values{} - // Request as many WAF rules as possible per page - API max is 100 - v.Set("per_page", "100") - - var rules []WAFRule - var res []byte - var err error - page := 1 - - // Loop over makeRequest until what we've fetched all records - for { - v.Set("page", strconv.Itoa(page)) - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s/rules?%s", zoneID, packageID, v.Encode()) - res, err = api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WAFRule{}, err - } - - var r WAFRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []WAFRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !r.Success { - // TODO: Provide an actual error message instead of always returning nil - return []WAFRule{}, err - } - - rules = append(rules, r.Result...) - if r.ResultInfo.Page >= r.ResultInfo.TotalPages { - break - } - - // Loop around and fetch the next page - page++ - } - - return rules, nil -} - -// WAFRule returns a WAF rule from the given WAF package. -// -// API Reference: https://api.cloudflare.com/#waf-rules-rule-details -func (api *API) WAFRule(ctx context.Context, zoneID, packageID, ruleID string) (WAFRule, error) { - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s/rules/%s", zoneID, packageID, ruleID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WAFRule{}, err - } - - var r WAFRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateWAFRule lets you update the mode of a WAF Rule. -// -// API Reference: https://api.cloudflare.com/#waf-rules-edit-rule -func (api *API) UpdateWAFRule(ctx context.Context, zoneID, packageID, ruleID, mode string) (WAFRule, error) { - opts := WAFRuleOptions{Mode: mode} - uri := fmt.Sprintf("/zones/%s/firewall/waf/packages/%s/rules/%s", zoneID, packageID, ruleID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, opts) - if err != nil { - return WAFRule{}, err - } - - var r WAFRuleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/waf_overrides.go b/vendor/github.com/cloudflare/cloudflare-go/waf_overrides.go deleted file mode 100644 index 76c0774..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/waf_overrides.go +++ /dev/null @@ -1,137 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// WAFOverridesResponse represents the response form the WAF overrides endpoint. -type WAFOverridesResponse struct { - Response - Result []WAFOverride `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFOverrideResponse represents the response form the WAF override endpoint. -type WAFOverrideResponse struct { - Response - Result WAFOverride `json:"result"` - ResultInfo ResultInfo `json:"result_info"` -} - -// WAFOverride represents a WAF override. -type WAFOverride struct { - ID string `json:"id,omitempty"` - Description string `json:"description"` - URLs []string `json:"urls"` - Priority int `json:"priority"` - Groups map[string]string `json:"groups"` - RewriteAction map[string]string `json:"rewrite_action"` - Rules map[string]string `json:"rules"` - Paused bool `json:"paused"` -} - -// ListWAFOverrides returns a slice of the WAF overrides. -// -// API Reference: https://api.cloudflare.com/#waf-overrides-list-uri-controlled-waf-configurations -func (api *API) ListWAFOverrides(ctx context.Context, zoneID string) ([]WAFOverride, error) { - var overrides []WAFOverride - var res []byte - var err error - - uri := fmt.Sprintf("/zones/%s/firewall/waf/overrides", zoneID) - res, err = api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WAFOverride{}, err - } - - var r WAFOverridesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - if !r.Success { - // TODO: Provide an actual error message instead of always returning nil - return []WAFOverride{}, err - } - - for ri := range r.Result { - overrides = append(overrides, r.Result[ri]) - } - return overrides, nil -} - -// WAFOverride returns a WAF override from the given override ID. -// -// API Reference: https://api.cloudflare.com/#waf-overrides-uri-controlled-waf-configuration-details -func (api *API) WAFOverride(ctx context.Context, zoneID, overrideID string) (WAFOverride, error) { - uri := fmt.Sprintf("/zones/%s/firewall/waf/overrides/%s", zoneID, overrideID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WAFOverride{}, err - } - - var r WAFOverrideResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// CreateWAFOverride creates a new WAF override. -// -// API reference: https://api.cloudflare.com/#waf-overrides-create-a-uri-controlled-waf-configuration -func (api *API) CreateWAFOverride(ctx context.Context, zoneID string, override WAFOverride) (WAFOverride, error) { - uri := fmt.Sprintf("/zones/%s/firewall/waf/overrides", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, override) - if err != nil { - return WAFOverride{}, err - } - var r WAFOverrideResponse - if err := json.Unmarshal(res, &r); err != nil { - return WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateWAFOverride updates an existing WAF override. -// -// API reference: https://api.cloudflare.com/#waf-overrides-update-uri-controlled-waf-configuration -func (api *API) UpdateWAFOverride(ctx context.Context, zoneID, overrideID string, override WAFOverride) (WAFOverride, error) { - uri := fmt.Sprintf("/zones/%s/firewall/waf/overrides/%s", zoneID, overrideID) - - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, override) - if err != nil { - return WAFOverride{}, err - } - - var r WAFOverrideResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// DeleteWAFOverride deletes a WAF override for a zone. -// -// API reference: https://api.cloudflare.com/#waf-overrides-delete-lockdown-rule -func (api *API) DeleteWAFOverride(ctx context.Context, zoneID, overrideID string) error { - uri := fmt.Sprintf("/zones/%s/firewall/waf/overrides/%s", zoneID, overrideID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r WAFOverrideResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/waiting_room.go b/vendor/github.com/cloudflare/cloudflare-go/waiting_room.go deleted file mode 100644 index a60b502..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/waiting_room.go +++ /dev/null @@ -1,534 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -var ( - ErrMissingWaitingRoomID = errors.New("missing required waiting room ID") - ErrMissingWaitingRoomRuleID = errors.New("missing required waiting room rule ID") -) - -// WaitingRoom describes a WaitingRoom object. -type WaitingRoom struct { - CreatedOn time.Time `json:"created_on,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty"` - Path string `json:"path"` - Name string `json:"name"` - Description string `json:"description,omitempty"` - QueueingMethod string `json:"queueing_method,omitempty"` - CustomPageHTML string `json:"custom_page_html,omitempty"` - DefaultTemplateLanguage string `json:"default_template_language,omitempty"` - Host string `json:"host"` - ID string `json:"id,omitempty"` - NewUsersPerMinute int `json:"new_users_per_minute"` - TotalActiveUsers int `json:"total_active_users"` - SessionDuration int `json:"session_duration"` - QueueAll bool `json:"queue_all"` - DisableSessionRenewal bool `json:"disable_session_renewal"` - Suspended bool `json:"suspended"` - JsonResponseEnabled bool `json:"json_response_enabled"` - NextEventPrequeueStartTime *time.Time `json:"next_event_prequeue_start_time,omitempty"` - NextEventStartTime *time.Time `json:"next_event_start_time,omitempty"` -} - -// WaitingRoomStatus describes the status of a waiting room. -type WaitingRoomStatus struct { - Status string `json:"status"` - EventID string `json:"event_id"` - EstimatedQueuedUsers int `json:"estimated_queued_users"` - EstimatedTotalActiveUsers int `json:"estimated_total_active_users"` - MaxEstimatedTimeMinutes int `json:"max_estimated_time_minutes"` -} - -// WaitingRoomEvent describes a WaitingRoomEvent object. -type WaitingRoomEvent struct { - EventEndTime time.Time `json:"event_end_time"` - CreatedOn time.Time `json:"created_on,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty"` - PrequeueStartTime *time.Time `json:"prequeue_start_time,omitempty"` - EventStartTime time.Time `json:"event_start_time"` - Name string `json:"name"` - Description string `json:"description,omitempty"` - QueueingMethod string `json:"queueing_method,omitempty"` - ID string `json:"id,omitempty"` - CustomPageHTML string `json:"custom_page_html,omitempty"` - NewUsersPerMinute int `json:"new_users_per_minute,omitempty"` - TotalActiveUsers int `json:"total_active_users,omitempty"` - SessionDuration int `json:"session_duration,omitempty"` - DisableSessionRenewal *bool `json:"disable_session_renewal,omitempty"` - Suspended bool `json:"suspended"` - ShuffleAtEventStart bool `json:"shuffle_at_event_start"` -} - -type WaitingRoomRule struct { - ID string `json:"id,omitempty"` - Version string `json:"version,omitempty"` - Action string `json:"action"` - Expression string `json:"expression"` - Description string `json:"description"` - LastUpdated *time.Time `json:"last_updated,omitempty"` - Enabled *bool `json:"enabled"` -} - -// WaitingRoomPagePreviewURL describes a WaitingRoomPagePreviewURL object. -type WaitingRoomPagePreviewURL struct { - PreviewURL string `json:"preview_url"` -} - -// WaitingRoomPagePreviewCustomHTML describes a WaitingRoomPagePreviewCustomHTML object. -type WaitingRoomPagePreviewCustomHTML struct { - CustomHTML string `json:"custom_html"` -} - -// WaitingRoomDetailResponse is the API response, containing a single WaitingRoom. -type WaitingRoomDetailResponse struct { - Response - Result WaitingRoom `json:"result"` -} - -// WaitingRoomsResponse is the API response, containing an array of WaitingRooms. -type WaitingRoomsResponse struct { - Response - Result []WaitingRoom `json:"result"` -} - -// WaitingRoomStatusResponse is the API response, containing the status of a waiting room. -type WaitingRoomStatusResponse struct { - Response - Result WaitingRoomStatus `json:"result"` -} - -// WaitingRoomPagePreviewResponse is the API response, containing the URL to a custom waiting room preview. -type WaitingRoomPagePreviewResponse struct { - Response - Result WaitingRoomPagePreviewURL `json:"result"` -} - -// WaitingRoomEventDetailResponse is the API response, containing a single WaitingRoomEvent. -type WaitingRoomEventDetailResponse struct { - Response - Result WaitingRoomEvent `json:"result"` -} - -// WaitingRoomEventsResponse is the API response, containing an array of WaitingRoomEvents. -type WaitingRoomEventsResponse struct { - Response - Result []WaitingRoomEvent `json:"result"` -} - -// WaitingRoomRulesResponse is the API response, containing an array of WaitingRoomRule. -type WaitingRoomRulesResponse struct { - Response - Result []WaitingRoomRule `json:"result"` -} - -// CreateWaitingRoom creates a new Waiting Room for a zone. -// -// API reference: https://api.cloudflare.com/#waiting-room-create-waiting-room -func (api *API) CreateWaitingRoom(ctx context.Context, zoneID string, waitingRoom WaitingRoom) (*WaitingRoom, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, waitingRoom) - if err != nil { - return nil, err - } - var r WaitingRoomDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return &r.Result, nil -} - -// ListWaitingRooms returns all Waiting Room for a zone. -// -// API reference: https://api.cloudflare.com/#waiting-room-list-waiting-rooms -func (api *API) ListWaitingRooms(ctx context.Context, zoneID string) ([]WaitingRoom, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WaitingRoom{}, err - } - var r WaitingRoomsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// WaitingRoom fetches detail about one Waiting room for a zone. -// -// API reference: https://api.cloudflare.com/#waiting-room-waiting-room-details -func (api *API) WaitingRoom(ctx context.Context, zoneID, waitingRoomID string) (WaitingRoom, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s", zoneID, waitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WaitingRoom{}, err - } - var r WaitingRoomDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ChangeWaitingRoom lets you change individual settings for a Waiting room. This is -// in contrast to UpdateWaitingRoom which replaces the entire Waiting room. -// -// API reference: https://api.cloudflare.com/#waiting-room-update-waiting-room -func (api *API) ChangeWaitingRoom(ctx context.Context, zoneID, waitingRoomID string, waitingRoom WaitingRoom) (WaitingRoom, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s", zoneID, waitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, waitingRoom) - if err != nil { - return WaitingRoom{}, err - } - var r WaitingRoomDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateWaitingRoom lets you replace a Waiting Room. This is in contrast to -// ChangeWaitingRoom which lets you change individual settings. -// -// API reference: https://api.cloudflare.com/#waiting-room-update-waiting-room -func (api *API) UpdateWaitingRoom(ctx context.Context, zoneID string, waitingRoom WaitingRoom) (WaitingRoom, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s", zoneID, waitingRoom.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, waitingRoom) - if err != nil { - return WaitingRoom{}, err - } - var r WaitingRoomDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteWaitingRoom deletes a Waiting Room for a zone. -// -// API reference: https://api.cloudflare.com/#waiting-room-delete-waiting-room -func (api *API) DeleteWaitingRoom(ctx context.Context, zoneID, waitingRoomID string) error { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s", zoneID, waitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r WaitingRoomDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -// WaitingRoomStatus returns the status of one Waiting Room for a zone. -// -// API reference: https://api.cloudflare.com/#waiting-room-get-waiting-room-status -func (api *API) WaitingRoomStatus(ctx context.Context, zoneID, waitingRoomID string) (WaitingRoomStatus, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/status", zoneID, waitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WaitingRoomStatus{}, err - } - var r WaitingRoomStatusResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoomStatus{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// WaitingRoomPagePreview uploads a custom waiting room page for preview and -// returns a preview URL. -// -// API reference: https://api.cloudflare.com/#waiting-room-create-a-custom-waiting-room-page-preview -func (api *API) WaitingRoomPagePreview(ctx context.Context, zoneID, customHTML string) (WaitingRoomPagePreviewURL, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/preview", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, WaitingRoomPagePreviewCustomHTML{CustomHTML: customHTML}) - - if err != nil { - return WaitingRoomPagePreviewURL{}, err - } - var r WaitingRoomPagePreviewResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoomPagePreviewURL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// CreateWaitingRoomEvent creates a new event for a Waiting Room. -// -// API reference: https://api.cloudflare.com/#waiting-room-create-event -func (api *API) CreateWaitingRoomEvent(ctx context.Context, zoneID string, waitingRoomID string, waitingRoomEvent WaitingRoomEvent) (*WaitingRoomEvent, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events", zoneID, waitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, waitingRoomEvent) - if err != nil { - return nil, err - } - var r WaitingRoomEventDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return &r.Result, nil -} - -// ListWaitingRoomEvents returns all Waiting Room Events for a zone. -// -// API reference: https://api.cloudflare.com/#waiting-room-list-events -func (api *API) ListWaitingRoomEvents(ctx context.Context, zoneID string, waitingRoomID string) ([]WaitingRoomEvent, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events", zoneID, waitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WaitingRoomEvent{}, err - } - var r WaitingRoomEventsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// WaitingRoomEvent fetches detail about one Waiting Room Event for a zone. -// -// API reference: https://api.cloudflare.com/#waiting-room-event-details -func (api *API) WaitingRoomEvent(ctx context.Context, zoneID string, waitingRoomID string, eventID string) (WaitingRoomEvent, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events/%s", zoneID, waitingRoomID, eventID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WaitingRoomEvent{}, err - } - var r WaitingRoomEventDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// WaitingRoomEventPreview returns an event's configuration as if it was active. -// Inherited fields from the waiting room will be displayed with their current values. -// -// API reference: https://api.cloudflare.com/#waiting-room-preview-active-event-details -func (api *API) WaitingRoomEventPreview(ctx context.Context, zoneID string, waitingRoomID string, eventID string) (WaitingRoomEvent, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events/%s/details", zoneID, waitingRoomID, eventID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WaitingRoomEvent{}, err - } - var r WaitingRoomEventDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ChangeWaitingRoomEvent lets you change individual settings for a Waiting Room Event. This is -// in contrast to UpdateWaitingRoomEvent which replaces the entire Waiting Room Event. -// -// API reference: https://api.cloudflare.com/#waiting-room-patch-event -func (api *API) ChangeWaitingRoomEvent(ctx context.Context, zoneID, waitingRoomID string, waitingRoomEvent WaitingRoomEvent) (WaitingRoomEvent, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events/%s", zoneID, waitingRoomID, waitingRoomEvent.ID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, waitingRoomEvent) - if err != nil { - return WaitingRoomEvent{}, err - } - var r WaitingRoomEventDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateWaitingRoomEvent lets you replace a Waiting Room Event. This is in contrast to -// ChangeWaitingRoomEvent which lets you change individual settings. -// -// API reference: https://api.cloudflare.com/#waiting-room-update-event -func (api *API) UpdateWaitingRoomEvent(ctx context.Context, zoneID string, waitingRoomID string, waitingRoomEvent WaitingRoomEvent) (WaitingRoomEvent, error) { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events/%s", zoneID, waitingRoomID, waitingRoomEvent.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, waitingRoomEvent) - if err != nil { - return WaitingRoomEvent{}, err - } - var r WaitingRoomEventDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// DeleteWaitingRoomEvent deletes an event for a Waiting Room. -// -// API reference: https://api.cloudflare.com/#waiting-room-delete-event -func (api *API) DeleteWaitingRoomEvent(ctx context.Context, zoneID string, waitingRoomID string, eventID string) error { - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/events/%s", zoneID, waitingRoomID, eventID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - var r WaitingRoomEventDetailResponse - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return nil -} - -type ListWaitingRoomRuleParams struct { - WaitingRoomID string -} - -type CreateWaitingRoomRuleParams struct { - WaitingRoomID string - Rule WaitingRoomRule -} - -type ReplaceWaitingRoomRuleParams struct { - WaitingRoomID string - Rules []WaitingRoomRule -} - -type UpdateWaitingRoomRuleParams struct { - WaitingRoomID string - Rule WaitingRoomRule -} - -type DeleteWaitingRoomRuleParams struct { - WaitingRoomID string - RuleID string -} - -// ListWaitingRoomRules lists all rules for a Waiting Room. -// -// API reference: https://api.cloudflare.com/#waiting-room-list-waiting-room-rules -func (api *API) ListWaitingRoomRules(ctx context.Context, rc *ResourceContainer, params ListWaitingRoomRuleParams) ([]WaitingRoomRule, error) { - if params.WaitingRoomID == "" { - return nil, ErrMissingWaitingRoomID - } - - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules", rc.Identifier, params.WaitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - var r WaitingRoomRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// CreateWaitingRoomRule creates a new rule for a Waiting Room. -// -// API reference: https://api.cloudflare.com/#waiting-room-create-waiting-room-rule -func (api *API) CreateWaitingRoomRule(ctx context.Context, rc *ResourceContainer, params CreateWaitingRoomRuleParams) ([]WaitingRoomRule, error) { - if params.WaitingRoomID == "" { - return nil, ErrMissingWaitingRoomID - } - - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules", rc.Identifier, params.WaitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params.Rule) - if err != nil { - return nil, err - } - - var r WaitingRoomRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// ReplaceWaitingRoomRules replaces all rules for a Waiting Room. -// -// API reference: https://api.cloudflare.com/#waiting-room-replace-waiting-room-rules -func (api *API) ReplaceWaitingRoomRules(ctx context.Context, rc *ResourceContainer, params ReplaceWaitingRoomRuleParams) ([]WaitingRoomRule, error) { - if params.WaitingRoomID == "" { - return nil, ErrMissingWaitingRoomID - } - - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules", rc.Identifier, params.WaitingRoomID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.Rules) - if err != nil { - return nil, err - } - - var r WaitingRoomRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateWaitingRoomRule updates a rule for a Waiting Room. -// -// API reference: https://api.cloudflare.com/#waiting-room-patch-waiting-room-rule -func (api *API) UpdateWaitingRoomRule(ctx context.Context, rc *ResourceContainer, params UpdateWaitingRoomRuleParams) ([]WaitingRoomRule, error) { - if params.WaitingRoomID == "" { - return nil, ErrMissingWaitingRoomID - } - - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules/%s", rc.Identifier, params.WaitingRoomID, params.Rule.ID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params.Rule) - if err != nil { - return nil, err - } - - var r WaitingRoomRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// DeleteWaitingRoomRule deletes a rule for a Waiting Room. -// -// API reference: https://api.cloudflare.com/#waiting-room-delete-waiting-room-rule -func (api *API) DeleteWaitingRoomRule(ctx context.Context, rc *ResourceContainer, params DeleteWaitingRoomRuleParams) ([]WaitingRoomRule, error) { - if params.WaitingRoomID == "" { - return nil, ErrMissingWaitingRoomID - } - - if params.RuleID == "" { - return nil, ErrMissingWaitingRoomRuleID - } - - uri := fmt.Sprintf("/zones/%s/waiting_rooms/%s/rules/%s", rc.Identifier, params.WaitingRoomID, params.RuleID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return nil, err - } - - var r WaitingRoomRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/web3.go b/vendor/github.com/cloudflare/cloudflare-go/web3.go deleted file mode 100644 index 298771e..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/web3.go +++ /dev/null @@ -1,197 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -var ( - // ErrMissingIdentifier is for when identifier is required but missing. - ErrMissingIdentifier = errors.New("identifier required but missing") - // ErrMissingName is for when name is required but missing. - ErrMissingName = errors.New("name required but missing") - // ErrMissingTarget is for when target is required but missing. - ErrMissingTarget = errors.New("target required but missing") -) - -// Web3Hostname represents a web3 hostname. -type Web3Hostname struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Status string `json:"status,omitempty"` - Target string `json:"target,omitempty"` - Dnslink string `json:"dnslink,omitempty"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` -} - -// Web3HostnameListParameters represents the parameters for listing web3 hostnames. -type Web3HostnameListParameters struct { - ZoneID string -} - -// Web3HostnameListResponse represents the API response body for listing web3 hostnames. -type Web3HostnameListResponse struct { - Response - Result []Web3Hostname `json:"result"` -} - -// Web3HostnameCreateParameters represents the parameters for creating a web3 hostname. -type Web3HostnameCreateParameters struct { - ZoneID string - Name string `json:"name,omitempty"` - Target string `json:"target,omitempty"` - Description string `json:"description,omitempty"` - DNSLink string `json:"dnslink,omitempty"` -} - -// Web3HostnameResponse represents an API response body for a web3 hostname. -type Web3HostnameResponse struct { - Response - Result Web3Hostname `json:"result,omitempty"` -} - -// Web3HostnameDetailsParameters represents the parameters for getting a single web3 hostname. -type Web3HostnameDetailsParameters struct { - ZoneID string - Identifier string -} - -// Web3HostnameUpdateParameters represents the parameters for editing a web3 hostname. -type Web3HostnameUpdateParameters struct { - ZoneID string - Identifier string - Description string `json:"description,omitempty"` - DNSLink string `json:"dnslink,omitempty"` -} - -// Web3HostnameDeleteResult represents the result of deleting a web3 hostname. -type Web3HostnameDeleteResult struct { - ID string `json:"id,omitempty"` -} - -// Web3HostnameDeleteResponse represents the API response body for deleting a web3 hostname. -type Web3HostnameDeleteResponse struct { - Response - Result Web3HostnameDeleteResult `json:"result,omitempty"` -} - -// ListWeb3Hostnames lists all web3 hostnames. -// -// API Reference: https://api.cloudflare.com/#web3-hostname-list-web3-hostnames -func (api *API) ListWeb3Hostnames(ctx context.Context, params Web3HostnameListParameters) ([]Web3Hostname, error) { - if params.ZoneID == "" { - return []Web3Hostname{}, ErrMissingZoneID - } - - uri := fmt.Sprintf("/zones/%s/web3/hostnames", params.ZoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []Web3Hostname{}, err - } - var web3ListResponse Web3HostnameListResponse - if err := json.Unmarshal(res, &web3ListResponse); err != nil { - return []Web3Hostname{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return web3ListResponse.Result, nil -} - -// CreateWeb3Hostname creates a web3 hostname. -// -// API Reference: https://api.cloudflare.com/#web3-hostname-create-web3-hostname -func (api *API) CreateWeb3Hostname(ctx context.Context, params Web3HostnameCreateParameters) (Web3Hostname, error) { - if params.ZoneID == "" { - return Web3Hostname{}, ErrMissingZoneID - } - if params.Name == "" { - return Web3Hostname{}, ErrMissingName - } - if params.Target == "" { - return Web3Hostname{}, ErrMissingTarget - } - - uri := fmt.Sprintf("/zones/%s/web3/hostnames", params.ZoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return Web3Hostname{}, err - } - var web3Response Web3HostnameResponse - if err := json.Unmarshal(res, &web3Response); err != nil { - return Web3Hostname{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return web3Response.Result, nil -} - -// GetWeb3Hostname gets a single web3 hostname by identifier. -// -// API Reference: https://api.cloudflare.com/#web3-hostname-web3-hostname-details -func (api *API) GetWeb3Hostname(ctx context.Context, params Web3HostnameDetailsParameters) (Web3Hostname, error) { - if params.ZoneID == "" { - return Web3Hostname{}, ErrMissingZoneID - } - if params.Identifier == "" { - return Web3Hostname{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/zones/%s/web3/hostnames/%s", params.ZoneID, params.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return Web3Hostname{}, err - } - var web3Response Web3HostnameResponse - if err := json.Unmarshal(res, &web3Response); err != nil { - return Web3Hostname{}, err - } - return web3Response.Result, nil -} - -// UpdateWeb3Hostname edits a web3 hostname. -// -// API Reference: https://api.cloudflare.com/#web3-hostname-edit-web3-hostname -func (api *API) UpdateWeb3Hostname(ctx context.Context, params Web3HostnameUpdateParameters) (Web3Hostname, error) { - if params.ZoneID == "" { - return Web3Hostname{}, ErrMissingZoneID - } - if params.Identifier == "" { - return Web3Hostname{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/zones/%s/web3/hostnames/%s", params.ZoneID, params.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) - if err != nil { - return Web3Hostname{}, err - } - var web3Response Web3HostnameResponse - if err := json.Unmarshal(res, &web3Response); err != nil { - return Web3Hostname{}, err - } - return web3Response.Result, nil -} - -// DeleteWeb3Hostname deletes a web3 hostname. -// -// API Reference: https://api.cloudflare.com/#web3-hostname-delete-web3-hostname -func (api *API) DeleteWeb3Hostname(ctx context.Context, params Web3HostnameDetailsParameters) (Web3HostnameDeleteResult, error) { - if params.ZoneID == "" { - return Web3HostnameDeleteResult{}, ErrMissingZoneID - } - if params.Identifier == "" { - return Web3HostnameDeleteResult{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/zones/%s/web3/hostnames/%s", params.ZoneID, params.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return Web3HostnameDeleteResult{}, err - } - var web3Response Web3HostnameDeleteResponse - if err := json.Unmarshal(res, &web3Response); err != nil { - return Web3HostnameDeleteResult{}, err - } - return web3Response.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers.go b/vendor/github.com/cloudflare/cloudflare-go/workers.go deleted file mode 100644 index 0a983bd..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers.go +++ /dev/null @@ -1,353 +0,0 @@ -package cloudflare - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "io" - "mime" - "mime/multipart" - "net/http" - "net/textproto" - "strings" - "time" -) - -// WorkerRequestParams provides parameters for worker requests for both enterprise and standard requests. -type WorkerRequestParams struct { - ZoneID string - ScriptName string -} - -type CreateWorkerParams struct { - ScriptName string - Script string - - // Module changes the Content-Type header to specify the script is an - // ES Module syntax script. - Module bool - - // Logpush opts the worker into Workers Logpush logging. A nil value leaves the current setting unchanged. - // https://developers.cloudflare.com/workers/platform/logpush/ - Logpush *bool - - // Bindings should be a map where the keys are the binding name, and the - // values are the binding content - Bindings map[string]WorkerBinding - - // CompatibilityDate is a date in the form yyyy-mm-dd, - // which will be used to determine which version of the Workers runtime is used. - // https://developers.cloudflare.com/workers/platform/compatibility-dates/ - CompatibilityDate string - - // CompatibilityFlags are the names of features of the Workers runtime to be enabled or disabled, - // usually used together with CompatibilityDate. - // https://developers.cloudflare.com/workers/platform/compatibility-dates/#compatibility-flags - CompatibilityFlags []string -} - -// WorkerScriptParams provides a worker script and the associated bindings. -type WorkerScriptParams struct { - ScriptName string - - // Module changes the Content-Type header to specify the script is an - // ES Module syntax script. - Module bool - - // Bindings should be a map where the keys are the binding name, and the - // values are the binding content - Bindings map[string]WorkerBinding -} - -// WorkerRoute is used to map traffic matching a URL pattern to a workers -// -// API reference: https://api.cloudflare.com/#worker-routes-properties -type WorkerRoute struct { - ID string `json:"id,omitempty"` - Pattern string `json:"pattern"` - ScriptName string `json:"script,omitempty"` -} - -// WorkerRoutesResponse embeds Response struct and slice of WorkerRoutes. -type WorkerRoutesResponse struct { - Response - Routes []WorkerRoute `json:"result"` -} - -// WorkerRouteResponse embeds Response struct and a single WorkerRoute. -type WorkerRouteResponse struct { - Response - WorkerRoute `json:"result"` -} - -// WorkerScript Cloudflare Worker struct with metadata. -type WorkerScript struct { - WorkerMetaData - Script string `json:"script"` - UsageModel string `json:"usage_model,omitempty"` -} - -// WorkerMetaData contains worker script information such as size, creation & modification dates. -type WorkerMetaData struct { - ID string `json:"id,omitempty"` - ETAG string `json:"etag,omitempty"` - Size int `json:"size,omitempty"` - CreatedOn time.Time `json:"created_on,omitempty"` - ModifiedOn time.Time `json:"modified_on,omitempty"` -} - -// WorkerListResponse wrapper struct for API response to worker script list API call. -type WorkerListResponse struct { - Response - ResultInfo - WorkerList []WorkerMetaData `json:"result"` -} - -// WorkerScriptResponse wrapper struct for API response to worker script calls. -type WorkerScriptResponse struct { - Response - Module bool - WorkerScript `json:"result"` -} - -type ListWorkersParams struct{} - -type DeleteWorkerParams struct { - ScriptName string -} - -// DeleteWorker deletes a single Worker. -// -// API reference: https://api.cloudflare.com/#worker-script-delete-worker -func (api *API) DeleteWorker(ctx context.Context, rc *ResourceContainer, params DeleteWorkerParams) error { - if rc.Level != AccountRouteLevel { - return ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s", rc.Identifier, params.ScriptName) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - - var r WorkerScriptResponse - if err != nil { - return err - } - - err = json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return nil -} - -// GetWorker fetch raw script content for your worker returns string containing -// worker code js. -// -// API reference: https://developers.cloudflare.com/workers/tooling/api/scripts/ -func (api *API) GetWorker(ctx context.Context, rc *ResourceContainer, scriptName string) (WorkerScriptResponse, error) { - if rc.Level != AccountRouteLevel { - return WorkerScriptResponse{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return WorkerScriptResponse{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s", rc.Identifier, scriptName) - res, err := api.makeRequestContextWithHeadersComplete(ctx, http.MethodGet, uri, nil, nil) - var r WorkerScriptResponse - if err != nil { - return r, err - } - - // Check if the response type is multipart, in which case this was a module worker - mediaType, mediaParams, _ := mime.ParseMediaType(res.Headers.Get("content-type")) - if strings.HasPrefix(mediaType, "multipart/") { - bytesReader := bytes.NewReader(res.Body) - mimeReader := multipart.NewReader(bytesReader, mediaParams["boundary"]) - mimePart, err := mimeReader.NextPart() - if err != nil { - return r, fmt.Errorf("could not get multipart response body: %w", err) - } - mimePartBody, err := io.ReadAll(mimePart) - if err != nil { - return r, fmt.Errorf("could not read multipart response body: %w", err) - } - r.Script = string(mimePartBody) - r.Module = true - } else { - r.Script = string(res.Body) - r.Module = false - } - - r.Success = true - return r, nil -} - -// ListWorkers returns list of Workers for given account. -// -// API reference: https://developers.cloudflare.com/workers/tooling/api/scripts/ -func (api *API) ListWorkers(ctx context.Context, rc *ResourceContainer, params ListWorkersParams) (WorkerListResponse, *ResultInfo, error) { - if rc.Level != AccountRouteLevel { - return WorkerListResponse{}, &ResultInfo{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return WorkerListResponse{}, &ResultInfo{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WorkerListResponse{}, &ResultInfo{}, err - } - - var r WorkerListResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WorkerListResponse{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r, &r.ResultInfo, nil -} - -// UploadWorker pushes raw script content for your Worker. -// -// API reference: https://api.cloudflare.com/#worker-script-upload-worker -func (api *API) UploadWorker(ctx context.Context, rc *ResourceContainer, params CreateWorkerParams) (WorkerScriptResponse, error) { - if rc.Level != AccountRouteLevel { - return WorkerScriptResponse{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return WorkerScriptResponse{}, ErrMissingAccountID - } - - body := []byte(params.Script) - var ( - contentType = "application/javascript" - err error - ) - - if params.Module || params.Logpush != nil || len(params.Bindings) > 0 || params.CompatibilityDate != "" || len(params.CompatibilityFlags) > 0 { - contentType, body, err = formatMultipartBody(params) - if err != nil { - return WorkerScriptResponse{}, err - } - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s", rc.Identifier, params.ScriptName) - headers := make(http.Header) - headers.Set("Content-Type", contentType) - res, err := api.makeRequestContextWithHeaders(ctx, http.MethodPut, uri, body, headers) - - var r WorkerScriptResponse - if err != nil { - return r, err - } - - err = json.Unmarshal(res, &r) - if err != nil { - return r, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r, nil -} - -// Returns content-type, body, error. -func formatMultipartBody(params CreateWorkerParams) (string, []byte, error) { - var buf = &bytes.Buffer{} - var mpw = multipart.NewWriter(buf) - defer mpw.Close() - - // Write metadata part - var scriptPartName string - meta := struct { - BodyPart string `json:"body_part,omitempty"` - MainModule string `json:"main_module,omitempty"` - Bindings []workerBindingMeta `json:"bindings"` - Logpush *bool `json:"logpush,omitempty"` - CompatibilityDate string `json:"compatibility_date,omitempty"` - CompatibilityFlags []string `json:"compatibility_flags,omitempty"` - }{ - Bindings: make([]workerBindingMeta, 0, len(params.Bindings)), - Logpush: params.Logpush, - CompatibilityDate: params.CompatibilityDate, - CompatibilityFlags: params.CompatibilityFlags, - } - - if params.Module { - scriptPartName = "worker.mjs" - meta.MainModule = scriptPartName - } else { - scriptPartName = "script" - meta.BodyPart = scriptPartName - } - - bodyWriters := make([]workerBindingBodyWriter, 0, len(params.Bindings)) - for name, b := range params.Bindings { - bindingMeta, bodyWriter, err := b.serialize(name) - if err != nil { - return "", nil, err - } - - meta.Bindings = append(meta.Bindings, bindingMeta) - bodyWriters = append(bodyWriters, bodyWriter) - } - - var hdr = textproto.MIMEHeader{} - hdr.Set("content-disposition", fmt.Sprintf(`form-data; name="%s"`, "metadata")) - hdr.Set("content-type", "application/json") - pw, err := mpw.CreatePart(hdr) - if err != nil { - return "", nil, err - } - metaJSON, err := json.Marshal(meta) - if err != nil { - return "", nil, err - } - _, err = pw.Write(metaJSON) - if err != nil { - return "", nil, err - } - - // Write script part - hdr = textproto.MIMEHeader{} - - contentType := "application/javascript" - if params.Module { - contentType = "application/javascript+module" - hdr.Set("content-disposition", fmt.Sprintf(`form-data; name="%s"; filename="%[1]s"`, scriptPartName)) - } else { - hdr.Set("content-disposition", fmt.Sprintf(`form-data; name="%s"`, scriptPartName)) - } - hdr.Set("content-type", contentType) - - pw, err = mpw.CreatePart(hdr) - if err != nil { - return "", nil, err - } - _, err = pw.Write([]byte(params.Script)) - if err != nil { - return "", nil, err - } - - // Write other bindings with parts - for _, w := range bodyWriters { - if w != nil { - err = w(mpw) - if err != nil { - return "", nil, err - } - } - } - - mpw.Close() - - return mpw.FormDataContentType(), buf.Bytes(), nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_account_settings.go b/vendor/github.com/cloudflare/cloudflare-go/workers_account_settings.go deleted file mode 100644 index 6b3b65d..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_account_settings.go +++ /dev/null @@ -1,82 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type WorkersAccountSettings struct { - DefaultUsageModel string `json:"default_usage_model,omitempty"` - GreenCompute bool `json:"green_compute,omitempty"` -} - -type CreateWorkersAccountSettingsParameters struct { - DefaultUsageModel string `json:"default_usage_model,omitempty"` - GreenCompute bool `json:"green_compute,omitempty"` -} - -type CreateWorkersAccountSettingsResponse struct { - Response - Result WorkersAccountSettings -} - -type WorkersAccountSettingsParameters struct{} - -type WorkersAccountSettingsResponse struct { - Response - Result WorkersAccountSettings -} - -// CreateWorkersAccountSettings sets the account settings for Workers. -// -// API reference: https://api.cloudflare.com/#worker-account-settings-create-worker-account-settings -func (api *API) CreateWorkersAccountSettings(ctx context.Context, rc *ResourceContainer, params CreateWorkersAccountSettingsParameters) (WorkersAccountSettings, error) { - if rc.Identifier == "" { - return WorkersAccountSettings{}, ErrMissingAccountID - } - - if rc.Level != AccountRouteLevel { - return WorkersAccountSettings{}, ErrRequiredAccountLevelResourceContainer - } - - uri := fmt.Sprintf("/accounts/%s/workers/account-settings", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return WorkersAccountSettings{}, err - } - - var workersAccountSettingsResponse CreateWorkersAccountSettingsResponse - if err := json.Unmarshal(res, &workersAccountSettingsResponse); err != nil { - return WorkersAccountSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return workersAccountSettingsResponse.Result, nil -} - -// WorkersAccountSettings returns the current account settings for Workers. -// -// API reference: https://api.cloudflare.com/#worker-account-settings-fetch-worker-account-settings -func (api *API) WorkersAccountSettings(ctx context.Context, rc *ResourceContainer, params WorkersAccountSettingsParameters) (WorkersAccountSettings, error) { - if rc.Identifier == "" { - return WorkersAccountSettings{}, ErrMissingAccountID - } - - if rc.Level != AccountRouteLevel { - return WorkersAccountSettings{}, ErrRequiredAccountLevelResourceContainer - } - - uri := fmt.Sprintf("/accounts/%s/workers/account-settings", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, params) - if err != nil { - return WorkersAccountSettings{}, err - } - - var workersAccountSettingsResponse CreateWorkersAccountSettingsResponse - if err := json.Unmarshal(res, &workersAccountSettingsResponse); err != nil { - return WorkersAccountSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return workersAccountSettingsResponse.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_bindings.go b/vendor/github.com/cloudflare/cloudflare-go/workers_bindings.go deleted file mode 100644 index 11f4ba7..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_bindings.go +++ /dev/null @@ -1,502 +0,0 @@ -package cloudflare - -import ( - "context" - rand "crypto/rand" - "encoding/hex" - "encoding/json" - "errors" - "fmt" - "io" - "mime/multipart" - "net/http" - "net/textproto" -) - -// WorkerBindingType represents a particular type of binding. -type WorkerBindingType string - -func (b WorkerBindingType) String() string { - return string(b) -} - -const ( - // WorkerDurableObjectBindingType is the type for Durable Object bindings. - WorkerDurableObjectBindingType WorkerBindingType = "durable_object_namespace" - // WorkerInheritBindingType is the type for inherited bindings. - WorkerInheritBindingType WorkerBindingType = "inherit" - // WorkerKvNamespaceBindingType is the type for KV Namespace bindings. - WorkerKvNamespaceBindingType WorkerBindingType = "kv_namespace" - // WorkerWebAssemblyBindingType is the type for Web Assembly module bindings. - WorkerWebAssemblyBindingType WorkerBindingType = "wasm_module" - // WorkerSecretTextBindingType is the type for secret text bindings. - WorkerSecretTextBindingType WorkerBindingType = "secret_text" - // WorkerPlainTextBindingType is the type for plain text bindings. - WorkerPlainTextBindingType WorkerBindingType = "plain_text" - // WorkerServiceBindingType is the type for service bindings. - WorkerServiceBindingType WorkerBindingType = "service" - // WorkerR2BucketBindingType is the type for R2 bucket bindings. - WorkerR2BucketBindingType WorkerBindingType = "r2_bucket" - // WorkerAnalyticsEngineBindingType is the type for Analytics Engine dataset bindings. - WorkerAnalyticsEngineBindingType WorkerBindingType = "analytics_engine" - // WorkerQueueBindingType is the type for queue bindings. - WorkerQueueBindingType WorkerBindingType = "queue" -) - -type ListWorkerBindingsParams struct { - ScriptName string -} - -// WorkerBindingListItem a struct representing an individual binding in a list of bindings. -type WorkerBindingListItem struct { - Name string `json:"name"` - Binding WorkerBinding -} - -// WorkerBindingListResponse wrapper struct for API response to worker binding list API call. -type WorkerBindingListResponse struct { - Response - BindingList []WorkerBindingListItem -} - -// Workers supports multiple types of bindings, e.g. KV namespaces or WebAssembly modules, and each type -// of binding will be represented differently in the upload request body. At a high-level, every binding -// will specify metadata, which is a JSON object with the properties "name" and "type". Some types of bindings -// will also have additional metadata properties. For example, KV bindings also specify the KV namespace. -// In addition to the metadata, some binding types may need to include additional data as part of the -// multipart form. For example, WebAssembly bindings will include the contents of the WebAssembly module. - -// WorkerBinding is the generic interface implemented by all of -// the various binding types. -type WorkerBinding interface { - Type() WorkerBindingType - - // serialize is responsible for returning the binding metadata as well as an optionally - // returning a function that can modify the multipart form body. For example, this is used - // by WebAssembly bindings to add a new part containing the WebAssembly module contents. - serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) -} - -// workerBindingMeta is the metadata portion of the binding. -type workerBindingMeta = map[string]interface{} - -// workerBindingBodyWriter allows for a binding to add additional parts to the multipart body. -type workerBindingBodyWriter func(*multipart.Writer) error - -// WorkerInheritBinding will just persist whatever binding content was previously uploaded. -type WorkerInheritBinding struct { - // Optional parameter that allows for renaming a binding without changing - // its contents. If `OldName` is empty, the binding name will not be changed. - OldName string -} - -// Type returns the type of the binding. -func (b WorkerInheritBinding) Type() WorkerBindingType { - return WorkerInheritBindingType -} - -func (b WorkerInheritBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - meta := workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - } - - if b.OldName != "" { - meta["old_name"] = b.OldName - } - - return meta, nil, nil -} - -// WorkerKvNamespaceBinding is a binding to a Workers KV Namespace. -// -// https://developers.cloudflare.com/workers/archive/api/resource-bindings/kv-namespaces/ -type WorkerKvNamespaceBinding struct { - NamespaceID string -} - -// Type returns the type of the binding. -func (b WorkerKvNamespaceBinding) Type() WorkerBindingType { - return WorkerKvNamespaceBindingType -} - -func (b WorkerKvNamespaceBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.NamespaceID == "" { - return nil, nil, fmt.Errorf(`NamespaceID for binding "%s" cannot be empty`, bindingName) - } - - return workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "namespace_id": b.NamespaceID, - }, nil, nil -} - -// WorkerDurableObjectBinding is a binding to a Workers Durable Object. -// -// https://api.cloudflare.com/#durable-objects-namespace-properties -type WorkerDurableObjectBinding struct { - ClassName string - ScriptName string -} - -// Type returns the type of the binding. -func (b WorkerDurableObjectBinding) Type() WorkerBindingType { - return WorkerDurableObjectBindingType -} - -func (b WorkerDurableObjectBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.ClassName == "" { - return nil, nil, fmt.Errorf(`ClassName for binding "%s" cannot be empty`, bindingName) - } - - return workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "class_name": b.ClassName, - "script_name": b.ScriptName, - }, nil, nil -} - -// WorkerWebAssemblyBinding is a binding to a WebAssembly module. -// -// https://developers.cloudflare.com/workers/archive/api/resource-bindings/webassembly-modules/ -type WorkerWebAssemblyBinding struct { - Module io.Reader -} - -// Type returns the type of the binding. -func (b WorkerWebAssemblyBinding) Type() WorkerBindingType { - return WorkerWebAssemblyBindingType -} - -func (b WorkerWebAssemblyBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - partName := getRandomPartName() - - bodyWriter := func(mpw *multipart.Writer) error { - var hdr = textproto.MIMEHeader{} - hdr.Set("content-disposition", fmt.Sprintf(`form-data; name="%s"`, partName)) - hdr.Set("content-type", "application/wasm") - pw, err := mpw.CreatePart(hdr) - if err != nil { - return err - } - _, err = io.Copy(pw, b.Module) - return err - } - - return workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "part": partName, - }, bodyWriter, nil -} - -// WorkerPlainTextBinding is a binding to plain text. -// -// https://developers.cloudflare.com/workers/tooling/api/scripts/#add-a-plain-text-binding -type WorkerPlainTextBinding struct { - Text string -} - -// Type returns the type of the binding. -func (b WorkerPlainTextBinding) Type() WorkerBindingType { - return WorkerPlainTextBindingType -} - -func (b WorkerPlainTextBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.Text == "" { - return nil, nil, fmt.Errorf(`Text for binding "%s" cannot be empty`, bindingName) - } - - return workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "text": b.Text, - }, nil, nil -} - -// WorkerSecretTextBinding is a binding to secret text. -// -// https://developers.cloudflare.com/workers/tooling/api/scripts/#add-a-secret-text-binding -type WorkerSecretTextBinding struct { - Text string -} - -// Type returns the type of the binding. -func (b WorkerSecretTextBinding) Type() WorkerBindingType { - return WorkerSecretTextBindingType -} - -func (b WorkerSecretTextBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.Text == "" { - return nil, nil, fmt.Errorf(`Text for binding "%s" cannot be empty`, bindingName) - } - - return workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "text": b.Text, - }, nil, nil -} - -type WorkerServiceBinding struct { - Service string - Environment *string -} - -func (b WorkerServiceBinding) Type() WorkerBindingType { - return WorkerServiceBindingType -} - -func (b WorkerServiceBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.Service == "" { - return nil, nil, fmt.Errorf(`Service for binding "%s" cannot be empty`, bindingName) - } - - meta := workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "service": b.Service, - } - - if b.Environment != nil { - meta["environment"] = *b.Environment - } - - return meta, nil, nil -} - -// WorkerR2BucketBinding is a binding to an R2 bucket. -type WorkerR2BucketBinding struct { - BucketName string -} - -// Type returns the type of the binding. -func (b WorkerR2BucketBinding) Type() WorkerBindingType { - return WorkerR2BucketBindingType -} - -func (b WorkerR2BucketBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.BucketName == "" { - return nil, nil, fmt.Errorf(`BucketName for binding "%s" cannot be empty`, bindingName) - } - - return workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "bucket_name": b.BucketName, - }, nil, nil -} - -// WorkerAnalyticsEngineBinding is a binding to an Analytics Engine dataset. -type WorkerAnalyticsEngineBinding struct { - Dataset string -} - -// Type returns the type of the binding. -func (b WorkerAnalyticsEngineBinding) Type() WorkerBindingType { - return WorkerAnalyticsEngineBindingType -} - -func (b WorkerAnalyticsEngineBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.Dataset == "" { - return nil, nil, fmt.Errorf(`Dataset for binding "%s" cannot be empty`, bindingName) - } - - return workerBindingMeta{ - "name": bindingName, - "type": b.Type(), - "dataset": b.Dataset, - }, nil, nil -} - -// WorkerQueueBinding is a binding to a Workers Queue. -// -// https://developers.cloudflare.com/workers/platform/bindings/#queue-bindings -type WorkerQueueBinding struct { - Binding string - Queue string -} - -// Type returns the type of the binding. -func (b WorkerQueueBinding) Type() WorkerBindingType { - return WorkerQueueBindingType -} - -func (b WorkerQueueBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { - if b.Binding == "" { - return nil, nil, fmt.Errorf(`Binding name for binding "%s" cannot be empty`, bindingName) - } - if b.Queue == "" { - return nil, nil, fmt.Errorf(`Queue name for binding "%s" cannot be empty`, bindingName) - } - - return workerBindingMeta{ - "type": b.Type(), - "name": b.Binding, - "queue_name": b.Queue, - }, nil, nil -} - -// Each binding that adds a part to the multipart form body will need -// a unique part name so we just generate a random 128bit hex string. -func getRandomPartName() string { - randBytes := make([]byte, 16) - rand.Read(randBytes) //nolint:errcheck - return hex.EncodeToString(randBytes) -} - -// ListWorkerBindings returns all the bindings for a particular worker. -func (api *API) ListWorkerBindings(ctx context.Context, rc *ResourceContainer, params ListWorkerBindingsParams) (WorkerBindingListResponse, error) { - if params.ScriptName == "" { - return WorkerBindingListResponse{}, errors.New("ScriptName is required") - } - - if rc.Level != AccountRouteLevel { - return WorkerBindingListResponse{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return WorkerBindingListResponse{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/bindings", rc.Identifier, params.ScriptName) - - var jsonRes struct { - Response - Bindings []workerBindingMeta `json:"result"` - } - var r WorkerBindingListResponse - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return r, err - } - err = json.Unmarshal(res, &jsonRes) - if err != nil { - return r, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - r = WorkerBindingListResponse{ - Response: jsonRes.Response, - BindingList: make([]WorkerBindingListItem, 0, len(jsonRes.Bindings)), - } - for _, jsonBinding := range jsonRes.Bindings { - name, ok := jsonBinding["name"].(string) - if !ok { - return r, fmt.Errorf("Binding missing name %v", jsonBinding) - } - bType, ok := jsonBinding["type"].(string) - if !ok { - return r, fmt.Errorf("Binding missing type %v", jsonBinding) - } - bindingListItem := WorkerBindingListItem{ - Name: name, - } - - switch WorkerBindingType(bType) { - case WorkerDurableObjectBindingType: - class_name := jsonBinding["class_name"].(string) - script_name := jsonBinding["script_name"].(string) - bindingListItem.Binding = WorkerDurableObjectBinding{ - ClassName: class_name, - ScriptName: script_name, - } - case WorkerKvNamespaceBindingType: - namespaceID := jsonBinding["namespace_id"].(string) - bindingListItem.Binding = WorkerKvNamespaceBinding{ - NamespaceID: namespaceID, - } - case WorkerQueueBindingType: - queueName := jsonBinding["queue_name"].(string) - bindingListItem.Binding = WorkerQueueBinding{ - Binding: name, - Queue: queueName, - } - case WorkerWebAssemblyBindingType: - bindingListItem.Binding = WorkerWebAssemblyBinding{ - Module: &bindingContentReader{ - api: api, - ctx: ctx, - accountID: rc.Identifier, - params: ¶ms, - bindingName: name, - }, - } - case WorkerPlainTextBindingType: - text := jsonBinding["text"].(string) - bindingListItem.Binding = WorkerPlainTextBinding{ - Text: text, - } - case WorkerServiceBindingType: - service := jsonBinding["service"].(string) - environment := jsonBinding["environment"].(string) - bindingListItem.Binding = WorkerServiceBinding{ - Service: service, - Environment: &environment, - } - case WorkerSecretTextBindingType: - bindingListItem.Binding = WorkerSecretTextBinding{} - case WorkerR2BucketBindingType: - bucketName := jsonBinding["bucket_name"].(string) - bindingListItem.Binding = WorkerR2BucketBinding{ - BucketName: bucketName, - } - case WorkerAnalyticsEngineBindingType: - dataset := jsonBinding["dataset"].(string) - bindingListItem.Binding = WorkerAnalyticsEngineBinding{ - Dataset: dataset, - } - default: - bindingListItem.Binding = WorkerInheritBinding{} - } - r.BindingList = append(r.BindingList, bindingListItem) - } - - return r, nil -} - -// bindingContentReader is an io.Reader that will lazily load the -// raw bytes for a binding from the API when the Read() method -// is first called. This is only useful for binding types -// that store raw bytes, like WebAssembly modules. -type bindingContentReader struct { - api *API - accountID string - params *ListWorkerBindingsParams - ctx context.Context - bindingName string - content []byte - position int -} - -func (b *bindingContentReader) Read(p []byte) (n int, err error) { - // Lazily load the content when Read() is first called - if b.content == nil { - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/bindings/%s/content", b.accountID, b.params.ScriptName, b.bindingName) - res, err := b.api.makeRequestContext(b.ctx, http.MethodGet, uri, nil) - if err != nil { - return 0, err - } - b.content = res - } - - if b.position >= len(b.content) { - return 0, io.EOF - } - - bytesRemaining := len(b.content) - b.position - bytesToProcess := 0 - if len(p) < bytesRemaining { - bytesToProcess = len(p) - } else { - bytesToProcess = bytesRemaining - } - - for i := 0; i < bytesToProcess; i++ { - p[i] = b.content[b.position] - b.position = b.position + 1 - } - - return bytesToProcess, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_cron_triggers.go b/vendor/github.com/cloudflare/cloudflare-go/workers_cron_triggers.go deleted file mode 100644 index 2322a5d..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_cron_triggers.go +++ /dev/null @@ -1,90 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -// WorkerCronTriggerResponse represents the response from the Worker cron trigger -// API endpoint. -type WorkerCronTriggerResponse struct { - Response - Result WorkerCronTriggerSchedules `json:"result"` -} - -// WorkerCronTriggerSchedules contains the schedule of Worker cron triggers. -type WorkerCronTriggerSchedules struct { - Schedules []WorkerCronTrigger `json:"schedules"` -} - -// WorkerCronTrigger holds an individual cron schedule for a worker. -type WorkerCronTrigger struct { - Cron string `json:"cron"` - CreatedOn *time.Time `json:"created_on,omitempty"` - ModifiedOn *time.Time `json:"modified_on,omitempty"` -} - -type ListWorkerCronTriggersParams struct { - ScriptName string -} - -type UpdateWorkerCronTriggersParams struct { - ScriptName string - Crons []WorkerCronTrigger -} - -// ListWorkerCronTriggers fetches all available cron triggers for a single Worker -// script. -// -// API reference: https://api.cloudflare.com/#worker-cron-trigger-get-cron-triggers -func (api *API) ListWorkerCronTriggers(ctx context.Context, rc *ResourceContainer, params ListWorkerCronTriggersParams) ([]WorkerCronTrigger, error) { - if rc.Level != AccountRouteLevel { - return []WorkerCronTrigger{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return []WorkerCronTrigger{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/schedules", rc.Identifier, params.ScriptName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WorkerCronTrigger{}, err - } - - result := WorkerCronTriggerResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []WorkerCronTrigger{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.Schedules, err -} - -// UpdateWorkerCronTriggers updates a single schedule for a Worker cron trigger. -// -// API reference: https://api.cloudflare.com/#worker-cron-trigger-update-cron-triggers -func (api *API) UpdateWorkerCronTriggers(ctx context.Context, rc *ResourceContainer, params UpdateWorkerCronTriggersParams) ([]WorkerCronTrigger, error) { - if rc.Level != AccountRouteLevel { - return []WorkerCronTrigger{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return []WorkerCronTrigger{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/schedules", rc.Identifier, params.ScriptName) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.Crons) - if err != nil { - return []WorkerCronTrigger{}, err - } - - result := WorkerCronTriggerResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return []WorkerCronTrigger{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result.Result.Schedules, err -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_domain.go b/vendor/github.com/cloudflare/cloudflare-go/workers_domain.go deleted file mode 100644 index 975786d..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_domain.go +++ /dev/null @@ -1,150 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -var ( - ErrMissingHostname = errors.New("required hostname missing") - ErrMissingService = errors.New("required service missing") - ErrMissingEnvironment = errors.New("required environment missing") -) - -type AttachWorkersDomainParams struct { - ID string `json:"id,omitempty"` - ZoneID string `json:"zone_id,omitempty"` - ZoneName string `json:"zone_name,omitempty"` - Hostname string `json:"hostname,omitempty"` - Service string `json:"service,omitempty"` - Environment string `json:"environment,omitempty"` -} - -type WorkersDomain struct { - ID string `json:"id,omitempty"` - ZoneID string `json:"zone_id,omitempty"` - ZoneName string `json:"zone_name,omitempty"` - Hostname string `json:"hostname,omitempty"` - Service string `json:"service,omitempty"` - Environment string `json:"environment,omitempty"` -} - -type WorkersDomainResponse struct { - Response - Result WorkersDomain `json:"result"` -} - -type ListWorkersDomainParams struct { - ZoneID string `url:"zone_id,omitempty"` - ZoneName string `url:"zone_name,omitempty"` - Hostname string `url:"hostname,omitempty"` - Service string `url:"service,omitempty"` - Environment string `url:"environment,omitempty"` -} - -type WorkersDomainListResponse struct { - Response - Result []WorkersDomain `json:"result"` -} - -// ListWorkersDomains lists all Worker Domains. -// -// API reference: https://api.cloudflare.com/#worker-domain-list-domains -func (api *API) ListWorkersDomains(ctx context.Context, rc *ResourceContainer, params ListWorkersDomainParams) ([]WorkersDomain, error) { - if rc.Identifier == "" { - return []WorkersDomain{}, ErrMissingAccountID - } - - uri := buildURI(fmt.Sprintf("/accounts/%s/workers/domains", rc.Identifier), params) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r WorkersDomainListResponse - if err := json.Unmarshal(res, &r); err != nil { - return []WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// AttachWorkersDomain attaches a worker to a zone and hostname. -// -// API reference: https://api.cloudflare.com/#worker-domain-attach-to-domain -func (api *API) AttachWorkersDomain(ctx context.Context, rc *ResourceContainer, domain AttachWorkersDomainParams) (WorkersDomain, error) { - if rc.Identifier == "" { - return WorkersDomain{}, ErrMissingAccountID - } - - if domain.ZoneID == "" { - return WorkersDomain{}, ErrMissingZoneID - } - - if domain.Hostname == "" { - return WorkersDomain{}, ErrMissingHostname - } - - if domain.Service == "" { - return WorkersDomain{}, ErrMissingService - } - - if domain.Environment == "" { - return WorkersDomain{}, ErrMissingEnvironment - } - - uri := fmt.Sprintf("/accounts/%s/workers/domains", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, domain) - if err != nil { - return WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r WorkersDomainResponse - if err := json.Unmarshal(res, &r); err != nil { - return WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// GetWorkersDomain gets a single Worker Domain. -// -// API reference: https://api.cloudflare.com/#worker-domain-get-a-domain -func (api *API) GetWorkersDomain(ctx context.Context, rc *ResourceContainer, domainID string) (WorkersDomain, error) { - if rc.Identifier == "" { - return WorkersDomain{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - var r WorkersDomainResponse - if err := json.Unmarshal(res, &r); err != nil { - return WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// DetachWorkersDomain detaches a worker from a zone and hostname. -// -// API reference: https://api.cloudflare.com/#worker-domain-detach-from-domain -func (api *API) DetachWorkersDomain(ctx context.Context, rc *ResourceContainer, domainID string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return fmt.Errorf("%s: %w", errMakeRequestError, err) - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_kv.go b/vendor/github.com/cloudflare/cloudflare-go/workers_kv.go deleted file mode 100644 index 8a62924..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_kv.go +++ /dev/null @@ -1,377 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" -) - -// CreateWorkersKVNamespaceParams provides parameters for creating and updating storage namespaces. -type CreateWorkersKVNamespaceParams struct { - Title string `json:"title"` -} - -type UpdateWorkersKVNamespaceParams struct { - NamespaceID string `json:"-"` - Title string `json:"title"` -} - -// WorkersKVPair is used in an array in the request to the bulk KV api. -type WorkersKVPair struct { - Key string `json:"key"` - Value string `json:"value"` - Expiration int `json:"expiration,omitempty"` - ExpirationTTL int `json:"expiration_ttl,omitempty"` - Metadata interface{} `json:"metadata,omitempty"` - Base64 bool `json:"base64,omitempty"` -} - -// WorkersKVNamespaceResponse is the response received when creating storage namespaces. -type WorkersKVNamespaceResponse struct { - Response - Result WorkersKVNamespace `json:"result"` -} - -// WorkersKVNamespace contains the unique identifier and title of a storage namespace. -type WorkersKVNamespace struct { - ID string `json:"id"` - Title string `json:"title"` -} - -// ListWorkersKVNamespacesResponse contains a slice of storage namespaces associated with an -// account, pagination information, and an embedded response struct. -type ListWorkersKVNamespacesResponse struct { - Response - Result []WorkersKVNamespace `json:"result"` - ResultInfo `json:"result_info"` -} - -// StorageKey is a key name used to identify a storage value. -type StorageKey struct { - Name string `json:"name"` - Expiration int `json:"expiration"` - Metadata interface{} `json:"metadata"` -} - -// ListStorageKeysResponse contains a slice of keys belonging to a storage namespace, -// pagination information, and an embedded response struct. -type ListStorageKeysResponse struct { - Response - Result []StorageKey `json:"result"` - ResultInfo `json:"result_info"` -} - -type ListWorkersKVNamespacesParams struct { - ResultInfo -} - -type WriteWorkersKVEntryParams struct { - NamespaceID string - Key string - Value []byte -} - -type WriteWorkersKVEntriesParams struct { - NamespaceID string - KVs []*WorkersKVPair -} - -type GetWorkersKVParams struct { - NamespaceID string - Key string -} - -type DeleteWorkersKVEntryParams struct { - NamespaceID string - Key string -} - -type DeleteWorkersKVEntriesParams struct { - NamespaceID string - Keys []string -} - -type ListWorkersKVsParams struct { - NamespaceID string `url:"-"` - Limit int `url:"limit,omitempty"` - Cursor string `url:"cursor,omitempty"` - Prefix string `url:"prefix,omitempty"` -} - -// CreateWorkersKVNamespace creates a namespace under the given title. -// A 400 is returned if the account already owns a namespace with this title. -// A namespace must be explicitly deleted to be replaced. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-create-a-namespace -func (api *API) CreateWorkersKVNamespace(ctx context.Context, rc *ResourceContainer, params CreateWorkersKVNamespaceParams) (WorkersKVNamespaceResponse, error) { - if rc.Level != AccountRouteLevel { - return WorkersKVNamespaceResponse{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return WorkersKVNamespaceResponse{}, ErrMissingIdentifier - } - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return WorkersKVNamespaceResponse{}, err - } - - result := WorkersKVNamespaceResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// ListWorkersKVNamespaces lists storage namespaces. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-list-namespaces -func (api *API) ListWorkersKVNamespaces(ctx context.Context, rc *ResourceContainer, params ListWorkersKVNamespacesParams) ([]WorkersKVNamespace, *ResultInfo, error) { - if rc.Level != AccountRouteLevel { - return []WorkersKVNamespace{}, &ResultInfo{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return []WorkersKVNamespace{}, &ResultInfo{}, ErrMissingIdentifier - } - - autoPaginate := true - if params.PerPage >= 1 || params.Page >= 1 { - autoPaginate = false - } - if params.PerPage < 1 { - params.PerPage = 50 - } - if params.Page < 1 { - params.Page = 1 - } - - var namespaces []WorkersKVNamespace - var nsResponse ListWorkersKVNamespacesResponse - for { - nsResponse = ListWorkersKVNamespacesResponse{} - uri := buildURI(fmt.Sprintf("/accounts/%s/storage/kv/namespaces", rc.Identifier), params) - - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []WorkersKVNamespace{}, &ResultInfo{}, err - } - - err = json.Unmarshal(res, &nsResponse) - if err != nil { - return []WorkersKVNamespace{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal workers KV namespaces JSON data: %w", err) - } - - namespaces = append(namespaces, nsResponse.Result...) - params.ResultInfo = nsResponse.ResultInfo.Next() - - if params.ResultInfo.Done() || !autoPaginate { - break - } - } - - return namespaces, &nsResponse.ResultInfo, nil -} - -// DeleteWorkersKVNamespace deletes the namespace corresponding to the given ID. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-remove-a-namespace -func (api *API) DeleteWorkersKVNamespace(ctx context.Context, rc *ResourceContainer, namespaceID string) (Response, error) { - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s", rc.Identifier, namespaceID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// UpdateWorkersKVNamespace modifies a KV namespace based on the ID. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-rename-a-namespace -func (api *API) UpdateWorkersKVNamespace(ctx context.Context, rc *ResourceContainer, params UpdateWorkersKVNamespaceParams) (Response, error) { - if rc.Level != AccountRouteLevel { - return Response{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return Response{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s", rc.Identifier, params.NamespaceID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// WriteWorkersKVEntry writes a single KV value based on the key. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-write-key-value-pair -func (api *API) WriteWorkersKVEntry(ctx context.Context, rc *ResourceContainer, params WriteWorkersKVEntryParams) (Response, error) { - if rc.Level != AccountRouteLevel { - return Response{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return Response{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s/values/%s", rc.Identifier, params.NamespaceID, url.PathEscape(params.Key)) - res, err := api.makeRequestContextWithHeaders( - ctx, http.MethodPut, uri, params.Value, http.Header{"Content-Type": []string{"application/octet-stream"}}, - ) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// WriteWorkersKVEntries writes multiple KVs at once. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-write-multiple-key-value-pairs -func (api *API) WriteWorkersKVEntries(ctx context.Context, rc *ResourceContainer, params WriteWorkersKVEntriesParams) (Response, error) { - if rc.Level != AccountRouteLevel { - return Response{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return Response{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s/bulk", rc.Identifier, params.NamespaceID) - res, err := api.makeRequestContextWithHeaders( - ctx, http.MethodPut, uri, params.KVs, http.Header{"Content-Type": []string{"application/json"}}, - ) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// GetWorkersKV returns the value associated with the given key in the -// given namespace. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-read-key-value-pair -func (api API) GetWorkersKV(ctx context.Context, rc *ResourceContainer, params GetWorkersKVParams) ([]byte, error) { - if rc.Level != AccountRouteLevel { - return []byte(``), ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return []byte(``), ErrMissingIdentifier - } - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s/values/%s", rc.Identifier, params.NamespaceID, url.PathEscape(params.Key)) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - return res, nil -} - -// DeleteWorkersKVEntry deletes a key and value for a provided storage namespace. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-delete-key-value-pair -func (api API) DeleteWorkersKVEntry(ctx context.Context, rc *ResourceContainer, params DeleteWorkersKVEntryParams) (Response, error) { - if rc.Level != AccountRouteLevel { - return Response{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return Response{}, ErrMissingIdentifier - } - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s/values/%s", rc.Identifier, params.NamespaceID, url.PathEscape(params.Key)) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return result, err -} - -// DeleteWorkersKVEntries deletes multiple KVs at once. -// -// API reference: https://api.cloudflare.com/#workers-kv-namespace-delete-multiple-key-value-pairs -func (api *API) DeleteWorkersKVEntries(ctx context.Context, rc *ResourceContainer, params DeleteWorkersKVEntriesParams) (Response, error) { - if rc.Level != AccountRouteLevel { - return Response{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return Response{}, ErrMissingIdentifier - } - uri := fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s/bulk", rc.Identifier, params.NamespaceID) - res, err := api.makeRequestContextWithHeaders( - ctx, http.MethodDelete, uri, params.Keys, http.Header{"Content-Type": []string{"application/json"}}, - ) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// ListWorkersKVKeys lists a namespace's keys. -// -// API Reference: https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys -func (api API) ListWorkersKVKeys(ctx context.Context, rc *ResourceContainer, params ListWorkersKVsParams) (ListStorageKeysResponse, error) { - if rc.Level != AccountRouteLevel { - return ListStorageKeysResponse{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return ListStorageKeysResponse{}, ErrMissingIdentifier - } - - uri := buildURI( - fmt.Sprintf("/accounts/%s/storage/kv/namespaces/%s/keys", rc.Identifier, params.NamespaceID), - params, - ) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ListStorageKeysResponse{}, err - } - - result := ListStorageKeysResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return result, err -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_routes.go b/vendor/github.com/cloudflare/cloudflare-go/workers_routes.go deleted file mode 100644 index d6dc1c2..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_routes.go +++ /dev/null @@ -1,161 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" -) - -var ErrMissingWorkerRouteID = errors.New("missing required route ID") - -type ListWorkerRoutes struct{} - -type CreateWorkerRouteParams struct { - Pattern string `json:"pattern"` - Script string `json:"script,omitempty"` -} - -type ListWorkerRoutesParams struct{} - -type UpdateWorkerRouteParams struct { - ID string `json:"id,omitempty"` - Pattern string `json:"pattern"` - Script string `json:"script,omitempty"` -} - -// CreateWorkerRoute creates worker route for a script. -// -// API reference: https://api.cloudflare.com/#worker-routes-create-route -func (api *API) CreateWorkerRoute(ctx context.Context, rc *ResourceContainer, params CreateWorkerRouteParams) (WorkerRouteResponse, error) { - if rc.Level != ZoneRouteLevel { - return WorkerRouteResponse{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if rc.Identifier == "" { - return WorkerRouteResponse{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/zones/%s/workers/routes", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) - if err != nil { - return WorkerRouteResponse{}, err - } - - var r WorkerRouteResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r, nil -} - -// DeleteWorkerRoute deletes worker route for a script. -// -// API reference: https://api.cloudflare.com/#worker-routes-delete-route -func (api *API) DeleteWorkerRoute(ctx context.Context, rc *ResourceContainer, routeID string) (WorkerRouteResponse, error) { - if rc.Level != ZoneRouteLevel { - return WorkerRouteResponse{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if rc.Identifier == "" { - return WorkerRouteResponse{}, ErrMissingIdentifier - } - - if routeID == "" { - return WorkerRouteResponse{}, errors.New("missing required route ID") - } - - uri := fmt.Sprintf("/zones/%s/workers/routes/%s", rc.Identifier, routeID) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return WorkerRouteResponse{}, err - } - var r WorkerRouteResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r, nil -} - -// ListWorkerRoutes returns list of Worker routes. -// -// API reference: https://api.cloudflare.com/#worker-routes-list-routes -func (api *API) ListWorkerRoutes(ctx context.Context, rc *ResourceContainer, params ListWorkerRoutesParams) (WorkerRoutesResponse, error) { - if rc.Level != ZoneRouteLevel { - return WorkerRoutesResponse{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if rc.Identifier == "" { - return WorkerRoutesResponse{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/zones/%s/workers/routes", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WorkerRoutesResponse{}, err - } - var r WorkerRoutesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WorkerRoutesResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r, nil -} - -// GetWorkerRoute returns a Workers route. -// -// API reference: https://api.cloudflare.com/#worker-routes-get-route -func (api *API) GetWorkerRoute(ctx context.Context, rc *ResourceContainer, routeID string) (WorkerRouteResponse, error) { - if rc.Level != ZoneRouteLevel { - return WorkerRouteResponse{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if rc.Identifier == "" { - return WorkerRouteResponse{}, ErrMissingIdentifier - } - - uri := fmt.Sprintf("/zones/%s/workers/routes/%s", rc.Identifier, routeID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WorkerRouteResponse{}, err - } - var r WorkerRouteResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r, nil -} - -// UpdateWorkerRoute updates worker route for a script. -// -// API reference: https://api.cloudflare.com/#worker-routes-update-route -func (api *API) UpdateWorkerRoute(ctx context.Context, rc *ResourceContainer, params UpdateWorkerRouteParams) (WorkerRouteResponse, error) { - if rc.Level != ZoneRouteLevel { - return WorkerRouteResponse{}, fmt.Errorf(errInvalidResourceContainerAccess, ZoneRouteLevel) - } - - if rc.Identifier == "" { - return WorkerRouteResponse{}, ErrMissingIdentifier - } - - if params.ID == "" { - return WorkerRouteResponse{}, ErrMissingWorkerRouteID - } - - uri := fmt.Sprintf("/zones/%s/workers/routes/%s", rc.Identifier, params.ID) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return WorkerRouteResponse{}, err - } - var r WorkerRouteResponse - err = json.Unmarshal(res, &r) - if err != nil { - return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_secrets.go b/vendor/github.com/cloudflare/cloudflare-go/workers_secrets.go deleted file mode 100644 index 458cd1a..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_secrets.go +++ /dev/null @@ -1,124 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -// WorkersPutSecretRequest provides parameters for creating and updating secrets. -type WorkersPutSecretRequest struct { - Name string `json:"name"` - Text string `json:"text"` - Type WorkerBindingType `json:"type"` -} - -// WorkersSecret contains the name and type of the secret. -type WorkersSecret struct { - Name string `json:"name"` - Type string `json:"secret_text"` -} - -// WorkersPutSecretResponse is the response received when creating or updating a secret. -type WorkersPutSecretResponse struct { - Response - Result WorkersSecret `json:"result"` -} - -// WorkersListSecretsResponse is the response received when listing secrets. -type WorkersListSecretsResponse struct { - Response - Result []WorkersSecret `json:"result"` -} - -type SetWorkersSecretParams struct { - ScriptName string - Secret *WorkersPutSecretRequest -} - -type DeleteWorkersSecretParams struct { - ScriptName string - SecretName string -} - -type ListWorkersSecretsParams struct { - ScriptName string -} - -// SetWorkersSecret creates or updates a secret. -// -// API reference: https://api.cloudflare.com/ -func (api *API) SetWorkersSecret(ctx context.Context, rc *ResourceContainer, params SetWorkersSecretParams) (WorkersPutSecretResponse, error) { - if rc.Level != AccountRouteLevel { - return WorkersPutSecretResponse{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return WorkersPutSecretResponse{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/secrets", rc.Identifier, params.ScriptName) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params.Secret) - if err != nil { - return WorkersPutSecretResponse{}, err - } - - result := WorkersPutSecretResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// DeleteWorkersSecret deletes a secret. -// -// API reference: https://api.cloudflare.com/ -func (api *API) DeleteWorkersSecret(ctx context.Context, rc *ResourceContainer, params DeleteWorkersSecretParams) (Response, error) { - if rc.Level != AccountRouteLevel { - return Response{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return Response{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/secrets/%s", rc.Identifier, params.ScriptName, params.SecretName) - res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return Response{}, err - } - - result := Response{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} - -// ListWorkersSecrets lists secrets for a given worker -// API reference: https://api.cloudflare.com/ -func (api *API) ListWorkersSecrets(ctx context.Context, rc *ResourceContainer, params ListWorkersSecretsParams) (WorkersListSecretsResponse, error) { - if rc.Level != AccountRouteLevel { - return WorkersListSecretsResponse{}, ErrRequiredAccountLevelResourceContainer - } - - if rc.Identifier == "" { - return WorkersListSecretsResponse{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/secrets", rc.Identifier, params.ScriptName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WorkersListSecretsResponse{}, err - } - - result := WorkersListSecretsResponse{} - if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return result, err -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_subdomain.go b/vendor/github.com/cloudflare/cloudflare-go/workers_subdomain.go deleted file mode 100644 index f67e7ad..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_subdomain.go +++ /dev/null @@ -1,57 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" -) - -type WorkersSubdomain struct { - Name string `json:"name,omitempty"` -} - -type WorkersSubdomainResponse struct { - Response - Result WorkersSubdomain -} - -// WorkersCreateSubdomain Creates a Workers subdomain for an account. -// -// API reference: https://api.cloudflare.com/#worker-subdomain-create-subdomain -func (api *API) WorkersCreateSubdomain(ctx context.Context, rc *ResourceContainer, params WorkersSubdomain) (WorkersSubdomain, error) { - if rc.Identifier == "" { - return WorkersSubdomain{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/subdomain", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params) - if err != nil { - return WorkersSubdomain{}, err - } - var r WorkersSubdomainResponse - if err := json.Unmarshal(res, &r); err != nil { - return WorkersSubdomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// WorkersGetSubdomain Creates a Workers subdomain for an account. -// -// API reference: https://api.cloudflare.com/#worker-subdomain-get-subdomain -func (api *API) WorkersGetSubdomain(ctx context.Context, rc *ResourceContainer) (WorkersSubdomain, error) { - if rc.Identifier == "" { - return WorkersSubdomain{}, ErrMissingAccountID - } - - uri := fmt.Sprintf("/accounts/%s/workers/subdomain", rc.Identifier) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WorkersSubdomain{}, err - } - var r WorkersSubdomainResponse - if err := json.Unmarshal(res, &r); err != nil { - return WorkersSubdomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/workers_tail.go b/vendor/github.com/cloudflare/cloudflare-go/workers_tail.go deleted file mode 100644 index 0f074b0..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/workers_tail.go +++ /dev/null @@ -1,113 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "time" -) - -var ( - ErrMissingScriptName = errors.New("required script name missing") - ErrMissingTailID = errors.New("required tail id missing") -) - -type WorkersTail struct { - ID string `json:"id"` - URL string `json:"url"` - ExpiresAt *time.Time `json:"expires_at"` -} - -type StartWorkersTailResponse struct { - Response - Result WorkersTail -} - -type ListWorkersTailParameters struct { - AccountID string - ScriptName string -} - -type ListWorkersTailResponse struct { - Response - Result WorkersTail -} - -// StartWorkersTail Starts a tail that receives logs and exception from a Worker. -// -// API reference: https://api.cloudflare.com/#worker-tail-logs-start-tail -func (api *API) StartWorkersTail(ctx context.Context, rc *ResourceContainer, scriptName string) (WorkersTail, error) { - if rc.Identifier == "" { - return WorkersTail{}, ErrMissingAccountID - } - - if scriptName == "" { - return WorkersTail{}, ErrMissingScriptName - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/tails", rc.Identifier, scriptName) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil) - if err != nil { - return WorkersTail{}, err - } - - var workerstailResponse StartWorkersTailResponse - if err := json.Unmarshal(res, &workerstailResponse); err != nil { - return WorkersTail{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return workerstailResponse.Result, nil -} - -// ListWorkersTail Get list of tails currently deployed on a Worker. -// -// API reference: https://api.cloudflare.com/#worker-tail-logs-list-tails -func (api *API) ListWorkersTail(ctx context.Context, rc *ResourceContainer, params ListWorkersTailParameters) (WorkersTail, error) { - if rc.Identifier == "" { - return WorkersTail{}, ErrMissingAccountID - } - - if params.ScriptName == "" { - return WorkersTail{}, ErrMissingScriptName - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/tails", rc.Identifier, params.ScriptName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return WorkersTail{}, err - } - - var workerstailResponse ListWorkersTailResponse - if err := json.Unmarshal(res, &workerstailResponse); err != nil { - return WorkersTail{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return workerstailResponse.Result, nil -} - -// DeleteWorkersTail Deletes a tail from a Worker. -// -// API reference: https://api.cloudflare.com/#worker-tail-logs-delete-tail -func (api *API) DeleteWorkersTail(ctx context.Context, rc *ResourceContainer, scriptName, tailID string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - - if scriptName == "" { - return ErrMissingScriptName - } - - if tailID == "" { - return ErrMissingTailID - } - - uri := fmt.Sprintf("/accounts/%s/workers/scripts/%s/tails/%s", rc.Identifier, scriptName, tailID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/zone.go b/vendor/github.com/cloudflare/cloudflare-go/zone.go deleted file mode 100644 index 3929356..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/zone.go +++ /dev/null @@ -1,1026 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" - "strconv" - "sync" - "time" - - "golang.org/x/net/idna" -) - -// Owner describes the resource owner. -type Owner struct { - ID string `json:"id"` - Email string `json:"email"` - Name string `json:"name"` - OwnerType string `json:"type"` -} - -// Zone describes a Cloudflare zone. -type Zone struct { - ID string `json:"id"` - Name string `json:"name"` - // DevMode contains the time in seconds until development expires (if - // positive) or since it expired (if negative). It will be 0 if never used. - DevMode int `json:"development_mode"` - OriginalNS []string `json:"original_name_servers"` - OriginalRegistrar string `json:"original_registrar"` - OriginalDNSHost string `json:"original_dnshost"` - CreatedOn time.Time `json:"created_on"` - ModifiedOn time.Time `json:"modified_on"` - NameServers []string `json:"name_servers"` - Owner Owner `json:"owner"` - Permissions []string `json:"permissions"` - Plan ZonePlan `json:"plan"` - PlanPending ZonePlan `json:"plan_pending,omitempty"` - Status string `json:"status"` - Paused bool `json:"paused"` - Type string `json:"type"` - Host struct { - Name string - Website string - } `json:"host"` - VanityNS []string `json:"vanity_name_servers"` - Betas []string `json:"betas"` - DeactReason string `json:"deactivation_reason"` - Meta ZoneMeta `json:"meta"` - Account Account `json:"account"` - VerificationKey string `json:"verification_key"` -} - -// ZoneMeta describes metadata about a zone. -type ZoneMeta struct { - // custom_certificate_quota is broken - sometimes it's a string, sometimes a number! - // CustCertQuota int `json:"custom_certificate_quota"` - PageRuleQuota int `json:"page_rule_quota"` - WildcardProxiable bool `json:"wildcard_proxiable"` - PhishingDetected bool `json:"phishing_detected"` -} - -// ZonePlan contains the plan information for a zone. -type ZonePlan struct { - ZonePlanCommon - LegacyID string `json:"legacy_id"` - IsSubscribed bool `json:"is_subscribed"` - CanSubscribe bool `json:"can_subscribe"` - LegacyDiscount bool `json:"legacy_discount"` - ExternallyManaged bool `json:"externally_managed"` -} - -// ZoneRatePlan contains the plan information for a zone. -type ZoneRatePlan struct { - ZonePlanCommon - Components []zoneRatePlanComponents `json:"components,omitempty"` -} - -// ZonePlanCommon contains fields used by various Plan endpoints. -type ZonePlanCommon struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - Price int `json:"price,omitempty"` - Currency string `json:"currency,omitempty"` - Frequency string `json:"frequency,omitempty"` -} - -type zoneRatePlanComponents struct { - Name string `json:"name"` - Default int `json:"Default"` - UnitPrice int `json:"unit_price"` -} - -// ZoneID contains only the zone ID. -type ZoneID struct { - ID string `json:"id"` -} - -// ZoneResponse represents the response from the Zone endpoint containing a single zone. -type ZoneResponse struct { - Response - Result Zone `json:"result"` -} - -// ZonesResponse represents the response from the Zone endpoint containing an array of zones. -type ZonesResponse struct { - Response - Result []Zone `json:"result"` - ResultInfo `json:"result_info"` -} - -// ZoneIDResponse represents the response from the Zone endpoint, containing only a zone ID. -type ZoneIDResponse struct { - Response - Result ZoneID `json:"result"` -} - -// AvailableZoneRatePlansResponse represents the response from the Available Rate Plans endpoint. -type AvailableZoneRatePlansResponse struct { - Response - Result []ZoneRatePlan `json:"result"` - ResultInfo `json:"result_info"` -} - -// AvailableZonePlansResponse represents the response from the Available Plans endpoint. -type AvailableZonePlansResponse struct { - Response - Result []ZonePlan `json:"result"` - ResultInfo -} - -// ZoneRatePlanResponse represents the response from the Plan Details endpoint. -type ZoneRatePlanResponse struct { - Response - Result ZoneRatePlan `json:"result"` -} - -// ZoneSetting contains settings for a zone. -type ZoneSetting struct { - ID string `json:"id"` - Editable bool `json:"editable"` - ModifiedOn string `json:"modified_on,omitempty"` - Value interface{} `json:"value"` - TimeRemaining int `json:"time_remaining"` -} - -// ZoneSettingResponse represents the response from the Zone Setting endpoint. -type ZoneSettingResponse struct { - Response - Result []ZoneSetting `json:"result"` -} - -// ZoneSettingSingleResponse represents the response from the Zone Setting endpoint for the specified setting. -type ZoneSettingSingleResponse struct { - Response - Result ZoneSetting `json:"result"` -} - -// ZoneSSLSetting contains ssl setting for a zone. -type ZoneSSLSetting struct { - ID string `json:"id"` - Editable bool `json:"editable"` - ModifiedOn string `json:"modified_on"` - Value string `json:"value"` - CertificateStatus string `json:"certificate_status"` -} - -// ZoneSSLSettingResponse represents the response from the Zone SSL Setting -// endpoint. -type ZoneSSLSettingResponse struct { - Response - Result ZoneSSLSetting `json:"result"` -} - -// ZoneAnalyticsData contains totals and timeseries analytics data for a zone. -type ZoneAnalyticsData struct { - Totals ZoneAnalytics `json:"totals"` - Timeseries []ZoneAnalytics `json:"timeseries"` -} - -// zoneAnalyticsDataResponse represents the response from the Zone Analytics Dashboard endpoint. -type zoneAnalyticsDataResponse struct { - Response - Result ZoneAnalyticsData `json:"result"` -} - -// ZoneAnalyticsColocation contains analytics data by datacenter. -type ZoneAnalyticsColocation struct { - ColocationID string `json:"colo_id"` - Timeseries []ZoneAnalytics `json:"timeseries"` -} - -// zoneAnalyticsColocationResponse represents the response from the Zone Analytics By Co-location endpoint. -type zoneAnalyticsColocationResponse struct { - Response - Result []ZoneAnalyticsColocation `json:"result"` -} - -// ZoneAnalytics contains analytics data for a zone. -type ZoneAnalytics struct { - Since time.Time `json:"since"` - Until time.Time `json:"until"` - Requests struct { - All int `json:"all"` - Cached int `json:"cached"` - Uncached int `json:"uncached"` - ContentType map[string]int `json:"content_type"` - Country map[string]int `json:"country"` - SSL struct { - Encrypted int `json:"encrypted"` - Unencrypted int `json:"unencrypted"` - } `json:"ssl"` - HTTPStatus map[string]int `json:"http_status"` - } `json:"requests"` - Bandwidth struct { - All int `json:"all"` - Cached int `json:"cached"` - Uncached int `json:"uncached"` - ContentType map[string]int `json:"content_type"` - Country map[string]int `json:"country"` - SSL struct { - Encrypted int `json:"encrypted"` - Unencrypted int `json:"unencrypted"` - } `json:"ssl"` - } `json:"bandwidth"` - Threats struct { - All int `json:"all"` - Country map[string]int `json:"country"` - Type map[string]int `json:"type"` - } `json:"threats"` - Pageviews struct { - All int `json:"all"` - SearchEngines map[string]int `json:"search_engines"` - } `json:"pageviews"` - Uniques struct { - All int `json:"all"` - } -} - -// ZoneAnalyticsOptions represents the optional parameters in Zone Analytics -// endpoint requests. -type ZoneAnalyticsOptions struct { - Since *time.Time - Until *time.Time - Continuous *bool -} - -// PurgeCacheRequest represents the request format made to the purge endpoint. -type PurgeCacheRequest struct { - Everything bool `json:"purge_everything,omitempty"` - // Purge by filepath (exact match). Limit of 30 - Files []string `json:"files,omitempty"` - // Purge by Tag (Enterprise only): - // https://support.cloudflare.com/hc/en-us/articles/206596608-How-to-Purge-Cache-Using-Cache-Tags-Enterprise-only- - Tags []string `json:"tags,omitempty"` - // Purge by hostname - e.g. "assets.example.com" - Hosts []string `json:"hosts,omitempty"` - // Purge by prefix - e.g. "example.com/css" - Prefixes []string `json:"prefixes,omitempty"` -} - -// PurgeCacheResponse represents the response from the purge endpoint. -type PurgeCacheResponse struct { - Response - Result struct { - ID string `json:"id"` - } `json:"result"` -} - -// newZone describes a new zone. -type newZone struct { - Name string `json:"name"` - JumpStart bool `json:"jump_start"` - Type string `json:"type"` - // We use a pointer to get a nil type when the field is empty. - // This allows us to completely omit this with json.Marshal(). - Account *Account `json:"organization,omitempty"` -} - -// FallbackOrigin describes a fallback origin. -type FallbackOrigin struct { - Value string `json:"value"` - ID string `json:"id,omitempty"` -} - -// FallbackOriginResponse represents the response from the fallback_origin endpoint. -type FallbackOriginResponse struct { - Response - Result FallbackOrigin `json:"result"` -} - -// zoneSubscriptionRatePlanPayload is used to build the JSON payload for -// setting a particular rate plan on an existing zone. -type zoneSubscriptionRatePlanPayload struct { - RatePlan struct { - ID string `json:"id"` - } `json:"rate_plan"` -} - -// CreateZone creates a zone on an account. -// -// Setting jumpstart to true will attempt to automatically scan for existing -// DNS records. Setting this to false will create the zone with no DNS records. -// -// If account is non-empty, it must have at least the ID field populated. -// This will add the new zone to the specified multi-user account. -// -// API reference: https://api.cloudflare.com/#zone-create-a-zone -func (api *API) CreateZone(ctx context.Context, name string, jumpstart bool, account Account, zoneType string) (Zone, error) { - var newzone newZone - newzone.Name = name - newzone.JumpStart = jumpstart - if account.ID != "" { - newzone.Account = &account - } - - if zoneType == "partial" { - newzone.Type = "partial" - } else { - newzone.Type = "full" - } - - res, err := api.makeRequestContext(ctx, http.MethodPost, "/zones", newzone) - if err != nil { - return Zone{}, err - } - - var r ZoneResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ZoneActivationCheck initiates another zone activation check for newly-created zones. -// -// API reference: https://api.cloudflare.com/#zone-initiate-another-zone-activation-check -func (api *API) ZoneActivationCheck(ctx context.Context, zoneID string) (Response, error) { - res, err := api.makeRequestContext(ctx, http.MethodPut, "/zones/"+zoneID+"/activation_check", nil) - if err != nil { - return Response{}, err - } - var r Response - err = json.Unmarshal(res, &r) - if err != nil { - return Response{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r, nil -} - -// ListZones lists zones on an account. Optionally takes a list of zone names -// to filter against. -// -// API reference: https://api.cloudflare.com/#zone-list-zones -func (api *API) ListZones(ctx context.Context, z ...string) ([]Zone, error) { - var zones []Zone - if len(z) > 0 { - var ( - v = url.Values{} - r ZonesResponse - ) - for _, zone := range z { - v.Set("name", normalizeZoneName(zone)) - res, err := api.makeRequestContext(ctx, http.MethodGet, "/zones?"+v.Encode(), nil) - if err != nil { - return []Zone{}, err - } - err = json.Unmarshal(res, &r) - if err != nil { - return []Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - if !r.Success { - // TODO: Provide an actual error message instead of always returning nil - return []Zone{}, err - } - zones = append(zones, r.Result...) - } - } else { - res, err := api.ListZonesContext(ctx) - if err != nil { - return nil, err - } - - zones = res.Result - } - - return zones, nil -} - -const listZonesPerPage = 50 - -// listZonesFetch fetches one page of zones. -// This is placed as a separate function to prevent any possibility of unintended capturing. -func (api *API) listZonesFetch(ctx context.Context, wg *sync.WaitGroup, errc chan error, - path string, pageSize int, buf []Zone) { - defer wg.Done() - - // recordError sends the error to errc in a non-blocking manner - recordError := func(err error) { - select { - case errc <- err: - default: - } - } - - res, err := api.makeRequestContext(ctx, http.MethodGet, path, nil) - if err != nil { - recordError(err) - return - } - - var r ZonesResponse - err = json.Unmarshal(res, &r) - if err != nil { - recordError(err) - return - } - - if len(r.Result) != pageSize { - recordError(errors.New(errResultInfo)) - return - } - - copy(buf, r.Result) -} - -// ListZonesContext lists all zones on an account automatically handling the -// pagination. Optionally takes a list of ReqOptions. -func (api *API) ListZonesContext(ctx context.Context, opts ...ReqOption) (r ZonesResponse, err error) { - opt := reqOption{ - params: url.Values{}, - } - for _, of := range opts { - of(&opt) - } - - if opt.params.Get("page") != "" || opt.params.Get("per_page") != "" { - return ZonesResponse{}, errors.New(errManualPagination) - } - - opt.params.Add("per_page", strconv.Itoa(listZonesPerPage)) - - res, err := api.makeRequestContext(ctx, http.MethodGet, "/zones?"+opt.params.Encode(), nil) - if err != nil { - return ZonesResponse{}, err - } - err = json.Unmarshal(res, &r) - if err != nil { - return ZonesResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - // avoid overhead in most common cases where the total #zones <= 50 - if r.TotalPages < 2 { - return r, nil - } - - // parameters of pagination - var ( - totalPageCount = r.TotalPages - totalCount = r.Total - - // zones is a large slice to prevent resizing during concurrent writes. - zones = make([]Zone, totalCount) - ) - - // Copy the first page into zones. - copy(zones, r.Result) - - var wg sync.WaitGroup - wg.Add(totalPageCount - 1) // all pages except the first one. - errc := make(chan error, 1) // getting the first error - - // Creating all the workers. - for pageNum := 2; pageNum <= totalPageCount; pageNum++ { - // Note: URL.Values is just a map[string], so this would override the existing 'page' - opt.params.Set("page", strconv.Itoa(pageNum)) - - // start is the first index in the zone buffer - start := listZonesPerPage * (pageNum - 1) - - pageSize := listZonesPerPage - if pageNum == totalPageCount { - // The size of the last page (which would be <= 50). - pageSize = totalCount - start - } - - go api.listZonesFetch(ctx, &wg, errc, "/zones?"+opt.params.Encode(), pageSize, zones[start:]) - } - - wg.Wait() - - select { - case err := <-errc: // if there were any errors - return ZonesResponse{}, err - default: // if there were no errors, the receive statement should block - r.Result = zones - return r, nil - } -} - -// ZoneDetails fetches information about a zone. -// -// API reference: https://api.cloudflare.com/#zone-zone-details -func (api *API) ZoneDetails(ctx context.Context, zoneID string) (Zone, error) { - res, err := api.makeRequestContext(ctx, http.MethodGet, "/zones/"+zoneID, nil) - if err != nil { - return Zone{}, err - } - var r ZoneResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ZoneOptions is a subset of Zone, for editable options. -type ZoneOptions struct { - Paused *bool `json:"paused,omitempty"` - VanityNS []string `json:"vanity_name_servers,omitempty"` - Plan *ZonePlan `json:"plan,omitempty"` - Type string `json:"type,omitempty"` -} - -// ZoneSetPaused pauses Cloudflare service for the entire zone, sending all -// traffic direct to the origin. -func (api *API) ZoneSetPaused(ctx context.Context, zoneID string, paused bool) (Zone, error) { - zoneopts := ZoneOptions{Paused: &paused} - zone, err := api.EditZone(ctx, zoneID, zoneopts) - if err != nil { - return Zone{}, err - } - - return zone, nil -} - -// ZoneSetType toggles the type for an existing zone. -// -// Valid values for `type` are "full" and "partial" -// -// API reference: https://api.cloudflare.com/#zone-edit-zone -func (api *API) ZoneSetType(ctx context.Context, zoneID string, zoneType string) (Zone, error) { - zoneopts := ZoneOptions{Type: zoneType} - zone, err := api.EditZone(ctx, zoneID, zoneopts) - if err != nil { - return Zone{}, err - } - - return zone, nil -} - -// ZoneSetVanityNS sets custom nameservers for the zone. -// These names must be within the same zone. -func (api *API) ZoneSetVanityNS(ctx context.Context, zoneID string, ns []string) (Zone, error) { - zoneopts := ZoneOptions{VanityNS: ns} - zone, err := api.EditZone(ctx, zoneID, zoneopts) - if err != nil { - return Zone{}, err - } - - return zone, nil -} - -// ZoneSetPlan sets the rate plan of an existing zone. -// -// Valid values for `planType` are "CF_FREE", "CF_PRO", "CF_BIZ" and -// "CF_ENT". -// -// API reference: https://api.cloudflare.com/#zone-subscription-create-zone-subscription -func (api *API) ZoneSetPlan(ctx context.Context, zoneID string, planType string) error { - zonePayload := zoneSubscriptionRatePlanPayload{} - zonePayload.RatePlan.ID = planType - - uri := fmt.Sprintf("/zones/%s/subscription", zoneID) - - _, err := api.makeRequestContext(ctx, http.MethodPost, uri, zonePayload) - if err != nil { - return err - } - - return nil -} - -// ZoneUpdatePlan updates the rate plan of an existing zone. -// -// Valid values for `planType` are "CF_FREE", "CF_PRO", "CF_BIZ" and -// "CF_ENT". -// -// API reference: https://api.cloudflare.com/#zone-subscription-update-zone-subscription -func (api *API) ZoneUpdatePlan(ctx context.Context, zoneID string, planType string) error { - zonePayload := zoneSubscriptionRatePlanPayload{} - zonePayload.RatePlan.ID = planType - - uri := fmt.Sprintf("/zones/%s/subscription", zoneID) - - _, err := api.makeRequestContext(ctx, http.MethodPut, uri, zonePayload) - if err != nil { - return err - } - - return nil -} - -// EditZone edits the given zone. -// -// This is usually called by ZoneSetPaused, ZoneSetType, or ZoneSetVanityNS. -// -// API reference: https://api.cloudflare.com/#zone-edit-zone-properties -func (api *API) EditZone(ctx context.Context, zoneID string, zoneOpts ZoneOptions) (Zone, error) { - res, err := api.makeRequestContext(ctx, http.MethodPatch, "/zones/"+zoneID, zoneOpts) - if err != nil { - return Zone{}, err - } - var r ZoneResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// PurgeEverything purges the cache for the given zone. -// -// Note: this will substantially increase load on the origin server for that -// zone if there is a high cached vs. uncached request ratio. -// -// API reference: https://api.cloudflare.com/#zone-purge-all-files -func (api *API) PurgeEverything(ctx context.Context, zoneID string) (PurgeCacheResponse, error) { - uri := fmt.Sprintf("/zones/%s/purge_cache", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, PurgeCacheRequest{true, nil, nil, nil, nil}) - if err != nil { - return PurgeCacheResponse{}, err - } - var r PurgeCacheResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PurgeCacheResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r, nil -} - -// PurgeCache purges the cache using the given PurgeCacheRequest (zone/url/tag). -// -// API reference: https://api.cloudflare.com/#zone-purge-individual-files-by-url-and-cache-tags -func (api *API) PurgeCache(ctx context.Context, zoneID string, pcr PurgeCacheRequest) (PurgeCacheResponse, error) { - return api.PurgeCacheContext(ctx, zoneID, pcr) -} - -// PurgeCacheContext purges the cache using the given PurgeCacheRequest (zone/url/tag). -// -// API reference: https://api.cloudflare.com/#zone-purge-individual-files-by-url-and-cache-tags -func (api *API) PurgeCacheContext(ctx context.Context, zoneID string, pcr PurgeCacheRequest) (PurgeCacheResponse, error) { - uri := fmt.Sprintf("/zones/%s/purge_cache", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, pcr) - if err != nil { - return PurgeCacheResponse{}, err - } - var r PurgeCacheResponse - err = json.Unmarshal(res, &r) - if err != nil { - return PurgeCacheResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r, nil -} - -// DeleteZone deletes the given zone. -// -// API reference: https://api.cloudflare.com/#zone-delete-a-zone -func (api *API) DeleteZone(ctx context.Context, zoneID string) (ZoneID, error) { - res, err := api.makeRequestContext(ctx, http.MethodDelete, "/zones/"+zoneID, nil) - if err != nil { - return ZoneID{}, err - } - var r ZoneIDResponse - err = json.Unmarshal(res, &r) - if err != nil { - return ZoneID{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// AvailableZoneRatePlans returns information about all plans available to the specified zone. -// -// API reference: https://api.cloudflare.com/#zone-plan-available-plans -func (api *API) AvailableZoneRatePlans(ctx context.Context, zoneID string) ([]ZoneRatePlan, error) { - uri := fmt.Sprintf("/zones/%s/available_rate_plans", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []ZoneRatePlan{}, err - } - var r AvailableZoneRatePlansResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []ZoneRatePlan{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// AvailableZonePlans returns information about all plans available to the specified zone. -// -// API reference: https://api.cloudflare.com/#zone-rate-plan-list-available-plans -func (api *API) AvailableZonePlans(ctx context.Context, zoneID string) ([]ZonePlan, error) { - uri := fmt.Sprintf("/zones/%s/available_plans", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return []ZonePlan{}, err - } - var r AvailableZonePlansResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []ZonePlan{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// encode encodes non-nil fields into URL encoded form. -func (o ZoneAnalyticsOptions) encode() string { - v := url.Values{} - if o.Since != nil { - v.Set("since", (*o.Since).Format(time.RFC3339)) - } - if o.Until != nil { - v.Set("until", (*o.Until).Format(time.RFC3339)) - } - if o.Continuous != nil { - v.Set("continuous", fmt.Sprintf("%t", *o.Continuous)) - } - return v.Encode() -} - -// ZoneAnalyticsDashboard returns zone analytics information. -// -// API reference: https://api.cloudflare.com/#zone-analytics-dashboard -func (api *API) ZoneAnalyticsDashboard(ctx context.Context, zoneID string, options ZoneAnalyticsOptions) (ZoneAnalyticsData, error) { - uri := fmt.Sprintf("/zones/%s/analytics/dashboard?%s", zoneID, options.encode()) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ZoneAnalyticsData{}, err - } - var r zoneAnalyticsDataResponse - err = json.Unmarshal(res, &r) - if err != nil { - return ZoneAnalyticsData{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ZoneAnalyticsByColocation returns zone analytics information by datacenter. -// -// API reference: https://api.cloudflare.com/#zone-analytics-analytics-by-co-locations -func (api *API) ZoneAnalyticsByColocation(ctx context.Context, zoneID string, options ZoneAnalyticsOptions) ([]ZoneAnalyticsColocation, error) { - uri := fmt.Sprintf("/zones/%s/analytics/colos?%s", zoneID, options.encode()) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - var r zoneAnalyticsColocationResponse - err = json.Unmarshal(res, &r) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// ZoneSettings returns all of the settings for a given zone. -// -// API reference: https://api.cloudflare.com/#zone-settings-get-all-zone-settings -func (api *API) ZoneSettings(ctx context.Context, zoneID string) (*ZoneSettingResponse, error) { - uri := fmt.Sprintf("/zones/%s/settings", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, err - } - - response := &ZoneSettingResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// UpdateZoneSettings updates the settings for a given zone. -// -// API reference: https://api.cloudflare.com/#zone-settings-edit-zone-settings-info -func (api *API) UpdateZoneSettings(ctx context.Context, zoneID string, settings []ZoneSetting) (*ZoneSettingResponse, error) { - uri := fmt.Sprintf("/zones/%s/settings", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, struct { - Items []ZoneSetting `json:"items"` - }{settings}) - if err != nil { - return nil, err - } - - response := &ZoneSettingResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// ZoneSSLSettings returns information about SSL setting to the specified zone. -// -// API reference: https://api.cloudflare.com/#zone-settings-get-ssl-setting -func (api *API) ZoneSSLSettings(ctx context.Context, zoneID string) (ZoneSSLSetting, error) { - uri := fmt.Sprintf("/zones/%s/settings/ssl", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ZoneSSLSetting{}, err - } - var r ZoneSSLSettingResponse - err = json.Unmarshal(res, &r) - if err != nil { - return ZoneSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateZoneSSLSettings update information about SSL setting to the specified zone. -// -// API reference: https://api.cloudflare.com/#zone-settings-change-ssl-setting -func (api *API) UpdateZoneSSLSettings(ctx context.Context, zoneID string, sslValue string) (ZoneSSLSetting, error) { - uri := fmt.Sprintf("/zones/%s/settings/ssl", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, ZoneSSLSetting{Value: sslValue}) - if err != nil { - return ZoneSSLSetting{}, err - } - var r ZoneSSLSettingResponse - err = json.Unmarshal(res, &r) - if err != nil { - return ZoneSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// FallbackOrigin returns information about the fallback origin for the specified zone. -// -// API reference: https://developers.cloudflare.com/ssl/ssl-for-saas/api-calls/#fallback-origin-configuration -func (api *API) FallbackOrigin(ctx context.Context, zoneID string) (FallbackOrigin, error) { - uri := fmt.Sprintf("/zones/%s/fallback_origin", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return FallbackOrigin{}, err - } - - var r FallbackOriginResponse - err = json.Unmarshal(res, &r) - if err != nil { - return FallbackOrigin{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return r.Result, nil -} - -// UpdateFallbackOrigin updates the fallback origin for a given zone. -// -// API reference: https://developers.cloudflare.com/ssl/ssl-for-saas/api-calls/#4-example-patch-to-change-fallback-origin -func (api *API) UpdateFallbackOrigin(ctx context.Context, zoneID string, fbo FallbackOrigin) (*FallbackOriginResponse, error) { - uri := fmt.Sprintf("/zones/%s/fallback_origin", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, fbo) - if err != nil { - return nil, err - } - - response := &FallbackOriginResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// normalizeZoneName tries to convert IDNs (international domain names) -// from Punycode to Unicode form. If the given zone name is not represented -// as Punycode, or converting fails (for invalid representations), it -// is returned unchanged. -// -// Because all the zone name comparison is currently done using the API service -// (except for comparison with the empty string), theoretically, we could -// remove this function from the Go library. However, there should be no harm -// calling this function other than gelable performance penalty. -// -// Note: conversion errors are silently discarded. -func normalizeZoneName(name string) string { - if n, err := idna.ToUnicode(name); err == nil { - return n - } - return name -} - -// ZoneSingleSetting returns information about specified setting to the specified zone. -// -// API reference: https://api.cloudflare.com/#zone-settings-get-all-zone-settings -func (api *API) ZoneSingleSetting(ctx context.Context, zoneID, settingName string) (ZoneSetting, error) { - uri := fmt.Sprintf("/zones/%s/settings/%s", zoneID, settingName) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ZoneSetting{}, err - } - var r ZoneSettingSingleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return ZoneSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateZoneSingleSetting updates the specified setting for a given zone. -// -// API reference: https://api.cloudflare.com/#zone-settings-edit-zone-settings-info -func (api *API) UpdateZoneSingleSetting(ctx context.Context, zoneID, settingName string, setting ZoneSetting) (*ZoneSettingSingleResponse, error) { - uri := fmt.Sprintf("/zones/%s/settings/%s", zoneID, settingName) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, setting) - if err != nil { - return nil, err - } - - response := &ZoneSettingSingleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response, nil -} - -// ZoneExport returns the text BIND config for the given zone -// -// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-export-dns-records -func (api *API) ZoneExport(ctx context.Context, zoneID string) (string, error) { - res, err := api.makeRequestContext(ctx, http.MethodGet, "/zones/"+zoneID+"/dns_records/export", nil) - if err != nil { - return "", err - } - return string(res), nil -} - -// ZoneDNSSECResponse represents the response from the Zone DNSSEC Setting. -type ZoneDNSSECResponse struct { - Response - Result ZoneDNSSEC `json:"result"` -} - -// ZoneDNSSEC represents the response from the Zone DNSSEC Setting result. -type ZoneDNSSEC struct { - Status string `json:"status"` - Flags int `json:"flags"` - Algorithm string `json:"algorithm"` - KeyType string `json:"key_type"` - DigestType string `json:"digest_type"` - DigestAlgorithm string `json:"digest_algorithm"` - Digest string `json:"digest"` - DS string `json:"ds"` - KeyTag int `json:"key_tag"` - PublicKey string `json:"public_key"` - ModifiedOn time.Time `json:"modified_on"` -} - -// ZoneDNSSECSetting returns the DNSSEC details of a zone -// -// API reference: https://api.cloudflare.com/#dnssec-dnssec-details -func (api *API) ZoneDNSSECSetting(ctx context.Context, zoneID string) (ZoneDNSSEC, error) { - res, err := api.makeRequestContext(ctx, http.MethodGet, "/zones/"+zoneID+"/dnssec", nil) - if err != nil { - return ZoneDNSSEC{}, err - } - response := ZoneDNSSECResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return ZoneDNSSEC{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// ZoneDNSSECDeleteResponse represents the response from the Zone DNSSEC Delete request. -type ZoneDNSSECDeleteResponse struct { - Response - Result string `json:"result"` -} - -// DeleteZoneDNSSEC deletes DNSSEC for zone -// -// API reference: https://api.cloudflare.com/#dnssec-delete-dnssec-records -func (api *API) DeleteZoneDNSSEC(ctx context.Context, zoneID string) (string, error) { - res, err := api.makeRequestContext(ctx, http.MethodDelete, "/zones/"+zoneID+"/dnssec", nil) - if err != nil { - return "", err - } - response := ZoneDNSSECDeleteResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return "", fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return response.Result, nil -} - -// ZoneDNSSECUpdateOptions represents the options for DNSSEC update. -type ZoneDNSSECUpdateOptions struct { - Status string `json:"status"` -} - -// UpdateZoneDNSSEC updates DNSSEC for a zone -// -// API reference: https://api.cloudflare.com/#dnssec-edit-dnssec-status -func (api *API) UpdateZoneDNSSEC(ctx context.Context, zoneID string, options ZoneDNSSECUpdateOptions) (ZoneDNSSEC, error) { - res, err := api.makeRequestContext(ctx, http.MethodPatch, "/zones/"+zoneID+"/dnssec", options) - if err != nil { - return ZoneDNSSEC{}, err - } - response := ZoneDNSSECResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return ZoneDNSSEC{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return response.Result, nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/zone_cache_variants.go b/vendor/github.com/cloudflare/cloudflare-go/zone_cache_variants.go deleted file mode 100644 index f7a18d5..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/zone_cache_variants.go +++ /dev/null @@ -1,88 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" -) - -type ZoneCacheVariantsValues struct { - Avif []string `json:"avif,omitempty"` - Bmp []string `json:"bmp,omitempty"` - Gif []string `json:"gif,omitempty"` - Jpeg []string `json:"jpeg,omitempty"` - Jpg []string `json:"jpg,omitempty"` - Jpg2 []string `json:"jpg2,omitempty"` - Jp2 []string `json:"jp2,omitempty"` - Png []string `json:"png,omitempty"` - Tiff []string `json:"tiff,omitempty"` - Tif []string `json:"tif,omitempty"` - Webp []string `json:"webp,omitempty"` -} - -type ZoneCacheVariants struct { - ModifiedOn time.Time `json:"modified_on"` - Value ZoneCacheVariantsValues `json:"value"` -} - -type updateZoneCacheVariantsRequest struct { - Value ZoneCacheVariantsValues `json:"value"` -} - -type zoneCacheVariantsSingleResponse struct { - Response - Result ZoneCacheVariants `json:"result"` -} - -// ZoneCacheVariants returns information about the current cache variants -// -// API reference: https://api.cloudflare.com/#zone-cache-settings-get-variants-setting -func (api *API) ZoneCacheVariants(ctx context.Context, zoneID string) (ZoneCacheVariants, error) { - uri := fmt.Sprintf("/zones/%s/cache/variants", zoneID) - res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) - if err != nil { - return ZoneCacheVariants{}, err - } - var r zoneCacheVariantsSingleResponse - err = json.Unmarshal(res, &r) - if err != nil { - return ZoneCacheVariants{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - return r.Result, nil -} - -// UpdateZoneCacheVariants updates the cache variants for a given zone. -// -// API reference: https://api.cloudflare.com/#zone-cache-settings-change-variants-setting -func (api *API) UpdateZoneCacheVariants(ctx context.Context, zoneID string, variants ZoneCacheVariantsValues) (ZoneCacheVariants, error) { - uri := fmt.Sprintf("/zones/%s/cache/variants", zoneID) - - updateReq := updateZoneCacheVariantsRequest{Value: variants} - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, updateReq) - if err != nil { - return ZoneCacheVariants{}, err - } - - response := &zoneCacheVariantsSingleResponse{} - err = json.Unmarshal(res, &response) - if err != nil { - return ZoneCacheVariants{}, fmt.Errorf("%s: %w", errUnmarshalError, err) - } - - return response.Result, nil -} - -// DeleteZoneCacheVariants deletes cache variants for a given zone. -// -// API reference: https://api.cloudflare.com/#zone-cache-settings-delete-variants-setting -func (api *API) DeleteZoneCacheVariants(ctx context.Context, zoneID string) error { - uri := fmt.Sprintf("/zones/%s/cache/variants", zoneID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/cloudflare/cloudflare-go/zones.go b/vendor/github.com/cloudflare/cloudflare-go/zones.go deleted file mode 100644 index f932e2c..0000000 --- a/vendor/github.com/cloudflare/cloudflare-go/zones.go +++ /dev/null @@ -1,143 +0,0 @@ -package cloudflare - -import ( - "context" - "encoding/json" - "fmt" -) - -const defaultZonesPerPage = 100 - -type ZonesService service - -type ZoneCreateParams struct { - Name string `json:"name"` - JumpStart bool `json:"jump_start"` - Type string `json:"type"` - Account *Account `json:"organization,omitempty"` -} - -type ZoneListParams struct { - Match string `url:"match,omitempty"` - Name string `url:"name,omitempty"` - AccountName string `url:"account.name,omitempty"` - Status string `url:"status,omitempty"` - AccountID string `url:"account.id,omitempty"` - Direction string `url:"direction,omitempty"` - - ResultInfo // Rename `ResultInfo` in the next major version. -} - -type ZoneUpdateParams struct { - ID string - Paused *bool `json:"paused"` - VanityNameServers []string `json:"vanity_name_servers,omitempty"` - Plan ZonePlan `json:"plan,omitempty"` - Type string `json:"type,omitempty"` -} - -// New creates a new zone. -// -// API reference: https://api.cloudflare.com/#zone-zone-details -func (s *ZonesService) New(ctx context.Context, zone *ZoneCreateParams) (Zone, error) { - res, err := s.client.post(ctx, "/zones", zone) - if err != nil { - return Zone{}, err - } - - var r ZoneResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Zone{}, fmt.Errorf("failed to unmarshal zone JSON data: %w", err) - } - - return r.Result, nil -} - -// Get fetches a single zone. -// -// API reference: https://api.cloudflare.com/#zone-zone-details -func (s *ZonesService) Get(ctx context.Context, rc *ResourceContainer) (Zone, error) { - uri := fmt.Sprintf("/zones/%s", rc.Identifier) - res, err := s.client.get(ctx, uri, nil) - if err != nil { - return Zone{}, fmt.Errorf("failed to fetch zones: %w", err) - } - - var r ZoneResponse - err = json.Unmarshal(res, &r) - if err != nil { - return Zone{}, fmt.Errorf("failed to unmarshal zone JSON data: %w", err) - } - - return r.Result, nil -} - -// List returns all zones that match the provided `ZoneParams` struct. -// -// Pagination is automatically handled unless `params.Page` is supplied. -// -// API reference: https://api.cloudflare.com/#zone-list-zones -func (s *ZonesService) List(ctx context.Context, params *ZoneListParams) ([]Zone, *ResultInfo, error) { - res, _ := s.client.get(ctx, buildURI("/zones", params), nil) - - var r ZonesResponse - err := json.Unmarshal(res, &r) - if err != nil { - return []Zone{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal zone JSON data: %w", err) - } - - if params.Page < 1 && params.PerPage < 1 { - var zones []Zone - params.PerPage = defaultZonesPerPage - params.Page = 1 - for !params.ResultInfo.Done() { - res, _ := s.client.get(ctx, buildURI("/zones", params), nil) - - var zResponse ZonesResponse - err := json.Unmarshal(res, &zResponse) - if err != nil { - return []Zone{}, &ResultInfo{}, fmt.Errorf("failed to unmarshal zone JSON data: %w", err) - } - - zones = append(zones, zResponse.Result...) - - params.ResultInfo = zResponse.ResultInfo.Next() - } - r.Result = zones - } - - return r.Result, &r.ResultInfo, nil -} - -// Update modifies an existing zone. -// -// API reference: https://api.cloudflare.com/#zone-edit-zone -func (s *ZonesService) Update(ctx context.Context, params *ZoneUpdateParams) ([]Zone, error) { - uri := fmt.Sprintf("/zones/%s", params.ID) - res, _ := s.client.patch(ctx, uri, params) - - var r ZonesResponse - err := json.Unmarshal(res, &r) - if err != nil { - return []Zone{}, fmt.Errorf("failed to unmarshal zone JSON data: %w", err) - } - - return r.Result, nil -} - -// Delete deletes a zone based on ID. -// -// API reference: https://api.cloudflare.com/#zone-delete-zone -func (s *ZonesService) Delete(ctx context.Context, rc *ResourceContainer) error { - uri := fmt.Sprintf("/zones/%s", rc.Identifier) - res, _ := s.client.delete(ctx, uri, nil) - - var r ZoneResponse - err := json.Unmarshal(res, &r) - if err != nil { - return fmt.Errorf("failed to unmarshal zone JSON data: %w", err) - } - - return nil -} diff --git a/vendor/github.com/google/go-querystring/LICENSE b/vendor/github.com/google/go-querystring/LICENSE deleted file mode 100644 index ae121a1..0000000 --- a/vendor/github.com/google/go-querystring/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2013 Google. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/google/go-querystring/query/encode.go b/vendor/github.com/google/go-querystring/query/encode.go deleted file mode 100644 index 91198f8..0000000 --- a/vendor/github.com/google/go-querystring/query/encode.go +++ /dev/null @@ -1,357 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package query implements encoding of structs into URL query parameters. -// -// As a simple example: -// -// type Options struct { -// Query string `url:"q"` -// ShowAll bool `url:"all"` -// Page int `url:"page"` -// } -// -// opt := Options{ "foo", true, 2 } -// v, _ := query.Values(opt) -// fmt.Print(v.Encode()) // will output: "q=foo&all=true&page=2" -// -// The exact mapping between Go values and url.Values is described in the -// documentation for the Values() function. -package query - -import ( - "bytes" - "fmt" - "net/url" - "reflect" - "strconv" - "strings" - "time" -) - -var timeType = reflect.TypeOf(time.Time{}) - -var encoderType = reflect.TypeOf(new(Encoder)).Elem() - -// Encoder is an interface implemented by any type that wishes to encode -// itself into URL values in a non-standard way. -type Encoder interface { - EncodeValues(key string, v *url.Values) error -} - -// Values returns the url.Values encoding of v. -// -// Values expects to be passed a struct, and traverses it recursively using the -// following encoding rules. -// -// Each exported struct field is encoded as a URL parameter unless -// -// - the field's tag is "-", or -// - the field is empty and its tag specifies the "omitempty" option -// -// The empty values are false, 0, any nil pointer or interface value, any array -// slice, map, or string of length zero, and any type (such as time.Time) that -// returns true for IsZero(). -// -// The URL parameter name defaults to the struct field name but can be -// specified in the struct field's tag value. The "url" key in the struct -// field's tag value is the key name, followed by an optional comma and -// options. For example: -// -// // Field is ignored by this package. -// Field int `url:"-"` -// -// // Field appears as URL parameter "myName". -// Field int `url:"myName"` -// -// // Field appears as URL parameter "myName" and the field is omitted if -// // its value is empty -// Field int `url:"myName,omitempty"` -// -// // Field appears as URL parameter "Field" (the default), but the field -// // is skipped if empty. Note the leading comma. -// Field int `url:",omitempty"` -// -// For encoding individual field values, the following type-dependent rules -// apply: -// -// Boolean values default to encoding as the strings "true" or "false". -// Including the "int" option signals that the field should be encoded as the -// strings "1" or "0". -// -// time.Time values default to encoding as RFC3339 timestamps. Including the -// "unix" option signals that the field should be encoded as a Unix time (see -// time.Unix()). The "unixmilli" and "unixnano" options will encode the number -// of milliseconds and nanoseconds, respectively, since January 1, 1970 (see -// time.UnixNano()). Including the "layout" struct tag (separate from the -// "url" tag) will use the value of the "layout" tag as a layout passed to -// time.Format. For example: -// -// // Encode a time.Time as YYYY-MM-DD -// Field time.Time `layout:"2006-01-02"` -// -// Slice and Array values default to encoding as multiple URL values of the -// same name. Including the "comma" option signals that the field should be -// encoded as a single comma-delimited value. Including the "space" option -// similarly encodes the value as a single space-delimited string. Including -// the "semicolon" option will encode the value as a semicolon-delimited string. -// Including the "brackets" option signals that the multiple URL values should -// have "[]" appended to the value name. "numbered" will append a number to -// the end of each incidence of the value name, example: -// name0=value0&name1=value1, etc. Including the "del" struct tag (separate -// from the "url" tag) will use the value of the "del" tag as the delimiter. -// For example: -// -// // Encode a slice of bools as ints ("1" for true, "0" for false), -// // separated by exclamation points "!". -// Field []bool `url:",int" del:"!"` -// -// Anonymous struct fields are usually encoded as if their inner exported -// fields were fields in the outer struct, subject to the standard Go -// visibility rules. An anonymous struct field with a name given in its URL -// tag is treated as having that name, rather than being anonymous. -// -// Non-nil pointer values are encoded as the value pointed to. -// -// Nested structs are encoded including parent fields in value names for -// scoping. e.g: -// -// "user[name]=acme&user[addr][postcode]=1234&user[addr][city]=SFO" -// -// All other values are encoded using their default string representation. -// -// Multiple fields that encode to the same URL parameter name will be included -// as multiple URL values of the same name. -func Values(v interface{}) (url.Values, error) { - values := make(url.Values) - val := reflect.ValueOf(v) - for val.Kind() == reflect.Ptr { - if val.IsNil() { - return values, nil - } - val = val.Elem() - } - - if v == nil { - return values, nil - } - - if val.Kind() != reflect.Struct { - return nil, fmt.Errorf("query: Values() expects struct input. Got %v", val.Kind()) - } - - err := reflectValue(values, val, "") - return values, err -} - -// reflectValue populates the values parameter from the struct fields in val. -// Embedded structs are followed recursively (using the rules defined in the -// Values function documentation) breadth-first. -func reflectValue(values url.Values, val reflect.Value, scope string) error { - var embedded []reflect.Value - - typ := val.Type() - for i := 0; i < typ.NumField(); i++ { - sf := typ.Field(i) - if sf.PkgPath != "" && !sf.Anonymous { // unexported - continue - } - - sv := val.Field(i) - tag := sf.Tag.Get("url") - if tag == "-" { - continue - } - name, opts := parseTag(tag) - - if name == "" { - if sf.Anonymous { - v := reflect.Indirect(sv) - if v.IsValid() && v.Kind() == reflect.Struct { - // save embedded struct for later processing - embedded = append(embedded, v) - continue - } - } - - name = sf.Name - } - - if scope != "" { - name = scope + "[" + name + "]" - } - - if opts.Contains("omitempty") && isEmptyValue(sv) { - continue - } - - if sv.Type().Implements(encoderType) { - // if sv is a nil pointer and the custom encoder is defined on a non-pointer - // method receiver, set sv to the zero value of the underlying type - if !reflect.Indirect(sv).IsValid() && sv.Type().Elem().Implements(encoderType) { - sv = reflect.New(sv.Type().Elem()) - } - - m := sv.Interface().(Encoder) - if err := m.EncodeValues(name, &values); err != nil { - return err - } - continue - } - - // recursively dereference pointers. break on nil pointers - for sv.Kind() == reflect.Ptr { - if sv.IsNil() { - break - } - sv = sv.Elem() - } - - if sv.Kind() == reflect.Slice || sv.Kind() == reflect.Array { - var del string - if opts.Contains("comma") { - del = "," - } else if opts.Contains("space") { - del = " " - } else if opts.Contains("semicolon") { - del = ";" - } else if opts.Contains("brackets") { - name = name + "[]" - } else { - del = sf.Tag.Get("del") - } - - if del != "" { - s := new(bytes.Buffer) - first := true - for i := 0; i < sv.Len(); i++ { - if first { - first = false - } else { - s.WriteString(del) - } - s.WriteString(valueString(sv.Index(i), opts, sf)) - } - values.Add(name, s.String()) - } else { - for i := 0; i < sv.Len(); i++ { - k := name - if opts.Contains("numbered") { - k = fmt.Sprintf("%s%d", name, i) - } - values.Add(k, valueString(sv.Index(i), opts, sf)) - } - } - continue - } - - if sv.Type() == timeType { - values.Add(name, valueString(sv, opts, sf)) - continue - } - - if sv.Kind() == reflect.Struct { - if err := reflectValue(values, sv, name); err != nil { - return err - } - continue - } - - values.Add(name, valueString(sv, opts, sf)) - } - - for _, f := range embedded { - if err := reflectValue(values, f, scope); err != nil { - return err - } - } - - return nil -} - -// valueString returns the string representation of a value. -func valueString(v reflect.Value, opts tagOptions, sf reflect.StructField) string { - for v.Kind() == reflect.Ptr { - if v.IsNil() { - return "" - } - v = v.Elem() - } - - if v.Kind() == reflect.Bool && opts.Contains("int") { - if v.Bool() { - return "1" - } - return "0" - } - - if v.Type() == timeType { - t := v.Interface().(time.Time) - if opts.Contains("unix") { - return strconv.FormatInt(t.Unix(), 10) - } - if opts.Contains("unixmilli") { - return strconv.FormatInt((t.UnixNano() / 1e6), 10) - } - if opts.Contains("unixnano") { - return strconv.FormatInt(t.UnixNano(), 10) - } - if layout := sf.Tag.Get("layout"); layout != "" { - return t.Format(layout) - } - return t.Format(time.RFC3339) - } - - return fmt.Sprint(v.Interface()) -} - -// isEmptyValue checks if a value should be considered empty for the purposes -// of omitting fields with the "omitempty" option. -func isEmptyValue(v reflect.Value) bool { - switch v.Kind() { - case reflect.Array, reflect.Map, reflect.Slice, reflect.String: - return v.Len() == 0 - case reflect.Bool: - return !v.Bool() - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return v.Int() == 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return v.Uint() == 0 - case reflect.Float32, reflect.Float64: - return v.Float() == 0 - case reflect.Interface, reflect.Ptr: - return v.IsNil() - } - - type zeroable interface { - IsZero() bool - } - - if z, ok := v.Interface().(zeroable); ok { - return z.IsZero() - } - - return false -} - -// tagOptions is the string following a comma in a struct field's "url" tag, or -// the empty string. It does not include the leading comma. -type tagOptions []string - -// parseTag splits a struct field's url tag into its name and comma-separated -// options. -func parseTag(tag string) (string, tagOptions) { - s := strings.Split(tag, ",") - return s[0], s[1:] -} - -// Contains checks whether the tagOptions contains the specified option. -func (o tagOptions) Contains(option string) bool { - for _, s := range o { - if s == option { - return true - } - } - return false -} diff --git a/vendor/github.com/hashicorp/go-cleanhttp/LICENSE b/vendor/github.com/hashicorp/go-cleanhttp/LICENSE deleted file mode 100644 index e87a115..0000000 --- a/vendor/github.com/hashicorp/go-cleanhttp/LICENSE +++ /dev/null @@ -1,363 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. "Contributor" - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. "Contributor Version" - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the terms of - a Secondary License. - -1.6. "Executable Form" - - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - - means a work that combines Covered Software with other material, in a - separate file or files, that is not Covered Software. - -1.8. "License" - - means this document. - -1.9. "Licensable" - - means having the right to grant, to the maximum extent possible, whether - at the time of the initial grant or subsequently, any and all of the - rights conveyed by this License. - -1.10. "Modifications" - - means any of the following: - - a. any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. "Patent Claims" of a Contributor - - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the License, - by the making, using, selling, offering for sale, having made, import, - or transfer of either its Contributions or its Contributor Version. - -1.12. "Secondary License" - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. "Source Code Form" - - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, "control" means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution - become effective for each Contribution on the date the Contributor first - distributes such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under - this License. No additional rights or licenses will be implied from the - distribution or licensing of Covered Software under this License. - Notwithstanding Section 2.1(b) above, no patent license is granted by a - Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of - its Contributions. - - This License does not grant any rights in the trademarks, service marks, - or logos of any Contributor (except as may be necessary to comply with - the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this - License (see Section 10.2) or under the terms of a Secondary License (if - permitted under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its - Contributions are its original creation(s) or it has sufficient rights to - grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under - applicable copyright doctrines of fair use, fair dealing, or other - equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under - the terms of this License. You must inform recipients that the Source - Code Form of the Covered Software is governed by the terms of this - License, and how they can obtain a copy of this License. You may not - attempt to alter or restrict the recipients' rights in the Source Code - Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter the - recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for - the Covered Software. If the Larger Work is a combination of Covered - Software with a work governed by one or more Secondary Licenses, and the - Covered Software is not Incompatible With Secondary Licenses, this - License permits You to additionally distribute such Covered Software - under the terms of such Secondary License(s), so that the recipient of - the Larger Work may, at their option, further distribute the Covered - Software under the terms of either this License or such Secondary - License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices - (including copyright notices, patent notices, disclaimers of warranty, or - limitations of liability) contained within the Source Code Form of the - Covered Software, except that You may alter any license notices to the - extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on - behalf of any Contributor. You must make it absolutely clear that any - such warranty, support, indemnity, or liability obligation is offered by - You alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, - judicial order, or regulation then You must: (a) comply with the terms of - this License to the maximum extent possible; and (b) describe the - limitations and the code they affect. Such description must be placed in a - text file included with all distributions of the Covered Software under - this License. Except to the extent prohibited by statute or regulation, - such description must be sufficiently detailed for a recipient of ordinary - skill to be able to understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing - basis, if such Contributor fails to notify You of the non-compliance by - some reasonable means prior to 60 days after You have come back into - compliance. Moreover, Your grants from a particular Contributor are - reinstated on an ongoing basis if such Contributor notifies You of the - non-compliance by some reasonable means, this is the first time You have - received notice of non-compliance with this License from such - Contributor, and You become compliant prior to 30 days after Your receipt - of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, - counter-claims, and cross-claims) alleging that a Contributor Version - directly or indirectly infringes any patent, then the rights granted to - You by any and all Contributors for the Covered Software under Section - 2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an "as is" basis, - without warranty of any kind, either expressed, implied, or statutory, - including, without limitation, warranties that the Covered Software is free - of defects, merchantable, fit for a particular purpose or non-infringing. - The entire risk as to the quality and performance of the Covered Software - is with You. Should any Covered Software prove defective in any respect, - You (not any Contributor) assume the cost of any necessary servicing, - repair, or correction. This disclaimer of warranty constitutes an essential - part of this License. No use of any Covered Software is authorized under - this License except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from - such party's negligence to the extent applicable law prohibits such - limitation. Some jurisdictions do not allow the exclusion or limitation of - incidental or consequential damages, so this exclusion and limitation may - not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts - of a jurisdiction where the defendant maintains its principal place of - business and such litigation shall be governed by laws of that - jurisdiction, without reference to its conflict-of-law provisions. Nothing - in this Section shall prevent a party's ability to bring cross-claims or - counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. Any law or regulation which provides that - the language of a contract shall be construed against the drafter shall not - be used to construe this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version - of the License under which You originally received the Covered Software, - or under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a - modified version of this License if you rename the license and remove - any references to the name of the license steward (except to note that - such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary - Licenses If You choose to distribute Source Code Form that is - Incompatible With Secondary Licenses under the terms of this version of - the License, the notice described in Exhibit B of this License must be - attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, -then You may include the notice in a location (such as a LICENSE file in a -relevant directory) where a recipient would be likely to look for such a -notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice - - This Source Code Form is "Incompatible - With Secondary Licenses", as defined by - the Mozilla Public License, v. 2.0. - diff --git a/vendor/github.com/hashicorp/go-cleanhttp/README.md b/vendor/github.com/hashicorp/go-cleanhttp/README.md deleted file mode 100644 index 036e531..0000000 --- a/vendor/github.com/hashicorp/go-cleanhttp/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# cleanhttp - -Functions for accessing "clean" Go http.Client values - -------------- - -The Go standard library contains a default `http.Client` called -`http.DefaultClient`. It is a common idiom in Go code to start with -`http.DefaultClient` and tweak it as necessary, and in fact, this is -encouraged; from the `http` package documentation: - -> The Client's Transport typically has internal state (cached TCP connections), -so Clients should be reused instead of created as needed. Clients are safe for -concurrent use by multiple goroutines. - -Unfortunately, this is a shared value, and it is not uncommon for libraries to -assume that they are free to modify it at will. With enough dependencies, it -can be very easy to encounter strange problems and race conditions due to -manipulation of this shared value across libraries and goroutines (clients are -safe for concurrent use, but writing values to the client struct itself is not -protected). - -Making things worse is the fact that a bare `http.Client` will use a default -`http.Transport` called `http.DefaultTransport`, which is another global value -that behaves the same way. So it is not simply enough to replace -`http.DefaultClient` with `&http.Client{}`. - -This repository provides some simple functions to get a "clean" `http.Client` --- one that uses the same default values as the Go standard library, but -returns a client that does not share any state with other clients. diff --git a/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go b/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go deleted file mode 100644 index fe28d15..0000000 --- a/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go +++ /dev/null @@ -1,58 +0,0 @@ -package cleanhttp - -import ( - "net" - "net/http" - "runtime" - "time" -) - -// DefaultTransport returns a new http.Transport with similar default values to -// http.DefaultTransport, but with idle connections and keepalives disabled. -func DefaultTransport() *http.Transport { - transport := DefaultPooledTransport() - transport.DisableKeepAlives = true - transport.MaxIdleConnsPerHost = -1 - return transport -} - -// DefaultPooledTransport returns a new http.Transport with similar default -// values to http.DefaultTransport. Do not use this for transient transports as -// it can leak file descriptors over time. Only use this for transports that -// will be re-used for the same host(s). -func DefaultPooledTransport() *http.Transport { - transport := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - DialContext: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - DualStack: true, - }).DialContext, - MaxIdleConns: 100, - IdleConnTimeout: 90 * time.Second, - TLSHandshakeTimeout: 10 * time.Second, - ExpectContinueTimeout: 1 * time.Second, - ForceAttemptHTTP2: true, - MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1, - } - return transport -} - -// DefaultClient returns a new http.Client with similar default values to -// http.Client, but with a non-shared Transport, idle connections disabled, and -// keepalives disabled. -func DefaultClient() *http.Client { - return &http.Client{ - Transport: DefaultTransport(), - } -} - -// DefaultPooledClient returns a new http.Client with similar default values to -// http.Client, but with a shared Transport. Do not use this function for -// transient clients as it can leak file descriptors over time. Only use this -// for clients that will be re-used for the same host(s). -func DefaultPooledClient() *http.Client { - return &http.Client{ - Transport: DefaultPooledTransport(), - } -} diff --git a/vendor/github.com/hashicorp/go-cleanhttp/doc.go b/vendor/github.com/hashicorp/go-cleanhttp/doc.go deleted file mode 100644 index 0584109..0000000 --- a/vendor/github.com/hashicorp/go-cleanhttp/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Package cleanhttp offers convenience utilities for acquiring "clean" -// http.Transport and http.Client structs. -// -// Values set on http.DefaultClient and http.DefaultTransport affect all -// callers. This can have detrimental effects, esepcially in TLS contexts, -// where client or root certificates set to talk to multiple endpoints can end -// up displacing each other, leading to hard-to-debug issues. This package -// provides non-shared http.Client and http.Transport structs to ensure that -// the configuration will not be overwritten by other parts of the application -// or dependencies. -// -// The DefaultClient and DefaultTransport functions disable idle connections -// and keepalives. Without ensuring that idle connections are closed before -// garbage collection, short-term clients/transports can leak file descriptors, -// eventually leading to "too many open files" errors. If you will be -// connecting to the same hosts repeatedly from the same client, you can use -// DefaultPooledClient to receive a client that has connection pooling -// semantics similar to http.DefaultClient. -// -package cleanhttp diff --git a/vendor/github.com/hashicorp/go-cleanhttp/handlers.go b/vendor/github.com/hashicorp/go-cleanhttp/handlers.go deleted file mode 100644 index 3c845dc..0000000 --- a/vendor/github.com/hashicorp/go-cleanhttp/handlers.go +++ /dev/null @@ -1,48 +0,0 @@ -package cleanhttp - -import ( - "net/http" - "strings" - "unicode" -) - -// HandlerInput provides input options to cleanhttp's handlers -type HandlerInput struct { - ErrStatus int -} - -// PrintablePathCheckHandler is a middleware that ensures the request path -// contains only printable runes. -func PrintablePathCheckHandler(next http.Handler, input *HandlerInput) http.Handler { - // Nil-check on input to make it optional - if input == nil { - input = &HandlerInput{ - ErrStatus: http.StatusBadRequest, - } - } - - // Default to http.StatusBadRequest on error - if input.ErrStatus == 0 { - input.ErrStatus = http.StatusBadRequest - } - - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r != nil { - // Check URL path for non-printable characters - idx := strings.IndexFunc(r.URL.Path, func(c rune) bool { - return !unicode.IsPrint(c) - }) - - if idx != -1 { - w.WriteHeader(input.ErrStatus) - return - } - - if next != nil { - next.ServeHTTP(w, r) - } - } - - return - }) -} diff --git a/vendor/github.com/hashicorp/go-retryablehttp/.gitignore b/vendor/github.com/hashicorp/go-retryablehttp/.gitignore deleted file mode 100644 index 4e309e0..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.idea/ -*.iml -*.test -.vscode/ \ No newline at end of file diff --git a/vendor/github.com/hashicorp/go-retryablehttp/LICENSE b/vendor/github.com/hashicorp/go-retryablehttp/LICENSE deleted file mode 100644 index e87a115..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/LICENSE +++ /dev/null @@ -1,363 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. "Contributor" - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. "Contributor Version" - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the terms of - a Secondary License. - -1.6. "Executable Form" - - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - - means a work that combines Covered Software with other material, in a - separate file or files, that is not Covered Software. - -1.8. "License" - - means this document. - -1.9. "Licensable" - - means having the right to grant, to the maximum extent possible, whether - at the time of the initial grant or subsequently, any and all of the - rights conveyed by this License. - -1.10. "Modifications" - - means any of the following: - - a. any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. "Patent Claims" of a Contributor - - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the License, - by the making, using, selling, offering for sale, having made, import, - or transfer of either its Contributions or its Contributor Version. - -1.12. "Secondary License" - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. "Source Code Form" - - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, "control" means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution - become effective for each Contribution on the date the Contributor first - distributes such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under - this License. No additional rights or licenses will be implied from the - distribution or licensing of Covered Software under this License. - Notwithstanding Section 2.1(b) above, no patent license is granted by a - Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of - its Contributions. - - This License does not grant any rights in the trademarks, service marks, - or logos of any Contributor (except as may be necessary to comply with - the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this - License (see Section 10.2) or under the terms of a Secondary License (if - permitted under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its - Contributions are its original creation(s) or it has sufficient rights to - grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under - applicable copyright doctrines of fair use, fair dealing, or other - equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under - the terms of this License. You must inform recipients that the Source - Code Form of the Covered Software is governed by the terms of this - License, and how they can obtain a copy of this License. You may not - attempt to alter or restrict the recipients' rights in the Source Code - Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter the - recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for - the Covered Software. If the Larger Work is a combination of Covered - Software with a work governed by one or more Secondary Licenses, and the - Covered Software is not Incompatible With Secondary Licenses, this - License permits You to additionally distribute such Covered Software - under the terms of such Secondary License(s), so that the recipient of - the Larger Work may, at their option, further distribute the Covered - Software under the terms of either this License or such Secondary - License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices - (including copyright notices, patent notices, disclaimers of warranty, or - limitations of liability) contained within the Source Code Form of the - Covered Software, except that You may alter any license notices to the - extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on - behalf of any Contributor. You must make it absolutely clear that any - such warranty, support, indemnity, or liability obligation is offered by - You alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, - judicial order, or regulation then You must: (a) comply with the terms of - this License to the maximum extent possible; and (b) describe the - limitations and the code they affect. Such description must be placed in a - text file included with all distributions of the Covered Software under - this License. Except to the extent prohibited by statute or regulation, - such description must be sufficiently detailed for a recipient of ordinary - skill to be able to understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing - basis, if such Contributor fails to notify You of the non-compliance by - some reasonable means prior to 60 days after You have come back into - compliance. Moreover, Your grants from a particular Contributor are - reinstated on an ongoing basis if such Contributor notifies You of the - non-compliance by some reasonable means, this is the first time You have - received notice of non-compliance with this License from such - Contributor, and You become compliant prior to 30 days after Your receipt - of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, - counter-claims, and cross-claims) alleging that a Contributor Version - directly or indirectly infringes any patent, then the rights granted to - You by any and all Contributors for the Covered Software under Section - 2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an "as is" basis, - without warranty of any kind, either expressed, implied, or statutory, - including, without limitation, warranties that the Covered Software is free - of defects, merchantable, fit for a particular purpose or non-infringing. - The entire risk as to the quality and performance of the Covered Software - is with You. Should any Covered Software prove defective in any respect, - You (not any Contributor) assume the cost of any necessary servicing, - repair, or correction. This disclaimer of warranty constitutes an essential - part of this License. No use of any Covered Software is authorized under - this License except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from - such party's negligence to the extent applicable law prohibits such - limitation. Some jurisdictions do not allow the exclusion or limitation of - incidental or consequential damages, so this exclusion and limitation may - not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts - of a jurisdiction where the defendant maintains its principal place of - business and such litigation shall be governed by laws of that - jurisdiction, without reference to its conflict-of-law provisions. Nothing - in this Section shall prevent a party's ability to bring cross-claims or - counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. Any law or regulation which provides that - the language of a contract shall be construed against the drafter shall not - be used to construe this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version - of the License under which You originally received the Covered Software, - or under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a - modified version of this License if you rename the license and remove - any references to the name of the license steward (except to note that - such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary - Licenses If You choose to distribute Source Code Form that is - Incompatible With Secondary Licenses under the terms of this version of - the License, the notice described in Exhibit B of this License must be - attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, -then You may include the notice in a location (such as a LICENSE file in a -relevant directory) where a recipient would be likely to look for such a -notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice - - This Source Code Form is "Incompatible - With Secondary Licenses", as defined by - the Mozilla Public License, v. 2.0. - diff --git a/vendor/github.com/hashicorp/go-retryablehttp/Makefile b/vendor/github.com/hashicorp/go-retryablehttp/Makefile deleted file mode 100644 index da17640..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -default: test - -test: - go vet ./... - go test -race ./... - -updatedeps: - go get -f -t -u ./... - go get -f -u ./... - -.PHONY: default test updatedeps diff --git a/vendor/github.com/hashicorp/go-retryablehttp/README.md b/vendor/github.com/hashicorp/go-retryablehttp/README.md deleted file mode 100644 index 8943bec..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/README.md +++ /dev/null @@ -1,62 +0,0 @@ -go-retryablehttp -================ - -[![Build Status](http://img.shields.io/travis/hashicorp/go-retryablehttp.svg?style=flat-square)][travis] -[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] - -[travis]: http://travis-ci.org/hashicorp/go-retryablehttp -[godocs]: http://godoc.org/github.com/hashicorp/go-retryablehttp - -The `retryablehttp` package provides a familiar HTTP client interface with -automatic retries and exponential backoff. It is a thin wrapper over the -standard `net/http` client library and exposes nearly the same public API. This -makes `retryablehttp` very easy to drop into existing programs. - -`retryablehttp` performs automatic retries under certain conditions. Mainly, if -an error is returned by the client (connection errors, etc.), or if a 500-range -response code is received (except 501), then a retry is invoked after a wait -period. Otherwise, the response is returned and left to the caller to -interpret. - -The main difference from `net/http` is that requests which take a request body -(POST/PUT et. al) can have the body provided in a number of ways (some more or -less efficient) that allow "rewinding" the request body if the initial request -fails so that the full request can be attempted again. See the -[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp) for more -details. - -Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required. -From 0.6.7 onward, Go 1.13+ is required. - -Example Use -=========== - -Using this library should look almost identical to what you would do with -`net/http`. The most simple example of a GET request is shown below: - -```go -resp, err := retryablehttp.Get("/foo") -if err != nil { - panic(err) -} -``` - -The returned response object is an `*http.Response`, the same thing you would -usually get from `net/http`. Had the request failed one or more times, the above -call would block and retry with exponential backoff. - -## Getting a stdlib `*http.Client` with retries - -It's possible to convert a `*retryablehttp.Client` directly to a `*http.Client`. -This makes use of retryablehttp broadly applicable with minimal effort. Simply -configure a `*retryablehttp.Client` as you wish, and then call `StandardClient()`: - -```go -retryClient := retryablehttp.NewClient() -retryClient.RetryMax = 10 - -standardClient := retryClient.StandardClient() // *http.Client -``` - -For more usage and examples see the -[godoc](http://godoc.org/github.com/hashicorp/go-retryablehttp). diff --git a/vendor/github.com/hashicorp/go-retryablehttp/client.go b/vendor/github.com/hashicorp/go-retryablehttp/client.go deleted file mode 100644 index f40d241..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/client.go +++ /dev/null @@ -1,822 +0,0 @@ -// Package retryablehttp provides a familiar HTTP client interface with -// automatic retries and exponential backoff. It is a thin wrapper over the -// standard net/http client library and exposes nearly the same public API. -// This makes retryablehttp very easy to drop into existing programs. -// -// retryablehttp performs automatic retries under certain conditions. Mainly, if -// an error is returned by the client (connection errors etc), or if a 500-range -// response is received, then a retry is invoked. Otherwise, the response is -// returned and left to the caller to interpret. -// -// Requests which take a request body should provide a non-nil function -// parameter. The best choice is to provide either a function satisfying -// ReaderFunc which provides multiple io.Readers in an efficient manner, a -// *bytes.Buffer (the underlying raw byte slice will be used) or a raw byte -// slice. As it is a reference type, and we will wrap it as needed by readers, -// we can efficiently re-use the request body without needing to copy it. If an -// io.Reader (such as a *bytes.Reader) is provided, the full body will be read -// prior to the first request, and will be efficiently re-used for any retries. -// ReadSeeker can be used, but some users have observed occasional data races -// between the net/http library and the Seek functionality of some -// implementations of ReadSeeker, so should be avoided if possible. -package retryablehttp - -import ( - "bytes" - "context" - "crypto/x509" - "fmt" - "io" - "io/ioutil" - "log" - "math" - "math/rand" - "net/http" - "net/url" - "os" - "regexp" - "strconv" - "strings" - "sync" - "time" - - cleanhttp "github.com/hashicorp/go-cleanhttp" -) - -var ( - // Default retry configuration - defaultRetryWaitMin = 1 * time.Second - defaultRetryWaitMax = 30 * time.Second - defaultRetryMax = 4 - - // defaultLogger is the logger provided with defaultClient - defaultLogger = log.New(os.Stderr, "", log.LstdFlags) - - // defaultClient is used for performing requests without explicitly making - // a new client. It is purposely private to avoid modifications. - defaultClient = NewClient() - - // We need to consume response bodies to maintain http connections, but - // limit the size we consume to respReadLimit. - respReadLimit = int64(4096) - - // A regular expression to match the error returned by net/http when the - // configured number of redirects is exhausted. This error isn't typed - // specifically so we resort to matching on the error string. - redirectsErrorRe = regexp.MustCompile(`stopped after \d+ redirects\z`) - - // A regular expression to match the error returned by net/http when the - // scheme specified in the URL is invalid. This error isn't typed - // specifically so we resort to matching on the error string. - schemeErrorRe = regexp.MustCompile(`unsupported protocol scheme`) - - // A regular expression to match the error returned by net/http when the - // TLS certificate is not trusted. This error isn't typed - // specifically so we resort to matching on the error string. - notTrustedErrorRe = regexp.MustCompile(`certificate is not trusted`) -) - -// ReaderFunc is the type of function that can be given natively to NewRequest -type ReaderFunc func() (io.Reader, error) - -// ResponseHandlerFunc is a type of function that takes in a Response, and does something with it. -// The ResponseHandlerFunc is called when the HTTP client successfully receives a response and the -// CheckRetry function indicates that a retry of the base request is not necessary. -// If an error is returned from this function, the CheckRetry policy will be used to determine -// whether to retry the whole request (including this handler). -// -// Make sure to check status codes! Even if the request was completed it may have a non-2xx status code. -// -// The response body is not automatically closed. It must be closed either by the ResponseHandlerFunc or -// by the caller out-of-band. Failure to do so will result in a memory leak. -type ResponseHandlerFunc func(*http.Response) error - -// LenReader is an interface implemented by many in-memory io.Reader's. Used -// for automatically sending the right Content-Length header when possible. -type LenReader interface { - Len() int -} - -// Request wraps the metadata needed to create HTTP requests. -type Request struct { - // body is a seekable reader over the request body payload. This is - // used to rewind the request data in between retries. - body ReaderFunc - - responseHandler ResponseHandlerFunc - - // Embed an HTTP request directly. This makes a *Request act exactly - // like an *http.Request so that all meta methods are supported. - *http.Request -} - -// WithContext returns wrapped Request with a shallow copy of underlying *http.Request -// with its context changed to ctx. The provided ctx must be non-nil. -func (r *Request) WithContext(ctx context.Context) *Request { - return &Request{ - body: r.body, - responseHandler: r.responseHandler, - Request: r.Request.WithContext(ctx), - } -} - -// SetResponseHandler allows setting the response handler. -func (r *Request) SetResponseHandler(fn ResponseHandlerFunc) { - r.responseHandler = fn -} - -// BodyBytes allows accessing the request body. It is an analogue to -// http.Request's Body variable, but it returns a copy of the underlying data -// rather than consuming it. -// -// This function is not thread-safe; do not call it at the same time as another -// call, or at the same time this request is being used with Client.Do. -func (r *Request) BodyBytes() ([]byte, error) { - if r.body == nil { - return nil, nil - } - body, err := r.body() - if err != nil { - return nil, err - } - buf := new(bytes.Buffer) - _, err = buf.ReadFrom(body) - if err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -// SetBody allows setting the request body. -// -// It is useful if a new body needs to be set without constructing a new Request. -func (r *Request) SetBody(rawBody interface{}) error { - bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody) - if err != nil { - return err - } - r.body = bodyReader - r.ContentLength = contentLength - return nil -} - -// WriteTo allows copying the request body into a writer. -// -// It writes data to w until there's no more data to write or -// when an error occurs. The return int64 value is the number of bytes -// written. Any error encountered during the write is also returned. -// The signature matches io.WriterTo interface. -func (r *Request) WriteTo(w io.Writer) (int64, error) { - body, err := r.body() - if err != nil { - return 0, err - } - if c, ok := body.(io.Closer); ok { - defer c.Close() - } - return io.Copy(w, body) -} - -func getBodyReaderAndContentLength(rawBody interface{}) (ReaderFunc, int64, error) { - var bodyReader ReaderFunc - var contentLength int64 - - switch body := rawBody.(type) { - // If they gave us a function already, great! Use it. - case ReaderFunc: - bodyReader = body - tmp, err := body() - if err != nil { - return nil, 0, err - } - if lr, ok := tmp.(LenReader); ok { - contentLength = int64(lr.Len()) - } - if c, ok := tmp.(io.Closer); ok { - c.Close() - } - - case func() (io.Reader, error): - bodyReader = body - tmp, err := body() - if err != nil { - return nil, 0, err - } - if lr, ok := tmp.(LenReader); ok { - contentLength = int64(lr.Len()) - } - if c, ok := tmp.(io.Closer); ok { - c.Close() - } - - // If a regular byte slice, we can read it over and over via new - // readers - case []byte: - buf := body - bodyReader = func() (io.Reader, error) { - return bytes.NewReader(buf), nil - } - contentLength = int64(len(buf)) - - // If a bytes.Buffer we can read the underlying byte slice over and - // over - case *bytes.Buffer: - buf := body - bodyReader = func() (io.Reader, error) { - return bytes.NewReader(buf.Bytes()), nil - } - contentLength = int64(buf.Len()) - - // We prioritize *bytes.Reader here because we don't really want to - // deal with it seeking so want it to match here instead of the - // io.ReadSeeker case. - case *bytes.Reader: - buf, err := ioutil.ReadAll(body) - if err != nil { - return nil, 0, err - } - bodyReader = func() (io.Reader, error) { - return bytes.NewReader(buf), nil - } - contentLength = int64(len(buf)) - - // Compat case - case io.ReadSeeker: - raw := body - bodyReader = func() (io.Reader, error) { - _, err := raw.Seek(0, 0) - return ioutil.NopCloser(raw), err - } - if lr, ok := raw.(LenReader); ok { - contentLength = int64(lr.Len()) - } - - // Read all in so we can reset - case io.Reader: - buf, err := ioutil.ReadAll(body) - if err != nil { - return nil, 0, err - } - bodyReader = func() (io.Reader, error) { - return bytes.NewReader(buf), nil - } - contentLength = int64(len(buf)) - - // No body provided, nothing to do - case nil: - - // Unrecognized type - default: - return nil, 0, fmt.Errorf("cannot handle type %T", rawBody) - } - return bodyReader, contentLength, nil -} - -// FromRequest wraps an http.Request in a retryablehttp.Request -func FromRequest(r *http.Request) (*Request, error) { - bodyReader, _, err := getBodyReaderAndContentLength(r.Body) - if err != nil { - return nil, err - } - // Could assert contentLength == r.ContentLength - return &Request{body: bodyReader, Request: r}, nil -} - -// NewRequest creates a new wrapped request. -func NewRequest(method, url string, rawBody interface{}) (*Request, error) { - return NewRequestWithContext(context.Background(), method, url, rawBody) -} - -// NewRequestWithContext creates a new wrapped request with the provided context. -// -// The context controls the entire lifetime of a request and its response: -// obtaining a connection, sending the request, and reading the response headers and body. -func NewRequestWithContext(ctx context.Context, method, url string, rawBody interface{}) (*Request, error) { - bodyReader, contentLength, err := getBodyReaderAndContentLength(rawBody) - if err != nil { - return nil, err - } - - httpReq, err := http.NewRequestWithContext(ctx, method, url, nil) - if err != nil { - return nil, err - } - httpReq.ContentLength = contentLength - - return &Request{body: bodyReader, Request: httpReq}, nil -} - -// Logger interface allows to use other loggers than -// standard log.Logger. -type Logger interface { - Printf(string, ...interface{}) -} - -// LeveledLogger is an interface that can be implemented by any logger or a -// logger wrapper to provide leveled logging. The methods accept a message -// string and a variadic number of key-value pairs. For log.Printf style -// formatting where message string contains a format specifier, use Logger -// interface. -type LeveledLogger interface { - Error(msg string, keysAndValues ...interface{}) - Info(msg string, keysAndValues ...interface{}) - Debug(msg string, keysAndValues ...interface{}) - Warn(msg string, keysAndValues ...interface{}) -} - -// hookLogger adapts an LeveledLogger to Logger for use by the existing hook functions -// without changing the API. -type hookLogger struct { - LeveledLogger -} - -func (h hookLogger) Printf(s string, args ...interface{}) { - h.Info(fmt.Sprintf(s, args...)) -} - -// RequestLogHook allows a function to run before each retry. The HTTP -// request which will be made, and the retry number (0 for the initial -// request) are available to users. The internal logger is exposed to -// consumers. -type RequestLogHook func(Logger, *http.Request, int) - -// ResponseLogHook is like RequestLogHook, but allows running a function -// on each HTTP response. This function will be invoked at the end of -// every HTTP request executed, regardless of whether a subsequent retry -// needs to be performed or not. If the response body is read or closed -// from this method, this will affect the response returned from Do(). -type ResponseLogHook func(Logger, *http.Response) - -// CheckRetry specifies a policy for handling retries. It is called -// following each request with the response and error values returned by -// the http.Client. If CheckRetry returns false, the Client stops retrying -// and returns the response to the caller. If CheckRetry returns an error, -// that error value is returned in lieu of the error from the request. The -// Client will close any response body when retrying, but if the retry is -// aborted it is up to the CheckRetry callback to properly close any -// response body before returning. -type CheckRetry func(ctx context.Context, resp *http.Response, err error) (bool, error) - -// Backoff specifies a policy for how long to wait between retries. -// It is called after a failing request to determine the amount of time -// that should pass before trying again. -type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration - -// ErrorHandler is called if retries are expired, containing the last status -// from the http library. If not specified, default behavior for the library is -// to close the body and return an error indicating how many tries were -// attempted. If overriding this, be sure to close the body if needed. -type ErrorHandler func(resp *http.Response, err error, numTries int) (*http.Response, error) - -// Client is used to make HTTP requests. It adds additional functionality -// like automatic retries to tolerate minor outages. -type Client struct { - HTTPClient *http.Client // Internal HTTP client. - Logger interface{} // Customer logger instance. Can be either Logger or LeveledLogger - - RetryWaitMin time.Duration // Minimum time to wait - RetryWaitMax time.Duration // Maximum time to wait - RetryMax int // Maximum number of retries - - // RequestLogHook allows a user-supplied function to be called - // before each retry. - RequestLogHook RequestLogHook - - // ResponseLogHook allows a user-supplied function to be called - // with the response from each HTTP request executed. - ResponseLogHook ResponseLogHook - - // CheckRetry specifies the policy for handling retries, and is called - // after each request. The default policy is DefaultRetryPolicy. - CheckRetry CheckRetry - - // Backoff specifies the policy for how long to wait between retries - Backoff Backoff - - // ErrorHandler specifies the custom error handler to use, if any - ErrorHandler ErrorHandler - - loggerInit sync.Once - clientInit sync.Once -} - -// NewClient creates a new Client with default settings. -func NewClient() *Client { - return &Client{ - HTTPClient: cleanhttp.DefaultPooledClient(), - Logger: defaultLogger, - RetryWaitMin: defaultRetryWaitMin, - RetryWaitMax: defaultRetryWaitMax, - RetryMax: defaultRetryMax, - CheckRetry: DefaultRetryPolicy, - Backoff: DefaultBackoff, - } -} - -func (c *Client) logger() interface{} { - c.loggerInit.Do(func() { - if c.Logger == nil { - return - } - - switch c.Logger.(type) { - case Logger, LeveledLogger: - // ok - default: - // This should happen in dev when they are setting Logger and work on code, not in prod. - panic(fmt.Sprintf("invalid logger type passed, must be Logger or LeveledLogger, was %T", c.Logger)) - } - }) - - return c.Logger -} - -// DefaultRetryPolicy provides a default callback for Client.CheckRetry, which -// will retry on connection errors and server errors. -func DefaultRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) { - // do not retry on context.Canceled or context.DeadlineExceeded - if ctx.Err() != nil { - return false, ctx.Err() - } - - // don't propagate other errors - shouldRetry, _ := baseRetryPolicy(resp, err) - return shouldRetry, nil -} - -// ErrorPropagatedRetryPolicy is the same as DefaultRetryPolicy, except it -// propagates errors back instead of returning nil. This allows you to inspect -// why it decided to retry or not. -func ErrorPropagatedRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error) { - // do not retry on context.Canceled or context.DeadlineExceeded - if ctx.Err() != nil { - return false, ctx.Err() - } - - return baseRetryPolicy(resp, err) -} - -func baseRetryPolicy(resp *http.Response, err error) (bool, error) { - if err != nil { - if v, ok := err.(*url.Error); ok { - // Don't retry if the error was due to too many redirects. - if redirectsErrorRe.MatchString(v.Error()) { - return false, v - } - - // Don't retry if the error was due to an invalid protocol scheme. - if schemeErrorRe.MatchString(v.Error()) { - return false, v - } - - // Don't retry if the error was due to TLS cert verification failure. - if notTrustedErrorRe.MatchString(v.Error()) { - return false, v - } - if _, ok := v.Err.(x509.UnknownAuthorityError); ok { - return false, v - } - } - - // The error is likely recoverable so retry. - return true, nil - } - - // 429 Too Many Requests is recoverable. Sometimes the server puts - // a Retry-After response header to indicate when the server is - // available to start processing request from client. - if resp.StatusCode == http.StatusTooManyRequests { - return true, nil - } - - // Check the response code. We retry on 500-range responses to allow - // the server time to recover, as 500's are typically not permanent - // errors and may relate to outages on the server side. This will catch - // invalid response codes as well, like 0 and 999. - if resp.StatusCode == 0 || (resp.StatusCode >= 500 && resp.StatusCode != http.StatusNotImplemented) { - return true, fmt.Errorf("unexpected HTTP status %s", resp.Status) - } - - return false, nil -} - -// DefaultBackoff provides a default callback for Client.Backoff which -// will perform exponential backoff based on the attempt number and limited -// by the provided minimum and maximum durations. -// -// It also tries to parse Retry-After response header when a http.StatusTooManyRequests -// (HTTP Code 429) is found in the resp parameter. Hence it will return the number of -// seconds the server states it may be ready to process more requests from this client. -func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { - if resp != nil { - if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable { - if s, ok := resp.Header["Retry-After"]; ok { - if sleep, err := strconv.ParseInt(s[0], 10, 64); err == nil { - return time.Second * time.Duration(sleep) - } - } - } - } - - mult := math.Pow(2, float64(attemptNum)) * float64(min) - sleep := time.Duration(mult) - if float64(sleep) != mult || sleep > max { - sleep = max - } - return sleep -} - -// LinearJitterBackoff provides a callback for Client.Backoff which will -// perform linear backoff based on the attempt number and with jitter to -// prevent a thundering herd. -// -// min and max here are *not* absolute values. The number to be multiplied by -// the attempt number will be chosen at random from between them, thus they are -// bounding the jitter. -// -// For instance: -// * To get strictly linear backoff of one second increasing each retry, set -// both to one second (1s, 2s, 3s, 4s, ...) -// * To get a small amount of jitter centered around one second increasing each -// retry, set to around one second, such as a min of 800ms and max of 1200ms -// (892ms, 2102ms, 2945ms, 4312ms, ...) -// * To get extreme jitter, set to a very wide spread, such as a min of 100ms -// and a max of 20s (15382ms, 292ms, 51321ms, 35234ms, ...) -func LinearJitterBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { - // attemptNum always starts at zero but we want to start at 1 for multiplication - attemptNum++ - - if max <= min { - // Unclear what to do here, or they are the same, so return min * - // attemptNum - return min * time.Duration(attemptNum) - } - - // Seed rand; doing this every time is fine - rand := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) - - // Pick a random number that lies somewhere between the min and max and - // multiply by the attemptNum. attemptNum starts at zero so we always - // increment here. We first get a random percentage, then apply that to the - // difference between min and max, and add to min. - jitter := rand.Float64() * float64(max-min) - jitterMin := int64(jitter) + int64(min) - return time.Duration(jitterMin * int64(attemptNum)) -} - -// PassthroughErrorHandler is an ErrorHandler that directly passes through the -// values from the net/http library for the final request. The body is not -// closed. -func PassthroughErrorHandler(resp *http.Response, err error, _ int) (*http.Response, error) { - return resp, err -} - -// Do wraps calling an HTTP method with retries. -func (c *Client) Do(req *Request) (*http.Response, error) { - c.clientInit.Do(func() { - if c.HTTPClient == nil { - c.HTTPClient = cleanhttp.DefaultPooledClient() - } - }) - - logger := c.logger() - - if logger != nil { - switch v := logger.(type) { - case LeveledLogger: - v.Debug("performing request", "method", req.Method, "url", req.URL) - case Logger: - v.Printf("[DEBUG] %s %s", req.Method, req.URL) - } - } - - var resp *http.Response - var attempt int - var shouldRetry bool - var doErr, respErr, checkErr error - - for i := 0; ; i++ { - doErr, respErr = nil, nil - attempt++ - - // Always rewind the request body when non-nil. - if req.body != nil { - body, err := req.body() - if err != nil { - c.HTTPClient.CloseIdleConnections() - return resp, err - } - if c, ok := body.(io.ReadCloser); ok { - req.Body = c - } else { - req.Body = ioutil.NopCloser(body) - } - } - - if c.RequestLogHook != nil { - switch v := logger.(type) { - case LeveledLogger: - c.RequestLogHook(hookLogger{v}, req.Request, i) - case Logger: - c.RequestLogHook(v, req.Request, i) - default: - c.RequestLogHook(nil, req.Request, i) - } - } - - // Attempt the request - resp, doErr = c.HTTPClient.Do(req.Request) - - // Check if we should continue with retries. - shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, doErr) - if !shouldRetry && doErr == nil && req.responseHandler != nil { - respErr = req.responseHandler(resp) - shouldRetry, checkErr = c.CheckRetry(req.Context(), resp, respErr) - } - - err := doErr - if respErr != nil { - err = respErr - } - if err != nil { - switch v := logger.(type) { - case LeveledLogger: - v.Error("request failed", "error", err, "method", req.Method, "url", req.URL) - case Logger: - v.Printf("[ERR] %s %s request failed: %v", req.Method, req.URL, err) - } - } else { - // Call this here to maintain the behavior of logging all requests, - // even if CheckRetry signals to stop. - if c.ResponseLogHook != nil { - // Call the response logger function if provided. - switch v := logger.(type) { - case LeveledLogger: - c.ResponseLogHook(hookLogger{v}, resp) - case Logger: - c.ResponseLogHook(v, resp) - default: - c.ResponseLogHook(nil, resp) - } - } - } - - if !shouldRetry { - break - } - - // We do this before drainBody because there's no need for the I/O if - // we're breaking out - remain := c.RetryMax - i - if remain <= 0 { - break - } - - // We're going to retry, consume any response to reuse the connection. - if doErr == nil { - c.drainBody(resp.Body) - } - - wait := c.Backoff(c.RetryWaitMin, c.RetryWaitMax, i, resp) - if logger != nil { - desc := fmt.Sprintf("%s %s", req.Method, req.URL) - if resp != nil { - desc = fmt.Sprintf("%s (status: %d)", desc, resp.StatusCode) - } - switch v := logger.(type) { - case LeveledLogger: - v.Debug("retrying request", "request", desc, "timeout", wait, "remaining", remain) - case Logger: - v.Printf("[DEBUG] %s: retrying in %s (%d left)", desc, wait, remain) - } - } - timer := time.NewTimer(wait) - select { - case <-req.Context().Done(): - timer.Stop() - c.HTTPClient.CloseIdleConnections() - return nil, req.Context().Err() - case <-timer.C: - } - - // Make shallow copy of http Request so that we can modify its body - // without racing against the closeBody call in persistConn.writeLoop. - httpreq := *req.Request - req.Request = &httpreq - } - - // this is the closest we have to success criteria - if doErr == nil && respErr == nil && checkErr == nil && !shouldRetry { - return resp, nil - } - - defer c.HTTPClient.CloseIdleConnections() - - var err error - if checkErr != nil { - err = checkErr - } else if respErr != nil { - err = respErr - } else { - err = doErr - } - - if c.ErrorHandler != nil { - return c.ErrorHandler(resp, err, attempt) - } - - // By default, we close the response body and return an error without - // returning the response - if resp != nil { - c.drainBody(resp.Body) - } - - // this means CheckRetry thought the request was a failure, but didn't - // communicate why - if err == nil { - return nil, fmt.Errorf("%s %s giving up after %d attempt(s)", - req.Method, req.URL, attempt) - } - - return nil, fmt.Errorf("%s %s giving up after %d attempt(s): %w", - req.Method, req.URL, attempt, err) -} - -// Try to read the response body so we can reuse this connection. -func (c *Client) drainBody(body io.ReadCloser) { - defer body.Close() - _, err := io.Copy(ioutil.Discard, io.LimitReader(body, respReadLimit)) - if err != nil { - if c.logger() != nil { - switch v := c.logger().(type) { - case LeveledLogger: - v.Error("error reading response body", "error", err) - case Logger: - v.Printf("[ERR] error reading response body: %v", err) - } - } - } -} - -// Get is a shortcut for doing a GET request without making a new client. -func Get(url string) (*http.Response, error) { - return defaultClient.Get(url) -} - -// Get is a convenience helper for doing simple GET requests. -func (c *Client) Get(url string) (*http.Response, error) { - req, err := NewRequest("GET", url, nil) - if err != nil { - return nil, err - } - return c.Do(req) -} - -// Head is a shortcut for doing a HEAD request without making a new client. -func Head(url string) (*http.Response, error) { - return defaultClient.Head(url) -} - -// Head is a convenience method for doing simple HEAD requests. -func (c *Client) Head(url string) (*http.Response, error) { - req, err := NewRequest("HEAD", url, nil) - if err != nil { - return nil, err - } - return c.Do(req) -} - -// Post is a shortcut for doing a POST request without making a new client. -func Post(url, bodyType string, body interface{}) (*http.Response, error) { - return defaultClient.Post(url, bodyType, body) -} - -// Post is a convenience method for doing simple POST requests. -func (c *Client) Post(url, bodyType string, body interface{}) (*http.Response, error) { - req, err := NewRequest("POST", url, body) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", bodyType) - return c.Do(req) -} - -// PostForm is a shortcut to perform a POST with form data without creating -// a new client. -func PostForm(url string, data url.Values) (*http.Response, error) { - return defaultClient.PostForm(url, data) -} - -// PostForm is a convenience method for doing simple POST operations using -// pre-filled url.Values form data. -func (c *Client) PostForm(url string, data url.Values) (*http.Response, error) { - return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) -} - -// StandardClient returns a stdlib *http.Client with a custom Transport, which -// shims in a *retryablehttp.Client for added retries. -func (c *Client) StandardClient() *http.Client { - return &http.Client{ - Transport: &RoundTripper{Client: c}, - } -} diff --git a/vendor/github.com/hashicorp/go-retryablehttp/roundtripper.go b/vendor/github.com/hashicorp/go-retryablehttp/roundtripper.go deleted file mode 100644 index 8f3ee35..0000000 --- a/vendor/github.com/hashicorp/go-retryablehttp/roundtripper.go +++ /dev/null @@ -1,52 +0,0 @@ -package retryablehttp - -import ( - "errors" - "net/http" - "net/url" - "sync" -) - -// RoundTripper implements the http.RoundTripper interface, using a retrying -// HTTP client to execute requests. -// -// It is important to note that retryablehttp doesn't always act exactly as a -// RoundTripper should. This is highly dependent on the retryable client's -// configuration. -type RoundTripper struct { - // The client to use during requests. If nil, the default retryablehttp - // client and settings will be used. - Client *Client - - // once ensures that the logic to initialize the default client runs at - // most once, in a single thread. - once sync.Once -} - -// init initializes the underlying retryable client. -func (rt *RoundTripper) init() { - if rt.Client == nil { - rt.Client = NewClient() - } -} - -// RoundTrip satisfies the http.RoundTripper interface. -func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { - rt.once.Do(rt.init) - - // Convert the request to be retryable. - retryableReq, err := FromRequest(req) - if err != nil { - return nil, err - } - - // Execute the request. - resp, err := rt.Client.Do(retryableReq) - // If we got an error returned by standard library's `Do` method, unwrap it - // otherwise we will wind up erroneously re-nesting the error. - if _, ok := err.(*url.Error); ok { - return resp, errors.Unwrap(err) - } - - return resp, err -} diff --git a/vendor/github.com/joho/godotenv/.gitignore b/vendor/github.com/joho/godotenv/.gitignore deleted file mode 100644 index e43b0f9..0000000 --- a/vendor/github.com/joho/godotenv/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store diff --git a/vendor/github.com/joho/godotenv/LICENCE b/vendor/github.com/joho/godotenv/LICENCE deleted file mode 100644 index e7ddd51..0000000 --- a/vendor/github.com/joho/godotenv/LICENCE +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) 2013 John Barton - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/vendor/github.com/joho/godotenv/README.md b/vendor/github.com/joho/godotenv/README.md deleted file mode 100644 index bfbe66a..0000000 --- a/vendor/github.com/joho/godotenv/README.md +++ /dev/null @@ -1,202 +0,0 @@ -# GoDotEnv ![CI](https://github.com/joho/godotenv/workflows/CI/badge.svg) [![Go Report Card](https://goreportcard.com/badge/github.com/joho/godotenv)](https://goreportcard.com/report/github.com/joho/godotenv) - -A Go (golang) port of the Ruby [dotenv](https://github.com/bkeepers/dotenv) project (which loads env vars from a .env file). - -From the original Library: - -> Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables. -> -> But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a .env file into ENV when the environment is bootstrapped. - -It can be used as a library (for loading in env for your own daemons etc.) or as a bin command. - -There is test coverage and CI for both linuxish and Windows environments, but I make no guarantees about the bin version working on Windows. - -## Installation - -As a library - -```shell -go get github.com/joho/godotenv -``` - -or if you want to use it as a bin command - -go >= 1.17 -```shell -go install github.com/joho/godotenv/cmd/godotenv@latest -``` - -go < 1.17 -```shell -go get github.com/joho/godotenv/cmd/godotenv -``` - -## Usage - -Add your application configuration to your `.env` file in the root of your project: - -```shell -S3_BUCKET=YOURS3BUCKET -SECRET_KEY=YOURSECRETKEYGOESHERE -``` - -Then in your Go app you can do something like - -```go -package main - -import ( - "log" - "os" - - "github.com/joho/godotenv" -) - -func main() { - err := godotenv.Load() - if err != nil { - log.Fatal("Error loading .env file") - } - - s3Bucket := os.Getenv("S3_BUCKET") - secretKey := os.Getenv("SECRET_KEY") - - // now do something with s3 or whatever -} -``` - -If you're even lazier than that, you can just take advantage of the autoload package which will read in `.env` on import - -```go -import _ "github.com/joho/godotenv/autoload" -``` - -While `.env` in the project root is the default, you don't have to be constrained, both examples below are 100% legit - -```go -godotenv.Load("somerandomfile") -godotenv.Load("filenumberone.env", "filenumbertwo.env") -``` - -If you want to be really fancy with your env file you can do comments and exports (below is a valid env file) - -```shell -# I am a comment and that is OK -SOME_VAR=someval -FOO=BAR # comments at line end are OK too -export BAR=BAZ -``` - -Or finally you can do YAML(ish) style - -```yaml -FOO: bar -BAR: baz -``` - -as a final aside, if you don't want godotenv munging your env you can just get a map back instead - -```go -var myEnv map[string]string -myEnv, err := godotenv.Read() - -s3Bucket := myEnv["S3_BUCKET"] -``` - -... or from an `io.Reader` instead of a local file - -```go -reader := getRemoteFile() -myEnv, err := godotenv.Parse(reader) -``` - -... or from a `string` if you so desire - -```go -content := getRemoteFileContent() -myEnv, err := godotenv.Unmarshal(content) -``` - -### Precedence & Conventions - -Existing envs take precedence of envs that are loaded later. - -The [convention](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use) -for managing multiple environments (i.e. development, test, production) -is to create an env named `{YOURAPP}_ENV` and load envs in this order: - -```go -env := os.Getenv("FOO_ENV") -if "" == env { - env = "development" -} - -godotenv.Load(".env." + env + ".local") -if "test" != env { - godotenv.Load(".env.local") -} -godotenv.Load(".env." + env) -godotenv.Load() // The Original .env -``` - -If you need to, you can also use `godotenv.Overload()` to defy this convention -and overwrite existing envs instead of only supplanting them. Use with caution. - -### Command Mode - -Assuming you've installed the command as above and you've got `$GOPATH/bin` in your `$PATH` - -``` -godotenv -f /some/path/to/.env some_command with some args -``` - -If you don't specify `-f` it will fall back on the default of loading `.env` in `PWD` - -By default, it won't override existing environment variables; you can do that with the `-o` flag. - -### Writing Env Files - -Godotenv can also write a map representing the environment to a correctly-formatted and escaped file - -```go -env, err := godotenv.Unmarshal("KEY=value") -err := godotenv.Write(env, "./.env") -``` - -... or to a string - -```go -env, err := godotenv.Unmarshal("KEY=value") -content, err := godotenv.Marshal(env) -``` - -## Contributing - -Contributions are welcome, but with some caveats. - -This library has been declared feature complete (see [#182](https://github.com/joho/godotenv/issues/182) for background) and will not be accepting issues or pull requests adding new functionality or breaking the library API. - -Contributions would be gladly accepted that: - -* bring this library's parsing into closer compatibility with the mainline dotenv implementations, in particular [Ruby's dotenv](https://github.com/bkeepers/dotenv) and [Node.js' dotenv](https://github.com/motdotla/dotenv) -* keep the library up to date with the go ecosystem (ie CI bumps, documentation changes, changes in the core libraries) -* bug fixes for use cases that pertain to the library's purpose of easing development of codebases deployed into twelve factor environments - -*code changes without tests and references to peer dotenv implementations will not be accepted* - -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Added some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request - -## Releases - -Releases should follow [Semver](http://semver.org/) though the first couple of releases are `v1` and `v1.1`. - -Use [annotated tags for all releases](https://github.com/joho/godotenv/issues/30). Example `git tag -a v1.2.1` - -## Who? - -The original library [dotenv](https://github.com/bkeepers/dotenv) was written by [Brandon Keepers](http://opensoul.org/), and this port was done by [John Barton](https://johnbarton.co/) based off the tests/fixtures in the original library. diff --git a/vendor/github.com/joho/godotenv/godotenv.go b/vendor/github.com/joho/godotenv/godotenv.go deleted file mode 100644 index 61b0ebb..0000000 --- a/vendor/github.com/joho/godotenv/godotenv.go +++ /dev/null @@ -1,228 +0,0 @@ -// Package godotenv is a go port of the ruby dotenv library (https://github.com/bkeepers/dotenv) -// -// Examples/readme can be found on the GitHub page at https://github.com/joho/godotenv -// -// The TL;DR is that you make a .env file that looks something like -// -// SOME_ENV_VAR=somevalue -// -// and then in your go code you can call -// -// godotenv.Load() -// -// and all the env vars declared in .env will be available through os.Getenv("SOME_ENV_VAR") -package godotenv - -import ( - "bytes" - "fmt" - "io" - "os" - "os/exec" - "sort" - "strconv" - "strings" -) - -const doubleQuoteSpecialChars = "\\\n\r\"!$`" - -// Parse reads an env file from io.Reader, returning a map of keys and values. -func Parse(r io.Reader) (map[string]string, error) { - var buf bytes.Buffer - _, err := io.Copy(&buf, r) - if err != nil { - return nil, err - } - - return UnmarshalBytes(buf.Bytes()) -} - -// Load will read your env file(s) and load them into ENV for this process. -// -// Call this function as close as possible to the start of your program (ideally in main). -// -// If you call Load without any args it will default to loading .env in the current path. -// -// You can otherwise tell it which files to load (there can be more than one) like: -// -// godotenv.Load("fileone", "filetwo") -// -// It's important to note that it WILL NOT OVERRIDE an env variable that already exists - consider the .env file to set dev vars or sensible defaults. -func Load(filenames ...string) (err error) { - filenames = filenamesOrDefault(filenames) - - for _, filename := range filenames { - err = loadFile(filename, false) - if err != nil { - return // return early on a spazout - } - } - return -} - -// Overload will read your env file(s) and load them into ENV for this process. -// -// Call this function as close as possible to the start of your program (ideally in main). -// -// If you call Overload without any args it will default to loading .env in the current path. -// -// You can otherwise tell it which files to load (there can be more than one) like: -// -// godotenv.Overload("fileone", "filetwo") -// -// It's important to note this WILL OVERRIDE an env variable that already exists - consider the .env file to forcefully set all vars. -func Overload(filenames ...string) (err error) { - filenames = filenamesOrDefault(filenames) - - for _, filename := range filenames { - err = loadFile(filename, true) - if err != nil { - return // return early on a spazout - } - } - return -} - -// Read all env (with same file loading semantics as Load) but return values as -// a map rather than automatically writing values into env -func Read(filenames ...string) (envMap map[string]string, err error) { - filenames = filenamesOrDefault(filenames) - envMap = make(map[string]string) - - for _, filename := range filenames { - individualEnvMap, individualErr := readFile(filename) - - if individualErr != nil { - err = individualErr - return // return early on a spazout - } - - for key, value := range individualEnvMap { - envMap[key] = value - } - } - - return -} - -// Unmarshal reads an env file from a string, returning a map of keys and values. -func Unmarshal(str string) (envMap map[string]string, err error) { - return UnmarshalBytes([]byte(str)) -} - -// UnmarshalBytes parses env file from byte slice of chars, returning a map of keys and values. -func UnmarshalBytes(src []byte) (map[string]string, error) { - out := make(map[string]string) - err := parseBytes(src, out) - - return out, err -} - -// Exec loads env vars from the specified filenames (empty map falls back to default) -// then executes the cmd specified. -// -// Simply hooks up os.Stdin/err/out to the command and calls Run(). -// -// If you want more fine grained control over your command it's recommended -// that you use `Load()`, `Overload()` or `Read()` and the `os/exec` package yourself. -func Exec(filenames []string, cmd string, cmdArgs []string, overload bool) error { - op := Load - if overload { - op = Overload - } - if err := op(filenames...); err != nil { - return err - } - - command := exec.Command(cmd, cmdArgs...) - command.Stdin = os.Stdin - command.Stdout = os.Stdout - command.Stderr = os.Stderr - return command.Run() -} - -// Write serializes the given environment and writes it to a file. -func Write(envMap map[string]string, filename string) error { - content, err := Marshal(envMap) - if err != nil { - return err - } - file, err := os.Create(filename) - if err != nil { - return err - } - defer file.Close() - _, err = file.WriteString(content + "\n") - if err != nil { - return err - } - return file.Sync() -} - -// Marshal outputs the given environment as a dotenv-formatted environment file. -// Each line is in the format: KEY="VALUE" where VALUE is backslash-escaped. -func Marshal(envMap map[string]string) (string, error) { - lines := make([]string, 0, len(envMap)) - for k, v := range envMap { - if d, err := strconv.Atoi(v); err == nil { - lines = append(lines, fmt.Sprintf(`%s=%d`, k, d)) - } else { - lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v))) - } - } - sort.Strings(lines) - return strings.Join(lines, "\n"), nil -} - -func filenamesOrDefault(filenames []string) []string { - if len(filenames) == 0 { - return []string{".env"} - } - return filenames -} - -func loadFile(filename string, overload bool) error { - envMap, err := readFile(filename) - if err != nil { - return err - } - - currentEnv := map[string]bool{} - rawEnv := os.Environ() - for _, rawEnvLine := range rawEnv { - key := strings.Split(rawEnvLine, "=")[0] - currentEnv[key] = true - } - - for key, value := range envMap { - if !currentEnv[key] || overload { - _ = os.Setenv(key, value) - } - } - - return nil -} - -func readFile(filename string) (envMap map[string]string, err error) { - file, err := os.Open(filename) - if err != nil { - return - } - defer file.Close() - - return Parse(file) -} - -func doubleQuoteEscape(line string) string { - for _, c := range doubleQuoteSpecialChars { - toReplace := "\\" + string(c) - if c == '\n' { - toReplace = `\n` - } - if c == '\r' { - toReplace = `\r` - } - line = strings.Replace(line, string(c), toReplace, -1) - } - return line -} diff --git a/vendor/github.com/joho/godotenv/parser.go b/vendor/github.com/joho/godotenv/parser.go deleted file mode 100644 index cc709af..0000000 --- a/vendor/github.com/joho/godotenv/parser.go +++ /dev/null @@ -1,271 +0,0 @@ -package godotenv - -import ( - "bytes" - "errors" - "fmt" - "regexp" - "strings" - "unicode" -) - -const ( - charComment = '#' - prefixSingleQuote = '\'' - prefixDoubleQuote = '"' - - exportPrefix = "export" -) - -func parseBytes(src []byte, out map[string]string) error { - src = bytes.Replace(src, []byte("\r\n"), []byte("\n"), -1) - cutset := src - for { - cutset = getStatementStart(cutset) - if cutset == nil { - // reached end of file - break - } - - key, left, err := locateKeyName(cutset) - if err != nil { - return err - } - - value, left, err := extractVarValue(left, out) - if err != nil { - return err - } - - out[key] = value - cutset = left - } - - return nil -} - -// getStatementPosition returns position of statement begin. -// -// It skips any comment line or non-whitespace character. -func getStatementStart(src []byte) []byte { - pos := indexOfNonSpaceChar(src) - if pos == -1 { - return nil - } - - src = src[pos:] - if src[0] != charComment { - return src - } - - // skip comment section - pos = bytes.IndexFunc(src, isCharFunc('\n')) - if pos == -1 { - return nil - } - - return getStatementStart(src[pos:]) -} - -// locateKeyName locates and parses key name and returns rest of slice -func locateKeyName(src []byte) (key string, cutset []byte, err error) { - // trim "export" and space at beginning - src = bytes.TrimLeftFunc(src, isSpace) - if bytes.HasPrefix(src, []byte(exportPrefix)) { - trimmed := bytes.TrimPrefix(src, []byte(exportPrefix)) - if bytes.IndexFunc(trimmed, isSpace) == 0 { - src = bytes.TrimLeftFunc(trimmed, isSpace) - } - } - - // locate key name end and validate it in single loop - offset := 0 -loop: - for i, char := range src { - rchar := rune(char) - if isSpace(rchar) { - continue - } - - switch char { - case '=', ':': - // library also supports yaml-style value declaration - key = string(src[0:i]) - offset = i + 1 - break loop - case '_': - default: - // variable name should match [A-Za-z0-9_.] - if unicode.IsLetter(rchar) || unicode.IsNumber(rchar) || rchar == '.' { - continue - } - - return "", nil, fmt.Errorf( - `unexpected character %q in variable name near %q`, - string(char), string(src)) - } - } - - if len(src) == 0 { - return "", nil, errors.New("zero length string") - } - - // trim whitespace - key = strings.TrimRightFunc(key, unicode.IsSpace) - cutset = bytes.TrimLeftFunc(src[offset:], isSpace) - return key, cutset, nil -} - -// extractVarValue extracts variable value and returns rest of slice -func extractVarValue(src []byte, vars map[string]string) (value string, rest []byte, err error) { - quote, hasPrefix := hasQuotePrefix(src) - if !hasPrefix { - // unquoted value - read until end of line - endOfLine := bytes.IndexFunc(src, isLineEnd) - - // Hit EOF without a trailing newline - if endOfLine == -1 { - endOfLine = len(src) - - if endOfLine == 0 { - return "", nil, nil - } - } - - // Convert line to rune away to do accurate countback of runes - line := []rune(string(src[0:endOfLine])) - - // Assume end of line is end of var - endOfVar := len(line) - if endOfVar == 0 { - return "", src[endOfLine:], nil - } - - // Work backwards to check if the line ends in whitespace then - // a comment (ie asdasd # some comment) - for i := endOfVar - 1; i >= 0; i-- { - if line[i] == charComment && i > 0 { - if isSpace(line[i-1]) { - endOfVar = i - break - } - } - } - - trimmed := strings.TrimFunc(string(line[0:endOfVar]), isSpace) - - return expandVariables(trimmed, vars), src[endOfLine:], nil - } - - // lookup quoted string terminator - for i := 1; i < len(src); i++ { - if char := src[i]; char != quote { - continue - } - - // skip escaped quote symbol (\" or \', depends on quote) - if prevChar := src[i-1]; prevChar == '\\' { - continue - } - - // trim quotes - trimFunc := isCharFunc(rune(quote)) - value = string(bytes.TrimLeftFunc(bytes.TrimRightFunc(src[0:i], trimFunc), trimFunc)) - if quote == prefixDoubleQuote { - // unescape newlines for double quote (this is compat feature) - // and expand environment variables - value = expandVariables(expandEscapes(value), vars) - } - - return value, src[i+1:], nil - } - - // return formatted error if quoted string is not terminated - valEndIndex := bytes.IndexFunc(src, isCharFunc('\n')) - if valEndIndex == -1 { - valEndIndex = len(src) - } - - return "", nil, fmt.Errorf("unterminated quoted value %s", src[:valEndIndex]) -} - -func expandEscapes(str string) string { - out := escapeRegex.ReplaceAllStringFunc(str, func(match string) string { - c := strings.TrimPrefix(match, `\`) - switch c { - case "n": - return "\n" - case "r": - return "\r" - default: - return match - } - }) - return unescapeCharsRegex.ReplaceAllString(out, "$1") -} - -func indexOfNonSpaceChar(src []byte) int { - return bytes.IndexFunc(src, func(r rune) bool { - return !unicode.IsSpace(r) - }) -} - -// hasQuotePrefix reports whether charset starts with single or double quote and returns quote character -func hasQuotePrefix(src []byte) (prefix byte, isQuored bool) { - if len(src) == 0 { - return 0, false - } - - switch prefix := src[0]; prefix { - case prefixDoubleQuote, prefixSingleQuote: - return prefix, true - default: - return 0, false - } -} - -func isCharFunc(char rune) func(rune) bool { - return func(v rune) bool { - return v == char - } -} - -// isSpace reports whether the rune is a space character but not line break character -// -// this differs from unicode.IsSpace, which also applies line break as space -func isSpace(r rune) bool { - switch r { - case '\t', '\v', '\f', '\r', ' ', 0x85, 0xA0: - return true - } - return false -} - -func isLineEnd(r rune) bool { - if r == '\n' || r == '\r' { - return true - } - return false -} - -var ( - escapeRegex = regexp.MustCompile(`\\.`) - expandVarRegex = regexp.MustCompile(`(\\)?(\$)(\()?\{?([A-Z0-9_]+)?\}?`) - unescapeCharsRegex = regexp.MustCompile(`\\([^$])`) -) - -func expandVariables(v string, m map[string]string) string { - return expandVarRegex.ReplaceAllStringFunc(v, func(s string) string { - submatch := expandVarRegex.FindStringSubmatch(s) - - if submatch == nil { - return s - } - if submatch[1] == "\\" || submatch[2] == "(" { - return submatch[0][1:] - } else if submatch[4] != "" { - return m[submatch[4]] - } - return s - }) -} diff --git a/vendor/github.com/sirupsen/logrus/.gitignore b/vendor/github.com/sirupsen/logrus/.gitignore deleted file mode 100644 index 1fb13ab..0000000 --- a/vendor/github.com/sirupsen/logrus/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -logrus -vendor - -.idea/ diff --git a/vendor/github.com/sirupsen/logrus/.golangci.yml b/vendor/github.com/sirupsen/logrus/.golangci.yml deleted file mode 100644 index 65dc285..0000000 --- a/vendor/github.com/sirupsen/logrus/.golangci.yml +++ /dev/null @@ -1,40 +0,0 @@ -run: - # do not run on test files yet - tests: false - -# all available settings of specific linters -linters-settings: - errcheck: - # report about not checking of errors in type assetions: `a := b.(MyStruct)`; - # default is false: such cases aren't reported by default. - check-type-assertions: false - - # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; - # default is false: such cases aren't reported by default. - check-blank: false - - lll: - line-length: 100 - tab-width: 4 - - prealloc: - simple: false - range-loops: false - for-loops: false - - whitespace: - multi-if: false # Enforces newlines (or comments) after every multi-line if statement - multi-func: false # Enforces newlines (or comments) after every multi-line function signature - -linters: - enable: - - megacheck - - govet - disable: - - maligned - - prealloc - disable-all: false - presets: - - bugs - - unused - fast: false diff --git a/vendor/github.com/sirupsen/logrus/.travis.yml b/vendor/github.com/sirupsen/logrus/.travis.yml deleted file mode 100644 index c1dbd5a..0000000 --- a/vendor/github.com/sirupsen/logrus/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: go -go_import_path: github.com/sirupsen/logrus -git: - depth: 1 -env: - - GO111MODULE=on -go: 1.15.x -os: linux -install: - - ./travis/install.sh -script: - - cd ci - - go run mage.go -v -w ../ crossBuild - - go run mage.go -v -w ../ lint - - go run mage.go -v -w ../ test diff --git a/vendor/github.com/sirupsen/logrus/CHANGELOG.md b/vendor/github.com/sirupsen/logrus/CHANGELOG.md deleted file mode 100644 index 7567f61..0000000 --- a/vendor/github.com/sirupsen/logrus/CHANGELOG.md +++ /dev/null @@ -1,259 +0,0 @@ -# 1.8.1 -Code quality: - * move magefile in its own subdir/submodule to remove magefile dependency on logrus consumer - * improve timestamp format documentation - -Fixes: - * fix race condition on logger hooks - - -# 1.8.0 - -Correct versioning number replacing v1.7.1. - -# 1.7.1 - -Beware this release has introduced a new public API and its semver is therefore incorrect. - -Code quality: - * use go 1.15 in travis - * use magefile as task runner - -Fixes: - * small fixes about new go 1.13 error formatting system - * Fix for long time race condiction with mutating data hooks - -Features: - * build support for zos - -# 1.7.0 -Fixes: - * the dependency toward a windows terminal library has been removed - -Features: - * a new buffer pool management API has been added - * a set of `Fn()` functions have been added - -# 1.6.0 -Fixes: - * end of line cleanup - * revert the entry concurrency bug fix whic leads to deadlock under some circumstances - * update dependency on go-windows-terminal-sequences to fix a crash with go 1.14 - -Features: - * add an option to the `TextFormatter` to completely disable fields quoting - -# 1.5.0 -Code quality: - * add golangci linter run on travis - -Fixes: - * add mutex for hooks concurrent access on `Entry` data - * caller function field for go1.14 - * fix build issue for gopherjs target - -Feature: - * add an hooks/writer sub-package whose goal is to split output on different stream depending on the trace level - * add a `DisableHTMLEscape` option in the `JSONFormatter` - * add `ForceQuote` and `PadLevelText` options in the `TextFormatter` - -# 1.4.2 - * Fixes build break for plan9, nacl, solaris -# 1.4.1 -This new release introduces: - * Enhance TextFormatter to not print caller information when they are empty (#944) - * Remove dependency on golang.org/x/crypto (#932, #943) - -Fixes: - * Fix Entry.WithContext method to return a copy of the initial entry (#941) - -# 1.4.0 -This new release introduces: - * Add `DeferExitHandler`, similar to `RegisterExitHandler` but prepending the handler to the list of handlers (semantically like `defer`) (#848). - * Add `CallerPrettyfier` to `JSONFormatter` and `TextFormatter` (#909, #911) - * Add `Entry.WithContext()` and `Entry.Context`, to set a context on entries to be used e.g. in hooks (#919). - -Fixes: - * Fix wrong method calls `Logger.Print` and `Logger.Warningln` (#893). - * Update `Entry.Logf` to not do string formatting unless the log level is enabled (#903) - * Fix infinite recursion on unknown `Level.String()` (#907) - * Fix race condition in `getCaller` (#916). - - -# 1.3.0 -This new release introduces: - * Log, Logf, Logln functions for Logger and Entry that take a Level - -Fixes: - * Building prometheus node_exporter on AIX (#840) - * Race condition in TextFormatter (#468) - * Travis CI import path (#868) - * Remove coloured output on Windows (#862) - * Pointer to func as field in JSONFormatter (#870) - * Properly marshal Levels (#873) - -# 1.2.0 -This new release introduces: - * A new method `SetReportCaller` in the `Logger` to enable the file, line and calling function from which the trace has been issued - * A new trace level named `Trace` whose level is below `Debug` - * A configurable exit function to be called upon a Fatal trace - * The `Level` object now implements `encoding.TextUnmarshaler` interface - -# 1.1.1 -This is a bug fix release. - * fix the build break on Solaris - * don't drop a whole trace in JSONFormatter when a field param is a function pointer which can not be serialized - -# 1.1.0 -This new release introduces: - * several fixes: - * a fix for a race condition on entry formatting - * proper cleanup of previously used entries before putting them back in the pool - * the extra new line at the end of message in text formatter has been removed - * a new global public API to check if a level is activated: IsLevelEnabled - * the following methods have been added to the Logger object - * IsLevelEnabled - * SetFormatter - * SetOutput - * ReplaceHooks - * introduction of go module - * an indent configuration for the json formatter - * output colour support for windows - * the field sort function is now configurable for text formatter - * the CLICOLOR and CLICOLOR\_FORCE environment variable support in text formater - -# 1.0.6 - -This new release introduces: - * a new api WithTime which allows to easily force the time of the log entry - which is mostly useful for logger wrapper - * a fix reverting the immutability of the entry given as parameter to the hooks - a new configuration field of the json formatter in order to put all the fields - in a nested dictionnary - * a new SetOutput method in the Logger - * a new configuration of the textformatter to configure the name of the default keys - * a new configuration of the text formatter to disable the level truncation - -# 1.0.5 - -* Fix hooks race (#707) -* Fix panic deadlock (#695) - -# 1.0.4 - -* Fix race when adding hooks (#612) -* Fix terminal check in AppEngine (#635) - -# 1.0.3 - -* Replace example files with testable examples - -# 1.0.2 - -* bug: quote non-string values in text formatter (#583) -* Make (*Logger) SetLevel a public method - -# 1.0.1 - -* bug: fix escaping in text formatter (#575) - -# 1.0.0 - -* Officially changed name to lower-case -* bug: colors on Windows 10 (#541) -* bug: fix race in accessing level (#512) - -# 0.11.5 - -* feature: add writer and writerlevel to entry (#372) - -# 0.11.4 - -* bug: fix undefined variable on solaris (#493) - -# 0.11.3 - -* formatter: configure quoting of empty values (#484) -* formatter: configure quoting character (default is `"`) (#484) -* bug: fix not importing io correctly in non-linux environments (#481) - -# 0.11.2 - -* bug: fix windows terminal detection (#476) - -# 0.11.1 - -* bug: fix tty detection with custom out (#471) - -# 0.11.0 - -* performance: Use bufferpool to allocate (#370) -* terminal: terminal detection for app-engine (#343) -* feature: exit handler (#375) - -# 0.10.0 - -* feature: Add a test hook (#180) -* feature: `ParseLevel` is now case-insensitive (#326) -* feature: `FieldLogger` interface that generalizes `Logger` and `Entry` (#308) -* performance: avoid re-allocations on `WithFields` (#335) - -# 0.9.0 - -* logrus/text_formatter: don't emit empty msg -* logrus/hooks/airbrake: move out of main repository -* logrus/hooks/sentry: move out of main repository -* logrus/hooks/papertrail: move out of main repository -* logrus/hooks/bugsnag: move out of main repository -* logrus/core: run tests with `-race` -* logrus/core: detect TTY based on `stderr` -* logrus/core: support `WithError` on logger -* logrus/core: Solaris support - -# 0.8.7 - -* logrus/core: fix possible race (#216) -* logrus/doc: small typo fixes and doc improvements - - -# 0.8.6 - -* hooks/raven: allow passing an initialized client - -# 0.8.5 - -* logrus/core: revert #208 - -# 0.8.4 - -* formatter/text: fix data race (#218) - -# 0.8.3 - -* logrus/core: fix entry log level (#208) -* logrus/core: improve performance of text formatter by 40% -* logrus/core: expose `LevelHooks` type -* logrus/core: add support for DragonflyBSD and NetBSD -* formatter/text: print structs more verbosely - -# 0.8.2 - -* logrus: fix more Fatal family functions - -# 0.8.1 - -* logrus: fix not exiting on `Fatalf` and `Fatalln` - -# 0.8.0 - -* logrus: defaults to stderr instead of stdout -* hooks/sentry: add special field for `*http.Request` -* formatter/text: ignore Windows for colors - -# 0.7.3 - -* formatter/\*: allow configuration of timestamp layout - -# 0.7.2 - -* formatter/text: Add configuration option for time format (#158) diff --git a/vendor/github.com/sirupsen/logrus/LICENSE b/vendor/github.com/sirupsen/logrus/LICENSE deleted file mode 100644 index f090cb4..0000000 --- a/vendor/github.com/sirupsen/logrus/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Simon Eskildsen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/sirupsen/logrus/README.md b/vendor/github.com/sirupsen/logrus/README.md deleted file mode 100644 index b042c89..0000000 --- a/vendor/github.com/sirupsen/logrus/README.md +++ /dev/null @@ -1,513 +0,0 @@ -# Logrus :walrus: [![Build Status](https://github.com/sirupsen/logrus/workflows/CI/badge.svg)](https://github.com/sirupsen/logrus/actions?query=workflow%3ACI) [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![Go Reference](https://pkg.go.dev/badge/github.com/sirupsen/logrus.svg)](https://pkg.go.dev/github.com/sirupsen/logrus) - -Logrus is a structured logger for Go (golang), completely API compatible with -the standard library logger. - -**Logrus is in maintenance-mode.** We will not be introducing new features. It's -simply too hard to do in a way that won't break many people's projects, which is -the last thing you want from your Logging library (again...). - -This does not mean Logrus is dead. Logrus will continue to be maintained for -security, (backwards compatible) bug fixes, and performance (where we are -limited by the interface). - -I believe Logrus' biggest contribution is to have played a part in today's -widespread use of structured logging in Golang. There doesn't seem to be a -reason to do a major, breaking iteration into Logrus V2, since the fantastic Go -community has built those independently. Many fantastic alternatives have sprung -up. Logrus would look like those, had it been re-designed with what we know -about structured logging in Go today. Check out, for example, -[Zerolog][zerolog], [Zap][zap], and [Apex][apex]. - -[zerolog]: https://github.com/rs/zerolog -[zap]: https://github.com/uber-go/zap -[apex]: https://github.com/apex/log - -**Seeing weird case-sensitive problems?** It's in the past been possible to -import Logrus as both upper- and lower-case. Due to the Go package environment, -this caused issues in the community and we needed a standard. Some environments -experienced problems with the upper-case variant, so the lower-case was decided. -Everything using `logrus` will need to use the lower-case: -`github.com/sirupsen/logrus`. Any package that isn't, should be changed. - -To fix Glide, see [these -comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437). -For an in-depth explanation of the casing issue, see [this -comment](https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276). - -Nicely color-coded in development (when a TTY is attached, otherwise just -plain text): - -![Colored](http://i.imgur.com/PY7qMwd.png) - -With `log.SetFormatter(&log.JSONFormatter{})`, for easy parsing by logstash -or Splunk: - -```json -{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the -ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"} - -{"level":"warning","msg":"The group's number increased tremendously!", -"number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"} - -{"animal":"walrus","level":"info","msg":"A giant walrus appears!", -"size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"} - -{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.", -"size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"} - -{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true, -"time":"2014-03-10 19:57:38.562543128 -0400 EDT"} -``` - -With the default `log.SetFormatter(&log.TextFormatter{})` when a TTY is not -attached, the output is compatible with the -[logfmt](http://godoc.org/github.com/kr/logfmt) format: - -```text -time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8 -time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10 -time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true -time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4 -time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009 -time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true -``` -To ensure this behaviour even if a TTY is attached, set your formatter as follows: - -```go - log.SetFormatter(&log.TextFormatter{ - DisableColors: true, - FullTimestamp: true, - }) -``` - -#### Logging Method Name - -If you wish to add the calling method as a field, instruct the logger via: -```go -log.SetReportCaller(true) -``` -This adds the caller as 'method' like so: - -```json -{"animal":"penguin","level":"fatal","method":"github.com/sirupsen/arcticcreatures.migrate","msg":"a penguin swims by", -"time":"2014-03-10 19:57:38.562543129 -0400 EDT"} -``` - -```text -time="2015-03-26T01:27:38-04:00" level=fatal method=github.com/sirupsen/arcticcreatures.migrate msg="a penguin swims by" animal=penguin -``` -Note that this does add measurable overhead - the cost will depend on the version of Go, but is -between 20 and 40% in recent tests with 1.6 and 1.7. You can validate this in your -environment via benchmarks: -``` -go test -bench=.*CallerTracing -``` - - -#### Case-sensitivity - -The organization's name was changed to lower-case--and this will not be changed -back. If you are getting import conflicts due to case sensitivity, please use -the lower-case import: `github.com/sirupsen/logrus`. - -#### Example - -The simplest way to use Logrus is simply the package-level exported logger: - -```go -package main - -import ( - log "github.com/sirupsen/logrus" -) - -func main() { - log.WithFields(log.Fields{ - "animal": "walrus", - }).Info("A walrus appears") -} -``` - -Note that it's completely api-compatible with the stdlib logger, so you can -replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"` -and you'll now have the flexibility of Logrus. You can customize it all you -want: - -```go -package main - -import ( - "os" - log "github.com/sirupsen/logrus" -) - -func init() { - // Log as JSON instead of the default ASCII formatter. - log.SetFormatter(&log.JSONFormatter{}) - - // Output to stdout instead of the default stderr - // Can be any io.Writer, see below for File example - log.SetOutput(os.Stdout) - - // Only log the warning severity or above. - log.SetLevel(log.WarnLevel) -} - -func main() { - log.WithFields(log.Fields{ - "animal": "walrus", - "size": 10, - }).Info("A group of walrus emerges from the ocean") - - log.WithFields(log.Fields{ - "omg": true, - "number": 122, - }).Warn("The group's number increased tremendously!") - - log.WithFields(log.Fields{ - "omg": true, - "number": 100, - }).Fatal("The ice breaks!") - - // A common pattern is to re-use fields between logging statements by re-using - // the logrus.Entry returned from WithFields() - contextLogger := log.WithFields(log.Fields{ - "common": "this is a common field", - "other": "I also should be logged always", - }) - - contextLogger.Info("I'll be logged with common and other field") - contextLogger.Info("Me too") -} -``` - -For more advanced usage such as logging to multiple locations from the same -application, you can also create an instance of the `logrus` Logger: - -```go -package main - -import ( - "os" - "github.com/sirupsen/logrus" -) - -// Create a new instance of the logger. You can have any number of instances. -var log = logrus.New() - -func main() { - // The API for setting attributes is a little different than the package level - // exported logger. See Godoc. - log.Out = os.Stdout - - // You could set this to any `io.Writer` such as a file - // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) - // if err == nil { - // log.Out = file - // } else { - // log.Info("Failed to log to file, using default stderr") - // } - - log.WithFields(logrus.Fields{ - "animal": "walrus", - "size": 10, - }).Info("A group of walrus emerges from the ocean") -} -``` - -#### Fields - -Logrus encourages careful, structured logging through logging fields instead of -long, unparseable error messages. For example, instead of: `log.Fatalf("Failed -to send event %s to topic %s with key %d")`, you should log the much more -discoverable: - -```go -log.WithFields(log.Fields{ - "event": event, - "topic": topic, - "key": key, -}).Fatal("Failed to send event") -``` - -We've found this API forces you to think about logging in a way that produces -much more useful logging messages. We've been in countless situations where just -a single added field to a log statement that was already there would've saved us -hours. The `WithFields` call is optional. - -In general, with Logrus using any of the `printf`-family functions should be -seen as a hint you should add a field, however, you can still use the -`printf`-family functions with Logrus. - -#### Default Fields - -Often it's helpful to have fields _always_ attached to log statements in an -application or parts of one. For example, you may want to always log the -`request_id` and `user_ip` in the context of a request. Instead of writing -`log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})` on -every line, you can create a `logrus.Entry` to pass around instead: - -```go -requestLogger := log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip}) -requestLogger.Info("something happened on that request") # will log request_id and user_ip -requestLogger.Warn("something not great happened") -``` - -#### Hooks - -You can add hooks for logging levels. For example to send errors to an exception -tracking service on `Error`, `Fatal` and `Panic`, info to StatsD or log to -multiple places simultaneously, e.g. syslog. - -Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in -`init`: - -```go -import ( - log "github.com/sirupsen/logrus" - "gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "airbrake" - logrus_syslog "github.com/sirupsen/logrus/hooks/syslog" - "log/syslog" -) - -func init() { - - // Use the Airbrake hook to report errors that have Error severity or above to - // an exception tracker. You can create custom hooks, see the Hooks section. - log.AddHook(airbrake.NewHook(123, "xyz", "production")) - - hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "") - if err != nil { - log.Error("Unable to connect to local syslog daemon") - } else { - log.AddHook(hook) - } -} -``` -Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md). - -A list of currently known service hooks can be found in this wiki [page](https://github.com/sirupsen/logrus/wiki/Hooks) - - -#### Level logging - -Logrus has seven logging levels: Trace, Debug, Info, Warning, Error, Fatal and Panic. - -```go -log.Trace("Something very low level.") -log.Debug("Useful debugging information.") -log.Info("Something noteworthy happened!") -log.Warn("You should probably take a look at this.") -log.Error("Something failed but I'm not quitting.") -// Calls os.Exit(1) after logging -log.Fatal("Bye.") -// Calls panic() after logging -log.Panic("I'm bailing.") -``` - -You can set the logging level on a `Logger`, then it will only log entries with -that severity or anything above it: - -```go -// Will log anything that is info or above (warn, error, fatal, panic). Default. -log.SetLevel(log.InfoLevel) -``` - -It may be useful to set `log.Level = logrus.DebugLevel` in a debug or verbose -environment if your application has that. - -#### Entries - -Besides the fields added with `WithField` or `WithFields` some fields are -automatically added to all logging events: - -1. `time`. The timestamp when the entry was created. -2. `msg`. The logging message passed to `{Info,Warn,Error,Fatal,Panic}` after - the `AddFields` call. E.g. `Failed to send event.` -3. `level`. The logging level. E.g. `info`. - -#### Environments - -Logrus has no notion of environment. - -If you wish for hooks and formatters to only be used in specific environments, -you should handle that yourself. For example, if your application has a global -variable `Environment`, which is a string representation of the environment you -could do: - -```go -import ( - log "github.com/sirupsen/logrus" -) - -func init() { - // do something here to set environment depending on an environment variable - // or command-line flag - if Environment == "production" { - log.SetFormatter(&log.JSONFormatter{}) - } else { - // The TextFormatter is default, you don't actually have to do this. - log.SetFormatter(&log.TextFormatter{}) - } -} -``` - -This configuration is how `logrus` was intended to be used, but JSON in -production is mostly only useful if you do log aggregation with tools like -Splunk or Logstash. - -#### Formatters - -The built-in logging formatters are: - -* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise - without colors. - * *Note:* to force colored output when there is no TTY, set the `ForceColors` - field to `true`. To force no colored output even if there is a TTY set the - `DisableColors` field to `true`. For Windows, see - [github.com/mattn/go-colorable](https://github.com/mattn/go-colorable). - * When colors are enabled, levels are truncated to 4 characters by default. To disable - truncation set the `DisableLevelTruncation` field to `true`. - * When outputting to a TTY, it's often helpful to visually scan down a column where all the levels are the same width. Setting the `PadLevelText` field to `true` enables this behavior, by adding padding to the level text. - * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter). -* `logrus.JSONFormatter`. Logs fields as JSON. - * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter). - -Third party logging formatters: - -* [`FluentdFormatter`](https://github.com/joonix/log). Formats entries that can be parsed by Kubernetes and Google Container Engine. -* [`GELF`](https://github.com/fabienm/go-logrus-formatters). Formats entries so they comply to Graylog's [GELF 1.1 specification](http://docs.graylog.org/en/2.4/pages/gelf.html). -* [`logstash`](https://github.com/bshuster-repo/logrus-logstash-hook). Logs fields as [Logstash](http://logstash.net) Events. -* [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout. -* [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the Power of Zalgo. -* [`nested-logrus-formatter`](https://github.com/antonfisher/nested-logrus-formatter). Converts logrus fields to a nested structure. -* [`powerful-logrus-formatter`](https://github.com/zput/zxcTool). get fileName, log's line number and the latest function's name when print log; Sava log to files. -* [`caption-json-formatter`](https://github.com/nolleh/caption_json_formatter). logrus's message json formatter with human-readable caption added. - -You can define your formatter by implementing the `Formatter` interface, -requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a -`Fields` type (`map[string]interface{}`) with all your fields as well as the -default ones (see Entries section above): - -```go -type MyJSONFormatter struct { -} - -log.SetFormatter(new(MyJSONFormatter)) - -func (f *MyJSONFormatter) Format(entry *Entry) ([]byte, error) { - // Note this doesn't include Time, Level and Message which are available on - // the Entry. Consult `godoc` on information about those fields or read the - // source of the official loggers. - serialized, err := json.Marshal(entry.Data) - if err != nil { - return nil, fmt.Errorf("Failed to marshal fields to JSON, %w", err) - } - return append(serialized, '\n'), nil -} -``` - -#### Logger as an `io.Writer` - -Logrus can be transformed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it. - -```go -w := logger.Writer() -defer w.Close() - -srv := http.Server{ - // create a stdlib log.Logger that writes to - // logrus.Logger. - ErrorLog: log.New(w, "", 0), -} -``` - -Each line written to that writer will be printed the usual way, using formatters -and hooks. The level for those entries is `info`. - -This means that we can override the standard library logger easily: - -```go -logger := logrus.New() -logger.Formatter = &logrus.JSONFormatter{} - -// Use logrus for standard log output -// Note that `log` here references stdlib's log -// Not logrus imported under the name `log`. -log.SetOutput(logger.Writer()) -``` - -#### Rotation - -Log rotation is not provided with Logrus. Log rotation should be done by an -external program (like `logrotate(8)`) that can compress and delete old log -entries. It should not be a feature of the application-level logger. - -#### Tools - -| Tool | Description | -| ---- | ----------- | -|[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will be generated with different configs in different environments.| -|[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper around Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) | - -#### Testing - -Logrus has a built in facility for asserting the presence of log messages. This is implemented through the `test` hook and provides: - -* decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just adds the `test` hook -* a test logger (`test.NewNullLogger`) that just records log messages (and does not output any): - -```go -import( - "github.com/sirupsen/logrus" - "github.com/sirupsen/logrus/hooks/test" - "github.com/stretchr/testify/assert" - "testing" -) - -func TestSomething(t*testing.T){ - logger, hook := test.NewNullLogger() - logger.Error("Helloerror") - - assert.Equal(t, 1, len(hook.Entries)) - assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level) - assert.Equal(t, "Helloerror", hook.LastEntry().Message) - - hook.Reset() - assert.Nil(t, hook.LastEntry()) -} -``` - -#### Fatal handlers - -Logrus can register one or more functions that will be called when any `fatal` -level message is logged. The registered handlers will be executed before -logrus performs an `os.Exit(1)`. This behavior may be helpful if callers need -to gracefully shutdown. Unlike a `panic("Something went wrong...")` call which can be intercepted with a deferred `recover` a call to `os.Exit(1)` can not be intercepted. - -``` -... -handler := func() { - // gracefully shutdown something... -} -logrus.RegisterExitHandler(handler) -... -``` - -#### Thread safety - -By default, Logger is protected by a mutex for concurrent writes. The mutex is held when calling hooks and writing logs. -If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking. - -Situation when locking is not needed includes: - -* You have no hooks registered, or hooks calling is already thread-safe. - -* Writing to logger.Out is already thread-safe, for example: - - 1) logger.Out is protected by locks. - - 2) logger.Out is an os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allows multi-thread/multi-process writing) - - (Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/) diff --git a/vendor/github.com/sirupsen/logrus/alt_exit.go b/vendor/github.com/sirupsen/logrus/alt_exit.go deleted file mode 100644 index 8fd189e..0000000 --- a/vendor/github.com/sirupsen/logrus/alt_exit.go +++ /dev/null @@ -1,76 +0,0 @@ -package logrus - -// The following code was sourced and modified from the -// https://github.com/tebeka/atexit package governed by the following license: -// -// Copyright (c) 2012 Miki Tebeka . -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import ( - "fmt" - "os" -) - -var handlers = []func(){} - -func runHandler(handler func()) { - defer func() { - if err := recover(); err != nil { - fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err) - } - }() - - handler() -} - -func runHandlers() { - for _, handler := range handlers { - runHandler(handler) - } -} - -// Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code) -func Exit(code int) { - runHandlers() - os.Exit(code) -} - -// RegisterExitHandler appends a Logrus Exit handler to the list of handlers, -// call logrus.Exit to invoke all handlers. The handlers will also be invoked when -// any Fatal log entry is made. -// -// This method is useful when a caller wishes to use logrus to log a fatal -// message but also needs to gracefully shutdown. An example usecase could be -// closing database connections, or sending a alert that the application is -// closing. -func RegisterExitHandler(handler func()) { - handlers = append(handlers, handler) -} - -// DeferExitHandler prepends a Logrus Exit handler to the list of handlers, -// call logrus.Exit to invoke all handlers. The handlers will also be invoked when -// any Fatal log entry is made. -// -// This method is useful when a caller wishes to use logrus to log a fatal -// message but also needs to gracefully shutdown. An example usecase could be -// closing database connections, or sending a alert that the application is -// closing. -func DeferExitHandler(handler func()) { - handlers = append([]func(){handler}, handlers...) -} diff --git a/vendor/github.com/sirupsen/logrus/appveyor.yml b/vendor/github.com/sirupsen/logrus/appveyor.yml deleted file mode 100644 index df9d65c..0000000 --- a/vendor/github.com/sirupsen/logrus/appveyor.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: "{build}" -platform: x64 -clone_folder: c:\gopath\src\github.com\sirupsen\logrus -environment: - GOPATH: c:\gopath -branches: - only: - - master -install: - - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% - - go version -build_script: - - go get -t - - go test diff --git a/vendor/github.com/sirupsen/logrus/buffer_pool.go b/vendor/github.com/sirupsen/logrus/buffer_pool.go deleted file mode 100644 index c7787f7..0000000 --- a/vendor/github.com/sirupsen/logrus/buffer_pool.go +++ /dev/null @@ -1,43 +0,0 @@ -package logrus - -import ( - "bytes" - "sync" -) - -var ( - bufferPool BufferPool -) - -type BufferPool interface { - Put(*bytes.Buffer) - Get() *bytes.Buffer -} - -type defaultPool struct { - pool *sync.Pool -} - -func (p *defaultPool) Put(buf *bytes.Buffer) { - p.pool.Put(buf) -} - -func (p *defaultPool) Get() *bytes.Buffer { - return p.pool.Get().(*bytes.Buffer) -} - -// SetBufferPool allows to replace the default logrus buffer pool -// to better meets the specific needs of an application. -func SetBufferPool(bp BufferPool) { - bufferPool = bp -} - -func init() { - SetBufferPool(&defaultPool{ - pool: &sync.Pool{ - New: func() interface{} { - return new(bytes.Buffer) - }, - }, - }) -} diff --git a/vendor/github.com/sirupsen/logrus/doc.go b/vendor/github.com/sirupsen/logrus/doc.go deleted file mode 100644 index da67aba..0000000 --- a/vendor/github.com/sirupsen/logrus/doc.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Package logrus is a structured logger for Go, completely API compatible with the standard library logger. - - -The simplest way to use Logrus is simply the package-level exported logger: - - package main - - import ( - log "github.com/sirupsen/logrus" - ) - - func main() { - log.WithFields(log.Fields{ - "animal": "walrus", - "number": 1, - "size": 10, - }).Info("A walrus appears") - } - -Output: - time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 - -For a full guide visit https://github.com/sirupsen/logrus -*/ -package logrus diff --git a/vendor/github.com/sirupsen/logrus/entry.go b/vendor/github.com/sirupsen/logrus/entry.go deleted file mode 100644 index 71cdbbc..0000000 --- a/vendor/github.com/sirupsen/logrus/entry.go +++ /dev/null @@ -1,442 +0,0 @@ -package logrus - -import ( - "bytes" - "context" - "fmt" - "os" - "reflect" - "runtime" - "strings" - "sync" - "time" -) - -var ( - - // qualified package name, cached at first use - logrusPackage string - - // Positions in the call stack when tracing to report the calling method - minimumCallerDepth int - - // Used for caller information initialisation - callerInitOnce sync.Once -) - -const ( - maximumCallerDepth int = 25 - knownLogrusFrames int = 4 -) - -func init() { - // start at the bottom of the stack before the package-name cache is primed - minimumCallerDepth = 1 -} - -// Defines the key when adding errors using WithError. -var ErrorKey = "error" - -// An entry is the final or intermediate Logrus logging entry. It contains all -// the fields passed with WithField{,s}. It's finally logged when Trace, Debug, -// Info, Warn, Error, Fatal or Panic is called on it. These objects can be -// reused and passed around as much as you wish to avoid field duplication. -type Entry struct { - Logger *Logger - - // Contains all the fields set by the user. - Data Fields - - // Time at which the log entry was created - Time time.Time - - // Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic - // This field will be set on entry firing and the value will be equal to the one in Logger struct field. - Level Level - - // Calling method, with package name - Caller *runtime.Frame - - // Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic - Message string - - // When formatter is called in entry.log(), a Buffer may be set to entry - Buffer *bytes.Buffer - - // Contains the context set by the user. Useful for hook processing etc. - Context context.Context - - // err may contain a field formatting error - err string -} - -func NewEntry(logger *Logger) *Entry { - return &Entry{ - Logger: logger, - // Default is three fields, plus one optional. Give a little extra room. - Data: make(Fields, 6), - } -} - -func (entry *Entry) Dup() *Entry { - data := make(Fields, len(entry.Data)) - for k, v := range entry.Data { - data[k] = v - } - return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, Context: entry.Context, err: entry.err} -} - -// Returns the bytes representation of this entry from the formatter. -func (entry *Entry) Bytes() ([]byte, error) { - return entry.Logger.Formatter.Format(entry) -} - -// Returns the string representation from the reader and ultimately the -// formatter. -func (entry *Entry) String() (string, error) { - serialized, err := entry.Bytes() - if err != nil { - return "", err - } - str := string(serialized) - return str, nil -} - -// Add an error as single field (using the key defined in ErrorKey) to the Entry. -func (entry *Entry) WithError(err error) *Entry { - return entry.WithField(ErrorKey, err) -} - -// Add a context to the Entry. -func (entry *Entry) WithContext(ctx context.Context) *Entry { - dataCopy := make(Fields, len(entry.Data)) - for k, v := range entry.Data { - dataCopy[k] = v - } - return &Entry{Logger: entry.Logger, Data: dataCopy, Time: entry.Time, err: entry.err, Context: ctx} -} - -// Add a single field to the Entry. -func (entry *Entry) WithField(key string, value interface{}) *Entry { - return entry.WithFields(Fields{key: value}) -} - -// Add a map of fields to the Entry. -func (entry *Entry) WithFields(fields Fields) *Entry { - data := make(Fields, len(entry.Data)+len(fields)) - for k, v := range entry.Data { - data[k] = v - } - fieldErr := entry.err - for k, v := range fields { - isErrField := false - if t := reflect.TypeOf(v); t != nil { - switch { - case t.Kind() == reflect.Func, t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Func: - isErrField = true - } - } - if isErrField { - tmp := fmt.Sprintf("can not add field %q", k) - if fieldErr != "" { - fieldErr = entry.err + ", " + tmp - } else { - fieldErr = tmp - } - } else { - data[k] = v - } - } - return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, err: fieldErr, Context: entry.Context} -} - -// Overrides the time of the Entry. -func (entry *Entry) WithTime(t time.Time) *Entry { - dataCopy := make(Fields, len(entry.Data)) - for k, v := range entry.Data { - dataCopy[k] = v - } - return &Entry{Logger: entry.Logger, Data: dataCopy, Time: t, err: entry.err, Context: entry.Context} -} - -// getPackageName reduces a fully qualified function name to the package name -// There really ought to be to be a better way... -func getPackageName(f string) string { - for { - lastPeriod := strings.LastIndex(f, ".") - lastSlash := strings.LastIndex(f, "/") - if lastPeriod > lastSlash { - f = f[:lastPeriod] - } else { - break - } - } - - return f -} - -// getCaller retrieves the name of the first non-logrus calling function -func getCaller() *runtime.Frame { - // cache this package's fully-qualified name - callerInitOnce.Do(func() { - pcs := make([]uintptr, maximumCallerDepth) - _ = runtime.Callers(0, pcs) - - // dynamic get the package name and the minimum caller depth - for i := 0; i < maximumCallerDepth; i++ { - funcName := runtime.FuncForPC(pcs[i]).Name() - if strings.Contains(funcName, "getCaller") { - logrusPackage = getPackageName(funcName) - break - } - } - - minimumCallerDepth = knownLogrusFrames - }) - - // Restrict the lookback frames to avoid runaway lookups - pcs := make([]uintptr, maximumCallerDepth) - depth := runtime.Callers(minimumCallerDepth, pcs) - frames := runtime.CallersFrames(pcs[:depth]) - - for f, again := frames.Next(); again; f, again = frames.Next() { - pkg := getPackageName(f.Function) - - // If the caller isn't part of this package, we're done - if pkg != logrusPackage { - return &f //nolint:scopelint - } - } - - // if we got here, we failed to find the caller's context - return nil -} - -func (entry Entry) HasCaller() (has bool) { - return entry.Logger != nil && - entry.Logger.ReportCaller && - entry.Caller != nil -} - -func (entry *Entry) log(level Level, msg string) { - var buffer *bytes.Buffer - - newEntry := entry.Dup() - - if newEntry.Time.IsZero() { - newEntry.Time = time.Now() - } - - newEntry.Level = level - newEntry.Message = msg - - newEntry.Logger.mu.Lock() - reportCaller := newEntry.Logger.ReportCaller - bufPool := newEntry.getBufferPool() - newEntry.Logger.mu.Unlock() - - if reportCaller { - newEntry.Caller = getCaller() - } - - newEntry.fireHooks() - buffer = bufPool.Get() - defer func() { - newEntry.Buffer = nil - buffer.Reset() - bufPool.Put(buffer) - }() - buffer.Reset() - newEntry.Buffer = buffer - - newEntry.write() - - newEntry.Buffer = nil - - // To avoid Entry#log() returning a value that only would make sense for - // panic() to use in Entry#Panic(), we avoid the allocation by checking - // directly here. - if level <= PanicLevel { - panic(newEntry) - } -} - -func (entry *Entry) getBufferPool() (pool BufferPool) { - if entry.Logger.BufferPool != nil { - return entry.Logger.BufferPool - } - return bufferPool -} - -func (entry *Entry) fireHooks() { - var tmpHooks LevelHooks - entry.Logger.mu.Lock() - tmpHooks = make(LevelHooks, len(entry.Logger.Hooks)) - for k, v := range entry.Logger.Hooks { - tmpHooks[k] = v - } - entry.Logger.mu.Unlock() - - err := tmpHooks.Fire(entry.Level, entry) - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err) - } -} - -func (entry *Entry) write() { - entry.Logger.mu.Lock() - defer entry.Logger.mu.Unlock() - serialized, err := entry.Logger.Formatter.Format(entry) - if err != nil { - fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) - return - } - if _, err := entry.Logger.Out.Write(serialized); err != nil { - fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) - } -} - -// Log will log a message at the level given as parameter. -// Warning: using Log at Panic or Fatal level will not respectively Panic nor Exit. -// For this behaviour Entry.Panic or Entry.Fatal should be used instead. -func (entry *Entry) Log(level Level, args ...interface{}) { - if entry.Logger.IsLevelEnabled(level) { - entry.log(level, fmt.Sprint(args...)) - } -} - -func (entry *Entry) Trace(args ...interface{}) { - entry.Log(TraceLevel, args...) -} - -func (entry *Entry) Debug(args ...interface{}) { - entry.Log(DebugLevel, args...) -} - -func (entry *Entry) Print(args ...interface{}) { - entry.Info(args...) -} - -func (entry *Entry) Info(args ...interface{}) { - entry.Log(InfoLevel, args...) -} - -func (entry *Entry) Warn(args ...interface{}) { - entry.Log(WarnLevel, args...) -} - -func (entry *Entry) Warning(args ...interface{}) { - entry.Warn(args...) -} - -func (entry *Entry) Error(args ...interface{}) { - entry.Log(ErrorLevel, args...) -} - -func (entry *Entry) Fatal(args ...interface{}) { - entry.Log(FatalLevel, args...) - entry.Logger.Exit(1) -} - -func (entry *Entry) Panic(args ...interface{}) { - entry.Log(PanicLevel, args...) -} - -// Entry Printf family functions - -func (entry *Entry) Logf(level Level, format string, args ...interface{}) { - if entry.Logger.IsLevelEnabled(level) { - entry.Log(level, fmt.Sprintf(format, args...)) - } -} - -func (entry *Entry) Tracef(format string, args ...interface{}) { - entry.Logf(TraceLevel, format, args...) -} - -func (entry *Entry) Debugf(format string, args ...interface{}) { - entry.Logf(DebugLevel, format, args...) -} - -func (entry *Entry) Infof(format string, args ...interface{}) { - entry.Logf(InfoLevel, format, args...) -} - -func (entry *Entry) Printf(format string, args ...interface{}) { - entry.Infof(format, args...) -} - -func (entry *Entry) Warnf(format string, args ...interface{}) { - entry.Logf(WarnLevel, format, args...) -} - -func (entry *Entry) Warningf(format string, args ...interface{}) { - entry.Warnf(format, args...) -} - -func (entry *Entry) Errorf(format string, args ...interface{}) { - entry.Logf(ErrorLevel, format, args...) -} - -func (entry *Entry) Fatalf(format string, args ...interface{}) { - entry.Logf(FatalLevel, format, args...) - entry.Logger.Exit(1) -} - -func (entry *Entry) Panicf(format string, args ...interface{}) { - entry.Logf(PanicLevel, format, args...) -} - -// Entry Println family functions - -func (entry *Entry) Logln(level Level, args ...interface{}) { - if entry.Logger.IsLevelEnabled(level) { - entry.Log(level, entry.sprintlnn(args...)) - } -} - -func (entry *Entry) Traceln(args ...interface{}) { - entry.Logln(TraceLevel, args...) -} - -func (entry *Entry) Debugln(args ...interface{}) { - entry.Logln(DebugLevel, args...) -} - -func (entry *Entry) Infoln(args ...interface{}) { - entry.Logln(InfoLevel, args...) -} - -func (entry *Entry) Println(args ...interface{}) { - entry.Infoln(args...) -} - -func (entry *Entry) Warnln(args ...interface{}) { - entry.Logln(WarnLevel, args...) -} - -func (entry *Entry) Warningln(args ...interface{}) { - entry.Warnln(args...) -} - -func (entry *Entry) Errorln(args ...interface{}) { - entry.Logln(ErrorLevel, args...) -} - -func (entry *Entry) Fatalln(args ...interface{}) { - entry.Logln(FatalLevel, args...) - entry.Logger.Exit(1) -} - -func (entry *Entry) Panicln(args ...interface{}) { - entry.Logln(PanicLevel, args...) -} - -// Sprintlnn => Sprint no newline. This is to get the behavior of how -// fmt.Sprintln where spaces are always added between operands, regardless of -// their type. Instead of vendoring the Sprintln implementation to spare a -// string allocation, we do the simplest thing. -func (entry *Entry) sprintlnn(args ...interface{}) string { - msg := fmt.Sprintln(args...) - return msg[:len(msg)-1] -} diff --git a/vendor/github.com/sirupsen/logrus/exported.go b/vendor/github.com/sirupsen/logrus/exported.go deleted file mode 100644 index 017c30c..0000000 --- a/vendor/github.com/sirupsen/logrus/exported.go +++ /dev/null @@ -1,270 +0,0 @@ -package logrus - -import ( - "context" - "io" - "time" -) - -var ( - // std is the name of the standard logger in stdlib `log` - std = New() -) - -func StandardLogger() *Logger { - return std -} - -// SetOutput sets the standard logger output. -func SetOutput(out io.Writer) { - std.SetOutput(out) -} - -// SetFormatter sets the standard logger formatter. -func SetFormatter(formatter Formatter) { - std.SetFormatter(formatter) -} - -// SetReportCaller sets whether the standard logger will include the calling -// method as a field. -func SetReportCaller(include bool) { - std.SetReportCaller(include) -} - -// SetLevel sets the standard logger level. -func SetLevel(level Level) { - std.SetLevel(level) -} - -// GetLevel returns the standard logger level. -func GetLevel() Level { - return std.GetLevel() -} - -// IsLevelEnabled checks if the log level of the standard logger is greater than the level param -func IsLevelEnabled(level Level) bool { - return std.IsLevelEnabled(level) -} - -// AddHook adds a hook to the standard logger hooks. -func AddHook(hook Hook) { - std.AddHook(hook) -} - -// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key. -func WithError(err error) *Entry { - return std.WithField(ErrorKey, err) -} - -// WithContext creates an entry from the standard logger and adds a context to it. -func WithContext(ctx context.Context) *Entry { - return std.WithContext(ctx) -} - -// WithField creates an entry from the standard logger and adds a field to -// it. If you want multiple fields, use `WithFields`. -// -// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal -// or Panic on the Entry it returns. -func WithField(key string, value interface{}) *Entry { - return std.WithField(key, value) -} - -// WithFields creates an entry from the standard logger and adds multiple -// fields to it. This is simply a helper for `WithField`, invoking it -// once for each field. -// -// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal -// or Panic on the Entry it returns. -func WithFields(fields Fields) *Entry { - return std.WithFields(fields) -} - -// WithTime creates an entry from the standard logger and overrides the time of -// logs generated with it. -// -// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal -// or Panic on the Entry it returns. -func WithTime(t time.Time) *Entry { - return std.WithTime(t) -} - -// Trace logs a message at level Trace on the standard logger. -func Trace(args ...interface{}) { - std.Trace(args...) -} - -// Debug logs a message at level Debug on the standard logger. -func Debug(args ...interface{}) { - std.Debug(args...) -} - -// Print logs a message at level Info on the standard logger. -func Print(args ...interface{}) { - std.Print(args...) -} - -// Info logs a message at level Info on the standard logger. -func Info(args ...interface{}) { - std.Info(args...) -} - -// Warn logs a message at level Warn on the standard logger. -func Warn(args ...interface{}) { - std.Warn(args...) -} - -// Warning logs a message at level Warn on the standard logger. -func Warning(args ...interface{}) { - std.Warning(args...) -} - -// Error logs a message at level Error on the standard logger. -func Error(args ...interface{}) { - std.Error(args...) -} - -// Panic logs a message at level Panic on the standard logger. -func Panic(args ...interface{}) { - std.Panic(args...) -} - -// Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1. -func Fatal(args ...interface{}) { - std.Fatal(args...) -} - -// TraceFn logs a message from a func at level Trace on the standard logger. -func TraceFn(fn LogFunction) { - std.TraceFn(fn) -} - -// DebugFn logs a message from a func at level Debug on the standard logger. -func DebugFn(fn LogFunction) { - std.DebugFn(fn) -} - -// PrintFn logs a message from a func at level Info on the standard logger. -func PrintFn(fn LogFunction) { - std.PrintFn(fn) -} - -// InfoFn logs a message from a func at level Info on the standard logger. -func InfoFn(fn LogFunction) { - std.InfoFn(fn) -} - -// WarnFn logs a message from a func at level Warn on the standard logger. -func WarnFn(fn LogFunction) { - std.WarnFn(fn) -} - -// WarningFn logs a message from a func at level Warn on the standard logger. -func WarningFn(fn LogFunction) { - std.WarningFn(fn) -} - -// ErrorFn logs a message from a func at level Error on the standard logger. -func ErrorFn(fn LogFunction) { - std.ErrorFn(fn) -} - -// PanicFn logs a message from a func at level Panic on the standard logger. -func PanicFn(fn LogFunction) { - std.PanicFn(fn) -} - -// FatalFn logs a message from a func at level Fatal on the standard logger then the process will exit with status set to 1. -func FatalFn(fn LogFunction) { - std.FatalFn(fn) -} - -// Tracef logs a message at level Trace on the standard logger. -func Tracef(format string, args ...interface{}) { - std.Tracef(format, args...) -} - -// Debugf logs a message at level Debug on the standard logger. -func Debugf(format string, args ...interface{}) { - std.Debugf(format, args...) -} - -// Printf logs a message at level Info on the standard logger. -func Printf(format string, args ...interface{}) { - std.Printf(format, args...) -} - -// Infof logs a message at level Info on the standard logger. -func Infof(format string, args ...interface{}) { - std.Infof(format, args...) -} - -// Warnf logs a message at level Warn on the standard logger. -func Warnf(format string, args ...interface{}) { - std.Warnf(format, args...) -} - -// Warningf logs a message at level Warn on the standard logger. -func Warningf(format string, args ...interface{}) { - std.Warningf(format, args...) -} - -// Errorf logs a message at level Error on the standard logger. -func Errorf(format string, args ...interface{}) { - std.Errorf(format, args...) -} - -// Panicf logs a message at level Panic on the standard logger. -func Panicf(format string, args ...interface{}) { - std.Panicf(format, args...) -} - -// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1. -func Fatalf(format string, args ...interface{}) { - std.Fatalf(format, args...) -} - -// Traceln logs a message at level Trace on the standard logger. -func Traceln(args ...interface{}) { - std.Traceln(args...) -} - -// Debugln logs a message at level Debug on the standard logger. -func Debugln(args ...interface{}) { - std.Debugln(args...) -} - -// Println logs a message at level Info on the standard logger. -func Println(args ...interface{}) { - std.Println(args...) -} - -// Infoln logs a message at level Info on the standard logger. -func Infoln(args ...interface{}) { - std.Infoln(args...) -} - -// Warnln logs a message at level Warn on the standard logger. -func Warnln(args ...interface{}) { - std.Warnln(args...) -} - -// Warningln logs a message at level Warn on the standard logger. -func Warningln(args ...interface{}) { - std.Warningln(args...) -} - -// Errorln logs a message at level Error on the standard logger. -func Errorln(args ...interface{}) { - std.Errorln(args...) -} - -// Panicln logs a message at level Panic on the standard logger. -func Panicln(args ...interface{}) { - std.Panicln(args...) -} - -// Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1. -func Fatalln(args ...interface{}) { - std.Fatalln(args...) -} diff --git a/vendor/github.com/sirupsen/logrus/formatter.go b/vendor/github.com/sirupsen/logrus/formatter.go deleted file mode 100644 index 4088837..0000000 --- a/vendor/github.com/sirupsen/logrus/formatter.go +++ /dev/null @@ -1,78 +0,0 @@ -package logrus - -import "time" - -// Default key names for the default fields -const ( - defaultTimestampFormat = time.RFC3339 - FieldKeyMsg = "msg" - FieldKeyLevel = "level" - FieldKeyTime = "time" - FieldKeyLogrusError = "logrus_error" - FieldKeyFunc = "func" - FieldKeyFile = "file" -) - -// The Formatter interface is used to implement a custom Formatter. It takes an -// `Entry`. It exposes all the fields, including the default ones: -// -// * `entry.Data["msg"]`. The message passed from Info, Warn, Error .. -// * `entry.Data["time"]`. The timestamp. -// * `entry.Data["level"]. The level the entry was logged at. -// -// Any additional fields added with `WithField` or `WithFields` are also in -// `entry.Data`. Format is expected to return an array of bytes which are then -// logged to `logger.Out`. -type Formatter interface { - Format(*Entry) ([]byte, error) -} - -// This is to not silently overwrite `time`, `msg`, `func` and `level` fields when -// dumping it. If this code wasn't there doing: -// -// logrus.WithField("level", 1).Info("hello") -// -// Would just silently drop the user provided level. Instead with this code -// it'll logged as: -// -// {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."} -// -// It's not exported because it's still using Data in an opinionated way. It's to -// avoid code duplication between the two default formatters. -func prefixFieldClashes(data Fields, fieldMap FieldMap, reportCaller bool) { - timeKey := fieldMap.resolve(FieldKeyTime) - if t, ok := data[timeKey]; ok { - data["fields."+timeKey] = t - delete(data, timeKey) - } - - msgKey := fieldMap.resolve(FieldKeyMsg) - if m, ok := data[msgKey]; ok { - data["fields."+msgKey] = m - delete(data, msgKey) - } - - levelKey := fieldMap.resolve(FieldKeyLevel) - if l, ok := data[levelKey]; ok { - data["fields."+levelKey] = l - delete(data, levelKey) - } - - logrusErrKey := fieldMap.resolve(FieldKeyLogrusError) - if l, ok := data[logrusErrKey]; ok { - data["fields."+logrusErrKey] = l - delete(data, logrusErrKey) - } - - // If reportCaller is not set, 'func' will not conflict. - if reportCaller { - funcKey := fieldMap.resolve(FieldKeyFunc) - if l, ok := data[funcKey]; ok { - data["fields."+funcKey] = l - } - fileKey := fieldMap.resolve(FieldKeyFile) - if l, ok := data[fileKey]; ok { - data["fields."+fileKey] = l - } - } -} diff --git a/vendor/github.com/sirupsen/logrus/hooks.go b/vendor/github.com/sirupsen/logrus/hooks.go deleted file mode 100644 index 3f151cd..0000000 --- a/vendor/github.com/sirupsen/logrus/hooks.go +++ /dev/null @@ -1,34 +0,0 @@ -package logrus - -// A hook to be fired when logging on the logging levels returned from -// `Levels()` on your implementation of the interface. Note that this is not -// fired in a goroutine or a channel with workers, you should handle such -// functionality yourself if your call is non-blocking and you don't wish for -// the logging calls for levels returned from `Levels()` to block. -type Hook interface { - Levels() []Level - Fire(*Entry) error -} - -// Internal type for storing the hooks on a logger instance. -type LevelHooks map[Level][]Hook - -// Add a hook to an instance of logger. This is called with -// `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. -func (hooks LevelHooks) Add(hook Hook) { - for _, level := range hook.Levels() { - hooks[level] = append(hooks[level], hook) - } -} - -// Fire all the hooks for the passed level. Used by `entry.log` to fire -// appropriate hooks for a log entry. -func (hooks LevelHooks) Fire(level Level, entry *Entry) error { - for _, hook := range hooks[level] { - if err := hook.Fire(entry); err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/sirupsen/logrus/json_formatter.go b/vendor/github.com/sirupsen/logrus/json_formatter.go deleted file mode 100644 index c96dc56..0000000 --- a/vendor/github.com/sirupsen/logrus/json_formatter.go +++ /dev/null @@ -1,128 +0,0 @@ -package logrus - -import ( - "bytes" - "encoding/json" - "fmt" - "runtime" -) - -type fieldKey string - -// FieldMap allows customization of the key names for default fields. -type FieldMap map[fieldKey]string - -func (f FieldMap) resolve(key fieldKey) string { - if k, ok := f[key]; ok { - return k - } - - return string(key) -} - -// JSONFormatter formats logs into parsable json -type JSONFormatter struct { - // TimestampFormat sets the format used for marshaling timestamps. - // The format to use is the same than for time.Format or time.Parse from the standard - // library. - // The standard Library already provides a set of predefined format. - TimestampFormat string - - // DisableTimestamp allows disabling automatic timestamps in output - DisableTimestamp bool - - // DisableHTMLEscape allows disabling html escaping in output - DisableHTMLEscape bool - - // DataKey allows users to put all the log entry parameters into a nested dictionary at a given key. - DataKey string - - // FieldMap allows users to customize the names of keys for default fields. - // As an example: - // formatter := &JSONFormatter{ - // FieldMap: FieldMap{ - // FieldKeyTime: "@timestamp", - // FieldKeyLevel: "@level", - // FieldKeyMsg: "@message", - // FieldKeyFunc: "@caller", - // }, - // } - FieldMap FieldMap - - // CallerPrettyfier can be set by the user to modify the content - // of the function and file keys in the json data when ReportCaller is - // activated. If any of the returned value is the empty string the - // corresponding key will be removed from json fields. - CallerPrettyfier func(*runtime.Frame) (function string, file string) - - // PrettyPrint will indent all json logs - PrettyPrint bool -} - -// Format renders a single log entry -func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { - data := make(Fields, len(entry.Data)+4) - for k, v := range entry.Data { - switch v := v.(type) { - case error: - // Otherwise errors are ignored by `encoding/json` - // https://github.com/sirupsen/logrus/issues/137 - data[k] = v.Error() - default: - data[k] = v - } - } - - if f.DataKey != "" { - newData := make(Fields, 4) - newData[f.DataKey] = data - data = newData - } - - prefixFieldClashes(data, f.FieldMap, entry.HasCaller()) - - timestampFormat := f.TimestampFormat - if timestampFormat == "" { - timestampFormat = defaultTimestampFormat - } - - if entry.err != "" { - data[f.FieldMap.resolve(FieldKeyLogrusError)] = entry.err - } - if !f.DisableTimestamp { - data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) - } - data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message - data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String() - if entry.HasCaller() { - funcVal := entry.Caller.Function - fileVal := fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line) - if f.CallerPrettyfier != nil { - funcVal, fileVal = f.CallerPrettyfier(entry.Caller) - } - if funcVal != "" { - data[f.FieldMap.resolve(FieldKeyFunc)] = funcVal - } - if fileVal != "" { - data[f.FieldMap.resolve(FieldKeyFile)] = fileVal - } - } - - var b *bytes.Buffer - if entry.Buffer != nil { - b = entry.Buffer - } else { - b = &bytes.Buffer{} - } - - encoder := json.NewEncoder(b) - encoder.SetEscapeHTML(!f.DisableHTMLEscape) - if f.PrettyPrint { - encoder.SetIndent("", " ") - } - if err := encoder.Encode(data); err != nil { - return nil, fmt.Errorf("failed to marshal fields to JSON, %w", err) - } - - return b.Bytes(), nil -} diff --git a/vendor/github.com/sirupsen/logrus/logger.go b/vendor/github.com/sirupsen/logrus/logger.go deleted file mode 100644 index 5ff0aef..0000000 --- a/vendor/github.com/sirupsen/logrus/logger.go +++ /dev/null @@ -1,417 +0,0 @@ -package logrus - -import ( - "context" - "io" - "os" - "sync" - "sync/atomic" - "time" -) - -// LogFunction For big messages, it can be more efficient to pass a function -// and only call it if the log level is actually enables rather than -// generating the log message and then checking if the level is enabled -type LogFunction func() []interface{} - -type Logger struct { - // The logs are `io.Copy`'d to this in a mutex. It's common to set this to a - // file, or leave it default which is `os.Stderr`. You can also set this to - // something more adventurous, such as logging to Kafka. - Out io.Writer - // Hooks for the logger instance. These allow firing events based on logging - // levels and log entries. For example, to send errors to an error tracking - // service, log to StatsD or dump the core on fatal errors. - Hooks LevelHooks - // All log entries pass through the formatter before logged to Out. The - // included formatters are `TextFormatter` and `JSONFormatter` for which - // TextFormatter is the default. In development (when a TTY is attached) it - // logs with colors, but to a file it wouldn't. You can easily implement your - // own that implements the `Formatter` interface, see the `README` or included - // formatters for examples. - Formatter Formatter - - // Flag for whether to log caller info (off by default) - ReportCaller bool - - // The logging level the logger should log at. This is typically (and defaults - // to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be - // logged. - Level Level - // Used to sync writing to the log. Locking is enabled by Default - mu MutexWrap - // Reusable empty entry - entryPool sync.Pool - // Function to exit the application, defaults to `os.Exit()` - ExitFunc exitFunc - // The buffer pool used to format the log. If it is nil, the default global - // buffer pool will be used. - BufferPool BufferPool -} - -type exitFunc func(int) - -type MutexWrap struct { - lock sync.Mutex - disabled bool -} - -func (mw *MutexWrap) Lock() { - if !mw.disabled { - mw.lock.Lock() - } -} - -func (mw *MutexWrap) Unlock() { - if !mw.disabled { - mw.lock.Unlock() - } -} - -func (mw *MutexWrap) Disable() { - mw.disabled = true -} - -// Creates a new logger. Configuration should be set by changing `Formatter`, -// `Out` and `Hooks` directly on the default logger instance. You can also just -// instantiate your own: -// -// var log = &logrus.Logger{ -// Out: os.Stderr, -// Formatter: new(logrus.TextFormatter), -// Hooks: make(logrus.LevelHooks), -// Level: logrus.DebugLevel, -// } -// -// It's recommended to make this a global instance called `log`. -func New() *Logger { - return &Logger{ - Out: os.Stderr, - Formatter: new(TextFormatter), - Hooks: make(LevelHooks), - Level: InfoLevel, - ExitFunc: os.Exit, - ReportCaller: false, - } -} - -func (logger *Logger) newEntry() *Entry { - entry, ok := logger.entryPool.Get().(*Entry) - if ok { - return entry - } - return NewEntry(logger) -} - -func (logger *Logger) releaseEntry(entry *Entry) { - entry.Data = map[string]interface{}{} - logger.entryPool.Put(entry) -} - -// WithField allocates a new entry and adds a field to it. -// Debug, Print, Info, Warn, Error, Fatal or Panic must be then applied to -// this new returned entry. -// If you want multiple fields, use `WithFields`. -func (logger *Logger) WithField(key string, value interface{}) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithField(key, value) -} - -// Adds a struct of fields to the log entry. All it does is call `WithField` for -// each `Field`. -func (logger *Logger) WithFields(fields Fields) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithFields(fields) -} - -// Add an error as single field to the log entry. All it does is call -// `WithError` for the given `error`. -func (logger *Logger) WithError(err error) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithError(err) -} - -// Add a context to the log entry. -func (logger *Logger) WithContext(ctx context.Context) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithContext(ctx) -} - -// Overrides the time of the log entry. -func (logger *Logger) WithTime(t time.Time) *Entry { - entry := logger.newEntry() - defer logger.releaseEntry(entry) - return entry.WithTime(t) -} - -func (logger *Logger) Logf(level Level, format string, args ...interface{}) { - if logger.IsLevelEnabled(level) { - entry := logger.newEntry() - entry.Logf(level, format, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Tracef(format string, args ...interface{}) { - logger.Logf(TraceLevel, format, args...) -} - -func (logger *Logger) Debugf(format string, args ...interface{}) { - logger.Logf(DebugLevel, format, args...) -} - -func (logger *Logger) Infof(format string, args ...interface{}) { - logger.Logf(InfoLevel, format, args...) -} - -func (logger *Logger) Printf(format string, args ...interface{}) { - entry := logger.newEntry() - entry.Printf(format, args...) - logger.releaseEntry(entry) -} - -func (logger *Logger) Warnf(format string, args ...interface{}) { - logger.Logf(WarnLevel, format, args...) -} - -func (logger *Logger) Warningf(format string, args ...interface{}) { - logger.Warnf(format, args...) -} - -func (logger *Logger) Errorf(format string, args ...interface{}) { - logger.Logf(ErrorLevel, format, args...) -} - -func (logger *Logger) Fatalf(format string, args ...interface{}) { - logger.Logf(FatalLevel, format, args...) - logger.Exit(1) -} - -func (logger *Logger) Panicf(format string, args ...interface{}) { - logger.Logf(PanicLevel, format, args...) -} - -// Log will log a message at the level given as parameter. -// Warning: using Log at Panic or Fatal level will not respectively Panic nor Exit. -// For this behaviour Logger.Panic or Logger.Fatal should be used instead. -func (logger *Logger) Log(level Level, args ...interface{}) { - if logger.IsLevelEnabled(level) { - entry := logger.newEntry() - entry.Log(level, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) LogFn(level Level, fn LogFunction) { - if logger.IsLevelEnabled(level) { - entry := logger.newEntry() - entry.Log(level, fn()...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Trace(args ...interface{}) { - logger.Log(TraceLevel, args...) -} - -func (logger *Logger) Debug(args ...interface{}) { - logger.Log(DebugLevel, args...) -} - -func (logger *Logger) Info(args ...interface{}) { - logger.Log(InfoLevel, args...) -} - -func (logger *Logger) Print(args ...interface{}) { - entry := logger.newEntry() - entry.Print(args...) - logger.releaseEntry(entry) -} - -func (logger *Logger) Warn(args ...interface{}) { - logger.Log(WarnLevel, args...) -} - -func (logger *Logger) Warning(args ...interface{}) { - logger.Warn(args...) -} - -func (logger *Logger) Error(args ...interface{}) { - logger.Log(ErrorLevel, args...) -} - -func (logger *Logger) Fatal(args ...interface{}) { - logger.Log(FatalLevel, args...) - logger.Exit(1) -} - -func (logger *Logger) Panic(args ...interface{}) { - logger.Log(PanicLevel, args...) -} - -func (logger *Logger) TraceFn(fn LogFunction) { - logger.LogFn(TraceLevel, fn) -} - -func (logger *Logger) DebugFn(fn LogFunction) { - logger.LogFn(DebugLevel, fn) -} - -func (logger *Logger) InfoFn(fn LogFunction) { - logger.LogFn(InfoLevel, fn) -} - -func (logger *Logger) PrintFn(fn LogFunction) { - entry := logger.newEntry() - entry.Print(fn()...) - logger.releaseEntry(entry) -} - -func (logger *Logger) WarnFn(fn LogFunction) { - logger.LogFn(WarnLevel, fn) -} - -func (logger *Logger) WarningFn(fn LogFunction) { - logger.WarnFn(fn) -} - -func (logger *Logger) ErrorFn(fn LogFunction) { - logger.LogFn(ErrorLevel, fn) -} - -func (logger *Logger) FatalFn(fn LogFunction) { - logger.LogFn(FatalLevel, fn) - logger.Exit(1) -} - -func (logger *Logger) PanicFn(fn LogFunction) { - logger.LogFn(PanicLevel, fn) -} - -func (logger *Logger) Logln(level Level, args ...interface{}) { - if logger.IsLevelEnabled(level) { - entry := logger.newEntry() - entry.Logln(level, args...) - logger.releaseEntry(entry) - } -} - -func (logger *Logger) Traceln(args ...interface{}) { - logger.Logln(TraceLevel, args...) -} - -func (logger *Logger) Debugln(args ...interface{}) { - logger.Logln(DebugLevel, args...) -} - -func (logger *Logger) Infoln(args ...interface{}) { - logger.Logln(InfoLevel, args...) -} - -func (logger *Logger) Println(args ...interface{}) { - entry := logger.newEntry() - entry.Println(args...) - logger.releaseEntry(entry) -} - -func (logger *Logger) Warnln(args ...interface{}) { - logger.Logln(WarnLevel, args...) -} - -func (logger *Logger) Warningln(args ...interface{}) { - logger.Warnln(args...) -} - -func (logger *Logger) Errorln(args ...interface{}) { - logger.Logln(ErrorLevel, args...) -} - -func (logger *Logger) Fatalln(args ...interface{}) { - logger.Logln(FatalLevel, args...) - logger.Exit(1) -} - -func (logger *Logger) Panicln(args ...interface{}) { - logger.Logln(PanicLevel, args...) -} - -func (logger *Logger) Exit(code int) { - runHandlers() - if logger.ExitFunc == nil { - logger.ExitFunc = os.Exit - } - logger.ExitFunc(code) -} - -//When file is opened with appending mode, it's safe to -//write concurrently to a file (within 4k message on Linux). -//In these cases user can choose to disable the lock. -func (logger *Logger) SetNoLock() { - logger.mu.Disable() -} - -func (logger *Logger) level() Level { - return Level(atomic.LoadUint32((*uint32)(&logger.Level))) -} - -// SetLevel sets the logger level. -func (logger *Logger) SetLevel(level Level) { - atomic.StoreUint32((*uint32)(&logger.Level), uint32(level)) -} - -// GetLevel returns the logger level. -func (logger *Logger) GetLevel() Level { - return logger.level() -} - -// AddHook adds a hook to the logger hooks. -func (logger *Logger) AddHook(hook Hook) { - logger.mu.Lock() - defer logger.mu.Unlock() - logger.Hooks.Add(hook) -} - -// IsLevelEnabled checks if the log level of the logger is greater than the level param -func (logger *Logger) IsLevelEnabled(level Level) bool { - return logger.level() >= level -} - -// SetFormatter sets the logger formatter. -func (logger *Logger) SetFormatter(formatter Formatter) { - logger.mu.Lock() - defer logger.mu.Unlock() - logger.Formatter = formatter -} - -// SetOutput sets the logger output. -func (logger *Logger) SetOutput(output io.Writer) { - logger.mu.Lock() - defer logger.mu.Unlock() - logger.Out = output -} - -func (logger *Logger) SetReportCaller(reportCaller bool) { - logger.mu.Lock() - defer logger.mu.Unlock() - logger.ReportCaller = reportCaller -} - -// ReplaceHooks replaces the logger hooks and returns the old ones -func (logger *Logger) ReplaceHooks(hooks LevelHooks) LevelHooks { - logger.mu.Lock() - oldHooks := logger.Hooks - logger.Hooks = hooks - logger.mu.Unlock() - return oldHooks -} - -// SetBufferPool sets the logger buffer pool. -func (logger *Logger) SetBufferPool(pool BufferPool) { - logger.mu.Lock() - defer logger.mu.Unlock() - logger.BufferPool = pool -} diff --git a/vendor/github.com/sirupsen/logrus/logrus.go b/vendor/github.com/sirupsen/logrus/logrus.go deleted file mode 100644 index 2f16224..0000000 --- a/vendor/github.com/sirupsen/logrus/logrus.go +++ /dev/null @@ -1,186 +0,0 @@ -package logrus - -import ( - "fmt" - "log" - "strings" -) - -// Fields type, used to pass to `WithFields`. -type Fields map[string]interface{} - -// Level type -type Level uint32 - -// Convert the Level to a string. E.g. PanicLevel becomes "panic". -func (level Level) String() string { - if b, err := level.MarshalText(); err == nil { - return string(b) - } else { - return "unknown" - } -} - -// ParseLevel takes a string level and returns the Logrus log level constant. -func ParseLevel(lvl string) (Level, error) { - switch strings.ToLower(lvl) { - case "panic": - return PanicLevel, nil - case "fatal": - return FatalLevel, nil - case "error": - return ErrorLevel, nil - case "warn", "warning": - return WarnLevel, nil - case "info": - return InfoLevel, nil - case "debug": - return DebugLevel, nil - case "trace": - return TraceLevel, nil - } - - var l Level - return l, fmt.Errorf("not a valid logrus Level: %q", lvl) -} - -// UnmarshalText implements encoding.TextUnmarshaler. -func (level *Level) UnmarshalText(text []byte) error { - l, err := ParseLevel(string(text)) - if err != nil { - return err - } - - *level = l - - return nil -} - -func (level Level) MarshalText() ([]byte, error) { - switch level { - case TraceLevel: - return []byte("trace"), nil - case DebugLevel: - return []byte("debug"), nil - case InfoLevel: - return []byte("info"), nil - case WarnLevel: - return []byte("warning"), nil - case ErrorLevel: - return []byte("error"), nil - case FatalLevel: - return []byte("fatal"), nil - case PanicLevel: - return []byte("panic"), nil - } - - return nil, fmt.Errorf("not a valid logrus level %d", level) -} - -// A constant exposing all logging levels -var AllLevels = []Level{ - PanicLevel, - FatalLevel, - ErrorLevel, - WarnLevel, - InfoLevel, - DebugLevel, - TraceLevel, -} - -// These are the different logging levels. You can set the logging level to log -// on your instance of logger, obtained with `logrus.New()`. -const ( - // PanicLevel level, highest level of severity. Logs and then calls panic with the - // message passed to Debug, Info, ... - PanicLevel Level = iota - // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the - // logging level is set to Panic. - FatalLevel - // ErrorLevel level. Logs. Used for errors that should definitely be noted. - // Commonly used for hooks to send errors to an error tracking service. - ErrorLevel - // WarnLevel level. Non-critical entries that deserve eyes. - WarnLevel - // InfoLevel level. General operational entries about what's going on inside the - // application. - InfoLevel - // DebugLevel level. Usually only enabled when debugging. Very verbose logging. - DebugLevel - // TraceLevel level. Designates finer-grained informational events than the Debug. - TraceLevel -) - -// Won't compile if StdLogger can't be realized by a log.Logger -var ( - _ StdLogger = &log.Logger{} - _ StdLogger = &Entry{} - _ StdLogger = &Logger{} -) - -// StdLogger is what your logrus-enabled library should take, that way -// it'll accept a stdlib logger and a logrus logger. There's no standard -// interface, this is the closest we get, unfortunately. -type StdLogger interface { - Print(...interface{}) - Printf(string, ...interface{}) - Println(...interface{}) - - Fatal(...interface{}) - Fatalf(string, ...interface{}) - Fatalln(...interface{}) - - Panic(...interface{}) - Panicf(string, ...interface{}) - Panicln(...interface{}) -} - -// The FieldLogger interface generalizes the Entry and Logger types -type FieldLogger interface { - WithField(key string, value interface{}) *Entry - WithFields(fields Fields) *Entry - WithError(err error) *Entry - - Debugf(format string, args ...interface{}) - Infof(format string, args ...interface{}) - Printf(format string, args ...interface{}) - Warnf(format string, args ...interface{}) - Warningf(format string, args ...interface{}) - Errorf(format string, args ...interface{}) - Fatalf(format string, args ...interface{}) - Panicf(format string, args ...interface{}) - - Debug(args ...interface{}) - Info(args ...interface{}) - Print(args ...interface{}) - Warn(args ...interface{}) - Warning(args ...interface{}) - Error(args ...interface{}) - Fatal(args ...interface{}) - Panic(args ...interface{}) - - Debugln(args ...interface{}) - Infoln(args ...interface{}) - Println(args ...interface{}) - Warnln(args ...interface{}) - Warningln(args ...interface{}) - Errorln(args ...interface{}) - Fatalln(args ...interface{}) - Panicln(args ...interface{}) - - // IsDebugEnabled() bool - // IsInfoEnabled() bool - // IsWarnEnabled() bool - // IsErrorEnabled() bool - // IsFatalEnabled() bool - // IsPanicEnabled() bool -} - -// Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is -// here for consistancy. Do not use. Use Logger or Entry instead. -type Ext1FieldLogger interface { - FieldLogger - Tracef(format string, args ...interface{}) - Trace(args ...interface{}) - Traceln(args ...interface{}) -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go b/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go deleted file mode 100644 index 2403de9..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_appengine.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build appengine - -package logrus - -import ( - "io" -) - -func checkIfTerminal(w io.Writer) bool { - return true -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go b/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go deleted file mode 100644 index 4997899..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build darwin dragonfly freebsd netbsd openbsd -// +build !js - -package logrus - -import "golang.org/x/sys/unix" - -const ioctlReadTermios = unix.TIOCGETA - -func isTerminal(fd int) bool { - _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) - return err == nil -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_js.go b/vendor/github.com/sirupsen/logrus/terminal_check_js.go deleted file mode 100644 index ebdae3e..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_js.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build js - -package logrus - -func isTerminal(fd int) bool { - return false -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go b/vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go deleted file mode 100644 index 97af92c..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build js nacl plan9 - -package logrus - -import ( - "io" -) - -func checkIfTerminal(w io.Writer) bool { - return false -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go b/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go deleted file mode 100644 index 3293fb3..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go +++ /dev/null @@ -1,17 +0,0 @@ -// +build !appengine,!js,!windows,!nacl,!plan9 - -package logrus - -import ( - "io" - "os" -) - -func checkIfTerminal(w io.Writer) bool { - switch v := w.(type) { - case *os.File: - return isTerminal(int(v.Fd())) - default: - return false - } -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_solaris.go b/vendor/github.com/sirupsen/logrus/terminal_check_solaris.go deleted file mode 100644 index f6710b3..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_solaris.go +++ /dev/null @@ -1,11 +0,0 @@ -package logrus - -import ( - "golang.org/x/sys/unix" -) - -// IsTerminal returns true if the given file descriptor is a terminal. -func isTerminal(fd int) bool { - _, err := unix.IoctlGetTermio(fd, unix.TCGETA) - return err == nil -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_unix.go b/vendor/github.com/sirupsen/logrus/terminal_check_unix.go deleted file mode 100644 index 04748b8..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_unix.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build linux aix zos -// +build !js - -package logrus - -import "golang.org/x/sys/unix" - -const ioctlReadTermios = unix.TCGETS - -func isTerminal(fd int) bool { - _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) - return err == nil -} diff --git a/vendor/github.com/sirupsen/logrus/terminal_check_windows.go b/vendor/github.com/sirupsen/logrus/terminal_check_windows.go deleted file mode 100644 index 2879eb5..0000000 --- a/vendor/github.com/sirupsen/logrus/terminal_check_windows.go +++ /dev/null @@ -1,27 +0,0 @@ -// +build !appengine,!js,windows - -package logrus - -import ( - "io" - "os" - - "golang.org/x/sys/windows" -) - -func checkIfTerminal(w io.Writer) bool { - switch v := w.(type) { - case *os.File: - handle := windows.Handle(v.Fd()) - var mode uint32 - if err := windows.GetConsoleMode(handle, &mode); err != nil { - return false - } - mode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING - if err := windows.SetConsoleMode(handle, mode); err != nil { - return false - } - return true - } - return false -} diff --git a/vendor/github.com/sirupsen/logrus/text_formatter.go b/vendor/github.com/sirupsen/logrus/text_formatter.go deleted file mode 100644 index be2c6ef..0000000 --- a/vendor/github.com/sirupsen/logrus/text_formatter.go +++ /dev/null @@ -1,339 +0,0 @@ -package logrus - -import ( - "bytes" - "fmt" - "os" - "runtime" - "sort" - "strconv" - "strings" - "sync" - "time" - "unicode/utf8" -) - -const ( - red = 31 - yellow = 33 - blue = 36 - gray = 37 -) - -var baseTimestamp time.Time - -func init() { - baseTimestamp = time.Now() -} - -// TextFormatter formats logs into text -type TextFormatter struct { - // Set to true to bypass checking for a TTY before outputting colors. - ForceColors bool - - // Force disabling colors. - DisableColors bool - - // Force quoting of all values - ForceQuote bool - - // DisableQuote disables quoting for all values. - // DisableQuote will have a lower priority than ForceQuote. - // If both of them are set to true, quote will be forced on all values. - DisableQuote bool - - // Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/ - EnvironmentOverrideColors bool - - // Disable timestamp logging. useful when output is redirected to logging - // system that already adds timestamps. - DisableTimestamp bool - - // Enable logging the full timestamp when a TTY is attached instead of just - // the time passed since beginning of execution. - FullTimestamp bool - - // TimestampFormat to use for display when a full timestamp is printed. - // The format to use is the same than for time.Format or time.Parse from the standard - // library. - // The standard Library already provides a set of predefined format. - TimestampFormat string - - // The fields are sorted by default for a consistent output. For applications - // that log extremely frequently and don't use the JSON formatter this may not - // be desired. - DisableSorting bool - - // The keys sorting function, when uninitialized it uses sort.Strings. - SortingFunc func([]string) - - // Disables the truncation of the level text to 4 characters. - DisableLevelTruncation bool - - // PadLevelText Adds padding the level text so that all the levels output at the same length - // PadLevelText is a superset of the DisableLevelTruncation option - PadLevelText bool - - // QuoteEmptyFields will wrap empty fields in quotes if true - QuoteEmptyFields bool - - // Whether the logger's out is to a terminal - isTerminal bool - - // FieldMap allows users to customize the names of keys for default fields. - // As an example: - // formatter := &TextFormatter{ - // FieldMap: FieldMap{ - // FieldKeyTime: "@timestamp", - // FieldKeyLevel: "@level", - // FieldKeyMsg: "@message"}} - FieldMap FieldMap - - // CallerPrettyfier can be set by the user to modify the content - // of the function and file keys in the data when ReportCaller is - // activated. If any of the returned value is the empty string the - // corresponding key will be removed from fields. - CallerPrettyfier func(*runtime.Frame) (function string, file string) - - terminalInitOnce sync.Once - - // The max length of the level text, generated dynamically on init - levelTextMaxLength int -} - -func (f *TextFormatter) init(entry *Entry) { - if entry.Logger != nil { - f.isTerminal = checkIfTerminal(entry.Logger.Out) - } - // Get the max length of the level text - for _, level := range AllLevels { - levelTextLength := utf8.RuneCount([]byte(level.String())) - if levelTextLength > f.levelTextMaxLength { - f.levelTextMaxLength = levelTextLength - } - } -} - -func (f *TextFormatter) isColored() bool { - isColored := f.ForceColors || (f.isTerminal && (runtime.GOOS != "windows")) - - if f.EnvironmentOverrideColors { - switch force, ok := os.LookupEnv("CLICOLOR_FORCE"); { - case ok && force != "0": - isColored = true - case ok && force == "0", os.Getenv("CLICOLOR") == "0": - isColored = false - } - } - - return isColored && !f.DisableColors -} - -// Format renders a single log entry -func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { - data := make(Fields) - for k, v := range entry.Data { - data[k] = v - } - prefixFieldClashes(data, f.FieldMap, entry.HasCaller()) - keys := make([]string, 0, len(data)) - for k := range data { - keys = append(keys, k) - } - - var funcVal, fileVal string - - fixedKeys := make([]string, 0, 4+len(data)) - if !f.DisableTimestamp { - fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyTime)) - } - fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyLevel)) - if entry.Message != "" { - fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyMsg)) - } - if entry.err != "" { - fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyLogrusError)) - } - if entry.HasCaller() { - if f.CallerPrettyfier != nil { - funcVal, fileVal = f.CallerPrettyfier(entry.Caller) - } else { - funcVal = entry.Caller.Function - fileVal = fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line) - } - - if funcVal != "" { - fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyFunc)) - } - if fileVal != "" { - fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyFile)) - } - } - - if !f.DisableSorting { - if f.SortingFunc == nil { - sort.Strings(keys) - fixedKeys = append(fixedKeys, keys...) - } else { - if !f.isColored() { - fixedKeys = append(fixedKeys, keys...) - f.SortingFunc(fixedKeys) - } else { - f.SortingFunc(keys) - } - } - } else { - fixedKeys = append(fixedKeys, keys...) - } - - var b *bytes.Buffer - if entry.Buffer != nil { - b = entry.Buffer - } else { - b = &bytes.Buffer{} - } - - f.terminalInitOnce.Do(func() { f.init(entry) }) - - timestampFormat := f.TimestampFormat - if timestampFormat == "" { - timestampFormat = defaultTimestampFormat - } - if f.isColored() { - f.printColored(b, entry, keys, data, timestampFormat) - } else { - - for _, key := range fixedKeys { - var value interface{} - switch { - case key == f.FieldMap.resolve(FieldKeyTime): - value = entry.Time.Format(timestampFormat) - case key == f.FieldMap.resolve(FieldKeyLevel): - value = entry.Level.String() - case key == f.FieldMap.resolve(FieldKeyMsg): - value = entry.Message - case key == f.FieldMap.resolve(FieldKeyLogrusError): - value = entry.err - case key == f.FieldMap.resolve(FieldKeyFunc) && entry.HasCaller(): - value = funcVal - case key == f.FieldMap.resolve(FieldKeyFile) && entry.HasCaller(): - value = fileVal - default: - value = data[key] - } - f.appendKeyValue(b, key, value) - } - } - - b.WriteByte('\n') - return b.Bytes(), nil -} - -func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, data Fields, timestampFormat string) { - var levelColor int - switch entry.Level { - case DebugLevel, TraceLevel: - levelColor = gray - case WarnLevel: - levelColor = yellow - case ErrorLevel, FatalLevel, PanicLevel: - levelColor = red - case InfoLevel: - levelColor = blue - default: - levelColor = blue - } - - levelText := strings.ToUpper(entry.Level.String()) - if !f.DisableLevelTruncation && !f.PadLevelText { - levelText = levelText[0:4] - } - if f.PadLevelText { - // Generates the format string used in the next line, for example "%-6s" or "%-7s". - // Based on the max level text length. - formatString := "%-" + strconv.Itoa(f.levelTextMaxLength) + "s" - // Formats the level text by appending spaces up to the max length, for example: - // - "INFO " - // - "WARNING" - levelText = fmt.Sprintf(formatString, levelText) - } - - // Remove a single newline if it already exists in the message to keep - // the behavior of logrus text_formatter the same as the stdlib log package - entry.Message = strings.TrimSuffix(entry.Message, "\n") - - caller := "" - if entry.HasCaller() { - funcVal := fmt.Sprintf("%s()", entry.Caller.Function) - fileVal := fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line) - - if f.CallerPrettyfier != nil { - funcVal, fileVal = f.CallerPrettyfier(entry.Caller) - } - - if fileVal == "" { - caller = funcVal - } else if funcVal == "" { - caller = fileVal - } else { - caller = fileVal + " " + funcVal - } - } - - switch { - case f.DisableTimestamp: - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m%s %-44s ", levelColor, levelText, caller, entry.Message) - case !f.FullTimestamp: - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d]%s %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), caller, entry.Message) - default: - fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s]%s %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), caller, entry.Message) - } - for _, k := range keys { - v := data[k] - fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k) - f.appendValue(b, v) - } -} - -func (f *TextFormatter) needsQuoting(text string) bool { - if f.ForceQuote { - return true - } - if f.QuoteEmptyFields && len(text) == 0 { - return true - } - if f.DisableQuote { - return false - } - for _, ch := range text { - if !((ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9') || - ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') { - return true - } - } - return false -} - -func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { - if b.Len() > 0 { - b.WriteByte(' ') - } - b.WriteString(key) - b.WriteByte('=') - f.appendValue(b, value) -} - -func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) { - stringVal, ok := value.(string) - if !ok { - stringVal = fmt.Sprint(value) - } - - if !f.needsQuoting(stringVal) { - b.WriteString(stringVal) - } else { - b.WriteString(fmt.Sprintf("%q", stringVal)) - } -} diff --git a/vendor/github.com/sirupsen/logrus/writer.go b/vendor/github.com/sirupsen/logrus/writer.go deleted file mode 100644 index 72e8e3a..0000000 --- a/vendor/github.com/sirupsen/logrus/writer.go +++ /dev/null @@ -1,70 +0,0 @@ -package logrus - -import ( - "bufio" - "io" - "runtime" -) - -// Writer at INFO level. See WriterLevel for details. -func (logger *Logger) Writer() *io.PipeWriter { - return logger.WriterLevel(InfoLevel) -} - -// WriterLevel returns an io.Writer that can be used to write arbitrary text to -// the logger at the given log level. Each line written to the writer will be -// printed in the usual way using formatters and hooks. The writer is part of an -// io.Pipe and it is the callers responsibility to close the writer when done. -// This can be used to override the standard library logger easily. -func (logger *Logger) WriterLevel(level Level) *io.PipeWriter { - return NewEntry(logger).WriterLevel(level) -} - -func (entry *Entry) Writer() *io.PipeWriter { - return entry.WriterLevel(InfoLevel) -} - -func (entry *Entry) WriterLevel(level Level) *io.PipeWriter { - reader, writer := io.Pipe() - - var printFunc func(args ...interface{}) - - switch level { - case TraceLevel: - printFunc = entry.Trace - case DebugLevel: - printFunc = entry.Debug - case InfoLevel: - printFunc = entry.Info - case WarnLevel: - printFunc = entry.Warn - case ErrorLevel: - printFunc = entry.Error - case FatalLevel: - printFunc = entry.Fatal - case PanicLevel: - printFunc = entry.Panic - default: - printFunc = entry.Print - } - - go entry.writerScanner(reader, printFunc) - runtime.SetFinalizer(writer, writerFinalizer) - - return writer -} - -func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) { - scanner := bufio.NewScanner(reader) - for scanner.Scan() { - printFunc(scanner.Text()) - } - if err := scanner.Err(); err != nil { - entry.Errorf("Error while reading from Writer: %s", err) - } - reader.Close() -} - -func writerFinalizer(writer *io.PipeWriter) { - writer.Close() -} diff --git a/vendor/golang.org/x/net/LICENSE b/vendor/golang.org/x/net/LICENSE deleted file mode 100644 index 6a66aea..0000000 --- a/vendor/golang.org/x/net/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/golang.org/x/net/PATENTS b/vendor/golang.org/x/net/PATENTS deleted file mode 100644 index 7330990..0000000 --- a/vendor/golang.org/x/net/PATENTS +++ /dev/null @@ -1,22 +0,0 @@ -Additional IP Rights Grant (Patents) - -"This implementation" means the copyrightable works distributed by -Google as part of the Go project. - -Google hereby grants to You a perpetual, worldwide, non-exclusive, -no-charge, royalty-free, irrevocable (except as stated in this section) -patent license to make, have made, use, offer to sell, sell, import, -transfer and otherwise run, modify and propagate the contents of this -implementation of Go, where such license applies only to those patent -claims, both currently owned or controlled by Google and acquired in -the future, licensable by Google that are necessarily infringed by this -implementation of Go. This grant does not include claims that would be -infringed only as a consequence of further modification of this -implementation. If you or your agent or exclusive licensee institute or -order or agree to the institution of patent litigation against any -entity (including a cross-claim or counterclaim in a lawsuit) alleging -that this implementation of Go or any code incorporated within this -implementation of Go constitutes direct or contributory patent -infringement, or inducement of patent infringement, then any patent -rights granted to you under this License for this implementation of Go -shall terminate as of the date such litigation is filed. diff --git a/vendor/golang.org/x/net/html/atom/atom.go b/vendor/golang.org/x/net/html/atom/atom.go deleted file mode 100644 index cd0a8ac..0000000 --- a/vendor/golang.org/x/net/html/atom/atom.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package atom provides integer codes (also known as atoms) for a fixed set of -// frequently occurring HTML strings: tag names and attribute keys such as "p" -// and "id". -// -// Sharing an atom's name between all elements with the same tag can result in -// fewer string allocations when tokenizing and parsing HTML. Integer -// comparisons are also generally faster than string comparisons. -// -// The value of an atom's particular code is not guaranteed to stay the same -// between versions of this package. Neither is any ordering guaranteed: -// whether atom.H1 < atom.H2 may also change. The codes are not guaranteed to -// be dense. The only guarantees are that e.g. looking up "div" will yield -// atom.Div, calling atom.Div.String will return "div", and atom.Div != 0. -package atom // import "golang.org/x/net/html/atom" - -// Atom is an integer code for a string. The zero value maps to "". -type Atom uint32 - -// String returns the atom's name. -func (a Atom) String() string { - start := uint32(a >> 8) - n := uint32(a & 0xff) - if start+n > uint32(len(atomText)) { - return "" - } - return atomText[start : start+n] -} - -func (a Atom) string() string { - return atomText[a>>8 : a>>8+a&0xff] -} - -// fnv computes the FNV hash with an arbitrary starting value h. -func fnv(h uint32, s []byte) uint32 { - for i := range s { - h ^= uint32(s[i]) - h *= 16777619 - } - return h -} - -func match(s string, t []byte) bool { - for i, c := range t { - if s[i] != c { - return false - } - } - return true -} - -// Lookup returns the atom whose name is s. It returns zero if there is no -// such atom. The lookup is case sensitive. -func Lookup(s []byte) Atom { - if len(s) == 0 || len(s) > maxAtomLen { - return 0 - } - h := fnv(hash0, s) - if a := table[h&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { - return a - } - if a := table[(h>>16)&uint32(len(table)-1)]; int(a&0xff) == len(s) && match(a.string(), s) { - return a - } - return 0 -} - -// String returns a string whose contents are equal to s. In that sense, it is -// equivalent to string(s) but may be more efficient. -func String(s []byte) string { - if a := Lookup(s); a != 0 { - return a.String() - } - return string(s) -} diff --git a/vendor/golang.org/x/net/html/atom/table.go b/vendor/golang.org/x/net/html/atom/table.go deleted file mode 100644 index 2a93886..0000000 --- a/vendor/golang.org/x/net/html/atom/table.go +++ /dev/null @@ -1,783 +0,0 @@ -// Code generated by go generate gen.go; DO NOT EDIT. - -//go:generate go run gen.go - -package atom - -const ( - A Atom = 0x1 - Abbr Atom = 0x4 - Accept Atom = 0x1a06 - AcceptCharset Atom = 0x1a0e - Accesskey Atom = 0x2c09 - Acronym Atom = 0xaa07 - Action Atom = 0x27206 - Address Atom = 0x6f307 - Align Atom = 0xb105 - Allowfullscreen Atom = 0x2080f - Allowpaymentrequest Atom = 0xc113 - Allowusermedia Atom = 0xdd0e - Alt Atom = 0xf303 - Annotation Atom = 0x1c90a - AnnotationXml Atom = 0x1c90e - Applet Atom = 0x31906 - Area Atom = 0x35604 - Article Atom = 0x3fc07 - As Atom = 0x3c02 - Aside Atom = 0x10705 - Async Atom = 0xff05 - Audio Atom = 0x11505 - Autocomplete Atom = 0x2780c - Autofocus Atom = 0x12109 - Autoplay Atom = 0x13c08 - B Atom = 0x101 - Base Atom = 0x3b04 - Basefont Atom = 0x3b08 - Bdi Atom = 0xba03 - Bdo Atom = 0x14b03 - Bgsound Atom = 0x15e07 - Big Atom = 0x17003 - Blink Atom = 0x17305 - Blockquote Atom = 0x1870a - Body Atom = 0x2804 - Br Atom = 0x202 - Button Atom = 0x19106 - Canvas Atom = 0x10306 - Caption Atom = 0x23107 - Center Atom = 0x22006 - Challenge Atom = 0x29b09 - Charset Atom = 0x2107 - Checked Atom = 0x47907 - Cite Atom = 0x19c04 - Class Atom = 0x56405 - Code Atom = 0x5c504 - Col Atom = 0x1ab03 - Colgroup Atom = 0x1ab08 - Color Atom = 0x1bf05 - Cols Atom = 0x1c404 - Colspan Atom = 0x1c407 - Command Atom = 0x1d707 - Content Atom = 0x58b07 - Contenteditable Atom = 0x58b0f - Contextmenu Atom = 0x3800b - Controls Atom = 0x1de08 - Coords Atom = 0x1ea06 - Crossorigin Atom = 0x1fb0b - Data Atom = 0x4a504 - Datalist Atom = 0x4a508 - Datetime Atom = 0x2b808 - Dd Atom = 0x2d702 - Default Atom = 0x10a07 - Defer Atom = 0x5c705 - Del Atom = 0x45203 - Desc Atom = 0x56104 - Details Atom = 0x7207 - Dfn Atom = 0x8703 - Dialog Atom = 0xbb06 - Dir Atom = 0x9303 - Dirname Atom = 0x9307 - Disabled Atom = 0x16408 - Div Atom = 0x16b03 - Dl Atom = 0x5e602 - Download Atom = 0x46308 - Draggable Atom = 0x17a09 - Dropzone Atom = 0x40508 - Dt Atom = 0x64b02 - Em Atom = 0x6e02 - Embed Atom = 0x6e05 - Enctype Atom = 0x28d07 - Face Atom = 0x21e04 - Fieldset Atom = 0x22608 - Figcaption Atom = 0x22e0a - Figure Atom = 0x24806 - Font Atom = 0x3f04 - Footer Atom = 0xf606 - For Atom = 0x25403 - ForeignObject Atom = 0x2540d - Foreignobject Atom = 0x2610d - Form Atom = 0x26e04 - Formaction Atom = 0x26e0a - Formenctype Atom = 0x2890b - Formmethod Atom = 0x2a40a - Formnovalidate Atom = 0x2ae0e - Formtarget Atom = 0x2c00a - Frame Atom = 0x8b05 - Frameset Atom = 0x8b08 - H1 Atom = 0x15c02 - H2 Atom = 0x2de02 - H3 Atom = 0x30d02 - H4 Atom = 0x34502 - H5 Atom = 0x34f02 - H6 Atom = 0x64d02 - Head Atom = 0x33104 - Header Atom = 0x33106 - Headers Atom = 0x33107 - Height Atom = 0x5206 - Hgroup Atom = 0x2ca06 - Hidden Atom = 0x2d506 - High Atom = 0x2db04 - Hr Atom = 0x15702 - Href Atom = 0x2e004 - Hreflang Atom = 0x2e008 - Html Atom = 0x5604 - HttpEquiv Atom = 0x2e80a - I Atom = 0x601 - Icon Atom = 0x58a04 - Id Atom = 0x10902 - Iframe Atom = 0x2fc06 - Image Atom = 0x30205 - Img Atom = 0x30703 - Input Atom = 0x44b05 - Inputmode Atom = 0x44b09 - Ins Atom = 0x20403 - Integrity Atom = 0x23f09 - Is Atom = 0x16502 - Isindex Atom = 0x30f07 - Ismap Atom = 0x31605 - Itemid Atom = 0x38b06 - Itemprop Atom = 0x19d08 - Itemref Atom = 0x3cd07 - Itemscope Atom = 0x67109 - Itemtype Atom = 0x31f08 - Kbd Atom = 0xb903 - Keygen Atom = 0x3206 - Keytype Atom = 0xd607 - Kind Atom = 0x17704 - Label Atom = 0x5905 - Lang Atom = 0x2e404 - Legend Atom = 0x18106 - Li Atom = 0xb202 - Link Atom = 0x17404 - List Atom = 0x4a904 - Listing Atom = 0x4a907 - Loop Atom = 0x5d04 - Low Atom = 0xc303 - Main Atom = 0x1004 - Malignmark Atom = 0xb00a - Manifest Atom = 0x6d708 - Map Atom = 0x31803 - Mark Atom = 0xb604 - Marquee Atom = 0x32707 - Math Atom = 0x32e04 - Max Atom = 0x33d03 - Maxlength Atom = 0x33d09 - Media Atom = 0xe605 - Mediagroup Atom = 0xe60a - Menu Atom = 0x38704 - Menuitem Atom = 0x38708 - Meta Atom = 0x4b804 - Meter Atom = 0x9805 - Method Atom = 0x2a806 - Mglyph Atom = 0x30806 - Mi Atom = 0x34702 - Min Atom = 0x34703 - Minlength Atom = 0x34709 - Mn Atom = 0x2b102 - Mo Atom = 0xa402 - Ms Atom = 0x67402 - Mtext Atom = 0x35105 - Multiple Atom = 0x35f08 - Muted Atom = 0x36705 - Name Atom = 0x9604 - Nav Atom = 0x1303 - Nobr Atom = 0x3704 - Noembed Atom = 0x6c07 - Noframes Atom = 0x8908 - Nomodule Atom = 0xa208 - Nonce Atom = 0x1a605 - Noscript Atom = 0x21608 - Novalidate Atom = 0x2b20a - Object Atom = 0x26806 - Ol Atom = 0x13702 - Onabort Atom = 0x19507 - Onafterprint Atom = 0x2360c - Onautocomplete Atom = 0x2760e - Onautocompleteerror Atom = 0x27613 - Onauxclick Atom = 0x61f0a - Onbeforeprint Atom = 0x69e0d - Onbeforeunload Atom = 0x6e70e - Onblur Atom = 0x56d06 - Oncancel Atom = 0x11908 - Oncanplay Atom = 0x14d09 - Oncanplaythrough Atom = 0x14d10 - Onchange Atom = 0x41b08 - Onclick Atom = 0x2f507 - Onclose Atom = 0x36c07 - Oncontextmenu Atom = 0x37e0d - Oncopy Atom = 0x39106 - Oncuechange Atom = 0x3970b - Oncut Atom = 0x3a205 - Ondblclick Atom = 0x3a70a - Ondrag Atom = 0x3b106 - Ondragend Atom = 0x3b109 - Ondragenter Atom = 0x3ba0b - Ondragexit Atom = 0x3c50a - Ondragleave Atom = 0x3df0b - Ondragover Atom = 0x3ea0a - Ondragstart Atom = 0x3f40b - Ondrop Atom = 0x40306 - Ondurationchange Atom = 0x41310 - Onemptied Atom = 0x40a09 - Onended Atom = 0x42307 - Onerror Atom = 0x42a07 - Onfocus Atom = 0x43107 - Onhashchange Atom = 0x43d0c - Oninput Atom = 0x44907 - Oninvalid Atom = 0x45509 - Onkeydown Atom = 0x45e09 - Onkeypress Atom = 0x46b0a - Onkeyup Atom = 0x48007 - Onlanguagechange Atom = 0x48d10 - Onload Atom = 0x49d06 - Onloadeddata Atom = 0x49d0c - Onloadedmetadata Atom = 0x4b010 - Onloadend Atom = 0x4c609 - Onloadstart Atom = 0x4cf0b - Onmessage Atom = 0x4da09 - Onmessageerror Atom = 0x4da0e - Onmousedown Atom = 0x4e80b - Onmouseenter Atom = 0x4f30c - Onmouseleave Atom = 0x4ff0c - Onmousemove Atom = 0x50b0b - Onmouseout Atom = 0x5160a - Onmouseover Atom = 0x5230b - Onmouseup Atom = 0x52e09 - Onmousewheel Atom = 0x53c0c - Onoffline Atom = 0x54809 - Ononline Atom = 0x55108 - Onpagehide Atom = 0x5590a - Onpageshow Atom = 0x5730a - Onpaste Atom = 0x57f07 - Onpause Atom = 0x59a07 - Onplay Atom = 0x5a406 - Onplaying Atom = 0x5a409 - Onpopstate Atom = 0x5ad0a - Onprogress Atom = 0x5b70a - Onratechange Atom = 0x5cc0c - Onrejectionhandled Atom = 0x5d812 - Onreset Atom = 0x5ea07 - Onresize Atom = 0x5f108 - Onscroll Atom = 0x60008 - Onsecuritypolicyviolation Atom = 0x60819 - Onseeked Atom = 0x62908 - Onseeking Atom = 0x63109 - Onselect Atom = 0x63a08 - Onshow Atom = 0x64406 - Onsort Atom = 0x64f06 - Onstalled Atom = 0x65909 - Onstorage Atom = 0x66209 - Onsubmit Atom = 0x66b08 - Onsuspend Atom = 0x67b09 - Ontimeupdate Atom = 0x400c - Ontoggle Atom = 0x68408 - Onunhandledrejection Atom = 0x68c14 - Onunload Atom = 0x6ab08 - Onvolumechange Atom = 0x6b30e - Onwaiting Atom = 0x6c109 - Onwheel Atom = 0x6ca07 - Open Atom = 0x1a304 - Optgroup Atom = 0x5f08 - Optimum Atom = 0x6d107 - Option Atom = 0x6e306 - Output Atom = 0x51d06 - P Atom = 0xc01 - Param Atom = 0xc05 - Pattern Atom = 0x6607 - Picture Atom = 0x7b07 - Ping Atom = 0xef04 - Placeholder Atom = 0x1310b - Plaintext Atom = 0x1b209 - Playsinline Atom = 0x1400b - Poster Atom = 0x2cf06 - Pre Atom = 0x47003 - Preload Atom = 0x48607 - Progress Atom = 0x5b908 - Prompt Atom = 0x53606 - Public Atom = 0x58606 - Q Atom = 0xcf01 - Radiogroup Atom = 0x30a - Rb Atom = 0x3a02 - Readonly Atom = 0x35708 - Referrerpolicy Atom = 0x3d10e - Rel Atom = 0x48703 - Required Atom = 0x24c08 - Reversed Atom = 0x8008 - Rows Atom = 0x9c04 - Rowspan Atom = 0x9c07 - Rp Atom = 0x23c02 - Rt Atom = 0x19a02 - Rtc Atom = 0x19a03 - Ruby Atom = 0xfb04 - S Atom = 0x2501 - Samp Atom = 0x7804 - Sandbox Atom = 0x12907 - Scope Atom = 0x67505 - Scoped Atom = 0x67506 - Script Atom = 0x21806 - Seamless Atom = 0x37108 - Section Atom = 0x56807 - Select Atom = 0x63c06 - Selected Atom = 0x63c08 - Shape Atom = 0x1e505 - Size Atom = 0x5f504 - Sizes Atom = 0x5f505 - Slot Atom = 0x1ef04 - Small Atom = 0x20605 - Sortable Atom = 0x65108 - Sorted Atom = 0x33706 - Source Atom = 0x37806 - Spacer Atom = 0x43706 - Span Atom = 0x9f04 - Spellcheck Atom = 0x4740a - Src Atom = 0x5c003 - Srcdoc Atom = 0x5c006 - Srclang Atom = 0x5f907 - Srcset Atom = 0x6f906 - Start Atom = 0x3fa05 - Step Atom = 0x58304 - Strike Atom = 0xd206 - Strong Atom = 0x6dd06 - Style Atom = 0x6ff05 - Sub Atom = 0x66d03 - Summary Atom = 0x70407 - Sup Atom = 0x70b03 - Svg Atom = 0x70e03 - System Atom = 0x71106 - Tabindex Atom = 0x4be08 - Table Atom = 0x59505 - Target Atom = 0x2c406 - Tbody Atom = 0x2705 - Td Atom = 0x9202 - Template Atom = 0x71408 - Textarea Atom = 0x35208 - Tfoot Atom = 0xf505 - Th Atom = 0x15602 - Thead Atom = 0x33005 - Time Atom = 0x4204 - Title Atom = 0x11005 - Tr Atom = 0xcc02 - Track Atom = 0x1ba05 - Translate Atom = 0x1f209 - Tt Atom = 0x6802 - Type Atom = 0xd904 - Typemustmatch Atom = 0x2900d - U Atom = 0xb01 - Ul Atom = 0xa702 - Updateviacache Atom = 0x460e - Usemap Atom = 0x59e06 - Value Atom = 0x1505 - Var Atom = 0x16d03 - Video Atom = 0x2f105 - Wbr Atom = 0x57c03 - Width Atom = 0x64905 - Workertype Atom = 0x71c0a - Wrap Atom = 0x72604 - Xmp Atom = 0x12f03 -) - -const hash0 = 0x81cdf10e - -const maxAtomLen = 25 - -var table = [1 << 9]Atom{ - 0x1: 0xe60a, // mediagroup - 0x2: 0x2e404, // lang - 0x4: 0x2c09, // accesskey - 0x5: 0x8b08, // frameset - 0x7: 0x63a08, // onselect - 0x8: 0x71106, // system - 0xa: 0x64905, // width - 0xc: 0x2890b, // formenctype - 0xd: 0x13702, // ol - 0xe: 0x3970b, // oncuechange - 0x10: 0x14b03, // bdo - 0x11: 0x11505, // audio - 0x12: 0x17a09, // draggable - 0x14: 0x2f105, // video - 0x15: 0x2b102, // mn - 0x16: 0x38704, // menu - 0x17: 0x2cf06, // poster - 0x19: 0xf606, // footer - 0x1a: 0x2a806, // method - 0x1b: 0x2b808, // datetime - 0x1c: 0x19507, // onabort - 0x1d: 0x460e, // updateviacache - 0x1e: 0xff05, // async - 0x1f: 0x49d06, // onload - 0x21: 0x11908, // oncancel - 0x22: 0x62908, // onseeked - 0x23: 0x30205, // image - 0x24: 0x5d812, // onrejectionhandled - 0x26: 0x17404, // link - 0x27: 0x51d06, // output - 0x28: 0x33104, // head - 0x29: 0x4ff0c, // onmouseleave - 0x2a: 0x57f07, // onpaste - 0x2b: 0x5a409, // onplaying - 0x2c: 0x1c407, // colspan - 0x2f: 0x1bf05, // color - 0x30: 0x5f504, // size - 0x31: 0x2e80a, // http-equiv - 0x33: 0x601, // i - 0x34: 0x5590a, // onpagehide - 0x35: 0x68c14, // onunhandledrejection - 0x37: 0x42a07, // onerror - 0x3a: 0x3b08, // basefont - 0x3f: 0x1303, // nav - 0x40: 0x17704, // kind - 0x41: 0x35708, // readonly - 0x42: 0x30806, // mglyph - 0x44: 0xb202, // li - 0x46: 0x2d506, // hidden - 0x47: 0x70e03, // svg - 0x48: 0x58304, // step - 0x49: 0x23f09, // integrity - 0x4a: 0x58606, // public - 0x4c: 0x1ab03, // col - 0x4d: 0x1870a, // blockquote - 0x4e: 0x34f02, // h5 - 0x50: 0x5b908, // progress - 0x51: 0x5f505, // sizes - 0x52: 0x34502, // h4 - 0x56: 0x33005, // thead - 0x57: 0xd607, // keytype - 0x58: 0x5b70a, // onprogress - 0x59: 0x44b09, // inputmode - 0x5a: 0x3b109, // ondragend - 0x5d: 0x3a205, // oncut - 0x5e: 0x43706, // spacer - 0x5f: 0x1ab08, // colgroup - 0x62: 0x16502, // is - 0x65: 0x3c02, // as - 0x66: 0x54809, // onoffline - 0x67: 0x33706, // sorted - 0x69: 0x48d10, // onlanguagechange - 0x6c: 0x43d0c, // onhashchange - 0x6d: 0x9604, // name - 0x6e: 0xf505, // tfoot - 0x6f: 0x56104, // desc - 0x70: 0x33d03, // max - 0x72: 0x1ea06, // coords - 0x73: 0x30d02, // h3 - 0x74: 0x6e70e, // onbeforeunload - 0x75: 0x9c04, // rows - 0x76: 0x63c06, // select - 0x77: 0x9805, // meter - 0x78: 0x38b06, // itemid - 0x79: 0x53c0c, // onmousewheel - 0x7a: 0x5c006, // srcdoc - 0x7d: 0x1ba05, // track - 0x7f: 0x31f08, // itemtype - 0x82: 0xa402, // mo - 0x83: 0x41b08, // onchange - 0x84: 0x33107, // headers - 0x85: 0x5cc0c, // onratechange - 0x86: 0x60819, // onsecuritypolicyviolation - 0x88: 0x4a508, // datalist - 0x89: 0x4e80b, // onmousedown - 0x8a: 0x1ef04, // slot - 0x8b: 0x4b010, // onloadedmetadata - 0x8c: 0x1a06, // accept - 0x8d: 0x26806, // object - 0x91: 0x6b30e, // onvolumechange - 0x92: 0x2107, // charset - 0x93: 0x27613, // onautocompleteerror - 0x94: 0xc113, // allowpaymentrequest - 0x95: 0x2804, // body - 0x96: 0x10a07, // default - 0x97: 0x63c08, // selected - 0x98: 0x21e04, // face - 0x99: 0x1e505, // shape - 0x9b: 0x68408, // ontoggle - 0x9e: 0x64b02, // dt - 0x9f: 0xb604, // mark - 0xa1: 0xb01, // u - 0xa4: 0x6ab08, // onunload - 0xa5: 0x5d04, // loop - 0xa6: 0x16408, // disabled - 0xaa: 0x42307, // onended - 0xab: 0xb00a, // malignmark - 0xad: 0x67b09, // onsuspend - 0xae: 0x35105, // mtext - 0xaf: 0x64f06, // onsort - 0xb0: 0x19d08, // itemprop - 0xb3: 0x67109, // itemscope - 0xb4: 0x17305, // blink - 0xb6: 0x3b106, // ondrag - 0xb7: 0xa702, // ul - 0xb8: 0x26e04, // form - 0xb9: 0x12907, // sandbox - 0xba: 0x8b05, // frame - 0xbb: 0x1505, // value - 0xbc: 0x66209, // onstorage - 0xbf: 0xaa07, // acronym - 0xc0: 0x19a02, // rt - 0xc2: 0x202, // br - 0xc3: 0x22608, // fieldset - 0xc4: 0x2900d, // typemustmatch - 0xc5: 0xa208, // nomodule - 0xc6: 0x6c07, // noembed - 0xc7: 0x69e0d, // onbeforeprint - 0xc8: 0x19106, // button - 0xc9: 0x2f507, // onclick - 0xca: 0x70407, // summary - 0xcd: 0xfb04, // ruby - 0xce: 0x56405, // class - 0xcf: 0x3f40b, // ondragstart - 0xd0: 0x23107, // caption - 0xd4: 0xdd0e, // allowusermedia - 0xd5: 0x4cf0b, // onloadstart - 0xd9: 0x16b03, // div - 0xda: 0x4a904, // list - 0xdb: 0x32e04, // math - 0xdc: 0x44b05, // input - 0xdf: 0x3ea0a, // ondragover - 0xe0: 0x2de02, // h2 - 0xe2: 0x1b209, // plaintext - 0xe4: 0x4f30c, // onmouseenter - 0xe7: 0x47907, // checked - 0xe8: 0x47003, // pre - 0xea: 0x35f08, // multiple - 0xeb: 0xba03, // bdi - 0xec: 0x33d09, // maxlength - 0xed: 0xcf01, // q - 0xee: 0x61f0a, // onauxclick - 0xf0: 0x57c03, // wbr - 0xf2: 0x3b04, // base - 0xf3: 0x6e306, // option - 0xf5: 0x41310, // ondurationchange - 0xf7: 0x8908, // noframes - 0xf9: 0x40508, // dropzone - 0xfb: 0x67505, // scope - 0xfc: 0x8008, // reversed - 0xfd: 0x3ba0b, // ondragenter - 0xfe: 0x3fa05, // start - 0xff: 0x12f03, // xmp - 0x100: 0x5f907, // srclang - 0x101: 0x30703, // img - 0x104: 0x101, // b - 0x105: 0x25403, // for - 0x106: 0x10705, // aside - 0x107: 0x44907, // oninput - 0x108: 0x35604, // area - 0x109: 0x2a40a, // formmethod - 0x10a: 0x72604, // wrap - 0x10c: 0x23c02, // rp - 0x10d: 0x46b0a, // onkeypress - 0x10e: 0x6802, // tt - 0x110: 0x34702, // mi - 0x111: 0x36705, // muted - 0x112: 0xf303, // alt - 0x113: 0x5c504, // code - 0x114: 0x6e02, // em - 0x115: 0x3c50a, // ondragexit - 0x117: 0x9f04, // span - 0x119: 0x6d708, // manifest - 0x11a: 0x38708, // menuitem - 0x11b: 0x58b07, // content - 0x11d: 0x6c109, // onwaiting - 0x11f: 0x4c609, // onloadend - 0x121: 0x37e0d, // oncontextmenu - 0x123: 0x56d06, // onblur - 0x124: 0x3fc07, // article - 0x125: 0x9303, // dir - 0x126: 0xef04, // ping - 0x127: 0x24c08, // required - 0x128: 0x45509, // oninvalid - 0x129: 0xb105, // align - 0x12b: 0x58a04, // icon - 0x12c: 0x64d02, // h6 - 0x12d: 0x1c404, // cols - 0x12e: 0x22e0a, // figcaption - 0x12f: 0x45e09, // onkeydown - 0x130: 0x66b08, // onsubmit - 0x131: 0x14d09, // oncanplay - 0x132: 0x70b03, // sup - 0x133: 0xc01, // p - 0x135: 0x40a09, // onemptied - 0x136: 0x39106, // oncopy - 0x137: 0x19c04, // cite - 0x138: 0x3a70a, // ondblclick - 0x13a: 0x50b0b, // onmousemove - 0x13c: 0x66d03, // sub - 0x13d: 0x48703, // rel - 0x13e: 0x5f08, // optgroup - 0x142: 0x9c07, // rowspan - 0x143: 0x37806, // source - 0x144: 0x21608, // noscript - 0x145: 0x1a304, // open - 0x146: 0x20403, // ins - 0x147: 0x2540d, // foreignObject - 0x148: 0x5ad0a, // onpopstate - 0x14a: 0x28d07, // enctype - 0x14b: 0x2760e, // onautocomplete - 0x14c: 0x35208, // textarea - 0x14e: 0x2780c, // autocomplete - 0x14f: 0x15702, // hr - 0x150: 0x1de08, // controls - 0x151: 0x10902, // id - 0x153: 0x2360c, // onafterprint - 0x155: 0x2610d, // foreignobject - 0x156: 0x32707, // marquee - 0x157: 0x59a07, // onpause - 0x158: 0x5e602, // dl - 0x159: 0x5206, // height - 0x15a: 0x34703, // min - 0x15b: 0x9307, // dirname - 0x15c: 0x1f209, // translate - 0x15d: 0x5604, // html - 0x15e: 0x34709, // minlength - 0x15f: 0x48607, // preload - 0x160: 0x71408, // template - 0x161: 0x3df0b, // ondragleave - 0x162: 0x3a02, // rb - 0x164: 0x5c003, // src - 0x165: 0x6dd06, // strong - 0x167: 0x7804, // samp - 0x168: 0x6f307, // address - 0x169: 0x55108, // ononline - 0x16b: 0x1310b, // placeholder - 0x16c: 0x2c406, // target - 0x16d: 0x20605, // small - 0x16e: 0x6ca07, // onwheel - 0x16f: 0x1c90a, // annotation - 0x170: 0x4740a, // spellcheck - 0x171: 0x7207, // details - 0x172: 0x10306, // canvas - 0x173: 0x12109, // autofocus - 0x174: 0xc05, // param - 0x176: 0x46308, // download - 0x177: 0x45203, // del - 0x178: 0x36c07, // onclose - 0x179: 0xb903, // kbd - 0x17a: 0x31906, // applet - 0x17b: 0x2e004, // href - 0x17c: 0x5f108, // onresize - 0x17e: 0x49d0c, // onloadeddata - 0x180: 0xcc02, // tr - 0x181: 0x2c00a, // formtarget - 0x182: 0x11005, // title - 0x183: 0x6ff05, // style - 0x184: 0xd206, // strike - 0x185: 0x59e06, // usemap - 0x186: 0x2fc06, // iframe - 0x187: 0x1004, // main - 0x189: 0x7b07, // picture - 0x18c: 0x31605, // ismap - 0x18e: 0x4a504, // data - 0x18f: 0x5905, // label - 0x191: 0x3d10e, // referrerpolicy - 0x192: 0x15602, // th - 0x194: 0x53606, // prompt - 0x195: 0x56807, // section - 0x197: 0x6d107, // optimum - 0x198: 0x2db04, // high - 0x199: 0x15c02, // h1 - 0x19a: 0x65909, // onstalled - 0x19b: 0x16d03, // var - 0x19c: 0x4204, // time - 0x19e: 0x67402, // ms - 0x19f: 0x33106, // header - 0x1a0: 0x4da09, // onmessage - 0x1a1: 0x1a605, // nonce - 0x1a2: 0x26e0a, // formaction - 0x1a3: 0x22006, // center - 0x1a4: 0x3704, // nobr - 0x1a5: 0x59505, // table - 0x1a6: 0x4a907, // listing - 0x1a7: 0x18106, // legend - 0x1a9: 0x29b09, // challenge - 0x1aa: 0x24806, // figure - 0x1ab: 0xe605, // media - 0x1ae: 0xd904, // type - 0x1af: 0x3f04, // font - 0x1b0: 0x4da0e, // onmessageerror - 0x1b1: 0x37108, // seamless - 0x1b2: 0x8703, // dfn - 0x1b3: 0x5c705, // defer - 0x1b4: 0xc303, // low - 0x1b5: 0x19a03, // rtc - 0x1b6: 0x5230b, // onmouseover - 0x1b7: 0x2b20a, // novalidate - 0x1b8: 0x71c0a, // workertype - 0x1ba: 0x3cd07, // itemref - 0x1bd: 0x1, // a - 0x1be: 0x31803, // map - 0x1bf: 0x400c, // ontimeupdate - 0x1c0: 0x15e07, // bgsound - 0x1c1: 0x3206, // keygen - 0x1c2: 0x2705, // tbody - 0x1c5: 0x64406, // onshow - 0x1c7: 0x2501, // s - 0x1c8: 0x6607, // pattern - 0x1cc: 0x14d10, // oncanplaythrough - 0x1ce: 0x2d702, // dd - 0x1cf: 0x6f906, // srcset - 0x1d0: 0x17003, // big - 0x1d2: 0x65108, // sortable - 0x1d3: 0x48007, // onkeyup - 0x1d5: 0x5a406, // onplay - 0x1d7: 0x4b804, // meta - 0x1d8: 0x40306, // ondrop - 0x1da: 0x60008, // onscroll - 0x1db: 0x1fb0b, // crossorigin - 0x1dc: 0x5730a, // onpageshow - 0x1dd: 0x4, // abbr - 0x1de: 0x9202, // td - 0x1df: 0x58b0f, // contenteditable - 0x1e0: 0x27206, // action - 0x1e1: 0x1400b, // playsinline - 0x1e2: 0x43107, // onfocus - 0x1e3: 0x2e008, // hreflang - 0x1e5: 0x5160a, // onmouseout - 0x1e6: 0x5ea07, // onreset - 0x1e7: 0x13c08, // autoplay - 0x1e8: 0x63109, // onseeking - 0x1ea: 0x67506, // scoped - 0x1ec: 0x30a, // radiogroup - 0x1ee: 0x3800b, // contextmenu - 0x1ef: 0x52e09, // onmouseup - 0x1f1: 0x2ca06, // hgroup - 0x1f2: 0x2080f, // allowfullscreen - 0x1f3: 0x4be08, // tabindex - 0x1f6: 0x30f07, // isindex - 0x1f7: 0x1a0e, // accept-charset - 0x1f8: 0x2ae0e, // formnovalidate - 0x1fb: 0x1c90e, // annotation-xml - 0x1fc: 0x6e05, // embed - 0x1fd: 0x21806, // script - 0x1fe: 0xbb06, // dialog - 0x1ff: 0x1d707, // command -} - -const atomText = "abbradiogrouparamainavalueaccept-charsetbodyaccesskeygenobrb" + - "asefontimeupdateviacacheightmlabelooptgroupatternoembedetail" + - "sampictureversedfnoframesetdirnameterowspanomoduleacronymali" + - "gnmarkbdialogallowpaymentrequestrikeytypeallowusermediagroup" + - "ingaltfooterubyasyncanvasidefaultitleaudioncancelautofocusan" + - "dboxmplaceholderautoplaysinlinebdoncanplaythrough1bgsoundisa" + - "bledivarbigblinkindraggablegendblockquotebuttonabortcitempro" + - "penoncecolgrouplaintextrackcolorcolspannotation-xmlcommandco" + - "ntrolshapecoordslotranslatecrossoriginsmallowfullscreenoscri" + - "ptfacenterfieldsetfigcaptionafterprintegrityfigurequiredfore" + - "ignObjectforeignobjectformactionautocompleteerrorformenctype" + - "mustmatchallengeformmethodformnovalidatetimeformtargethgroup" + - "osterhiddenhigh2hreflanghttp-equivideonclickiframeimageimgly" + - "ph3isindexismappletitemtypemarqueematheadersortedmaxlength4m" + - "inlength5mtextareadonlymultiplemutedoncloseamlessourceoncont" + - "extmenuitemidoncopyoncuechangeoncutondblclickondragendondrag" + - "enterondragexitemreferrerpolicyondragleaveondragoverondragst" + - "articleondropzonemptiedondurationchangeonendedonerroronfocus" + - "paceronhashchangeoninputmodeloninvalidonkeydownloadonkeypres" + - "spellcheckedonkeyupreloadonlanguagechangeonloadeddatalisting" + - "onloadedmetadatabindexonloadendonloadstartonmessageerroronmo" + - "usedownonmouseenteronmouseleaveonmousemoveonmouseoutputonmou" + - "seoveronmouseupromptonmousewheelonofflineononlineonpagehides" + - "classectionbluronpageshowbronpastepublicontenteditableonpaus" + - "emaponplayingonpopstateonprogressrcdocodeferonratechangeonre" + - "jectionhandledonresetonresizesrclangonscrollonsecuritypolicy" + - "violationauxclickonseekedonseekingonselectedonshowidth6onsor" + - "tableonstalledonstorageonsubmitemscopedonsuspendontoggleonun" + - "handledrejectionbeforeprintonunloadonvolumechangeonwaitingon" + - "wheeloptimumanifestrongoptionbeforeunloaddressrcsetstylesumm" + - "arysupsvgsystemplateworkertypewrap" diff --git a/vendor/golang.org/x/net/html/const.go b/vendor/golang.org/x/net/html/const.go deleted file mode 100644 index ff7acf2..0000000 --- a/vendor/golang.org/x/net/html/const.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package html - -// Section 12.2.4.2 of the HTML5 specification says "The following elements -// have varying levels of special parsing rules". -// https://html.spec.whatwg.org/multipage/syntax.html#the-stack-of-open-elements -var isSpecialElementMap = map[string]bool{ - "address": true, - "applet": true, - "area": true, - "article": true, - "aside": true, - "base": true, - "basefont": true, - "bgsound": true, - "blockquote": true, - "body": true, - "br": true, - "button": true, - "caption": true, - "center": true, - "col": true, - "colgroup": true, - "dd": true, - "details": true, - "dir": true, - "div": true, - "dl": true, - "dt": true, - "embed": true, - "fieldset": true, - "figcaption": true, - "figure": true, - "footer": true, - "form": true, - "frame": true, - "frameset": true, - "h1": true, - "h2": true, - "h3": true, - "h4": true, - "h5": true, - "h6": true, - "head": true, - "header": true, - "hgroup": true, - "hr": true, - "html": true, - "iframe": true, - "img": true, - "input": true, - "keygen": true, // "keygen" has been removed from the spec, but are kept here for backwards compatibility. - "li": true, - "link": true, - "listing": true, - "main": true, - "marquee": true, - "menu": true, - "meta": true, - "nav": true, - "noembed": true, - "noframes": true, - "noscript": true, - "object": true, - "ol": true, - "p": true, - "param": true, - "plaintext": true, - "pre": true, - "script": true, - "section": true, - "select": true, - "source": true, - "style": true, - "summary": true, - "table": true, - "tbody": true, - "td": true, - "template": true, - "textarea": true, - "tfoot": true, - "th": true, - "thead": true, - "title": true, - "tr": true, - "track": true, - "ul": true, - "wbr": true, - "xmp": true, -} - -func isSpecialElement(element *Node) bool { - switch element.Namespace { - case "", "html": - return isSpecialElementMap[element.Data] - case "math": - switch element.Data { - case "mi", "mo", "mn", "ms", "mtext", "annotation-xml": - return true - } - case "svg": - switch element.Data { - case "foreignObject", "desc", "title": - return true - } - } - return false -} diff --git a/vendor/golang.org/x/net/html/doc.go b/vendor/golang.org/x/net/html/doc.go deleted file mode 100644 index 822ed42..0000000 --- a/vendor/golang.org/x/net/html/doc.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2010 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package html implements an HTML5-compliant tokenizer and parser. - -Tokenization is done by creating a Tokenizer for an io.Reader r. It is the -caller's responsibility to ensure that r provides UTF-8 encoded HTML. - - z := html.NewTokenizer(r) - -Given a Tokenizer z, the HTML is tokenized by repeatedly calling z.Next(), -which parses the next token and returns its type, or an error: - - for { - tt := z.Next() - if tt == html.ErrorToken { - // ... - return ... - } - // Process the current token. - } - -There are two APIs for retrieving the current token. The high-level API is to -call Token; the low-level API is to call Text or TagName / TagAttr. Both APIs -allow optionally calling Raw after Next but before Token, Text, TagName, or -TagAttr. In EBNF notation, the valid call sequence per token is: - - Next {Raw} [ Token | Text | TagName {TagAttr} ] - -Token returns an independent data structure that completely describes a token. -Entities (such as "<") are unescaped, tag names and attribute keys are -lower-cased, and attributes are collected into a []Attribute. For example: - - for { - if z.Next() == html.ErrorToken { - // Returning io.EOF indicates success. - return z.Err() - } - emitToken(z.Token()) - } - -The low-level API performs fewer allocations and copies, but the contents of -the []byte values returned by Text, TagName and TagAttr may change on the next -call to Next. For example, to extract an HTML page's anchor text: - - depth := 0 - for { - tt := z.Next() - switch tt { - case html.ErrorToken: - return z.Err() - case html.TextToken: - if depth > 0 { - // emitBytes should copy the []byte it receives, - // if it doesn't process it immediately. - emitBytes(z.Text()) - } - case html.StartTagToken, html.EndTagToken: - tn, _ := z.TagName() - if len(tn) == 1 && tn[0] == 'a' { - if tt == html.StartTagToken { - depth++ - } else { - depth-- - } - } - } - } - -Parsing is done by calling Parse with an io.Reader, which returns the root of -the parse tree (the document element) as a *Node. It is the caller's -responsibility to ensure that the Reader provides UTF-8 encoded HTML. For -example, to process each anchor node in depth-first order: - - doc, err := html.Parse(r) - if err != nil { - // ... - } - var f func(*html.Node) - f = func(n *html.Node) { - if n.Type == html.ElementNode && n.Data == "a" { - // Do something with n... - } - for c := n.FirstChild; c != nil; c = c.NextSibling { - f(c) - } - } - f(doc) - -The relevant specifications include: -https://html.spec.whatwg.org/multipage/syntax.html and -https://html.spec.whatwg.org/multipage/syntax.html#tokenization -*/ -package html // import "golang.org/x/net/html" - -// The tokenization algorithm implemented by this package is not a line-by-line -// transliteration of the relatively verbose state-machine in the WHATWG -// specification. A more direct approach is used instead, where the program -// counter implies the state, such as whether it is tokenizing a tag or a text -// node. Specification compliance is verified by checking expected and actual -// outputs over a test suite rather than aiming for algorithmic fidelity. - -// TODO(nigeltao): Does a DOM API belong in this package or a separate one? -// TODO(nigeltao): How does parsing interact with a JavaScript engine? diff --git a/vendor/golang.org/x/net/html/doctype.go b/vendor/golang.org/x/net/html/doctype.go deleted file mode 100644 index c484e5a..0000000 --- a/vendor/golang.org/x/net/html/doctype.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package html - -import ( - "strings" -) - -// parseDoctype parses the data from a DoctypeToken into a name, -// public identifier, and system identifier. It returns a Node whose Type -// is DoctypeNode, whose Data is the name, and which has attributes -// named "system" and "public" for the two identifiers if they were present. -// quirks is whether the document should be parsed in "quirks mode". -func parseDoctype(s string) (n *Node, quirks bool) { - n = &Node{Type: DoctypeNode} - - // Find the name. - space := strings.IndexAny(s, whitespace) - if space == -1 { - space = len(s) - } - n.Data = s[:space] - // The comparison to "html" is case-sensitive. - if n.Data != "html" { - quirks = true - } - n.Data = strings.ToLower(n.Data) - s = strings.TrimLeft(s[space:], whitespace) - - if len(s) < 6 { - // It can't start with "PUBLIC" or "SYSTEM". - // Ignore the rest of the string. - return n, quirks || s != "" - } - - key := strings.ToLower(s[:6]) - s = s[6:] - for key == "public" || key == "system" { - s = strings.TrimLeft(s, whitespace) - if s == "" { - break - } - quote := s[0] - if quote != '"' && quote != '\'' { - break - } - s = s[1:] - q := strings.IndexRune(s, rune(quote)) - var id string - if q == -1 { - id = s - s = "" - } else { - id = s[:q] - s = s[q+1:] - } - n.Attr = append(n.Attr, Attribute{Key: key, Val: id}) - if key == "public" { - key = "system" - } else { - key = "" - } - } - - if key != "" || s != "" { - quirks = true - } else if len(n.Attr) > 0 { - if n.Attr[0].Key == "public" { - public := strings.ToLower(n.Attr[0].Val) - switch public { - case "-//w3o//dtd w3 html strict 3.0//en//", "-/w3d/dtd html 4.0 transitional/en", "html": - quirks = true - default: - for _, q := range quirkyIDs { - if strings.HasPrefix(public, q) { - quirks = true - break - } - } - } - // The following two public IDs only cause quirks mode if there is no system ID. - if len(n.Attr) == 1 && (strings.HasPrefix(public, "-//w3c//dtd html 4.01 frameset//") || - strings.HasPrefix(public, "-//w3c//dtd html 4.01 transitional//")) { - quirks = true - } - } - if lastAttr := n.Attr[len(n.Attr)-1]; lastAttr.Key == "system" && - strings.ToLower(lastAttr.Val) == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd" { - quirks = true - } - } - - return n, quirks -} - -// quirkyIDs is a list of public doctype identifiers that cause a document -// to be interpreted in quirks mode. The identifiers should be in lower case. -var quirkyIDs = []string{ - "+//silmaril//dtd html pro v0r11 19970101//", - "-//advasoft ltd//dtd html 3.0 aswedit + extensions//", - "-//as//dtd html 3.0 aswedit + extensions//", - "-//ietf//dtd html 2.0 level 1//", - "-//ietf//dtd html 2.0 level 2//", - "-//ietf//dtd html 2.0 strict level 1//", - "-//ietf//dtd html 2.0 strict level 2//", - "-//ietf//dtd html 2.0 strict//", - "-//ietf//dtd html 2.0//", - "-//ietf//dtd html 2.1e//", - "-//ietf//dtd html 3.0//", - "-//ietf//dtd html 3.2 final//", - "-//ietf//dtd html 3.2//", - "-//ietf//dtd html 3//", - "-//ietf//dtd html level 0//", - "-//ietf//dtd html level 1//", - "-//ietf//dtd html level 2//", - "-//ietf//dtd html level 3//", - "-//ietf//dtd html strict level 0//", - "-//ietf//dtd html strict level 1//", - "-//ietf//dtd html strict level 2//", - "-//ietf//dtd html strict level 3//", - "-//ietf//dtd html strict//", - "-//ietf//dtd html//", - "-//metrius//dtd metrius presentational//", - "-//microsoft//dtd internet explorer 2.0 html strict//", - "-//microsoft//dtd internet explorer 2.0 html//", - "-//microsoft//dtd internet explorer 2.0 tables//", - "-//microsoft//dtd internet explorer 3.0 html strict//", - "-//microsoft//dtd internet explorer 3.0 html//", - "-//microsoft//dtd internet explorer 3.0 tables//", - "-//netscape comm. corp.//dtd html//", - "-//netscape comm. corp.//dtd strict html//", - "-//o'reilly and associates//dtd html 2.0//", - "-//o'reilly and associates//dtd html extended 1.0//", - "-//o'reilly and associates//dtd html extended relaxed 1.0//", - "-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//", - "-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//", - "-//spyglass//dtd html 2.0 extended//", - "-//sq//dtd html 2.0 hotmetal + extensions//", - "-//sun microsystems corp.//dtd hotjava html//", - "-//sun microsystems corp.//dtd hotjava strict html//", - "-//w3c//dtd html 3 1995-03-24//", - "-//w3c//dtd html 3.2 draft//", - "-//w3c//dtd html 3.2 final//", - "-//w3c//dtd html 3.2//", - "-//w3c//dtd html 3.2s draft//", - "-//w3c//dtd html 4.0 frameset//", - "-//w3c//dtd html 4.0 transitional//", - "-//w3c//dtd html experimental 19960712//", - "-//w3c//dtd html experimental 970421//", - "-//w3c//dtd w3 html//", - "-//w3o//dtd w3 html 3.0//", - "-//webtechs//dtd mozilla html 2.0//", - "-//webtechs//dtd mozilla html//", -} diff --git a/vendor/golang.org/x/net/html/entity.go b/vendor/golang.org/x/net/html/entity.go deleted file mode 100644 index b628880..0000000 --- a/vendor/golang.org/x/net/html/entity.go +++ /dev/null @@ -1,2253 +0,0 @@ -// Copyright 2010 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package html - -// All entities that do not end with ';' are 6 or fewer bytes long. -const longestEntityWithoutSemicolon = 6 - -// entity is a map from HTML entity names to their values. The semicolon matters: -// https://html.spec.whatwg.org/multipage/syntax.html#named-character-references -// lists both "amp" and "amp;" as two separate entries. -// -// Note that the HTML5 list is larger than the HTML4 list at -// http://www.w3.org/TR/html4/sgml/entities.html -var entity = map[string]rune{ - "AElig;": '\U000000C6', - "AMP;": '\U00000026', - "Aacute;": '\U000000C1', - "Abreve;": '\U00000102', - "Acirc;": '\U000000C2', - "Acy;": '\U00000410', - "Afr;": '\U0001D504', - "Agrave;": '\U000000C0', - "Alpha;": '\U00000391', - "Amacr;": '\U00000100', - "And;": '\U00002A53', - "Aogon;": '\U00000104', - "Aopf;": '\U0001D538', - "ApplyFunction;": '\U00002061', - "Aring;": '\U000000C5', - "Ascr;": '\U0001D49C', - "Assign;": '\U00002254', - "Atilde;": '\U000000C3', - "Auml;": '\U000000C4', - "Backslash;": '\U00002216', - "Barv;": '\U00002AE7', - "Barwed;": '\U00002306', - "Bcy;": '\U00000411', - "Because;": '\U00002235', - "Bernoullis;": '\U0000212C', - "Beta;": '\U00000392', - "Bfr;": '\U0001D505', - "Bopf;": '\U0001D539', - "Breve;": '\U000002D8', - "Bscr;": '\U0000212C', - "Bumpeq;": '\U0000224E', - "CHcy;": '\U00000427', - "COPY;": '\U000000A9', - "Cacute;": '\U00000106', - "Cap;": '\U000022D2', - "CapitalDifferentialD;": '\U00002145', - "Cayleys;": '\U0000212D', - "Ccaron;": '\U0000010C', - "Ccedil;": '\U000000C7', - "Ccirc;": '\U00000108', - "Cconint;": '\U00002230', - "Cdot;": '\U0000010A', - "Cedilla;": '\U000000B8', - "CenterDot;": '\U000000B7', - "Cfr;": '\U0000212D', - "Chi;": '\U000003A7', - "CircleDot;": '\U00002299', - "CircleMinus;": '\U00002296', - "CirclePlus;": '\U00002295', - "CircleTimes;": '\U00002297', - "ClockwiseContourIntegral;": '\U00002232', - "CloseCurlyDoubleQuote;": '\U0000201D', - "CloseCurlyQuote;": '\U00002019', - "Colon;": '\U00002237', - "Colone;": '\U00002A74', - "Congruent;": '\U00002261', - "Conint;": '\U0000222F', - "ContourIntegral;": '\U0000222E', - "Copf;": '\U00002102', - "Coproduct;": '\U00002210', - "CounterClockwiseContourIntegral;": '\U00002233', - "Cross;": '\U00002A2F', - "Cscr;": '\U0001D49E', - "Cup;": '\U000022D3', - "CupCap;": '\U0000224D', - "DD;": '\U00002145', - "DDotrahd;": '\U00002911', - "DJcy;": '\U00000402', - "DScy;": '\U00000405', - "DZcy;": '\U0000040F', - "Dagger;": '\U00002021', - "Darr;": '\U000021A1', - "Dashv;": '\U00002AE4', - "Dcaron;": '\U0000010E', - "Dcy;": '\U00000414', - "Del;": '\U00002207', - "Delta;": '\U00000394', - "Dfr;": '\U0001D507', - "DiacriticalAcute;": '\U000000B4', - "DiacriticalDot;": '\U000002D9', - "DiacriticalDoubleAcute;": '\U000002DD', - "DiacriticalGrave;": '\U00000060', - "DiacriticalTilde;": '\U000002DC', - "Diamond;": '\U000022C4', - "DifferentialD;": '\U00002146', - "Dopf;": '\U0001D53B', - "Dot;": '\U000000A8', - "DotDot;": '\U000020DC', - "DotEqual;": '\U00002250', - "DoubleContourIntegral;": '\U0000222F', - "DoubleDot;": '\U000000A8', - "DoubleDownArrow;": '\U000021D3', - "DoubleLeftArrow;": '\U000021D0', - "DoubleLeftRightArrow;": '\U000021D4', - "DoubleLeftTee;": '\U00002AE4', - "DoubleLongLeftArrow;": '\U000027F8', - "DoubleLongLeftRightArrow;": '\U000027FA', - "DoubleLongRightArrow;": '\U000027F9', - "DoubleRightArrow;": '\U000021D2', - "DoubleRightTee;": '\U000022A8', - "DoubleUpArrow;": '\U000021D1', - "DoubleUpDownArrow;": '\U000021D5', - "DoubleVerticalBar;": '\U00002225', - "DownArrow;": '\U00002193', - "DownArrowBar;": '\U00002913', - "DownArrowUpArrow;": '\U000021F5', - "DownBreve;": '\U00000311', - "DownLeftRightVector;": '\U00002950', - "DownLeftTeeVector;": '\U0000295E', - "DownLeftVector;": '\U000021BD', - "DownLeftVectorBar;": '\U00002956', - "DownRightTeeVector;": '\U0000295F', - "DownRightVector;": '\U000021C1', - "DownRightVectorBar;": '\U00002957', - "DownTee;": '\U000022A4', - "DownTeeArrow;": '\U000021A7', - "Downarrow;": '\U000021D3', - "Dscr;": '\U0001D49F', - "Dstrok;": '\U00000110', - "ENG;": '\U0000014A', - "ETH;": '\U000000D0', - "Eacute;": '\U000000C9', - "Ecaron;": '\U0000011A', - "Ecirc;": '\U000000CA', - "Ecy;": '\U0000042D', - "Edot;": '\U00000116', - "Efr;": '\U0001D508', - "Egrave;": '\U000000C8', - "Element;": '\U00002208', - "Emacr;": '\U00000112', - "EmptySmallSquare;": '\U000025FB', - "EmptyVerySmallSquare;": '\U000025AB', - "Eogon;": '\U00000118', - "Eopf;": '\U0001D53C', - "Epsilon;": '\U00000395', - "Equal;": '\U00002A75', - "EqualTilde;": '\U00002242', - "Equilibrium;": '\U000021CC', - "Escr;": '\U00002130', - "Esim;": '\U00002A73', - "Eta;": '\U00000397', - "Euml;": '\U000000CB', - "Exists;": '\U00002203', - "ExponentialE;": '\U00002147', - "Fcy;": '\U00000424', - "Ffr;": '\U0001D509', - "FilledSmallSquare;": '\U000025FC', - "FilledVerySmallSquare;": '\U000025AA', - "Fopf;": '\U0001D53D', - "ForAll;": '\U00002200', - "Fouriertrf;": '\U00002131', - "Fscr;": '\U00002131', - "GJcy;": '\U00000403', - "GT;": '\U0000003E', - "Gamma;": '\U00000393', - "Gammad;": '\U000003DC', - "Gbreve;": '\U0000011E', - "Gcedil;": '\U00000122', - "Gcirc;": '\U0000011C', - "Gcy;": '\U00000413', - "Gdot;": '\U00000120', - "Gfr;": '\U0001D50A', - "Gg;": '\U000022D9', - "Gopf;": '\U0001D53E', - "GreaterEqual;": '\U00002265', - "GreaterEqualLess;": '\U000022DB', - "GreaterFullEqual;": '\U00002267', - "GreaterGreater;": '\U00002AA2', - "GreaterLess;": '\U00002277', - "GreaterSlantEqual;": '\U00002A7E', - "GreaterTilde;": '\U00002273', - "Gscr;": '\U0001D4A2', - "Gt;": '\U0000226B', - "HARDcy;": '\U0000042A', - "Hacek;": '\U000002C7', - "Hat;": '\U0000005E', - "Hcirc;": '\U00000124', - "Hfr;": '\U0000210C', - "HilbertSpace;": '\U0000210B', - "Hopf;": '\U0000210D', - "HorizontalLine;": '\U00002500', - "Hscr;": '\U0000210B', - "Hstrok;": '\U00000126', - "HumpDownHump;": '\U0000224E', - "HumpEqual;": '\U0000224F', - "IEcy;": '\U00000415', - "IJlig;": '\U00000132', - "IOcy;": '\U00000401', - "Iacute;": '\U000000CD', - "Icirc;": '\U000000CE', - "Icy;": '\U00000418', - "Idot;": '\U00000130', - "Ifr;": '\U00002111', - "Igrave;": '\U000000CC', - "Im;": '\U00002111', - "Imacr;": '\U0000012A', - "ImaginaryI;": '\U00002148', - "Implies;": '\U000021D2', - "Int;": '\U0000222C', - "Integral;": '\U0000222B', - "Intersection;": '\U000022C2', - "InvisibleComma;": '\U00002063', - "InvisibleTimes;": '\U00002062', - "Iogon;": '\U0000012E', - "Iopf;": '\U0001D540', - "Iota;": '\U00000399', - "Iscr;": '\U00002110', - "Itilde;": '\U00000128', - "Iukcy;": '\U00000406', - "Iuml;": '\U000000CF', - "Jcirc;": '\U00000134', - "Jcy;": '\U00000419', - "Jfr;": '\U0001D50D', - "Jopf;": '\U0001D541', - "Jscr;": '\U0001D4A5', - "Jsercy;": '\U00000408', - "Jukcy;": '\U00000404', - "KHcy;": '\U00000425', - "KJcy;": '\U0000040C', - "Kappa;": '\U0000039A', - "Kcedil;": '\U00000136', - "Kcy;": '\U0000041A', - "Kfr;": '\U0001D50E', - "Kopf;": '\U0001D542', - "Kscr;": '\U0001D4A6', - "LJcy;": '\U00000409', - "LT;": '\U0000003C', - "Lacute;": '\U00000139', - "Lambda;": '\U0000039B', - "Lang;": '\U000027EA', - "Laplacetrf;": '\U00002112', - "Larr;": '\U0000219E', - "Lcaron;": '\U0000013D', - "Lcedil;": '\U0000013B', - "Lcy;": '\U0000041B', - "LeftAngleBracket;": '\U000027E8', - "LeftArrow;": '\U00002190', - "LeftArrowBar;": '\U000021E4', - "LeftArrowRightArrow;": '\U000021C6', - "LeftCeiling;": '\U00002308', - "LeftDoubleBracket;": '\U000027E6', - "LeftDownTeeVector;": '\U00002961', - "LeftDownVector;": '\U000021C3', - "LeftDownVectorBar;": '\U00002959', - "LeftFloor;": '\U0000230A', - "LeftRightArrow;": '\U00002194', - "LeftRightVector;": '\U0000294E', - "LeftTee;": '\U000022A3', - "LeftTeeArrow;": '\U000021A4', - "LeftTeeVector;": '\U0000295A', - "LeftTriangle;": '\U000022B2', - "LeftTriangleBar;": '\U000029CF', - "LeftTriangleEqual;": '\U000022B4', - "LeftUpDownVector;": '\U00002951', - "LeftUpTeeVector;": '\U00002960', - "LeftUpVector;": '\U000021BF', - "LeftUpVectorBar;": '\U00002958', - "LeftVector;": '\U000021BC', - "LeftVectorBar;": '\U00002952', - "Leftarrow;": '\U000021D0', - "Leftrightarrow;": '\U000021D4', - "LessEqualGreater;": '\U000022DA', - "LessFullEqual;": '\U00002266', - "LessGreater;": '\U00002276', - "LessLess;": '\U00002AA1', - "LessSlantEqual;": '\U00002A7D', - "LessTilde;": '\U00002272', - "Lfr;": '\U0001D50F', - "Ll;": '\U000022D8', - "Lleftarrow;": '\U000021DA', - "Lmidot;": '\U0000013F', - "LongLeftArrow;": '\U000027F5', - "LongLeftRightArrow;": '\U000027F7', - "LongRightArrow;": '\U000027F6', - "Longleftarrow;": '\U000027F8', - "Longleftrightarrow;": '\U000027FA', - "Longrightarrow;": '\U000027F9', - "Lopf;": '\U0001D543', - "LowerLeftArrow;": '\U00002199', - "LowerRightArrow;": '\U00002198', - "Lscr;": '\U00002112', - "Lsh;": '\U000021B0', - "Lstrok;": '\U00000141', - "Lt;": '\U0000226A', - "Map;": '\U00002905', - "Mcy;": '\U0000041C', - "MediumSpace;": '\U0000205F', - "Mellintrf;": '\U00002133', - "Mfr;": '\U0001D510', - "MinusPlus;": '\U00002213', - "Mopf;": '\U0001D544', - "Mscr;": '\U00002133', - "Mu;": '\U0000039C', - "NJcy;": '\U0000040A', - "Nacute;": '\U00000143', - "Ncaron;": '\U00000147', - "Ncedil;": '\U00000145', - "Ncy;": '\U0000041D', - "NegativeMediumSpace;": '\U0000200B', - "NegativeThickSpace;": '\U0000200B', - "NegativeThinSpace;": '\U0000200B', - "NegativeVeryThinSpace;": '\U0000200B', - "NestedGreaterGreater;": '\U0000226B', - "NestedLessLess;": '\U0000226A', - "NewLine;": '\U0000000A', - "Nfr;": '\U0001D511', - "NoBreak;": '\U00002060', - "NonBreakingSpace;": '\U000000A0', - "Nopf;": '\U00002115', - "Not;": '\U00002AEC', - "NotCongruent;": '\U00002262', - "NotCupCap;": '\U0000226D', - "NotDoubleVerticalBar;": '\U00002226', - "NotElement;": '\U00002209', - "NotEqual;": '\U00002260', - "NotExists;": '\U00002204', - "NotGreater;": '\U0000226F', - "NotGreaterEqual;": '\U00002271', - "NotGreaterLess;": '\U00002279', - "NotGreaterTilde;": '\U00002275', - "NotLeftTriangle;": '\U000022EA', - "NotLeftTriangleEqual;": '\U000022EC', - "NotLess;": '\U0000226E', - "NotLessEqual;": '\U00002270', - "NotLessGreater;": '\U00002278', - "NotLessTilde;": '\U00002274', - "NotPrecedes;": '\U00002280', - "NotPrecedesSlantEqual;": '\U000022E0', - "NotReverseElement;": '\U0000220C', - "NotRightTriangle;": '\U000022EB', - "NotRightTriangleEqual;": '\U000022ED', - "NotSquareSubsetEqual;": '\U000022E2', - "NotSquareSupersetEqual;": '\U000022E3', - "NotSubsetEqual;": '\U00002288', - "NotSucceeds;": '\U00002281', - "NotSucceedsSlantEqual;": '\U000022E1', - "NotSupersetEqual;": '\U00002289', - "NotTilde;": '\U00002241', - "NotTildeEqual;": '\U00002244', - "NotTildeFullEqual;": '\U00002247', - "NotTildeTilde;": '\U00002249', - "NotVerticalBar;": '\U00002224', - "Nscr;": '\U0001D4A9', - "Ntilde;": '\U000000D1', - "Nu;": '\U0000039D', - "OElig;": '\U00000152', - "Oacute;": '\U000000D3', - "Ocirc;": '\U000000D4', - "Ocy;": '\U0000041E', - "Odblac;": '\U00000150', - "Ofr;": '\U0001D512', - "Ograve;": '\U000000D2', - "Omacr;": '\U0000014C', - "Omega;": '\U000003A9', - "Omicron;": '\U0000039F', - "Oopf;": '\U0001D546', - "OpenCurlyDoubleQuote;": '\U0000201C', - "OpenCurlyQuote;": '\U00002018', - "Or;": '\U00002A54', - "Oscr;": '\U0001D4AA', - "Oslash;": '\U000000D8', - "Otilde;": '\U000000D5', - "Otimes;": '\U00002A37', - "Ouml;": '\U000000D6', - "OverBar;": '\U0000203E', - "OverBrace;": '\U000023DE', - "OverBracket;": '\U000023B4', - "OverParenthesis;": '\U000023DC', - "PartialD;": '\U00002202', - "Pcy;": '\U0000041F', - "Pfr;": '\U0001D513', - "Phi;": '\U000003A6', - "Pi;": '\U000003A0', - "PlusMinus;": '\U000000B1', - "Poincareplane;": '\U0000210C', - "Popf;": '\U00002119', - "Pr;": '\U00002ABB', - "Precedes;": '\U0000227A', - "PrecedesEqual;": '\U00002AAF', - "PrecedesSlantEqual;": '\U0000227C', - "PrecedesTilde;": '\U0000227E', - "Prime;": '\U00002033', - "Product;": '\U0000220F', - "Proportion;": '\U00002237', - "Proportional;": '\U0000221D', - "Pscr;": '\U0001D4AB', - "Psi;": '\U000003A8', - "QUOT;": '\U00000022', - "Qfr;": '\U0001D514', - "Qopf;": '\U0000211A', - "Qscr;": '\U0001D4AC', - "RBarr;": '\U00002910', - "REG;": '\U000000AE', - "Racute;": '\U00000154', - "Rang;": '\U000027EB', - "Rarr;": '\U000021A0', - "Rarrtl;": '\U00002916', - "Rcaron;": '\U00000158', - "Rcedil;": '\U00000156', - "Rcy;": '\U00000420', - "Re;": '\U0000211C', - "ReverseElement;": '\U0000220B', - "ReverseEquilibrium;": '\U000021CB', - "ReverseUpEquilibrium;": '\U0000296F', - "Rfr;": '\U0000211C', - "Rho;": '\U000003A1', - "RightAngleBracket;": '\U000027E9', - "RightArrow;": '\U00002192', - "RightArrowBar;": '\U000021E5', - "RightArrowLeftArrow;": '\U000021C4', - "RightCeiling;": '\U00002309', - "RightDoubleBracket;": '\U000027E7', - "RightDownTeeVector;": '\U0000295D', - "RightDownVector;": '\U000021C2', - "RightDownVectorBar;": '\U00002955', - "RightFloor;": '\U0000230B', - "RightTee;": '\U000022A2', - "RightTeeArrow;": '\U000021A6', - "RightTeeVector;": '\U0000295B', - "RightTriangle;": '\U000022B3', - "RightTriangleBar;": '\U000029D0', - "RightTriangleEqual;": '\U000022B5', - "RightUpDownVector;": '\U0000294F', - "RightUpTeeVector;": '\U0000295C', - "RightUpVector;": '\U000021BE', - "RightUpVectorBar;": '\U00002954', - "RightVector;": '\U000021C0', - "RightVectorBar;": '\U00002953', - "Rightarrow;": '\U000021D2', - "Ropf;": '\U0000211D', - "RoundImplies;": '\U00002970', - "Rrightarrow;": '\U000021DB', - "Rscr;": '\U0000211B', - "Rsh;": '\U000021B1', - "RuleDelayed;": '\U000029F4', - "SHCHcy;": '\U00000429', - "SHcy;": '\U00000428', - "SOFTcy;": '\U0000042C', - "Sacute;": '\U0000015A', - "Sc;": '\U00002ABC', - "Scaron;": '\U00000160', - "Scedil;": '\U0000015E', - "Scirc;": '\U0000015C', - "Scy;": '\U00000421', - "Sfr;": '\U0001D516', - "ShortDownArrow;": '\U00002193', - "ShortLeftArrow;": '\U00002190', - "ShortRightArrow;": '\U00002192', - "ShortUpArrow;": '\U00002191', - "Sigma;": '\U000003A3', - "SmallCircle;": '\U00002218', - "Sopf;": '\U0001D54A', - "Sqrt;": '\U0000221A', - "Square;": '\U000025A1', - "SquareIntersection;": '\U00002293', - "SquareSubset;": '\U0000228F', - "SquareSubsetEqual;": '\U00002291', - "SquareSuperset;": '\U00002290', - "SquareSupersetEqual;": '\U00002292', - "SquareUnion;": '\U00002294', - "Sscr;": '\U0001D4AE', - "Star;": '\U000022C6', - "Sub;": '\U000022D0', - "Subset;": '\U000022D0', - "SubsetEqual;": '\U00002286', - "Succeeds;": '\U0000227B', - "SucceedsEqual;": '\U00002AB0', - "SucceedsSlantEqual;": '\U0000227D', - "SucceedsTilde;": '\U0000227F', - "SuchThat;": '\U0000220B', - "Sum;": '\U00002211', - "Sup;": '\U000022D1', - "Superset;": '\U00002283', - "SupersetEqual;": '\U00002287', - "Supset;": '\U000022D1', - "THORN;": '\U000000DE', - "TRADE;": '\U00002122', - "TSHcy;": '\U0000040B', - "TScy;": '\U00000426', - "Tab;": '\U00000009', - "Tau;": '\U000003A4', - "Tcaron;": '\U00000164', - "Tcedil;": '\U00000162', - "Tcy;": '\U00000422', - "Tfr;": '\U0001D517', - "Therefore;": '\U00002234', - "Theta;": '\U00000398', - "ThinSpace;": '\U00002009', - "Tilde;": '\U0000223C', - "TildeEqual;": '\U00002243', - "TildeFullEqual;": '\U00002245', - "TildeTilde;": '\U00002248', - "Topf;": '\U0001D54B', - "TripleDot;": '\U000020DB', - "Tscr;": '\U0001D4AF', - "Tstrok;": '\U00000166', - "Uacute;": '\U000000DA', - "Uarr;": '\U0000219F', - "Uarrocir;": '\U00002949', - "Ubrcy;": '\U0000040E', - "Ubreve;": '\U0000016C', - "Ucirc;": '\U000000DB', - "Ucy;": '\U00000423', - "Udblac;": '\U00000170', - "Ufr;": '\U0001D518', - "Ugrave;": '\U000000D9', - "Umacr;": '\U0000016A', - "UnderBar;": '\U0000005F', - "UnderBrace;": '\U000023DF', - "UnderBracket;": '\U000023B5', - "UnderParenthesis;": '\U000023DD', - "Union;": '\U000022C3', - "UnionPlus;": '\U0000228E', - "Uogon;": '\U00000172', - "Uopf;": '\U0001D54C', - "UpArrow;": '\U00002191', - "UpArrowBar;": '\U00002912', - "UpArrowDownArrow;": '\U000021C5', - "UpDownArrow;": '\U00002195', - "UpEquilibrium;": '\U0000296E', - "UpTee;": '\U000022A5', - "UpTeeArrow;": '\U000021A5', - "Uparrow;": '\U000021D1', - "Updownarrow;": '\U000021D5', - "UpperLeftArrow;": '\U00002196', - "UpperRightArrow;": '\U00002197', - "Upsi;": '\U000003D2', - "Upsilon;": '\U000003A5', - "Uring;": '\U0000016E', - "Uscr;": '\U0001D4B0', - "Utilde;": '\U00000168', - "Uuml;": '\U000000DC', - "VDash;": '\U000022AB', - "Vbar;": '\U00002AEB', - "Vcy;": '\U00000412', - "Vdash;": '\U000022A9', - "Vdashl;": '\U00002AE6', - "Vee;": '\U000022C1', - "Verbar;": '\U00002016', - "Vert;": '\U00002016', - "VerticalBar;": '\U00002223', - "VerticalLine;": '\U0000007C', - "VerticalSeparator;": '\U00002758', - "VerticalTilde;": '\U00002240', - "VeryThinSpace;": '\U0000200A', - "Vfr;": '\U0001D519', - "Vopf;": '\U0001D54D', - "Vscr;": '\U0001D4B1', - "Vvdash;": '\U000022AA', - "Wcirc;": '\U00000174', - "Wedge;": '\U000022C0', - "Wfr;": '\U0001D51A', - "Wopf;": '\U0001D54E', - "Wscr;": '\U0001D4B2', - "Xfr;": '\U0001D51B', - "Xi;": '\U0000039E', - "Xopf;": '\U0001D54F', - "Xscr;": '\U0001D4B3', - "YAcy;": '\U0000042F', - "YIcy;": '\U00000407', - "YUcy;": '\U0000042E', - "Yacute;": '\U000000DD', - "Ycirc;": '\U00000176', - "Ycy;": '\U0000042B', - "Yfr;": '\U0001D51C', - "Yopf;": '\U0001D550', - "Yscr;": '\U0001D4B4', - "Yuml;": '\U00000178', - "ZHcy;": '\U00000416', - "Zacute;": '\U00000179', - "Zcaron;": '\U0000017D', - "Zcy;": '\U00000417', - "Zdot;": '\U0000017B', - "ZeroWidthSpace;": '\U0000200B', - "Zeta;": '\U00000396', - "Zfr;": '\U00002128', - "Zopf;": '\U00002124', - "Zscr;": '\U0001D4B5', - "aacute;": '\U000000E1', - "abreve;": '\U00000103', - "ac;": '\U0000223E', - "acd;": '\U0000223F', - "acirc;": '\U000000E2', - "acute;": '\U000000B4', - "acy;": '\U00000430', - "aelig;": '\U000000E6', - "af;": '\U00002061', - "afr;": '\U0001D51E', - "agrave;": '\U000000E0', - "alefsym;": '\U00002135', - "aleph;": '\U00002135', - "alpha;": '\U000003B1', - "amacr;": '\U00000101', - "amalg;": '\U00002A3F', - "amp;": '\U00000026', - "and;": '\U00002227', - "andand;": '\U00002A55', - "andd;": '\U00002A5C', - "andslope;": '\U00002A58', - "andv;": '\U00002A5A', - "ang;": '\U00002220', - "ange;": '\U000029A4', - "angle;": '\U00002220', - "angmsd;": '\U00002221', - "angmsdaa;": '\U000029A8', - "angmsdab;": '\U000029A9', - "angmsdac;": '\U000029AA', - "angmsdad;": '\U000029AB', - "angmsdae;": '\U000029AC', - "angmsdaf;": '\U000029AD', - "angmsdag;": '\U000029AE', - "angmsdah;": '\U000029AF', - "angrt;": '\U0000221F', - "angrtvb;": '\U000022BE', - "angrtvbd;": '\U0000299D', - "angsph;": '\U00002222', - "angst;": '\U000000C5', - "angzarr;": '\U0000237C', - "aogon;": '\U00000105', - "aopf;": '\U0001D552', - "ap;": '\U00002248', - "apE;": '\U00002A70', - "apacir;": '\U00002A6F', - "ape;": '\U0000224A', - "apid;": '\U0000224B', - "apos;": '\U00000027', - "approx;": '\U00002248', - "approxeq;": '\U0000224A', - "aring;": '\U000000E5', - "ascr;": '\U0001D4B6', - "ast;": '\U0000002A', - "asymp;": '\U00002248', - "asympeq;": '\U0000224D', - "atilde;": '\U000000E3', - "auml;": '\U000000E4', - "awconint;": '\U00002233', - "awint;": '\U00002A11', - "bNot;": '\U00002AED', - "backcong;": '\U0000224C', - "backepsilon;": '\U000003F6', - "backprime;": '\U00002035', - "backsim;": '\U0000223D', - "backsimeq;": '\U000022CD', - "barvee;": '\U000022BD', - "barwed;": '\U00002305', - "barwedge;": '\U00002305', - "bbrk;": '\U000023B5', - "bbrktbrk;": '\U000023B6', - "bcong;": '\U0000224C', - "bcy;": '\U00000431', - "bdquo;": '\U0000201E', - "becaus;": '\U00002235', - "because;": '\U00002235', - "bemptyv;": '\U000029B0', - "bepsi;": '\U000003F6', - "bernou;": '\U0000212C', - "beta;": '\U000003B2', - "beth;": '\U00002136', - "between;": '\U0000226C', - "bfr;": '\U0001D51F', - "bigcap;": '\U000022C2', - "bigcirc;": '\U000025EF', - "bigcup;": '\U000022C3', - "bigodot;": '\U00002A00', - "bigoplus;": '\U00002A01', - "bigotimes;": '\U00002A02', - "bigsqcup;": '\U00002A06', - "bigstar;": '\U00002605', - "bigtriangledown;": '\U000025BD', - "bigtriangleup;": '\U000025B3', - "biguplus;": '\U00002A04', - "bigvee;": '\U000022C1', - "bigwedge;": '\U000022C0', - "bkarow;": '\U0000290D', - "blacklozenge;": '\U000029EB', - "blacksquare;": '\U000025AA', - "blacktriangle;": '\U000025B4', - "blacktriangledown;": '\U000025BE', - "blacktriangleleft;": '\U000025C2', - "blacktriangleright;": '\U000025B8', - "blank;": '\U00002423', - "blk12;": '\U00002592', - "blk14;": '\U00002591', - "blk34;": '\U00002593', - "block;": '\U00002588', - "bnot;": '\U00002310', - "bopf;": '\U0001D553', - "bot;": '\U000022A5', - "bottom;": '\U000022A5', - "bowtie;": '\U000022C8', - "boxDL;": '\U00002557', - "boxDR;": '\U00002554', - "boxDl;": '\U00002556', - "boxDr;": '\U00002553', - "boxH;": '\U00002550', - "boxHD;": '\U00002566', - "boxHU;": '\U00002569', - "boxHd;": '\U00002564', - "boxHu;": '\U00002567', - "boxUL;": '\U0000255D', - "boxUR;": '\U0000255A', - "boxUl;": '\U0000255C', - "boxUr;": '\U00002559', - "boxV;": '\U00002551', - "boxVH;": '\U0000256C', - "boxVL;": '\U00002563', - "boxVR;": '\U00002560', - "boxVh;": '\U0000256B', - "boxVl;": '\U00002562', - "boxVr;": '\U0000255F', - "boxbox;": '\U000029C9', - "boxdL;": '\U00002555', - "boxdR;": '\U00002552', - "boxdl;": '\U00002510', - "boxdr;": '\U0000250C', - "boxh;": '\U00002500', - "boxhD;": '\U00002565', - "boxhU;": '\U00002568', - "boxhd;": '\U0000252C', - "boxhu;": '\U00002534', - "boxminus;": '\U0000229F', - "boxplus;": '\U0000229E', - "boxtimes;": '\U000022A0', - "boxuL;": '\U0000255B', - "boxuR;": '\U00002558', - "boxul;": '\U00002518', - "boxur;": '\U00002514', - "boxv;": '\U00002502', - "boxvH;": '\U0000256A', - "boxvL;": '\U00002561', - "boxvR;": '\U0000255E', - "boxvh;": '\U0000253C', - "boxvl;": '\U00002524', - "boxvr;": '\U0000251C', - "bprime;": '\U00002035', - "breve;": '\U000002D8', - "brvbar;": '\U000000A6', - "bscr;": '\U0001D4B7', - "bsemi;": '\U0000204F', - "bsim;": '\U0000223D', - "bsime;": '\U000022CD', - "bsol;": '\U0000005C', - "bsolb;": '\U000029C5', - "bsolhsub;": '\U000027C8', - "bull;": '\U00002022', - "bullet;": '\U00002022', - "bump;": '\U0000224E', - "bumpE;": '\U00002AAE', - "bumpe;": '\U0000224F', - "bumpeq;": '\U0000224F', - "cacute;": '\U00000107', - "cap;": '\U00002229', - "capand;": '\U00002A44', - "capbrcup;": '\U00002A49', - "capcap;": '\U00002A4B', - "capcup;": '\U00002A47', - "capdot;": '\U00002A40', - "caret;": '\U00002041', - "caron;": '\U000002C7', - "ccaps;": '\U00002A4D', - "ccaron;": '\U0000010D', - "ccedil;": '\U000000E7', - "ccirc;": '\U00000109', - "ccups;": '\U00002A4C', - "ccupssm;": '\U00002A50', - "cdot;": '\U0000010B', - "cedil;": '\U000000B8', - "cemptyv;": '\U000029B2', - "cent;": '\U000000A2', - "centerdot;": '\U000000B7', - "cfr;": '\U0001D520', - "chcy;": '\U00000447', - "check;": '\U00002713', - "checkmark;": '\U00002713', - "chi;": '\U000003C7', - "cir;": '\U000025CB', - "cirE;": '\U000029C3', - "circ;": '\U000002C6', - "circeq;": '\U00002257', - "circlearrowleft;": '\U000021BA', - "circlearrowright;": '\U000021BB', - "circledR;": '\U000000AE', - "circledS;": '\U000024C8', - "circledast;": '\U0000229B', - "circledcirc;": '\U0000229A', - "circleddash;": '\U0000229D', - "cire;": '\U00002257', - "cirfnint;": '\U00002A10', - "cirmid;": '\U00002AEF', - "cirscir;": '\U000029C2', - "clubs;": '\U00002663', - "clubsuit;": '\U00002663', - "colon;": '\U0000003A', - "colone;": '\U00002254', - "coloneq;": '\U00002254', - "comma;": '\U0000002C', - "commat;": '\U00000040', - "comp;": '\U00002201', - "compfn;": '\U00002218', - "complement;": '\U00002201', - "complexes;": '\U00002102', - "cong;": '\U00002245', - "congdot;": '\U00002A6D', - "conint;": '\U0000222E', - "copf;": '\U0001D554', - "coprod;": '\U00002210', - "copy;": '\U000000A9', - "copysr;": '\U00002117', - "crarr;": '\U000021B5', - "cross;": '\U00002717', - "cscr;": '\U0001D4B8', - "csub;": '\U00002ACF', - "csube;": '\U00002AD1', - "csup;": '\U00002AD0', - "csupe;": '\U00002AD2', - "ctdot;": '\U000022EF', - "cudarrl;": '\U00002938', - "cudarrr;": '\U00002935', - "cuepr;": '\U000022DE', - "cuesc;": '\U000022DF', - "cularr;": '\U000021B6', - "cularrp;": '\U0000293D', - "cup;": '\U0000222A', - "cupbrcap;": '\U00002A48', - "cupcap;": '\U00002A46', - "cupcup;": '\U00002A4A', - "cupdot;": '\U0000228D', - "cupor;": '\U00002A45', - "curarr;": '\U000021B7', - "curarrm;": '\U0000293C', - "curlyeqprec;": '\U000022DE', - "curlyeqsucc;": '\U000022DF', - "curlyvee;": '\U000022CE', - "curlywedge;": '\U000022CF', - "curren;": '\U000000A4', - "curvearrowleft;": '\U000021B6', - "curvearrowright;": '\U000021B7', - "cuvee;": '\U000022CE', - "cuwed;": '\U000022CF', - "cwconint;": '\U00002232', - "cwint;": '\U00002231', - "cylcty;": '\U0000232D', - "dArr;": '\U000021D3', - "dHar;": '\U00002965', - "dagger;": '\U00002020', - "daleth;": '\U00002138', - "darr;": '\U00002193', - "dash;": '\U00002010', - "dashv;": '\U000022A3', - "dbkarow;": '\U0000290F', - "dblac;": '\U000002DD', - "dcaron;": '\U0000010F', - "dcy;": '\U00000434', - "dd;": '\U00002146', - "ddagger;": '\U00002021', - "ddarr;": '\U000021CA', - "ddotseq;": '\U00002A77', - "deg;": '\U000000B0', - "delta;": '\U000003B4', - "demptyv;": '\U000029B1', - "dfisht;": '\U0000297F', - "dfr;": '\U0001D521', - "dharl;": '\U000021C3', - "dharr;": '\U000021C2', - "diam;": '\U000022C4', - "diamond;": '\U000022C4', - "diamondsuit;": '\U00002666', - "diams;": '\U00002666', - "die;": '\U000000A8', - "digamma;": '\U000003DD', - "disin;": '\U000022F2', - "div;": '\U000000F7', - "divide;": '\U000000F7', - "divideontimes;": '\U000022C7', - "divonx;": '\U000022C7', - "djcy;": '\U00000452', - "dlcorn;": '\U0000231E', - "dlcrop;": '\U0000230D', - "dollar;": '\U00000024', - "dopf;": '\U0001D555', - "dot;": '\U000002D9', - "doteq;": '\U00002250', - "doteqdot;": '\U00002251', - "dotminus;": '\U00002238', - "dotplus;": '\U00002214', - "dotsquare;": '\U000022A1', - "doublebarwedge;": '\U00002306', - "downarrow;": '\U00002193', - "downdownarrows;": '\U000021CA', - "downharpoonleft;": '\U000021C3', - "downharpoonright;": '\U000021C2', - "drbkarow;": '\U00002910', - "drcorn;": '\U0000231F', - "drcrop;": '\U0000230C', - "dscr;": '\U0001D4B9', - "dscy;": '\U00000455', - "dsol;": '\U000029F6', - "dstrok;": '\U00000111', - "dtdot;": '\U000022F1', - "dtri;": '\U000025BF', - "dtrif;": '\U000025BE', - "duarr;": '\U000021F5', - "duhar;": '\U0000296F', - "dwangle;": '\U000029A6', - "dzcy;": '\U0000045F', - "dzigrarr;": '\U000027FF', - "eDDot;": '\U00002A77', - "eDot;": '\U00002251', - "eacute;": '\U000000E9', - "easter;": '\U00002A6E', - "ecaron;": '\U0000011B', - "ecir;": '\U00002256', - "ecirc;": '\U000000EA', - "ecolon;": '\U00002255', - "ecy;": '\U0000044D', - "edot;": '\U00000117', - "ee;": '\U00002147', - "efDot;": '\U00002252', - "efr;": '\U0001D522', - "eg;": '\U00002A9A', - "egrave;": '\U000000E8', - "egs;": '\U00002A96', - "egsdot;": '\U00002A98', - "el;": '\U00002A99', - "elinters;": '\U000023E7', - "ell;": '\U00002113', - "els;": '\U00002A95', - "elsdot;": '\U00002A97', - "emacr;": '\U00000113', - "empty;": '\U00002205', - "emptyset;": '\U00002205', - "emptyv;": '\U00002205', - "emsp;": '\U00002003', - "emsp13;": '\U00002004', - "emsp14;": '\U00002005', - "eng;": '\U0000014B', - "ensp;": '\U00002002', - "eogon;": '\U00000119', - "eopf;": '\U0001D556', - "epar;": '\U000022D5', - "eparsl;": '\U000029E3', - "eplus;": '\U00002A71', - "epsi;": '\U000003B5', - "epsilon;": '\U000003B5', - "epsiv;": '\U000003F5', - "eqcirc;": '\U00002256', - "eqcolon;": '\U00002255', - "eqsim;": '\U00002242', - "eqslantgtr;": '\U00002A96', - "eqslantless;": '\U00002A95', - "equals;": '\U0000003D', - "equest;": '\U0000225F', - "equiv;": '\U00002261', - "equivDD;": '\U00002A78', - "eqvparsl;": '\U000029E5', - "erDot;": '\U00002253', - "erarr;": '\U00002971', - "escr;": '\U0000212F', - "esdot;": '\U00002250', - "esim;": '\U00002242', - "eta;": '\U000003B7', - "eth;": '\U000000F0', - "euml;": '\U000000EB', - "euro;": '\U000020AC', - "excl;": '\U00000021', - "exist;": '\U00002203', - "expectation;": '\U00002130', - "exponentiale;": '\U00002147', - "fallingdotseq;": '\U00002252', - "fcy;": '\U00000444', - "female;": '\U00002640', - "ffilig;": '\U0000FB03', - "fflig;": '\U0000FB00', - "ffllig;": '\U0000FB04', - "ffr;": '\U0001D523', - "filig;": '\U0000FB01', - "flat;": '\U0000266D', - "fllig;": '\U0000FB02', - "fltns;": '\U000025B1', - "fnof;": '\U00000192', - "fopf;": '\U0001D557', - "forall;": '\U00002200', - "fork;": '\U000022D4', - "forkv;": '\U00002AD9', - "fpartint;": '\U00002A0D', - "frac12;": '\U000000BD', - "frac13;": '\U00002153', - "frac14;": '\U000000BC', - "frac15;": '\U00002155', - "frac16;": '\U00002159', - "frac18;": '\U0000215B', - "frac23;": '\U00002154', - "frac25;": '\U00002156', - "frac34;": '\U000000BE', - "frac35;": '\U00002157', - "frac38;": '\U0000215C', - "frac45;": '\U00002158', - "frac56;": '\U0000215A', - "frac58;": '\U0000215D', - "frac78;": '\U0000215E', - "frasl;": '\U00002044', - "frown;": '\U00002322', - "fscr;": '\U0001D4BB', - "gE;": '\U00002267', - "gEl;": '\U00002A8C', - "gacute;": '\U000001F5', - "gamma;": '\U000003B3', - "gammad;": '\U000003DD', - "gap;": '\U00002A86', - "gbreve;": '\U0000011F', - "gcirc;": '\U0000011D', - "gcy;": '\U00000433', - "gdot;": '\U00000121', - "ge;": '\U00002265', - "gel;": '\U000022DB', - "geq;": '\U00002265', - "geqq;": '\U00002267', - "geqslant;": '\U00002A7E', - "ges;": '\U00002A7E', - "gescc;": '\U00002AA9', - "gesdot;": '\U00002A80', - "gesdoto;": '\U00002A82', - "gesdotol;": '\U00002A84', - "gesles;": '\U00002A94', - "gfr;": '\U0001D524', - "gg;": '\U0000226B', - "ggg;": '\U000022D9', - "gimel;": '\U00002137', - "gjcy;": '\U00000453', - "gl;": '\U00002277', - "glE;": '\U00002A92', - "gla;": '\U00002AA5', - "glj;": '\U00002AA4', - "gnE;": '\U00002269', - "gnap;": '\U00002A8A', - "gnapprox;": '\U00002A8A', - "gne;": '\U00002A88', - "gneq;": '\U00002A88', - "gneqq;": '\U00002269', - "gnsim;": '\U000022E7', - "gopf;": '\U0001D558', - "grave;": '\U00000060', - "gscr;": '\U0000210A', - "gsim;": '\U00002273', - "gsime;": '\U00002A8E', - "gsiml;": '\U00002A90', - "gt;": '\U0000003E', - "gtcc;": '\U00002AA7', - "gtcir;": '\U00002A7A', - "gtdot;": '\U000022D7', - "gtlPar;": '\U00002995', - "gtquest;": '\U00002A7C', - "gtrapprox;": '\U00002A86', - "gtrarr;": '\U00002978', - "gtrdot;": '\U000022D7', - "gtreqless;": '\U000022DB', - "gtreqqless;": '\U00002A8C', - "gtrless;": '\U00002277', - "gtrsim;": '\U00002273', - "hArr;": '\U000021D4', - "hairsp;": '\U0000200A', - "half;": '\U000000BD', - "hamilt;": '\U0000210B', - "hardcy;": '\U0000044A', - "harr;": '\U00002194', - "harrcir;": '\U00002948', - "harrw;": '\U000021AD', - "hbar;": '\U0000210F', - "hcirc;": '\U00000125', - "hearts;": '\U00002665', - "heartsuit;": '\U00002665', - "hellip;": '\U00002026', - "hercon;": '\U000022B9', - "hfr;": '\U0001D525', - "hksearow;": '\U00002925', - "hkswarow;": '\U00002926', - "hoarr;": '\U000021FF', - "homtht;": '\U0000223B', - "hookleftarrow;": '\U000021A9', - "hookrightarrow;": '\U000021AA', - "hopf;": '\U0001D559', - "horbar;": '\U00002015', - "hscr;": '\U0001D4BD', - "hslash;": '\U0000210F', - "hstrok;": '\U00000127', - "hybull;": '\U00002043', - "hyphen;": '\U00002010', - "iacute;": '\U000000ED', - "ic;": '\U00002063', - "icirc;": '\U000000EE', - "icy;": '\U00000438', - "iecy;": '\U00000435', - "iexcl;": '\U000000A1', - "iff;": '\U000021D4', - "ifr;": '\U0001D526', - "igrave;": '\U000000EC', - "ii;": '\U00002148', - "iiiint;": '\U00002A0C', - "iiint;": '\U0000222D', - "iinfin;": '\U000029DC', - "iiota;": '\U00002129', - "ijlig;": '\U00000133', - "imacr;": '\U0000012B', - "image;": '\U00002111', - "imagline;": '\U00002110', - "imagpart;": '\U00002111', - "imath;": '\U00000131', - "imof;": '\U000022B7', - "imped;": '\U000001B5', - "in;": '\U00002208', - "incare;": '\U00002105', - "infin;": '\U0000221E', - "infintie;": '\U000029DD', - "inodot;": '\U00000131', - "int;": '\U0000222B', - "intcal;": '\U000022BA', - "integers;": '\U00002124', - "intercal;": '\U000022BA', - "intlarhk;": '\U00002A17', - "intprod;": '\U00002A3C', - "iocy;": '\U00000451', - "iogon;": '\U0000012F', - "iopf;": '\U0001D55A', - "iota;": '\U000003B9', - "iprod;": '\U00002A3C', - "iquest;": '\U000000BF', - "iscr;": '\U0001D4BE', - "isin;": '\U00002208', - "isinE;": '\U000022F9', - "isindot;": '\U000022F5', - "isins;": '\U000022F4', - "isinsv;": '\U000022F3', - "isinv;": '\U00002208', - "it;": '\U00002062', - "itilde;": '\U00000129', - "iukcy;": '\U00000456', - "iuml;": '\U000000EF', - "jcirc;": '\U00000135', - "jcy;": '\U00000439', - "jfr;": '\U0001D527', - "jmath;": '\U00000237', - "jopf;": '\U0001D55B', - "jscr;": '\U0001D4BF', - "jsercy;": '\U00000458', - "jukcy;": '\U00000454', - "kappa;": '\U000003BA', - "kappav;": '\U000003F0', - "kcedil;": '\U00000137', - "kcy;": '\U0000043A', - "kfr;": '\U0001D528', - "kgreen;": '\U00000138', - "khcy;": '\U00000445', - "kjcy;": '\U0000045C', - "kopf;": '\U0001D55C', - "kscr;": '\U0001D4C0', - "lAarr;": '\U000021DA', - "lArr;": '\U000021D0', - "lAtail;": '\U0000291B', - "lBarr;": '\U0000290E', - "lE;": '\U00002266', - "lEg;": '\U00002A8B', - "lHar;": '\U00002962', - "lacute;": '\U0000013A', - "laemptyv;": '\U000029B4', - "lagran;": '\U00002112', - "lambda;": '\U000003BB', - "lang;": '\U000027E8', - "langd;": '\U00002991', - "langle;": '\U000027E8', - "lap;": '\U00002A85', - "laquo;": '\U000000AB', - "larr;": '\U00002190', - "larrb;": '\U000021E4', - "larrbfs;": '\U0000291F', - "larrfs;": '\U0000291D', - "larrhk;": '\U000021A9', - "larrlp;": '\U000021AB', - "larrpl;": '\U00002939', - "larrsim;": '\U00002973', - "larrtl;": '\U000021A2', - "lat;": '\U00002AAB', - "latail;": '\U00002919', - "late;": '\U00002AAD', - "lbarr;": '\U0000290C', - "lbbrk;": '\U00002772', - "lbrace;": '\U0000007B', - "lbrack;": '\U0000005B', - "lbrke;": '\U0000298B', - "lbrksld;": '\U0000298F', - "lbrkslu;": '\U0000298D', - "lcaron;": '\U0000013E', - "lcedil;": '\U0000013C', - "lceil;": '\U00002308', - "lcub;": '\U0000007B', - "lcy;": '\U0000043B', - "ldca;": '\U00002936', - "ldquo;": '\U0000201C', - "ldquor;": '\U0000201E', - "ldrdhar;": '\U00002967', - "ldrushar;": '\U0000294B', - "ldsh;": '\U000021B2', - "le;": '\U00002264', - "leftarrow;": '\U00002190', - "leftarrowtail;": '\U000021A2', - "leftharpoondown;": '\U000021BD', - "leftharpoonup;": '\U000021BC', - "leftleftarrows;": '\U000021C7', - "leftrightarrow;": '\U00002194', - "leftrightarrows;": '\U000021C6', - "leftrightharpoons;": '\U000021CB', - "leftrightsquigarrow;": '\U000021AD', - "leftthreetimes;": '\U000022CB', - "leg;": '\U000022DA', - "leq;": '\U00002264', - "leqq;": '\U00002266', - "leqslant;": '\U00002A7D', - "les;": '\U00002A7D', - "lescc;": '\U00002AA8', - "lesdot;": '\U00002A7F', - "lesdoto;": '\U00002A81', - "lesdotor;": '\U00002A83', - "lesges;": '\U00002A93', - "lessapprox;": '\U00002A85', - "lessdot;": '\U000022D6', - "lesseqgtr;": '\U000022DA', - "lesseqqgtr;": '\U00002A8B', - "lessgtr;": '\U00002276', - "lesssim;": '\U00002272', - "lfisht;": '\U0000297C', - "lfloor;": '\U0000230A', - "lfr;": '\U0001D529', - "lg;": '\U00002276', - "lgE;": '\U00002A91', - "lhard;": '\U000021BD', - "lharu;": '\U000021BC', - "lharul;": '\U0000296A', - "lhblk;": '\U00002584', - "ljcy;": '\U00000459', - "ll;": '\U0000226A', - "llarr;": '\U000021C7', - "llcorner;": '\U0000231E', - "llhard;": '\U0000296B', - "lltri;": '\U000025FA', - "lmidot;": '\U00000140', - "lmoust;": '\U000023B0', - "lmoustache;": '\U000023B0', - "lnE;": '\U00002268', - "lnap;": '\U00002A89', - "lnapprox;": '\U00002A89', - "lne;": '\U00002A87', - "lneq;": '\U00002A87', - "lneqq;": '\U00002268', - "lnsim;": '\U000022E6', - "loang;": '\U000027EC', - "loarr;": '\U000021FD', - "lobrk;": '\U000027E6', - "longleftarrow;": '\U000027F5', - "longleftrightarrow;": '\U000027F7', - "longmapsto;": '\U000027FC', - "longrightarrow;": '\U000027F6', - "looparrowleft;": '\U000021AB', - "looparrowright;": '\U000021AC', - "lopar;": '\U00002985', - "lopf;": '\U0001D55D', - "loplus;": '\U00002A2D', - "lotimes;": '\U00002A34', - "lowast;": '\U00002217', - "lowbar;": '\U0000005F', - "loz;": '\U000025CA', - "lozenge;": '\U000025CA', - "lozf;": '\U000029EB', - "lpar;": '\U00000028', - "lparlt;": '\U00002993', - "lrarr;": '\U000021C6', - "lrcorner;": '\U0000231F', - "lrhar;": '\U000021CB', - "lrhard;": '\U0000296D', - "lrm;": '\U0000200E', - "lrtri;": '\U000022BF', - "lsaquo;": '\U00002039', - "lscr;": '\U0001D4C1', - "lsh;": '\U000021B0', - "lsim;": '\U00002272', - "lsime;": '\U00002A8D', - "lsimg;": '\U00002A8F', - "lsqb;": '\U0000005B', - "lsquo;": '\U00002018', - "lsquor;": '\U0000201A', - "lstrok;": '\U00000142', - "lt;": '\U0000003C', - "ltcc;": '\U00002AA6', - "ltcir;": '\U00002A79', - "ltdot;": '\U000022D6', - "lthree;": '\U000022CB', - "ltimes;": '\U000022C9', - "ltlarr;": '\U00002976', - "ltquest;": '\U00002A7B', - "ltrPar;": '\U00002996', - "ltri;": '\U000025C3', - "ltrie;": '\U000022B4', - "ltrif;": '\U000025C2', - "lurdshar;": '\U0000294A', - "luruhar;": '\U00002966', - "mDDot;": '\U0000223A', - "macr;": '\U000000AF', - "male;": '\U00002642', - "malt;": '\U00002720', - "maltese;": '\U00002720', - "map;": '\U000021A6', - "mapsto;": '\U000021A6', - "mapstodown;": '\U000021A7', - "mapstoleft;": '\U000021A4', - "mapstoup;": '\U000021A5', - "marker;": '\U000025AE', - "mcomma;": '\U00002A29', - "mcy;": '\U0000043C', - "mdash;": '\U00002014', - "measuredangle;": '\U00002221', - "mfr;": '\U0001D52A', - "mho;": '\U00002127', - "micro;": '\U000000B5', - "mid;": '\U00002223', - "midast;": '\U0000002A', - "midcir;": '\U00002AF0', - "middot;": '\U000000B7', - "minus;": '\U00002212', - "minusb;": '\U0000229F', - "minusd;": '\U00002238', - "minusdu;": '\U00002A2A', - "mlcp;": '\U00002ADB', - "mldr;": '\U00002026', - "mnplus;": '\U00002213', - "models;": '\U000022A7', - "mopf;": '\U0001D55E', - "mp;": '\U00002213', - "mscr;": '\U0001D4C2', - "mstpos;": '\U0000223E', - "mu;": '\U000003BC', - "multimap;": '\U000022B8', - "mumap;": '\U000022B8', - "nLeftarrow;": '\U000021CD', - "nLeftrightarrow;": '\U000021CE', - "nRightarrow;": '\U000021CF', - "nVDash;": '\U000022AF', - "nVdash;": '\U000022AE', - "nabla;": '\U00002207', - "nacute;": '\U00000144', - "nap;": '\U00002249', - "napos;": '\U00000149', - "napprox;": '\U00002249', - "natur;": '\U0000266E', - "natural;": '\U0000266E', - "naturals;": '\U00002115', - "nbsp;": '\U000000A0', - "ncap;": '\U00002A43', - "ncaron;": '\U00000148', - "ncedil;": '\U00000146', - "ncong;": '\U00002247', - "ncup;": '\U00002A42', - "ncy;": '\U0000043D', - "ndash;": '\U00002013', - "ne;": '\U00002260', - "neArr;": '\U000021D7', - "nearhk;": '\U00002924', - "nearr;": '\U00002197', - "nearrow;": '\U00002197', - "nequiv;": '\U00002262', - "nesear;": '\U00002928', - "nexist;": '\U00002204', - "nexists;": '\U00002204', - "nfr;": '\U0001D52B', - "nge;": '\U00002271', - "ngeq;": '\U00002271', - "ngsim;": '\U00002275', - "ngt;": '\U0000226F', - "ngtr;": '\U0000226F', - "nhArr;": '\U000021CE', - "nharr;": '\U000021AE', - "nhpar;": '\U00002AF2', - "ni;": '\U0000220B', - "nis;": '\U000022FC', - "nisd;": '\U000022FA', - "niv;": '\U0000220B', - "njcy;": '\U0000045A', - "nlArr;": '\U000021CD', - "nlarr;": '\U0000219A', - "nldr;": '\U00002025', - "nle;": '\U00002270', - "nleftarrow;": '\U0000219A', - "nleftrightarrow;": '\U000021AE', - "nleq;": '\U00002270', - "nless;": '\U0000226E', - "nlsim;": '\U00002274', - "nlt;": '\U0000226E', - "nltri;": '\U000022EA', - "nltrie;": '\U000022EC', - "nmid;": '\U00002224', - "nopf;": '\U0001D55F', - "not;": '\U000000AC', - "notin;": '\U00002209', - "notinva;": '\U00002209', - "notinvb;": '\U000022F7', - "notinvc;": '\U000022F6', - "notni;": '\U0000220C', - "notniva;": '\U0000220C', - "notnivb;": '\U000022FE', - "notnivc;": '\U000022FD', - "npar;": '\U00002226', - "nparallel;": '\U00002226', - "npolint;": '\U00002A14', - "npr;": '\U00002280', - "nprcue;": '\U000022E0', - "nprec;": '\U00002280', - "nrArr;": '\U000021CF', - "nrarr;": '\U0000219B', - "nrightarrow;": '\U0000219B', - "nrtri;": '\U000022EB', - "nrtrie;": '\U000022ED', - "nsc;": '\U00002281', - "nsccue;": '\U000022E1', - "nscr;": '\U0001D4C3', - "nshortmid;": '\U00002224', - "nshortparallel;": '\U00002226', - "nsim;": '\U00002241', - "nsime;": '\U00002244', - "nsimeq;": '\U00002244', - "nsmid;": '\U00002224', - "nspar;": '\U00002226', - "nsqsube;": '\U000022E2', - "nsqsupe;": '\U000022E3', - "nsub;": '\U00002284', - "nsube;": '\U00002288', - "nsubseteq;": '\U00002288', - "nsucc;": '\U00002281', - "nsup;": '\U00002285', - "nsupe;": '\U00002289', - "nsupseteq;": '\U00002289', - "ntgl;": '\U00002279', - "ntilde;": '\U000000F1', - "ntlg;": '\U00002278', - "ntriangleleft;": '\U000022EA', - "ntrianglelefteq;": '\U000022EC', - "ntriangleright;": '\U000022EB', - "ntrianglerighteq;": '\U000022ED', - "nu;": '\U000003BD', - "num;": '\U00000023', - "numero;": '\U00002116', - "numsp;": '\U00002007', - "nvDash;": '\U000022AD', - "nvHarr;": '\U00002904', - "nvdash;": '\U000022AC', - "nvinfin;": '\U000029DE', - "nvlArr;": '\U00002902', - "nvrArr;": '\U00002903', - "nwArr;": '\U000021D6', - "nwarhk;": '\U00002923', - "nwarr;": '\U00002196', - "nwarrow;": '\U00002196', - "nwnear;": '\U00002927', - "oS;": '\U000024C8', - "oacute;": '\U000000F3', - "oast;": '\U0000229B', - "ocir;": '\U0000229A', - "ocirc;": '\U000000F4', - "ocy;": '\U0000043E', - "odash;": '\U0000229D', - "odblac;": '\U00000151', - "odiv;": '\U00002A38', - "odot;": '\U00002299', - "odsold;": '\U000029BC', - "oelig;": '\U00000153', - "ofcir;": '\U000029BF', - "ofr;": '\U0001D52C', - "ogon;": '\U000002DB', - "ograve;": '\U000000F2', - "ogt;": '\U000029C1', - "ohbar;": '\U000029B5', - "ohm;": '\U000003A9', - "oint;": '\U0000222E', - "olarr;": '\U000021BA', - "olcir;": '\U000029BE', - "olcross;": '\U000029BB', - "oline;": '\U0000203E', - "olt;": '\U000029C0', - "omacr;": '\U0000014D', - "omega;": '\U000003C9', - "omicron;": '\U000003BF', - "omid;": '\U000029B6', - "ominus;": '\U00002296', - "oopf;": '\U0001D560', - "opar;": '\U000029B7', - "operp;": '\U000029B9', - "oplus;": '\U00002295', - "or;": '\U00002228', - "orarr;": '\U000021BB', - "ord;": '\U00002A5D', - "order;": '\U00002134', - "orderof;": '\U00002134', - "ordf;": '\U000000AA', - "ordm;": '\U000000BA', - "origof;": '\U000022B6', - "oror;": '\U00002A56', - "orslope;": '\U00002A57', - "orv;": '\U00002A5B', - "oscr;": '\U00002134', - "oslash;": '\U000000F8', - "osol;": '\U00002298', - "otilde;": '\U000000F5', - "otimes;": '\U00002297', - "otimesas;": '\U00002A36', - "ouml;": '\U000000F6', - "ovbar;": '\U0000233D', - "par;": '\U00002225', - "para;": '\U000000B6', - "parallel;": '\U00002225', - "parsim;": '\U00002AF3', - "parsl;": '\U00002AFD', - "part;": '\U00002202', - "pcy;": '\U0000043F', - "percnt;": '\U00000025', - "period;": '\U0000002E', - "permil;": '\U00002030', - "perp;": '\U000022A5', - "pertenk;": '\U00002031', - "pfr;": '\U0001D52D', - "phi;": '\U000003C6', - "phiv;": '\U000003D5', - "phmmat;": '\U00002133', - "phone;": '\U0000260E', - "pi;": '\U000003C0', - "pitchfork;": '\U000022D4', - "piv;": '\U000003D6', - "planck;": '\U0000210F', - "planckh;": '\U0000210E', - "plankv;": '\U0000210F', - "plus;": '\U0000002B', - "plusacir;": '\U00002A23', - "plusb;": '\U0000229E', - "pluscir;": '\U00002A22', - "plusdo;": '\U00002214', - "plusdu;": '\U00002A25', - "pluse;": '\U00002A72', - "plusmn;": '\U000000B1', - "plussim;": '\U00002A26', - "plustwo;": '\U00002A27', - "pm;": '\U000000B1', - "pointint;": '\U00002A15', - "popf;": '\U0001D561', - "pound;": '\U000000A3', - "pr;": '\U0000227A', - "prE;": '\U00002AB3', - "prap;": '\U00002AB7', - "prcue;": '\U0000227C', - "pre;": '\U00002AAF', - "prec;": '\U0000227A', - "precapprox;": '\U00002AB7', - "preccurlyeq;": '\U0000227C', - "preceq;": '\U00002AAF', - "precnapprox;": '\U00002AB9', - "precneqq;": '\U00002AB5', - "precnsim;": '\U000022E8', - "precsim;": '\U0000227E', - "prime;": '\U00002032', - "primes;": '\U00002119', - "prnE;": '\U00002AB5', - "prnap;": '\U00002AB9', - "prnsim;": '\U000022E8', - "prod;": '\U0000220F', - "profalar;": '\U0000232E', - "profline;": '\U00002312', - "profsurf;": '\U00002313', - "prop;": '\U0000221D', - "propto;": '\U0000221D', - "prsim;": '\U0000227E', - "prurel;": '\U000022B0', - "pscr;": '\U0001D4C5', - "psi;": '\U000003C8', - "puncsp;": '\U00002008', - "qfr;": '\U0001D52E', - "qint;": '\U00002A0C', - "qopf;": '\U0001D562', - "qprime;": '\U00002057', - "qscr;": '\U0001D4C6', - "quaternions;": '\U0000210D', - "quatint;": '\U00002A16', - "quest;": '\U0000003F', - "questeq;": '\U0000225F', - "quot;": '\U00000022', - "rAarr;": '\U000021DB', - "rArr;": '\U000021D2', - "rAtail;": '\U0000291C', - "rBarr;": '\U0000290F', - "rHar;": '\U00002964', - "racute;": '\U00000155', - "radic;": '\U0000221A', - "raemptyv;": '\U000029B3', - "rang;": '\U000027E9', - "rangd;": '\U00002992', - "range;": '\U000029A5', - "rangle;": '\U000027E9', - "raquo;": '\U000000BB', - "rarr;": '\U00002192', - "rarrap;": '\U00002975', - "rarrb;": '\U000021E5', - "rarrbfs;": '\U00002920', - "rarrc;": '\U00002933', - "rarrfs;": '\U0000291E', - "rarrhk;": '\U000021AA', - "rarrlp;": '\U000021AC', - "rarrpl;": '\U00002945', - "rarrsim;": '\U00002974', - "rarrtl;": '\U000021A3', - "rarrw;": '\U0000219D', - "ratail;": '\U0000291A', - "ratio;": '\U00002236', - "rationals;": '\U0000211A', - "rbarr;": '\U0000290D', - "rbbrk;": '\U00002773', - "rbrace;": '\U0000007D', - "rbrack;": '\U0000005D', - "rbrke;": '\U0000298C', - "rbrksld;": '\U0000298E', - "rbrkslu;": '\U00002990', - "rcaron;": '\U00000159', - "rcedil;": '\U00000157', - "rceil;": '\U00002309', - "rcub;": '\U0000007D', - "rcy;": '\U00000440', - "rdca;": '\U00002937', - "rdldhar;": '\U00002969', - "rdquo;": '\U0000201D', - "rdquor;": '\U0000201D', - "rdsh;": '\U000021B3', - "real;": '\U0000211C', - "realine;": '\U0000211B', - "realpart;": '\U0000211C', - "reals;": '\U0000211D', - "rect;": '\U000025AD', - "reg;": '\U000000AE', - "rfisht;": '\U0000297D', - "rfloor;": '\U0000230B', - "rfr;": '\U0001D52F', - "rhard;": '\U000021C1', - "rharu;": '\U000021C0', - "rharul;": '\U0000296C', - "rho;": '\U000003C1', - "rhov;": '\U000003F1', - "rightarrow;": '\U00002192', - "rightarrowtail;": '\U000021A3', - "rightharpoondown;": '\U000021C1', - "rightharpoonup;": '\U000021C0', - "rightleftarrows;": '\U000021C4', - "rightleftharpoons;": '\U000021CC', - "rightrightarrows;": '\U000021C9', - "rightsquigarrow;": '\U0000219D', - "rightthreetimes;": '\U000022CC', - "ring;": '\U000002DA', - "risingdotseq;": '\U00002253', - "rlarr;": '\U000021C4', - "rlhar;": '\U000021CC', - "rlm;": '\U0000200F', - "rmoust;": '\U000023B1', - "rmoustache;": '\U000023B1', - "rnmid;": '\U00002AEE', - "roang;": '\U000027ED', - "roarr;": '\U000021FE', - "robrk;": '\U000027E7', - "ropar;": '\U00002986', - "ropf;": '\U0001D563', - "roplus;": '\U00002A2E', - "rotimes;": '\U00002A35', - "rpar;": '\U00000029', - "rpargt;": '\U00002994', - "rppolint;": '\U00002A12', - "rrarr;": '\U000021C9', - "rsaquo;": '\U0000203A', - "rscr;": '\U0001D4C7', - "rsh;": '\U000021B1', - "rsqb;": '\U0000005D', - "rsquo;": '\U00002019', - "rsquor;": '\U00002019', - "rthree;": '\U000022CC', - "rtimes;": '\U000022CA', - "rtri;": '\U000025B9', - "rtrie;": '\U000022B5', - "rtrif;": '\U000025B8', - "rtriltri;": '\U000029CE', - "ruluhar;": '\U00002968', - "rx;": '\U0000211E', - "sacute;": '\U0000015B', - "sbquo;": '\U0000201A', - "sc;": '\U0000227B', - "scE;": '\U00002AB4', - "scap;": '\U00002AB8', - "scaron;": '\U00000161', - "sccue;": '\U0000227D', - "sce;": '\U00002AB0', - "scedil;": '\U0000015F', - "scirc;": '\U0000015D', - "scnE;": '\U00002AB6', - "scnap;": '\U00002ABA', - "scnsim;": '\U000022E9', - "scpolint;": '\U00002A13', - "scsim;": '\U0000227F', - "scy;": '\U00000441', - "sdot;": '\U000022C5', - "sdotb;": '\U000022A1', - "sdote;": '\U00002A66', - "seArr;": '\U000021D8', - "searhk;": '\U00002925', - "searr;": '\U00002198', - "searrow;": '\U00002198', - "sect;": '\U000000A7', - "semi;": '\U0000003B', - "seswar;": '\U00002929', - "setminus;": '\U00002216', - "setmn;": '\U00002216', - "sext;": '\U00002736', - "sfr;": '\U0001D530', - "sfrown;": '\U00002322', - "sharp;": '\U0000266F', - "shchcy;": '\U00000449', - "shcy;": '\U00000448', - "shortmid;": '\U00002223', - "shortparallel;": '\U00002225', - "shy;": '\U000000AD', - "sigma;": '\U000003C3', - "sigmaf;": '\U000003C2', - "sigmav;": '\U000003C2', - "sim;": '\U0000223C', - "simdot;": '\U00002A6A', - "sime;": '\U00002243', - "simeq;": '\U00002243', - "simg;": '\U00002A9E', - "simgE;": '\U00002AA0', - "siml;": '\U00002A9D', - "simlE;": '\U00002A9F', - "simne;": '\U00002246', - "simplus;": '\U00002A24', - "simrarr;": '\U00002972', - "slarr;": '\U00002190', - "smallsetminus;": '\U00002216', - "smashp;": '\U00002A33', - "smeparsl;": '\U000029E4', - "smid;": '\U00002223', - "smile;": '\U00002323', - "smt;": '\U00002AAA', - "smte;": '\U00002AAC', - "softcy;": '\U0000044C', - "sol;": '\U0000002F', - "solb;": '\U000029C4', - "solbar;": '\U0000233F', - "sopf;": '\U0001D564', - "spades;": '\U00002660', - "spadesuit;": '\U00002660', - "spar;": '\U00002225', - "sqcap;": '\U00002293', - "sqcup;": '\U00002294', - "sqsub;": '\U0000228F', - "sqsube;": '\U00002291', - "sqsubset;": '\U0000228F', - "sqsubseteq;": '\U00002291', - "sqsup;": '\U00002290', - "sqsupe;": '\U00002292', - "sqsupset;": '\U00002290', - "sqsupseteq;": '\U00002292', - "squ;": '\U000025A1', - "square;": '\U000025A1', - "squarf;": '\U000025AA', - "squf;": '\U000025AA', - "srarr;": '\U00002192', - "sscr;": '\U0001D4C8', - "ssetmn;": '\U00002216', - "ssmile;": '\U00002323', - "sstarf;": '\U000022C6', - "star;": '\U00002606', - "starf;": '\U00002605', - "straightepsilon;": '\U000003F5', - "straightphi;": '\U000003D5', - "strns;": '\U000000AF', - "sub;": '\U00002282', - "subE;": '\U00002AC5', - "subdot;": '\U00002ABD', - "sube;": '\U00002286', - "subedot;": '\U00002AC3', - "submult;": '\U00002AC1', - "subnE;": '\U00002ACB', - "subne;": '\U0000228A', - "subplus;": '\U00002ABF', - "subrarr;": '\U00002979', - "subset;": '\U00002282', - "subseteq;": '\U00002286', - "subseteqq;": '\U00002AC5', - "subsetneq;": '\U0000228A', - "subsetneqq;": '\U00002ACB', - "subsim;": '\U00002AC7', - "subsub;": '\U00002AD5', - "subsup;": '\U00002AD3', - "succ;": '\U0000227B', - "succapprox;": '\U00002AB8', - "succcurlyeq;": '\U0000227D', - "succeq;": '\U00002AB0', - "succnapprox;": '\U00002ABA', - "succneqq;": '\U00002AB6', - "succnsim;": '\U000022E9', - "succsim;": '\U0000227F', - "sum;": '\U00002211', - "sung;": '\U0000266A', - "sup;": '\U00002283', - "sup1;": '\U000000B9', - "sup2;": '\U000000B2', - "sup3;": '\U000000B3', - "supE;": '\U00002AC6', - "supdot;": '\U00002ABE', - "supdsub;": '\U00002AD8', - "supe;": '\U00002287', - "supedot;": '\U00002AC4', - "suphsol;": '\U000027C9', - "suphsub;": '\U00002AD7', - "suplarr;": '\U0000297B', - "supmult;": '\U00002AC2', - "supnE;": '\U00002ACC', - "supne;": '\U0000228B', - "supplus;": '\U00002AC0', - "supset;": '\U00002283', - "supseteq;": '\U00002287', - "supseteqq;": '\U00002AC6', - "supsetneq;": '\U0000228B', - "supsetneqq;": '\U00002ACC', - "supsim;": '\U00002AC8', - "supsub;": '\U00002AD4', - "supsup;": '\U00002AD6', - "swArr;": '\U000021D9', - "swarhk;": '\U00002926', - "swarr;": '\U00002199', - "swarrow;": '\U00002199', - "swnwar;": '\U0000292A', - "szlig;": '\U000000DF', - "target;": '\U00002316', - "tau;": '\U000003C4', - "tbrk;": '\U000023B4', - "tcaron;": '\U00000165', - "tcedil;": '\U00000163', - "tcy;": '\U00000442', - "tdot;": '\U000020DB', - "telrec;": '\U00002315', - "tfr;": '\U0001D531', - "there4;": '\U00002234', - "therefore;": '\U00002234', - "theta;": '\U000003B8', - "thetasym;": '\U000003D1', - "thetav;": '\U000003D1', - "thickapprox;": '\U00002248', - "thicksim;": '\U0000223C', - "thinsp;": '\U00002009', - "thkap;": '\U00002248', - "thksim;": '\U0000223C', - "thorn;": '\U000000FE', - "tilde;": '\U000002DC', - "times;": '\U000000D7', - "timesb;": '\U000022A0', - "timesbar;": '\U00002A31', - "timesd;": '\U00002A30', - "tint;": '\U0000222D', - "toea;": '\U00002928', - "top;": '\U000022A4', - "topbot;": '\U00002336', - "topcir;": '\U00002AF1', - "topf;": '\U0001D565', - "topfork;": '\U00002ADA', - "tosa;": '\U00002929', - "tprime;": '\U00002034', - "trade;": '\U00002122', - "triangle;": '\U000025B5', - "triangledown;": '\U000025BF', - "triangleleft;": '\U000025C3', - "trianglelefteq;": '\U000022B4', - "triangleq;": '\U0000225C', - "triangleright;": '\U000025B9', - "trianglerighteq;": '\U000022B5', - "tridot;": '\U000025EC', - "trie;": '\U0000225C', - "triminus;": '\U00002A3A', - "triplus;": '\U00002A39', - "trisb;": '\U000029CD', - "tritime;": '\U00002A3B', - "trpezium;": '\U000023E2', - "tscr;": '\U0001D4C9', - "tscy;": '\U00000446', - "tshcy;": '\U0000045B', - "tstrok;": '\U00000167', - "twixt;": '\U0000226C', - "twoheadleftarrow;": '\U0000219E', - "twoheadrightarrow;": '\U000021A0', - "uArr;": '\U000021D1', - "uHar;": '\U00002963', - "uacute;": '\U000000FA', - "uarr;": '\U00002191', - "ubrcy;": '\U0000045E', - "ubreve;": '\U0000016D', - "ucirc;": '\U000000FB', - "ucy;": '\U00000443', - "udarr;": '\U000021C5', - "udblac;": '\U00000171', - "udhar;": '\U0000296E', - "ufisht;": '\U0000297E', - "ufr;": '\U0001D532', - "ugrave;": '\U000000F9', - "uharl;": '\U000021BF', - "uharr;": '\U000021BE', - "uhblk;": '\U00002580', - "ulcorn;": '\U0000231C', - "ulcorner;": '\U0000231C', - "ulcrop;": '\U0000230F', - "ultri;": '\U000025F8', - "umacr;": '\U0000016B', - "uml;": '\U000000A8', - "uogon;": '\U00000173', - "uopf;": '\U0001D566', - "uparrow;": '\U00002191', - "updownarrow;": '\U00002195', - "upharpoonleft;": '\U000021BF', - "upharpoonright;": '\U000021BE', - "uplus;": '\U0000228E', - "upsi;": '\U000003C5', - "upsih;": '\U000003D2', - "upsilon;": '\U000003C5', - "upuparrows;": '\U000021C8', - "urcorn;": '\U0000231D', - "urcorner;": '\U0000231D', - "urcrop;": '\U0000230E', - "uring;": '\U0000016F', - "urtri;": '\U000025F9', - "uscr;": '\U0001D4CA', - "utdot;": '\U000022F0', - "utilde;": '\U00000169', - "utri;": '\U000025B5', - "utrif;": '\U000025B4', - "uuarr;": '\U000021C8', - "uuml;": '\U000000FC', - "uwangle;": '\U000029A7', - "vArr;": '\U000021D5', - "vBar;": '\U00002AE8', - "vBarv;": '\U00002AE9', - "vDash;": '\U000022A8', - "vangrt;": '\U0000299C', - "varepsilon;": '\U000003F5', - "varkappa;": '\U000003F0', - "varnothing;": '\U00002205', - "varphi;": '\U000003D5', - "varpi;": '\U000003D6', - "varpropto;": '\U0000221D', - "varr;": '\U00002195', - "varrho;": '\U000003F1', - "varsigma;": '\U000003C2', - "vartheta;": '\U000003D1', - "vartriangleleft;": '\U000022B2', - "vartriangleright;": '\U000022B3', - "vcy;": '\U00000432', - "vdash;": '\U000022A2', - "vee;": '\U00002228', - "veebar;": '\U000022BB', - "veeeq;": '\U0000225A', - "vellip;": '\U000022EE', - "verbar;": '\U0000007C', - "vert;": '\U0000007C', - "vfr;": '\U0001D533', - "vltri;": '\U000022B2', - "vopf;": '\U0001D567', - "vprop;": '\U0000221D', - "vrtri;": '\U000022B3', - "vscr;": '\U0001D4CB', - "vzigzag;": '\U0000299A', - "wcirc;": '\U00000175', - "wedbar;": '\U00002A5F', - "wedge;": '\U00002227', - "wedgeq;": '\U00002259', - "weierp;": '\U00002118', - "wfr;": '\U0001D534', - "wopf;": '\U0001D568', - "wp;": '\U00002118', - "wr;": '\U00002240', - "wreath;": '\U00002240', - "wscr;": '\U0001D4CC', - "xcap;": '\U000022C2', - "xcirc;": '\U000025EF', - "xcup;": '\U000022C3', - "xdtri;": '\U000025BD', - "xfr;": '\U0001D535', - "xhArr;": '\U000027FA', - "xharr;": '\U000027F7', - "xi;": '\U000003BE', - "xlArr;": '\U000027F8', - "xlarr;": '\U000027F5', - "xmap;": '\U000027FC', - "xnis;": '\U000022FB', - "xodot;": '\U00002A00', - "xopf;": '\U0001D569', - "xoplus;": '\U00002A01', - "xotime;": '\U00002A02', - "xrArr;": '\U000027F9', - "xrarr;": '\U000027F6', - "xscr;": '\U0001D4CD', - "xsqcup;": '\U00002A06', - "xuplus;": '\U00002A04', - "xutri;": '\U000025B3', - "xvee;": '\U000022C1', - "xwedge;": '\U000022C0', - "yacute;": '\U000000FD', - "yacy;": '\U0000044F', - "ycirc;": '\U00000177', - "ycy;": '\U0000044B', - "yen;": '\U000000A5', - "yfr;": '\U0001D536', - "yicy;": '\U00000457', - "yopf;": '\U0001D56A', - "yscr;": '\U0001D4CE', - "yucy;": '\U0000044E', - "yuml;": '\U000000FF', - "zacute;": '\U0000017A', - "zcaron;": '\U0000017E', - "zcy;": '\U00000437', - "zdot;": '\U0000017C', - "zeetrf;": '\U00002128', - "zeta;": '\U000003B6', - "zfr;": '\U0001D537', - "zhcy;": '\U00000436', - "zigrarr;": '\U000021DD', - "zopf;": '\U0001D56B', - "zscr;": '\U0001D4CF', - "zwj;": '\U0000200D', - "zwnj;": '\U0000200C', - "AElig": '\U000000C6', - "AMP": '\U00000026', - "Aacute": '\U000000C1', - "Acirc": '\U000000C2', - "Agrave": '\U000000C0', - "Aring": '\U000000C5', - "Atilde": '\U000000C3', - "Auml": '\U000000C4', - "COPY": '\U000000A9', - "Ccedil": '\U000000C7', - "ETH": '\U000000D0', - "Eacute": '\U000000C9', - "Ecirc": '\U000000CA', - "Egrave": '\U000000C8', - "Euml": '\U000000CB', - "GT": '\U0000003E', - "Iacute": '\U000000CD', - "Icirc": '\U000000CE', - "Igrave": '\U000000CC', - "Iuml": '\U000000CF', - "LT": '\U0000003C', - "Ntilde": '\U000000D1', - "Oacute": '\U000000D3', - "Ocirc": '\U000000D4', - "Ograve": '\U000000D2', - "Oslash": '\U000000D8', - "Otilde": '\U000000D5', - "Ouml": '\U000000D6', - "QUOT": '\U00000022', - "REG": '\U000000AE', - "THORN": '\U000000DE', - "Uacute": '\U000000DA', - "Ucirc": '\U000000DB', - "Ugrave": '\U000000D9', - "Uuml": '\U000000DC', - "Yacute": '\U000000DD', - "aacute": '\U000000E1', - "acirc": '\U000000E2', - "acute": '\U000000B4', - "aelig": '\U000000E6', - "agrave": '\U000000E0', - "amp": '\U00000026', - "aring": '\U000000E5', - "atilde": '\U000000E3', - "auml": '\U000000E4', - "brvbar": '\U000000A6', - "ccedil": '\U000000E7', - "cedil": '\U000000B8', - "cent": '\U000000A2', - "copy": '\U000000A9', - "curren": '\U000000A4', - "deg": '\U000000B0', - "divide": '\U000000F7', - "eacute": '\U000000E9', - "ecirc": '\U000000EA', - "egrave": '\U000000E8', - "eth": '\U000000F0', - "euml": '\U000000EB', - "frac12": '\U000000BD', - "frac14": '\U000000BC', - "frac34": '\U000000BE', - "gt": '\U0000003E', - "iacute": '\U000000ED', - "icirc": '\U000000EE', - "iexcl": '\U000000A1', - "igrave": '\U000000EC', - "iquest": '\U000000BF', - "iuml": '\U000000EF', - "laquo": '\U000000AB', - "lt": '\U0000003C', - "macr": '\U000000AF', - "micro": '\U000000B5', - "middot": '\U000000B7', - "nbsp": '\U000000A0', - "not": '\U000000AC', - "ntilde": '\U000000F1', - "oacute": '\U000000F3', - "ocirc": '\U000000F4', - "ograve": '\U000000F2', - "ordf": '\U000000AA', - "ordm": '\U000000BA', - "oslash": '\U000000F8', - "otilde": '\U000000F5', - "ouml": '\U000000F6', - "para": '\U000000B6', - "plusmn": '\U000000B1', - "pound": '\U000000A3', - "quot": '\U00000022', - "raquo": '\U000000BB', - "reg": '\U000000AE', - "sect": '\U000000A7', - "shy": '\U000000AD', - "sup1": '\U000000B9', - "sup2": '\U000000B2', - "sup3": '\U000000B3', - "szlig": '\U000000DF', - "thorn": '\U000000FE', - "times": '\U000000D7', - "uacute": '\U000000FA', - "ucirc": '\U000000FB', - "ugrave": '\U000000F9', - "uml": '\U000000A8', - "uuml": '\U000000FC', - "yacute": '\U000000FD', - "yen": '\U000000A5', - "yuml": '\U000000FF', -} - -// HTML entities that are two unicode codepoints. -var entity2 = map[string][2]rune{ - // TODO(nigeltao): Handle replacements that are wider than their names. - // "nLt;": {'\u226A', '\u20D2'}, - // "nGt;": {'\u226B', '\u20D2'}, - "NotEqualTilde;": {'\u2242', '\u0338'}, - "NotGreaterFullEqual;": {'\u2267', '\u0338'}, - "NotGreaterGreater;": {'\u226B', '\u0338'}, - "NotGreaterSlantEqual;": {'\u2A7E', '\u0338'}, - "NotHumpDownHump;": {'\u224E', '\u0338'}, - "NotHumpEqual;": {'\u224F', '\u0338'}, - "NotLeftTriangleBar;": {'\u29CF', '\u0338'}, - "NotLessLess;": {'\u226A', '\u0338'}, - "NotLessSlantEqual;": {'\u2A7D', '\u0338'}, - "NotNestedGreaterGreater;": {'\u2AA2', '\u0338'}, - "NotNestedLessLess;": {'\u2AA1', '\u0338'}, - "NotPrecedesEqual;": {'\u2AAF', '\u0338'}, - "NotRightTriangleBar;": {'\u29D0', '\u0338'}, - "NotSquareSubset;": {'\u228F', '\u0338'}, - "NotSquareSuperset;": {'\u2290', '\u0338'}, - "NotSubset;": {'\u2282', '\u20D2'}, - "NotSucceedsEqual;": {'\u2AB0', '\u0338'}, - "NotSucceedsTilde;": {'\u227F', '\u0338'}, - "NotSuperset;": {'\u2283', '\u20D2'}, - "ThickSpace;": {'\u205F', '\u200A'}, - "acE;": {'\u223E', '\u0333'}, - "bne;": {'\u003D', '\u20E5'}, - "bnequiv;": {'\u2261', '\u20E5'}, - "caps;": {'\u2229', '\uFE00'}, - "cups;": {'\u222A', '\uFE00'}, - "fjlig;": {'\u0066', '\u006A'}, - "gesl;": {'\u22DB', '\uFE00'}, - "gvertneqq;": {'\u2269', '\uFE00'}, - "gvnE;": {'\u2269', '\uFE00'}, - "lates;": {'\u2AAD', '\uFE00'}, - "lesg;": {'\u22DA', '\uFE00'}, - "lvertneqq;": {'\u2268', '\uFE00'}, - "lvnE;": {'\u2268', '\uFE00'}, - "nGg;": {'\u22D9', '\u0338'}, - "nGtv;": {'\u226B', '\u0338'}, - "nLl;": {'\u22D8', '\u0338'}, - "nLtv;": {'\u226A', '\u0338'}, - "nang;": {'\u2220', '\u20D2'}, - "napE;": {'\u2A70', '\u0338'}, - "napid;": {'\u224B', '\u0338'}, - "nbump;": {'\u224E', '\u0338'}, - "nbumpe;": {'\u224F', '\u0338'}, - "ncongdot;": {'\u2A6D', '\u0338'}, - "nedot;": {'\u2250', '\u0338'}, - "nesim;": {'\u2242', '\u0338'}, - "ngE;": {'\u2267', '\u0338'}, - "ngeqq;": {'\u2267', '\u0338'}, - "ngeqslant;": {'\u2A7E', '\u0338'}, - "nges;": {'\u2A7E', '\u0338'}, - "nlE;": {'\u2266', '\u0338'}, - "nleqq;": {'\u2266', '\u0338'}, - "nleqslant;": {'\u2A7D', '\u0338'}, - "nles;": {'\u2A7D', '\u0338'}, - "notinE;": {'\u22F9', '\u0338'}, - "notindot;": {'\u22F5', '\u0338'}, - "nparsl;": {'\u2AFD', '\u20E5'}, - "npart;": {'\u2202', '\u0338'}, - "npre;": {'\u2AAF', '\u0338'}, - "npreceq;": {'\u2AAF', '\u0338'}, - "nrarrc;": {'\u2933', '\u0338'}, - "nrarrw;": {'\u219D', '\u0338'}, - "nsce;": {'\u2AB0', '\u0338'}, - "nsubE;": {'\u2AC5', '\u0338'}, - "nsubset;": {'\u2282', '\u20D2'}, - "nsubseteqq;": {'\u2AC5', '\u0338'}, - "nsucceq;": {'\u2AB0', '\u0338'}, - "nsupE;": {'\u2AC6', '\u0338'}, - "nsupset;": {'\u2283', '\u20D2'}, - "nsupseteqq;": {'\u2AC6', '\u0338'}, - "nvap;": {'\u224D', '\u20D2'}, - "nvge;": {'\u2265', '\u20D2'}, - "nvgt;": {'\u003E', '\u20D2'}, - "nvle;": {'\u2264', '\u20D2'}, - "nvlt;": {'\u003C', '\u20D2'}, - "nvltrie;": {'\u22B4', '\u20D2'}, - "nvrtrie;": {'\u22B5', '\u20D2'}, - "nvsim;": {'\u223C', '\u20D2'}, - "race;": {'\u223D', '\u0331'}, - "smtes;": {'\u2AAC', '\uFE00'}, - "sqcaps;": {'\u2293', '\uFE00'}, - "sqcups;": {'\u2294', '\uFE00'}, - "varsubsetneq;": {'\u228A', '\uFE00'}, - "varsubsetneqq;": {'\u2ACB', '\uFE00'}, - "varsupsetneq;": {'\u228B', '\uFE00'}, - "varsupsetneqq;": {'\u2ACC', '\uFE00'}, - "vnsub;": {'\u2282', '\u20D2'}, - "vnsup;": {'\u2283', '\u20D2'}, - "vsubnE;": {'\u2ACB', '\uFE00'}, - "vsubne;": {'\u228A', '\uFE00'}, - "vsupnE;": {'\u2ACC', '\uFE00'}, - "vsupne;": {'\u228B', '\uFE00'}, -} diff --git a/vendor/golang.org/x/net/html/escape.go b/vendor/golang.org/x/net/html/escape.go deleted file mode 100644 index d856139..0000000 --- a/vendor/golang.org/x/net/html/escape.go +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2010 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package html - -import ( - "bytes" - "strings" - "unicode/utf8" -) - -// These replacements permit compatibility with old numeric entities that -// assumed Windows-1252 encoding. -// https://html.spec.whatwg.org/multipage/syntax.html#consume-a-character-reference -var replacementTable = [...]rune{ - '\u20AC', // First entry is what 0x80 should be replaced with. - '\u0081', - '\u201A', - '\u0192', - '\u201E', - '\u2026', - '\u2020', - '\u2021', - '\u02C6', - '\u2030', - '\u0160', - '\u2039', - '\u0152', - '\u008D', - '\u017D', - '\u008F', - '\u0090', - '\u2018', - '\u2019', - '\u201C', - '\u201D', - '\u2022', - '\u2013', - '\u2014', - '\u02DC', - '\u2122', - '\u0161', - '\u203A', - '\u0153', - '\u009D', - '\u017E', - '\u0178', // Last entry is 0x9F. - // 0x00->'\uFFFD' is handled programmatically. - // 0x0D->'\u000D' is a no-op. -} - -// unescapeEntity reads an entity like "<" from b[src:] and writes the -// corresponding "<" to b[dst:], returning the incremented dst and src cursors. -// Precondition: b[src] == '&' && dst <= src. -// attribute should be true if parsing an attribute value. -func unescapeEntity(b []byte, dst, src int, attribute bool) (dst1, src1 int) { - // https://html.spec.whatwg.org/multipage/syntax.html#consume-a-character-reference - - // i starts at 1 because we already know that s[0] == '&'. - i, s := 1, b[src:] - - if len(s) <= 1 { - b[dst] = b[src] - return dst + 1, src + 1 - } - - if s[i] == '#' { - if len(s) <= 3 { // We need to have at least "&#.". - b[dst] = b[src] - return dst + 1, src + 1 - } - i++ - c := s[i] - hex := false - if c == 'x' || c == 'X' { - hex = true - i++ - } - - x := '\x00' - for i < len(s) { - c = s[i] - i++ - if hex { - if '0' <= c && c <= '9' { - x = 16*x + rune(c) - '0' - continue - } else if 'a' <= c && c <= 'f' { - x = 16*x + rune(c) - 'a' + 10 - continue - } else if 'A' <= c && c <= 'F' { - x = 16*x + rune(c) - 'A' + 10 - continue - } - } else if '0' <= c && c <= '9' { - x = 10*x + rune(c) - '0' - continue - } - if c != ';' { - i-- - } - break - } - - if i <= 3 { // No characters matched. - b[dst] = b[src] - return dst + 1, src + 1 - } - - if 0x80 <= x && x <= 0x9F { - // Replace characters from Windows-1252 with UTF-8 equivalents. - x = replacementTable[x-0x80] - } else if x == 0 || (0xD800 <= x && x <= 0xDFFF) || x > 0x10FFFF { - // Replace invalid characters with the replacement character. - x = '\uFFFD' - } - - return dst + utf8.EncodeRune(b[dst:], x), src + i - } - - // Consume the maximum number of characters possible, with the - // consumed characters matching one of the named references. - - for i < len(s) { - c := s[i] - i++ - // Lower-cased characters are more common in entities, so we check for them first. - if 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' { - continue - } - if c != ';' { - i-- - } - break - } - - entityName := string(s[1:i]) - if entityName == "" { - // No-op. - } else if attribute && entityName[len(entityName)-1] != ';' && len(s) > i && s[i] == '=' { - // No-op. - } else if x := entity[entityName]; x != 0 { - return dst + utf8.EncodeRune(b[dst:], x), src + i - } else if x := entity2[entityName]; x[0] != 0 { - dst1 := dst + utf8.EncodeRune(b[dst:], x[0]) - return dst1 + utf8.EncodeRune(b[dst1:], x[1]), src + i - } else if !attribute { - maxLen := len(entityName) - 1 - if maxLen > longestEntityWithoutSemicolon { - maxLen = longestEntityWithoutSemicolon - } - for j := maxLen; j > 1; j-- { - if x := entity[entityName[:j]]; x != 0 { - return dst + utf8.EncodeRune(b[dst:], x), src + j + 1 - } - } - } - - dst1, src1 = dst+i, src+i - copy(b[dst:dst1], b[src:src1]) - return dst1, src1 -} - -// unescape unescapes b's entities in-place, so that "a<b" becomes "a': - esc = ">" - case '"': - // """ is shorter than """. - esc = """ - case '\r': - esc = " " - default: - panic("unrecognized escape character") - } - s = s[i+1:] - if _, err := w.WriteString(esc); err != nil { - return err - } - i = strings.IndexAny(s, escapedChars) - } - _, err := w.WriteString(s) - return err -} - -// EscapeString escapes special characters like "<" to become "<". It -// escapes only five such characters: <, >, &, ' and ". -// UnescapeString(EscapeString(s)) == s always holds, but the converse isn't -// always true. -func EscapeString(s string) string { - if strings.IndexAny(s, escapedChars) == -1 { - return s - } - var buf bytes.Buffer - escape(&buf, s) - return buf.String() -} - -// UnescapeString unescapes entities like "<" to become "<". It unescapes a -// larger range of entities than EscapeString escapes. For example, "á" -// unescapes to "á", as does "á" and "&xE1;". -// UnescapeString(EscapeString(s)) == s always holds, but the converse isn't -// always true. -func UnescapeString(s string) string { - for _, c := range s { - if c == '&' { - return string(unescape([]byte(s), false)) - } - } - return s -} diff --git a/vendor/golang.org/x/net/html/foreign.go b/vendor/golang.org/x/net/html/foreign.go deleted file mode 100644 index 9da9e9d..0000000 --- a/vendor/golang.org/x/net/html/foreign.go +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package html - -import ( - "strings" -) - -func adjustAttributeNames(aa []Attribute, nameMap map[string]string) { - for i := range aa { - if newName, ok := nameMap[aa[i].Key]; ok { - aa[i].Key = newName - } - } -} - -func adjustForeignAttributes(aa []Attribute) { - for i, a := range aa { - if a.Key == "" || a.Key[0] != 'x' { - continue - } - switch a.Key { - case "xlink:actuate", "xlink:arcrole", "xlink:href", "xlink:role", "xlink:show", - "xlink:title", "xlink:type", "xml:base", "xml:lang", "xml:space", "xmlns:xlink": - j := strings.Index(a.Key, ":") - aa[i].Namespace = a.Key[:j] - aa[i].Key = a.Key[j+1:] - } - } -} - -func htmlIntegrationPoint(n *Node) bool { - if n.Type != ElementNode { - return false - } - switch n.Namespace { - case "math": - if n.Data == "annotation-xml" { - for _, a := range n.Attr { - if a.Key == "encoding" { - val := strings.ToLower(a.Val) - if val == "text/html" || val == "application/xhtml+xml" { - return true - } - } - } - } - case "svg": - switch n.Data { - case "desc", "foreignObject", "title": - return true - } - } - return false -} - -func mathMLTextIntegrationPoint(n *Node) bool { - if n.Namespace != "math" { - return false - } - switch n.Data { - case "mi", "mo", "mn", "ms", "mtext": - return true - } - return false -} - -// Section 12.2.6.5. -var breakout = map[string]bool{ - "b": true, - "big": true, - "blockquote": true, - "body": true, - "br": true, - "center": true, - "code": true, - "dd": true, - "div": true, - "dl": true, - "dt": true, - "em": true, - "embed": true, - "h1": true, - "h2": true, - "h3": true, - "h4": true, - "h5": true, - "h6": true, - "head": true, - "hr": true, - "i": true, - "img": true, - "li": true, - "listing": true, - "menu": true, - "meta": true, - "nobr": true, - "ol": true, - "p": true, - "pre": true, - "ruby": true, - "s": true, - "small": true, - "span": true, - "strong": true, - "strike": true, - "sub": true, - "sup": true, - "table": true, - "tt": true, - "u": true, - "ul": true, - "var": true, -} - -// Section 12.2.6.5. -var svgTagNameAdjustments = map[string]string{ - "altglyph": "altGlyph", - "altglyphdef": "altGlyphDef", - "altglyphitem": "altGlyphItem", - "animatecolor": "animateColor", - "animatemotion": "animateMotion", - "animatetransform": "animateTransform", - "clippath": "clipPath", - "feblend": "feBlend", - "fecolormatrix": "feColorMatrix", - "fecomponenttransfer": "feComponentTransfer", - "fecomposite": "feComposite", - "feconvolvematrix": "feConvolveMatrix", - "fediffuselighting": "feDiffuseLighting", - "fedisplacementmap": "feDisplacementMap", - "fedistantlight": "feDistantLight", - "feflood": "feFlood", - "fefunca": "feFuncA", - "fefuncb": "feFuncB", - "fefuncg": "feFuncG", - "fefuncr": "feFuncR", - "fegaussianblur": "feGaussianBlur", - "feimage": "feImage", - "femerge": "feMerge", - "femergenode": "feMergeNode", - "femorphology": "feMorphology", - "feoffset": "feOffset", - "fepointlight": "fePointLight", - "fespecularlighting": "feSpecularLighting", - "fespotlight": "feSpotLight", - "fetile": "feTile", - "feturbulence": "feTurbulence", - "foreignobject": "foreignObject", - "glyphref": "glyphRef", - "lineargradient": "linearGradient", - "radialgradient": "radialGradient", - "textpath": "textPath", -} - -// Section 12.2.6.1 -var mathMLAttributeAdjustments = map[string]string{ - "definitionurl": "definitionURL", -} - -var svgAttributeAdjustments = map[string]string{ - "attributename": "attributeName", - "attributetype": "attributeType", - "basefrequency": "baseFrequency", - "baseprofile": "baseProfile", - "calcmode": "calcMode", - "clippathunits": "clipPathUnits", - "diffuseconstant": "diffuseConstant", - "edgemode": "edgeMode", - "filterunits": "filterUnits", - "glyphref": "glyphRef", - "gradienttransform": "gradientTransform", - "gradientunits": "gradientUnits", - "kernelmatrix": "kernelMatrix", - "kernelunitlength": "kernelUnitLength", - "keypoints": "keyPoints", - "keysplines": "keySplines", - "keytimes": "keyTimes", - "lengthadjust": "lengthAdjust", - "limitingconeangle": "limitingConeAngle", - "markerheight": "markerHeight", - "markerunits": "markerUnits", - "markerwidth": "markerWidth", - "maskcontentunits": "maskContentUnits", - "maskunits": "maskUnits", - "numoctaves": "numOctaves", - "pathlength": "pathLength", - "patterncontentunits": "patternContentUnits", - "patterntransform": "patternTransform", - "patternunits": "patternUnits", - "pointsatx": "pointsAtX", - "pointsaty": "pointsAtY", - "pointsatz": "pointsAtZ", - "preservealpha": "preserveAlpha", - "preserveaspectratio": "preserveAspectRatio", - "primitiveunits": "primitiveUnits", - "refx": "refX", - "refy": "refY", - "repeatcount": "repeatCount", - "repeatdur": "repeatDur", - "requiredextensions": "requiredExtensions", - "requiredfeatures": "requiredFeatures", - "specularconstant": "specularConstant", - "specularexponent": "specularExponent", - "spreadmethod": "spreadMethod", - "startoffset": "startOffset", - "stddeviation": "stdDeviation", - "stitchtiles": "stitchTiles", - "surfacescale": "surfaceScale", - "systemlanguage": "systemLanguage", - "tablevalues": "tableValues", - "targetx": "targetX", - "targety": "targetY", - "textlength": "textLength", - "viewbox": "viewBox", - "viewtarget": "viewTarget", - "xchannelselector": "xChannelSelector", - "ychannelselector": "yChannelSelector", - "zoomandpan": "zoomAndPan", -} diff --git a/vendor/golang.org/x/net/html/node.go b/vendor/golang.org/x/net/html/node.go deleted file mode 100644 index 1350eef..0000000 --- a/vendor/golang.org/x/net/html/node.go +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package html - -import ( - "golang.org/x/net/html/atom" -) - -// A NodeType is the type of a Node. -type NodeType uint32 - -const ( - ErrorNode NodeType = iota - TextNode - DocumentNode - ElementNode - CommentNode - DoctypeNode - // RawNode nodes are not returned by the parser, but can be part of the - // Node tree passed to func Render to insert raw HTML (without escaping). - // If so, this package makes no guarantee that the rendered HTML is secure - // (from e.g. Cross Site Scripting attacks) or well-formed. - RawNode - scopeMarkerNode -) - -// Section 12.2.4.3 says "The markers are inserted when entering applet, -// object, marquee, template, td, th, and caption elements, and are used -// to prevent formatting from "leaking" into applet, object, marquee, -// template, td, th, and caption elements". -var scopeMarker = Node{Type: scopeMarkerNode} - -// A Node consists of a NodeType and some Data (tag name for element nodes, -// content for text) and are part of a tree of Nodes. Element nodes may also -// have a Namespace and contain a slice of Attributes. Data is unescaped, so -// that it looks like "a 0 { - return (*s)[i-1] - } - return nil -} - -// index returns the index of the top-most occurrence of n in the stack, or -1 -// if n is not present. -func (s *nodeStack) index(n *Node) int { - for i := len(*s) - 1; i >= 0; i-- { - if (*s)[i] == n { - return i - } - } - return -1 -} - -// contains returns whether a is within s. -func (s *nodeStack) contains(a atom.Atom) bool { - for _, n := range *s { - if n.DataAtom == a && n.Namespace == "" { - return true - } - } - return false -} - -// insert inserts a node at the given index. -func (s *nodeStack) insert(i int, n *Node) { - (*s) = append(*s, nil) - copy((*s)[i+1:], (*s)[i:]) - (*s)[i] = n -} - -// remove removes a node from the stack. It is a no-op if n is not present. -func (s *nodeStack) remove(n *Node) { - i := s.index(n) - if i == -1 { - return - } - copy((*s)[i:], (*s)[i+1:]) - j := len(*s) - 1 - (*s)[j] = nil - *s = (*s)[:j] -} - -type insertionModeStack []insertionMode - -func (s *insertionModeStack) pop() (im insertionMode) { - i := len(*s) - im = (*s)[i-1] - *s = (*s)[:i-1] - return im -} - -func (s *insertionModeStack) top() insertionMode { - if i := len(*s); i > 0 { - return (*s)[i-1] - } - return nil -} diff --git a/vendor/golang.org/x/net/html/parse.go b/vendor/golang.org/x/net/html/parse.go deleted file mode 100644 index 46a89ed..0000000 --- a/vendor/golang.org/x/net/html/parse.go +++ /dev/null @@ -1,2460 +0,0 @@ -// Copyright 2010 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package html - -import ( - "errors" - "fmt" - "io" - "strings" - - a "golang.org/x/net/html/atom" -) - -// A parser implements the HTML5 parsing algorithm: -// https://html.spec.whatwg.org/multipage/syntax.html#tree-construction -type parser struct { - // tokenizer provides the tokens for the parser. - tokenizer *Tokenizer - // tok is the most recently read token. - tok Token - // Self-closing tags like
are treated as start tags, except that - // hasSelfClosingToken is set while they are being processed. - hasSelfClosingToken bool - // doc is the document root element. - doc *Node - // The stack of open elements (section 12.2.4.2) and active formatting - // elements (section 12.2.4.3). - oe, afe nodeStack - // Element pointers (section 12.2.4.4). - head, form *Node - // Other parsing state flags (section 12.2.4.5). - scripting, framesetOK bool - // The stack of template insertion modes - templateStack insertionModeStack - // im is the current insertion mode. - im insertionMode - // originalIM is the insertion mode to go back to after completing a text - // or inTableText insertion mode. - originalIM insertionMode - // fosterParenting is whether new elements should be inserted according to - // the foster parenting rules (section 12.2.6.1). - fosterParenting bool - // quirks is whether the parser is operating in "quirks mode." - quirks bool - // fragment is whether the parser is parsing an HTML fragment. - fragment bool - // context is the context element when parsing an HTML fragment - // (section 12.4). - context *Node -} - -func (p *parser) top() *Node { - if n := p.oe.top(); n != nil { - return n - } - return p.doc -} - -// Stop tags for use in popUntil. These come from section 12.2.4.2. -var ( - defaultScopeStopTags = map[string][]a.Atom{ - "": {a.Applet, a.Caption, a.Html, a.Table, a.Td, a.Th, a.Marquee, a.Object, a.Template}, - "math": {a.AnnotationXml, a.Mi, a.Mn, a.Mo, a.Ms, a.Mtext}, - "svg": {a.Desc, a.ForeignObject, a.Title}, - } -) - -type scope int - -const ( - defaultScope scope = iota - listItemScope - buttonScope - tableScope - tableRowScope - tableBodyScope - selectScope -) - -// popUntil pops the stack of open elements at the highest element whose tag -// is in matchTags, provided there is no higher element in the scope's stop -// tags (as defined in section 12.2.4.2). It returns whether or not there was -// such an element. If there was not, popUntil leaves the stack unchanged. -// -// For example, the set of stop tags for table scope is: "html", "table". If -// the stack was: -// ["html", "body", "font", "table", "b", "i", "u"] -// then popUntil(tableScope, "font") would return false, but -// popUntil(tableScope, "i") would return true and the stack would become: -// ["html", "body", "font", "table", "b"] -// -// If an element's tag is in both the stop tags and matchTags, then the stack -// will be popped and the function returns true (provided, of course, there was -// no higher element in the stack that was also in the stop tags). For example, -// popUntil(tableScope, "table") returns true and leaves: -// ["html", "body", "font"] -func (p *parser) popUntil(s scope, matchTags ...a.Atom) bool { - if i := p.indexOfElementInScope(s, matchTags...); i != -1 { - p.oe = p.oe[:i] - return true - } - return false -} - -// indexOfElementInScope returns the index in p.oe of the highest element whose -// tag is in matchTags that is in scope. If no matching element is in scope, it -// returns -1. -func (p *parser) indexOfElementInScope(s scope, matchTags ...a.Atom) int { - for i := len(p.oe) - 1; i >= 0; i-- { - tagAtom := p.oe[i].DataAtom - if p.oe[i].Namespace == "" { - for _, t := range matchTags { - if t == tagAtom { - return i - } - } - switch s { - case defaultScope: - // No-op. - case listItemScope: - if tagAtom == a.Ol || tagAtom == a.Ul { - return -1 - } - case buttonScope: - if tagAtom == a.Button { - return -1 - } - case tableScope: - if tagAtom == a.Html || tagAtom == a.Table || tagAtom == a.Template { - return -1 - } - case selectScope: - if tagAtom != a.Optgroup && tagAtom != a.Option { - return -1 - } - default: - panic("unreachable") - } - } - switch s { - case defaultScope, listItemScope, buttonScope: - for _, t := range defaultScopeStopTags[p.oe[i].Namespace] { - if t == tagAtom { - return -1 - } - } - } - } - return -1 -} - -// elementInScope is like popUntil, except that it doesn't modify the stack of -// open elements. -func (p *parser) elementInScope(s scope, matchTags ...a.Atom) bool { - return p.indexOfElementInScope(s, matchTags...) != -1 -} - -// clearStackToContext pops elements off the stack of open elements until a -// scope-defined element is found. -func (p *parser) clearStackToContext(s scope) { - for i := len(p.oe) - 1; i >= 0; i-- { - tagAtom := p.oe[i].DataAtom - switch s { - case tableScope: - if tagAtom == a.Html || tagAtom == a.Table || tagAtom == a.Template { - p.oe = p.oe[:i+1] - return - } - case tableRowScope: - if tagAtom == a.Html || tagAtom == a.Tr || tagAtom == a.Template { - p.oe = p.oe[:i+1] - return - } - case tableBodyScope: - if tagAtom == a.Html || tagAtom == a.Tbody || tagAtom == a.Tfoot || tagAtom == a.Thead || tagAtom == a.Template { - p.oe = p.oe[:i+1] - return - } - default: - panic("unreachable") - } - } -} - -// parseGenericRawTextElement implements the generic raw text element parsing -// algorithm defined in 12.2.6.2. -// https://html.spec.whatwg.org/multipage/parsing.html#parsing-elements-that-contain-only-text -// TODO: Since both RAWTEXT and RCDATA states are treated as tokenizer's part -// officially, need to make tokenizer consider both states. -func (p *parser) parseGenericRawTextElement() { - p.addElement() - p.originalIM = p.im - p.im = textIM -} - -// generateImpliedEndTags pops nodes off the stack of open elements as long as -// the top node has a tag name of dd, dt, li, optgroup, option, p, rb, rp, rt or rtc. -// If exceptions are specified, nodes with that name will not be popped off. -func (p *parser) generateImpliedEndTags(exceptions ...string) { - var i int -loop: - for i = len(p.oe) - 1; i >= 0; i-- { - n := p.oe[i] - if n.Type != ElementNode { - break - } - switch n.DataAtom { - case a.Dd, a.Dt, a.Li, a.Optgroup, a.Option, a.P, a.Rb, a.Rp, a.Rt, a.Rtc: - for _, except := range exceptions { - if n.Data == except { - break loop - } - } - continue - } - break - } - - p.oe = p.oe[:i+1] -} - -// addChild adds a child node n to the top element, and pushes n onto the stack -// of open elements if it is an element node. -func (p *parser) addChild(n *Node) { - if p.shouldFosterParent() { - p.fosterParent(n) - } else { - p.top().AppendChild(n) - } - - if n.Type == ElementNode { - p.oe = append(p.oe, n) - } -} - -// shouldFosterParent returns whether the next node to be added should be -// foster parented. -func (p *parser) shouldFosterParent() bool { - if p.fosterParenting { - switch p.top().DataAtom { - case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr: - return true - } - } - return false -} - -// fosterParent adds a child node according to the foster parenting rules. -// Section 12.2.6.1, "foster parenting". -func (p *parser) fosterParent(n *Node) { - var table, parent, prev, template *Node - var i int - for i = len(p.oe) - 1; i >= 0; i-- { - if p.oe[i].DataAtom == a.Table { - table = p.oe[i] - break - } - } - - var j int - for j = len(p.oe) - 1; j >= 0; j-- { - if p.oe[j].DataAtom == a.Template { - template = p.oe[j] - break - } - } - - if template != nil && (table == nil || j > i) { - template.AppendChild(n) - return - } - - if table == nil { - // The foster parent is the html element. - parent = p.oe[0] - } else { - parent = table.Parent - } - if parent == nil { - parent = p.oe[i-1] - } - - if table != nil { - prev = table.PrevSibling - } else { - prev = parent.LastChild - } - if prev != nil && prev.Type == TextNode && n.Type == TextNode { - prev.Data += n.Data - return - } - - parent.InsertBefore(n, table) -} - -// addText adds text to the preceding node if it is a text node, or else it -// calls addChild with a new text node. -func (p *parser) addText(text string) { - if text == "" { - return - } - - if p.shouldFosterParent() { - p.fosterParent(&Node{ - Type: TextNode, - Data: text, - }) - return - } - - t := p.top() - if n := t.LastChild; n != nil && n.Type == TextNode { - n.Data += text - return - } - p.addChild(&Node{ - Type: TextNode, - Data: text, - }) -} - -// addElement adds a child element based on the current token. -func (p *parser) addElement() { - p.addChild(&Node{ - Type: ElementNode, - DataAtom: p.tok.DataAtom, - Data: p.tok.Data, - Attr: p.tok.Attr, - }) -} - -// Section 12.2.4.3. -func (p *parser) addFormattingElement() { - tagAtom, attr := p.tok.DataAtom, p.tok.Attr - p.addElement() - - // Implement the Noah's Ark clause, but with three per family instead of two. - identicalElements := 0 -findIdenticalElements: - for i := len(p.afe) - 1; i >= 0; i-- { - n := p.afe[i] - if n.Type == scopeMarkerNode { - break - } - if n.Type != ElementNode { - continue - } - if n.Namespace != "" { - continue - } - if n.DataAtom != tagAtom { - continue - } - if len(n.Attr) != len(attr) { - continue - } - compareAttributes: - for _, t0 := range n.Attr { - for _, t1 := range attr { - if t0.Key == t1.Key && t0.Namespace == t1.Namespace && t0.Val == t1.Val { - // Found a match for this attribute, continue with the next attribute. - continue compareAttributes - } - } - // If we get here, there is no attribute that matches a. - // Therefore the element is not identical to the new one. - continue findIdenticalElements - } - - identicalElements++ - if identicalElements >= 3 { - p.afe.remove(n) - } - } - - p.afe = append(p.afe, p.top()) -} - -// Section 12.2.4.3. -func (p *parser) clearActiveFormattingElements() { - for { - if n := p.afe.pop(); len(p.afe) == 0 || n.Type == scopeMarkerNode { - return - } - } -} - -// Section 12.2.4.3. -func (p *parser) reconstructActiveFormattingElements() { - n := p.afe.top() - if n == nil { - return - } - if n.Type == scopeMarkerNode || p.oe.index(n) != -1 { - return - } - i := len(p.afe) - 1 - for n.Type != scopeMarkerNode && p.oe.index(n) == -1 { - if i == 0 { - i = -1 - break - } - i-- - n = p.afe[i] - } - for { - i++ - clone := p.afe[i].clone() - p.addChild(clone) - p.afe[i] = clone - if i == len(p.afe)-1 { - break - } - } -} - -// Section 12.2.5. -func (p *parser) acknowledgeSelfClosingTag() { - p.hasSelfClosingToken = false -} - -// An insertion mode (section 12.2.4.1) is the state transition function from -// a particular state in the HTML5 parser's state machine. It updates the -// parser's fields depending on parser.tok (where ErrorToken means EOF). -// It returns whether the token was consumed. -type insertionMode func(*parser) bool - -// setOriginalIM sets the insertion mode to return to after completing a text or -// inTableText insertion mode. -// Section 12.2.4.1, "using the rules for". -func (p *parser) setOriginalIM() { - if p.originalIM != nil { - panic("html: bad parser state: originalIM was set twice") - } - p.originalIM = p.im -} - -// Section 12.2.4.1, "reset the insertion mode". -func (p *parser) resetInsertionMode() { - for i := len(p.oe) - 1; i >= 0; i-- { - n := p.oe[i] - last := i == 0 - if last && p.context != nil { - n = p.context - } - - switch n.DataAtom { - case a.Select: - if !last { - for ancestor, first := n, p.oe[0]; ancestor != first; { - ancestor = p.oe[p.oe.index(ancestor)-1] - switch ancestor.DataAtom { - case a.Template: - p.im = inSelectIM - return - case a.Table: - p.im = inSelectInTableIM - return - } - } - } - p.im = inSelectIM - case a.Td, a.Th: - // TODO: remove this divergence from the HTML5 spec. - // - // See https://bugs.chromium.org/p/chromium/issues/detail?id=829668 - p.im = inCellIM - case a.Tr: - p.im = inRowIM - case a.Tbody, a.Thead, a.Tfoot: - p.im = inTableBodyIM - case a.Caption: - p.im = inCaptionIM - case a.Colgroup: - p.im = inColumnGroupIM - case a.Table: - p.im = inTableIM - case a.Template: - // TODO: remove this divergence from the HTML5 spec. - if n.Namespace != "" { - continue - } - p.im = p.templateStack.top() - case a.Head: - // TODO: remove this divergence from the HTML5 spec. - // - // See https://bugs.chromium.org/p/chromium/issues/detail?id=829668 - p.im = inHeadIM - case a.Body: - p.im = inBodyIM - case a.Frameset: - p.im = inFramesetIM - case a.Html: - if p.head == nil { - p.im = beforeHeadIM - } else { - p.im = afterHeadIM - } - default: - if last { - p.im = inBodyIM - return - } - continue - } - return - } -} - -const whitespace = " \t\r\n\f" - -// Section 12.2.6.4.1. -func initialIM(p *parser) bool { - switch p.tok.Type { - case TextToken: - p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace) - if len(p.tok.Data) == 0 { - // It was all whitespace, so ignore it. - return true - } - case CommentToken: - p.doc.AppendChild(&Node{ - Type: CommentNode, - Data: p.tok.Data, - }) - return true - case DoctypeToken: - n, quirks := parseDoctype(p.tok.Data) - p.doc.AppendChild(n) - p.quirks = quirks - p.im = beforeHTMLIM - return true - } - p.quirks = true - p.im = beforeHTMLIM - return false -} - -// Section 12.2.6.4.2. -func beforeHTMLIM(p *parser) bool { - switch p.tok.Type { - case DoctypeToken: - // Ignore the token. - return true - case TextToken: - p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace) - if len(p.tok.Data) == 0 { - // It was all whitespace, so ignore it. - return true - } - case StartTagToken: - if p.tok.DataAtom == a.Html { - p.addElement() - p.im = beforeHeadIM - return true - } - case EndTagToken: - switch p.tok.DataAtom { - case a.Head, a.Body, a.Html, a.Br: - p.parseImpliedToken(StartTagToken, a.Html, a.Html.String()) - return false - default: - // Ignore the token. - return true - } - case CommentToken: - p.doc.AppendChild(&Node{ - Type: CommentNode, - Data: p.tok.Data, - }) - return true - } - p.parseImpliedToken(StartTagToken, a.Html, a.Html.String()) - return false -} - -// Section 12.2.6.4.3. -func beforeHeadIM(p *parser) bool { - switch p.tok.Type { - case TextToken: - p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace) - if len(p.tok.Data) == 0 { - // It was all whitespace, so ignore it. - return true - } - case StartTagToken: - switch p.tok.DataAtom { - case a.Head: - p.addElement() - p.head = p.top() - p.im = inHeadIM - return true - case a.Html: - return inBodyIM(p) - } - case EndTagToken: - switch p.tok.DataAtom { - case a.Head, a.Body, a.Html, a.Br: - p.parseImpliedToken(StartTagToken, a.Head, a.Head.String()) - return false - default: - // Ignore the token. - return true - } - case CommentToken: - p.addChild(&Node{ - Type: CommentNode, - Data: p.tok.Data, - }) - return true - case DoctypeToken: - // Ignore the token. - return true - } - - p.parseImpliedToken(StartTagToken, a.Head, a.Head.String()) - return false -} - -// Section 12.2.6.4.4. -func inHeadIM(p *parser) bool { - switch p.tok.Type { - case TextToken: - s := strings.TrimLeft(p.tok.Data, whitespace) - if len(s) < len(p.tok.Data) { - // Add the initial whitespace to the current node. - p.addText(p.tok.Data[:len(p.tok.Data)-len(s)]) - if s == "" { - return true - } - p.tok.Data = s - } - case StartTagToken: - switch p.tok.DataAtom { - case a.Html: - return inBodyIM(p) - case a.Base, a.Basefont, a.Bgsound, a.Link, a.Meta: - p.addElement() - p.oe.pop() - p.acknowledgeSelfClosingTag() - return true - case a.Noscript: - if p.scripting { - p.parseGenericRawTextElement() - return true - } - p.addElement() - p.im = inHeadNoscriptIM - // Don't let the tokenizer go into raw text mode when scripting is disabled. - p.tokenizer.NextIsNotRawText() - return true - case a.Script, a.Title: - p.addElement() - p.setOriginalIM() - p.im = textIM - return true - case a.Noframes, a.Style: - p.parseGenericRawTextElement() - return true - case a.Head: - // Ignore the token. - return true - case a.Template: - // TODO: remove this divergence from the HTML5 spec. - // - // We don't handle all of the corner cases when mixing foreign - // content (i.e. or ) with tag. - case a.Template: - return inHeadIM(p) - default: - // Ignore the token. - return true - } - case CommentToken: - p.addChild(&Node{ - Type: CommentNode, - Data: p.tok.Data, - }) - return true - case DoctypeToken: - // Ignore the token. - return true - } - - p.parseImpliedToken(StartTagToken, a.Body, a.Body.String()) - p.framesetOK = true - return false -} - -// copyAttributes copies attributes of src not found on dst to dst. -func copyAttributes(dst *Node, src Token) { - if len(src.Attr) == 0 { - return - } - attr := map[string]string{} - for _, t := range dst.Attr { - attr[t.Key] = t.Val - } - for _, t := range src.Attr { - if _, ok := attr[t.Key]; !ok { - dst.Attr = append(dst.Attr, t) - attr[t.Key] = t.Val - } - } -} - -// Section 12.2.6.4.7. -func inBodyIM(p *parser) bool { - switch p.tok.Type { - case TextToken: - d := p.tok.Data - switch n := p.oe.top(); n.DataAtom { - case a.Pre, a.Listing: - if n.FirstChild == nil { - // Ignore a newline at the start of a
 block.
-				if d != "" && d[0] == '\r' {
-					d = d[1:]
-				}
-				if d != "" && d[0] == '\n' {
-					d = d[1:]
-				}
-			}
-		}
-		d = strings.Replace(d, "\x00", "", -1)
-		if d == "" {
-			return true
-		}
-		p.reconstructActiveFormattingElements()
-		p.addText(d)
-		if p.framesetOK && strings.TrimLeft(d, whitespace) != "" {
-			// There were non-whitespace characters inserted.
-			p.framesetOK = false
-		}
-	case StartTagToken:
-		switch p.tok.DataAtom {
-		case a.Html:
-			if p.oe.contains(a.Template) {
-				return true
-			}
-			copyAttributes(p.oe[0], p.tok)
-		case a.Base, a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Script, a.Style, a.Template, a.Title:
-			return inHeadIM(p)
-		case a.Body:
-			if p.oe.contains(a.Template) {
-				return true
-			}
-			if len(p.oe) >= 2 {
-				body := p.oe[1]
-				if body.Type == ElementNode && body.DataAtom == a.Body {
-					p.framesetOK = false
-					copyAttributes(body, p.tok)
-				}
-			}
-		case a.Frameset:
-			if !p.framesetOK || len(p.oe) < 2 || p.oe[1].DataAtom != a.Body {
-				// Ignore the token.
-				return true
-			}
-			body := p.oe[1]
-			if body.Parent != nil {
-				body.Parent.RemoveChild(body)
-			}
-			p.oe = p.oe[:1]
-			p.addElement()
-			p.im = inFramesetIM
-			return true
-		case a.Address, a.Article, a.Aside, a.Blockquote, a.Center, a.Details, a.Dialog, a.Dir, a.Div, a.Dl, a.Fieldset, a.Figcaption, a.Figure, a.Footer, a.Header, a.Hgroup, a.Main, a.Menu, a.Nav, a.Ol, a.P, a.Section, a.Summary, a.Ul:
-			p.popUntil(buttonScope, a.P)
-			p.addElement()
-		case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6:
-			p.popUntil(buttonScope, a.P)
-			switch n := p.top(); n.DataAtom {
-			case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6:
-				p.oe.pop()
-			}
-			p.addElement()
-		case a.Pre, a.Listing:
-			p.popUntil(buttonScope, a.P)
-			p.addElement()
-			// The newline, if any, will be dealt with by the TextToken case.
-			p.framesetOK = false
-		case a.Form:
-			if p.form != nil && !p.oe.contains(a.Template) {
-				// Ignore the token
-				return true
-			}
-			p.popUntil(buttonScope, a.P)
-			p.addElement()
-			if !p.oe.contains(a.Template) {
-				p.form = p.top()
-			}
-		case a.Li:
-			p.framesetOK = false
-			for i := len(p.oe) - 1; i >= 0; i-- {
-				node := p.oe[i]
-				switch node.DataAtom {
-				case a.Li:
-					p.oe = p.oe[:i]
-				case a.Address, a.Div, a.P:
-					continue
-				default:
-					if !isSpecialElement(node) {
-						continue
-					}
-				}
-				break
-			}
-			p.popUntil(buttonScope, a.P)
-			p.addElement()
-		case a.Dd, a.Dt:
-			p.framesetOK = false
-			for i := len(p.oe) - 1; i >= 0; i-- {
-				node := p.oe[i]
-				switch node.DataAtom {
-				case a.Dd, a.Dt:
-					p.oe = p.oe[:i]
-				case a.Address, a.Div, a.P:
-					continue
-				default:
-					if !isSpecialElement(node) {
-						continue
-					}
-				}
-				break
-			}
-			p.popUntil(buttonScope, a.P)
-			p.addElement()
-		case a.Plaintext:
-			p.popUntil(buttonScope, a.P)
-			p.addElement()
-		case a.Button:
-			p.popUntil(defaultScope, a.Button)
-			p.reconstructActiveFormattingElements()
-			p.addElement()
-			p.framesetOK = false
-		case a.A:
-			for i := len(p.afe) - 1; i >= 0 && p.afe[i].Type != scopeMarkerNode; i-- {
-				if n := p.afe[i]; n.Type == ElementNode && n.DataAtom == a.A {
-					p.inBodyEndTagFormatting(a.A, "a")
-					p.oe.remove(n)
-					p.afe.remove(n)
-					break
-				}
-			}
-			p.reconstructActiveFormattingElements()
-			p.addFormattingElement()
-		case a.B, a.Big, a.Code, a.Em, a.Font, a.I, a.S, a.Small, a.Strike, a.Strong, a.Tt, a.U:
-			p.reconstructActiveFormattingElements()
-			p.addFormattingElement()
-		case a.Nobr:
-			p.reconstructActiveFormattingElements()
-			if p.elementInScope(defaultScope, a.Nobr) {
-				p.inBodyEndTagFormatting(a.Nobr, "nobr")
-				p.reconstructActiveFormattingElements()
-			}
-			p.addFormattingElement()
-		case a.Applet, a.Marquee, a.Object:
-			p.reconstructActiveFormattingElements()
-			p.addElement()
-			p.afe = append(p.afe, &scopeMarker)
-			p.framesetOK = false
-		case a.Table:
-			if !p.quirks {
-				p.popUntil(buttonScope, a.P)
-			}
-			p.addElement()
-			p.framesetOK = false
-			p.im = inTableIM
-			return true
-		case a.Area, a.Br, a.Embed, a.Img, a.Input, a.Keygen, a.Wbr:
-			p.reconstructActiveFormattingElements()
-			p.addElement()
-			p.oe.pop()
-			p.acknowledgeSelfClosingTag()
-			if p.tok.DataAtom == a.Input {
-				for _, t := range p.tok.Attr {
-					if t.Key == "type" {
-						if strings.ToLower(t.Val) == "hidden" {
-							// Skip setting framesetOK = false
-							return true
-						}
-					}
-				}
-			}
-			p.framesetOK = false
-		case a.Param, a.Source, a.Track:
-			p.addElement()
-			p.oe.pop()
-			p.acknowledgeSelfClosingTag()
-		case a.Hr:
-			p.popUntil(buttonScope, a.P)
-			p.addElement()
-			p.oe.pop()
-			p.acknowledgeSelfClosingTag()
-			p.framesetOK = false
-		case a.Image:
-			p.tok.DataAtom = a.Img
-			p.tok.Data = a.Img.String()
-			return false
-		case a.Textarea:
-			p.addElement()
-			p.setOriginalIM()
-			p.framesetOK = false
-			p.im = textIM
-		case a.Xmp:
-			p.popUntil(buttonScope, a.P)
-			p.reconstructActiveFormattingElements()
-			p.framesetOK = false
-			p.parseGenericRawTextElement()
-		case a.Iframe:
-			p.framesetOK = false
-			p.parseGenericRawTextElement()
-		case a.Noembed:
-			p.parseGenericRawTextElement()
-		case a.Noscript:
-			if p.scripting {
-				p.parseGenericRawTextElement()
-				return true
-			}
-			p.reconstructActiveFormattingElements()
-			p.addElement()
-			// Don't let the tokenizer go into raw text mode when scripting is disabled.
-			p.tokenizer.NextIsNotRawText()
-		case a.Select:
-			p.reconstructActiveFormattingElements()
-			p.addElement()
-			p.framesetOK = false
-			p.im = inSelectIM
-			return true
-		case a.Optgroup, a.Option:
-			if p.top().DataAtom == a.Option {
-				p.oe.pop()
-			}
-			p.reconstructActiveFormattingElements()
-			p.addElement()
-		case a.Rb, a.Rtc:
-			if p.elementInScope(defaultScope, a.Ruby) {
-				p.generateImpliedEndTags()
-			}
-			p.addElement()
-		case a.Rp, a.Rt:
-			if p.elementInScope(defaultScope, a.Ruby) {
-				p.generateImpliedEndTags("rtc")
-			}
-			p.addElement()
-		case a.Math, a.Svg:
-			p.reconstructActiveFormattingElements()
-			if p.tok.DataAtom == a.Math {
-				adjustAttributeNames(p.tok.Attr, mathMLAttributeAdjustments)
-			} else {
-				adjustAttributeNames(p.tok.Attr, svgAttributeAdjustments)
-			}
-			adjustForeignAttributes(p.tok.Attr)
-			p.addElement()
-			p.top().Namespace = p.tok.Data
-			if p.hasSelfClosingToken {
-				p.oe.pop()
-				p.acknowledgeSelfClosingTag()
-			}
-			return true
-		case a.Caption, a.Col, a.Colgroup, a.Frame, a.Head, a.Tbody, a.Td, a.Tfoot, a.Th, a.Thead, a.Tr:
-			// Ignore the token.
-		default:
-			p.reconstructActiveFormattingElements()
-			p.addElement()
-		}
-	case EndTagToken:
-		switch p.tok.DataAtom {
-		case a.Body:
-			if p.elementInScope(defaultScope, a.Body) {
-				p.im = afterBodyIM
-			}
-		case a.Html:
-			if p.elementInScope(defaultScope, a.Body) {
-				p.parseImpliedToken(EndTagToken, a.Body, a.Body.String())
-				return false
-			}
-			return true
-		case a.Address, a.Article, a.Aside, a.Blockquote, a.Button, a.Center, a.Details, a.Dialog, a.Dir, a.Div, a.Dl, a.Fieldset, a.Figcaption, a.Figure, a.Footer, a.Header, a.Hgroup, a.Listing, a.Main, a.Menu, a.Nav, a.Ol, a.Pre, a.Section, a.Summary, a.Ul:
-			p.popUntil(defaultScope, p.tok.DataAtom)
-		case a.Form:
-			if p.oe.contains(a.Template) {
-				i := p.indexOfElementInScope(defaultScope, a.Form)
-				if i == -1 {
-					// Ignore the token.
-					return true
-				}
-				p.generateImpliedEndTags()
-				if p.oe[i].DataAtom != a.Form {
-					// Ignore the token.
-					return true
-				}
-				p.popUntil(defaultScope, a.Form)
-			} else {
-				node := p.form
-				p.form = nil
-				i := p.indexOfElementInScope(defaultScope, a.Form)
-				if node == nil || i == -1 || p.oe[i] != node {
-					// Ignore the token.
-					return true
-				}
-				p.generateImpliedEndTags()
-				p.oe.remove(node)
-			}
-		case a.P:
-			if !p.elementInScope(buttonScope, a.P) {
-				p.parseImpliedToken(StartTagToken, a.P, a.P.String())
-			}
-			p.popUntil(buttonScope, a.P)
-		case a.Li:
-			p.popUntil(listItemScope, a.Li)
-		case a.Dd, a.Dt:
-			p.popUntil(defaultScope, p.tok.DataAtom)
-		case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6:
-			p.popUntil(defaultScope, a.H1, a.H2, a.H3, a.H4, a.H5, a.H6)
-		case a.A, a.B, a.Big, a.Code, a.Em, a.Font, a.I, a.Nobr, a.S, a.Small, a.Strike, a.Strong, a.Tt, a.U:
-			p.inBodyEndTagFormatting(p.tok.DataAtom, p.tok.Data)
-		case a.Applet, a.Marquee, a.Object:
-			if p.popUntil(defaultScope, p.tok.DataAtom) {
-				p.clearActiveFormattingElements()
-			}
-		case a.Br:
-			p.tok.Type = StartTagToken
-			return false
-		case a.Template:
-			return inHeadIM(p)
-		default:
-			p.inBodyEndTagOther(p.tok.DataAtom, p.tok.Data)
-		}
-	case CommentToken:
-		p.addChild(&Node{
-			Type: CommentNode,
-			Data: p.tok.Data,
-		})
-	case ErrorToken:
-		// TODO: remove this divergence from the HTML5 spec.
-		if len(p.templateStack) > 0 {
-			p.im = inTemplateIM
-			return false
-		}
-		for _, e := range p.oe {
-			switch e.DataAtom {
-			case a.Dd, a.Dt, a.Li, a.Optgroup, a.Option, a.P, a.Rb, a.Rp, a.Rt, a.Rtc, a.Tbody, a.Td, a.Tfoot, a.Th,
-				a.Thead, a.Tr, a.Body, a.Html:
-			default:
-				return true
-			}
-		}
-	}
-
-	return true
-}
-
-func (p *parser) inBodyEndTagFormatting(tagAtom a.Atom, tagName string) {
-	// This is the "adoption agency" algorithm, described at
-	// https://html.spec.whatwg.org/multipage/syntax.html#adoptionAgency
-
-	// TODO: this is a fairly literal line-by-line translation of that algorithm.
-	// Once the code successfully parses the comprehensive test suite, we should
-	// refactor this code to be more idiomatic.
-
-	// Steps 1-2
-	if current := p.oe.top(); current.Data == tagName && p.afe.index(current) == -1 {
-		p.oe.pop()
-		return
-	}
-
-	// Steps 3-5. The outer loop.
-	for i := 0; i < 8; i++ {
-		// Step 6. Find the formatting element.
-		var formattingElement *Node
-		for j := len(p.afe) - 1; j >= 0; j-- {
-			if p.afe[j].Type == scopeMarkerNode {
-				break
-			}
-			if p.afe[j].DataAtom == tagAtom {
-				formattingElement = p.afe[j]
-				break
-			}
-		}
-		if formattingElement == nil {
-			p.inBodyEndTagOther(tagAtom, tagName)
-			return
-		}
-
-		// Step 7. Ignore the tag if formatting element is not in the stack of open elements.
-		feIndex := p.oe.index(formattingElement)
-		if feIndex == -1 {
-			p.afe.remove(formattingElement)
-			return
-		}
-		// Step 8. Ignore the tag if formatting element is not in the scope.
-		if !p.elementInScope(defaultScope, tagAtom) {
-			// Ignore the tag.
-			return
-		}
-
-		// Step 9. This step is omitted because it's just a parse error but no need to return.
-
-		// Steps 10-11. Find the furthest block.
-		var furthestBlock *Node
-		for _, e := range p.oe[feIndex:] {
-			if isSpecialElement(e) {
-				furthestBlock = e
-				break
-			}
-		}
-		if furthestBlock == nil {
-			e := p.oe.pop()
-			for e != formattingElement {
-				e = p.oe.pop()
-			}
-			p.afe.remove(e)
-			return
-		}
-
-		// Steps 12-13. Find the common ancestor and bookmark node.
-		commonAncestor := p.oe[feIndex-1]
-		bookmark := p.afe.index(formattingElement)
-
-		// Step 14. The inner loop. Find the lastNode to reparent.
-		lastNode := furthestBlock
-		node := furthestBlock
-		x := p.oe.index(node)
-		// Step 14.1.
-		j := 0
-		for {
-			// Step 14.2.
-			j++
-			// Step. 14.3.
-			x--
-			node = p.oe[x]
-			// Step 14.4. Go to the next step if node is formatting element.
-			if node == formattingElement {
-				break
-			}
-			// Step 14.5. Remove node from the list of active formatting elements if
-			// inner loop counter is greater than three and node is in the list of
-			// active formatting elements.
-			if ni := p.afe.index(node); j > 3 && ni > -1 {
-				p.afe.remove(node)
-				// If any element of the list of active formatting elements is removed,
-				// we need to take care whether bookmark should be decremented or not.
-				// This is because the value of bookmark may exceed the size of the
-				// list by removing elements from the list.
-				if ni <= bookmark {
-					bookmark--
-				}
-				continue
-			}
-			// Step 14.6. Continue the next inner loop if node is not in the list of
-			// active formatting elements.
-			if p.afe.index(node) == -1 {
-				p.oe.remove(node)
-				continue
-			}
-			// Step 14.7.
-			clone := node.clone()
-			p.afe[p.afe.index(node)] = clone
-			p.oe[p.oe.index(node)] = clone
-			node = clone
-			// Step 14.8.
-			if lastNode == furthestBlock {
-				bookmark = p.afe.index(node) + 1
-			}
-			// Step 14.9.
-			if lastNode.Parent != nil {
-				lastNode.Parent.RemoveChild(lastNode)
-			}
-			node.AppendChild(lastNode)
-			// Step 14.10.
-			lastNode = node
-		}
-
-		// Step 15. Reparent lastNode to the common ancestor,
-		// or for misnested table nodes, to the foster parent.
-		if lastNode.Parent != nil {
-			lastNode.Parent.RemoveChild(lastNode)
-		}
-		switch commonAncestor.DataAtom {
-		case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr:
-			p.fosterParent(lastNode)
-		default:
-			commonAncestor.AppendChild(lastNode)
-		}
-
-		// Steps 16-18. Reparent nodes from the furthest block's children
-		// to a clone of the formatting element.
-		clone := formattingElement.clone()
-		reparentChildren(clone, furthestBlock)
-		furthestBlock.AppendChild(clone)
-
-		// Step 19. Fix up the list of active formatting elements.
-		if oldLoc := p.afe.index(formattingElement); oldLoc != -1 && oldLoc < bookmark {
-			// Move the bookmark with the rest of the list.
-			bookmark--
-		}
-		p.afe.remove(formattingElement)
-		p.afe.insert(bookmark, clone)
-
-		// Step 20. Fix up the stack of open elements.
-		p.oe.remove(formattingElement)
-		p.oe.insert(p.oe.index(furthestBlock)+1, clone)
-	}
-}
-
-// inBodyEndTagOther performs the "any other end tag" algorithm for inBodyIM.
-// "Any other end tag" handling from 12.2.6.5 The rules for parsing tokens in foreign content
-// https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inforeign
-func (p *parser) inBodyEndTagOther(tagAtom a.Atom, tagName string) {
-	for i := len(p.oe) - 1; i >= 0; i-- {
-		// Two element nodes have the same tag if they have the same Data (a
-		// string-typed field). As an optimization, for common HTML tags, each
-		// Data string is assigned a unique, non-zero DataAtom (a uint32-typed
-		// field), since integer comparison is faster than string comparison.
-		// Uncommon (custom) tags get a zero DataAtom.
-		//
-		// The if condition here is equivalent to (p.oe[i].Data == tagName).
-		if (p.oe[i].DataAtom == tagAtom) &&
-			((tagAtom != 0) || (p.oe[i].Data == tagName)) {
-			p.oe = p.oe[:i]
-			break
-		}
-		if isSpecialElement(p.oe[i]) {
-			break
-		}
-	}
-}
-
-// Section 12.2.6.4.8.
-func textIM(p *parser) bool {
-	switch p.tok.Type {
-	case ErrorToken:
-		p.oe.pop()
-	case TextToken:
-		d := p.tok.Data
-		if n := p.oe.top(); n.DataAtom == a.Textarea && n.FirstChild == nil {
-			// Ignore a newline at the start of a