planetscale 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +24 -0
- data/.github/workflows/gem-push.yml +38 -0
- data/.github/workflows/licensed.yml +43 -0
- data/.gitignore +10 -0
- data/.licensed.yml +9 -0
- data/.licenses/go/github.com/armon/circbuf.dep.yml +31 -0
- data/.licenses/go/github.com/gorilla/mux.dep.yml +41 -0
- data/.licenses/go/github.com/hashicorp/go-cleanhttp.dep.yml +375 -0
- data/.licenses/go/github.com/mitchellh/go-homedir.dep.yml +32 -0
- data/.licenses/go/github.com/pkg/errors.dep.yml +36 -0
- data/.licenses/go/github.com/planetscale/planetscale-go/planetscale.dep.yml +160 -0
- data/.licenses/go/github.com/planetscale/sql-proxy/proxy.dep.yml +180 -0
- data/.licenses/go/go.uber.org/atomic.dep.yml +31 -0
- data/.licenses/go/go.uber.org/multierr.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/buffer.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/internal/bufferpool.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/internal/color.dep.yml +30 -0
- data/.licenses/go/go.uber.org/zap/internal/exit.dep.yml +31 -0
- data/.licenses/go/go.uber.org/zap/zapcore.dep.yml +31 -0
- data/.licenses/go/golang.org/x/net/context/ctxhttp.dep.yml +63 -0
- data/.licenses/go/golang.org/x/oauth2.dep.yml +44 -0
- data/.licenses/go/golang.org/x/oauth2/internal.dep.yml +38 -0
- data/.ruby_version +1 -0
- data/Gemfile +8 -0
- data/LICENSE +201 -0
- data/README.md +88 -0
- data/Rakefile +10 -0
- data/bin/console +15 -0
- data/bin/setup +17 -0
- data/controller.go +255 -0
- data/go.mod +16 -0
- data/go.sum +428 -0
- data/lib/generators/planetscale/install_generator.rb +58 -0
- data/lib/planetscale.rb +137 -0
- data/lib/planetscale/version.rb +5 -0
- data/planetscale.gemspec +44 -0
- data/proxy.go +128 -0
- data/vendor/github.com/armon/circbuf/.gitignore +22 -0
- data/vendor/github.com/armon/circbuf/LICENSE +20 -0
- data/vendor/github.com/armon/circbuf/README.md +28 -0
- data/vendor/github.com/armon/circbuf/circbuf.go +92 -0
- data/vendor/github.com/armon/circbuf/go.mod +1 -0
- data/vendor/github.com/golang/protobuf/AUTHORS +3 -0
- data/vendor/github.com/golang/protobuf/CONTRIBUTORS +3 -0
- data/vendor/github.com/golang/protobuf/LICENSE +28 -0
- data/vendor/github.com/golang/protobuf/proto/buffer.go +324 -0
- data/vendor/github.com/golang/protobuf/proto/defaults.go +63 -0
- data/vendor/github.com/golang/protobuf/proto/deprecated.go +113 -0
- data/vendor/github.com/golang/protobuf/proto/discard.go +58 -0
- data/vendor/github.com/golang/protobuf/proto/extensions.go +356 -0
- data/vendor/github.com/golang/protobuf/proto/properties.go +306 -0
- data/vendor/github.com/golang/protobuf/proto/proto.go +167 -0
- data/vendor/github.com/golang/protobuf/proto/registry.go +317 -0
- data/vendor/github.com/golang/protobuf/proto/text_decode.go +801 -0
- data/vendor/github.com/golang/protobuf/proto/text_encode.go +560 -0
- data/vendor/github.com/golang/protobuf/proto/wire.go +78 -0
- data/vendor/github.com/golang/protobuf/proto/wrappers.go +34 -0
- data/vendor/github.com/gorilla/mux/AUTHORS +8 -0
- data/vendor/github.com/gorilla/mux/LICENSE +27 -0
- data/vendor/github.com/gorilla/mux/README.md +805 -0
- data/vendor/github.com/gorilla/mux/doc.go +306 -0
- data/vendor/github.com/gorilla/mux/go.mod +3 -0
- data/vendor/github.com/gorilla/mux/middleware.go +74 -0
- data/vendor/github.com/gorilla/mux/mux.go +606 -0
- data/vendor/github.com/gorilla/mux/regexp.go +388 -0
- data/vendor/github.com/gorilla/mux/route.go +736 -0
- data/vendor/github.com/gorilla/mux/test_helpers.go +19 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/LICENSE +363 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/README.md +30 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go +58 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/doc.go +20 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/go.mod +3 -0
- data/vendor/github.com/hashicorp/go-cleanhttp/handlers.go +48 -0
- data/vendor/github.com/mitchellh/go-homedir/LICENSE +21 -0
- data/vendor/github.com/mitchellh/go-homedir/README.md +14 -0
- data/vendor/github.com/mitchellh/go-homedir/go.mod +1 -0
- data/vendor/github.com/mitchellh/go-homedir/homedir.go +167 -0
- data/vendor/github.com/pkg/errors/.gitignore +24 -0
- data/vendor/github.com/pkg/errors/.travis.yml +10 -0
- data/vendor/github.com/pkg/errors/LICENSE +23 -0
- data/vendor/github.com/pkg/errors/Makefile +44 -0
- data/vendor/github.com/pkg/errors/README.md +59 -0
- data/vendor/github.com/pkg/errors/appveyor.yml +32 -0
- data/vendor/github.com/pkg/errors/errors.go +288 -0
- data/vendor/github.com/pkg/errors/go113.go +38 -0
- data/vendor/github.com/pkg/errors/stack.go +177 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/backups.go +139 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/branches.go +258 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/certs.go +142 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/client.go +305 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/databases.go +131 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/deploy_requests.go +368 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/organizations.go +78 -0
- data/vendor/github.com/planetscale/planetscale-go/planetscale/service_tokens.go +163 -0
- data/vendor/github.com/planetscale/sql-proxy/proxy/client.go +467 -0
- data/vendor/github.com/planetscale/sql-proxy/proxy/tls_cache.go +73 -0
- data/vendor/go.uber.org/atomic/.codecov.yml +19 -0
- data/vendor/go.uber.org/atomic/.gitignore +12 -0
- data/vendor/go.uber.org/atomic/.travis.yml +27 -0
- data/vendor/go.uber.org/atomic/CHANGELOG.md +76 -0
- data/vendor/go.uber.org/atomic/LICENSE.txt +19 -0
- data/vendor/go.uber.org/atomic/Makefile +78 -0
- data/vendor/go.uber.org/atomic/README.md +63 -0
- data/vendor/go.uber.org/atomic/bool.go +81 -0
- data/vendor/go.uber.org/atomic/bool_ext.go +53 -0
- data/vendor/go.uber.org/atomic/doc.go +23 -0
- data/vendor/go.uber.org/atomic/duration.go +82 -0
- data/vendor/go.uber.org/atomic/duration_ext.go +40 -0
- data/vendor/go.uber.org/atomic/error.go +51 -0
- data/vendor/go.uber.org/atomic/error_ext.go +39 -0
- data/vendor/go.uber.org/atomic/float64.go +76 -0
- data/vendor/go.uber.org/atomic/float64_ext.go +47 -0
- data/vendor/go.uber.org/atomic/gen.go +26 -0
- data/vendor/go.uber.org/atomic/go.mod +8 -0
- data/vendor/go.uber.org/atomic/go.sum +9 -0
- data/vendor/go.uber.org/atomic/int32.go +102 -0
- data/vendor/go.uber.org/atomic/int64.go +102 -0
- data/vendor/go.uber.org/atomic/nocmp.go +35 -0
- data/vendor/go.uber.org/atomic/string.go +54 -0
- data/vendor/go.uber.org/atomic/string_ext.go +43 -0
- data/vendor/go.uber.org/atomic/uint32.go +102 -0
- data/vendor/go.uber.org/atomic/uint64.go +102 -0
- data/vendor/go.uber.org/atomic/value.go +31 -0
- data/vendor/go.uber.org/multierr/.codecov.yml +15 -0
- data/vendor/go.uber.org/multierr/.gitignore +4 -0
- data/vendor/go.uber.org/multierr/.travis.yml +23 -0
- data/vendor/go.uber.org/multierr/CHANGELOG.md +60 -0
- data/vendor/go.uber.org/multierr/LICENSE.txt +19 -0
- data/vendor/go.uber.org/multierr/Makefile +42 -0
- data/vendor/go.uber.org/multierr/README.md +23 -0
- data/vendor/go.uber.org/multierr/error.go +449 -0
- data/vendor/go.uber.org/multierr/glide.yaml +8 -0
- data/vendor/go.uber.org/multierr/go.mod +8 -0
- data/vendor/go.uber.org/multierr/go.sum +11 -0
- data/vendor/go.uber.org/multierr/go113.go +52 -0
- data/vendor/go.uber.org/zap/.codecov.yml +17 -0
- data/vendor/go.uber.org/zap/.gitignore +32 -0
- data/vendor/go.uber.org/zap/.readme.tmpl +109 -0
- data/vendor/go.uber.org/zap/.travis.yml +23 -0
- data/vendor/go.uber.org/zap/CHANGELOG.md +432 -0
- data/vendor/go.uber.org/zap/CODE_OF_CONDUCT.md +75 -0
- data/vendor/go.uber.org/zap/CONTRIBUTING.md +81 -0
- data/vendor/go.uber.org/zap/FAQ.md +156 -0
- data/vendor/go.uber.org/zap/LICENSE.txt +19 -0
- data/vendor/go.uber.org/zap/Makefile +63 -0
- data/vendor/go.uber.org/zap/README.md +134 -0
- data/vendor/go.uber.org/zap/array.go +320 -0
- data/vendor/go.uber.org/zap/buffer/buffer.go +123 -0
- data/vendor/go.uber.org/zap/buffer/pool.go +49 -0
- data/vendor/go.uber.org/zap/checklicense.sh +17 -0
- data/vendor/go.uber.org/zap/config.go +264 -0
- data/vendor/go.uber.org/zap/doc.go +113 -0
- data/vendor/go.uber.org/zap/encoder.go +79 -0
- data/vendor/go.uber.org/zap/error.go +80 -0
- data/vendor/go.uber.org/zap/field.go +539 -0
- data/vendor/go.uber.org/zap/flag.go +39 -0
- data/vendor/go.uber.org/zap/glide.yaml +34 -0
- data/vendor/go.uber.org/zap/global.go +168 -0
- data/vendor/go.uber.org/zap/global_go112.go +26 -0
- data/vendor/go.uber.org/zap/global_prego112.go +26 -0
- data/vendor/go.uber.org/zap/go.mod +13 -0
- data/vendor/go.uber.org/zap/go.sum +56 -0
- data/vendor/go.uber.org/zap/http_handler.go +81 -0
- data/vendor/go.uber.org/zap/internal/bufferpool/bufferpool.go +31 -0
- data/vendor/go.uber.org/zap/internal/color/color.go +44 -0
- data/vendor/go.uber.org/zap/internal/exit/exit.go +64 -0
- data/vendor/go.uber.org/zap/level.go +132 -0
- data/vendor/go.uber.org/zap/logger.go +344 -0
- data/vendor/go.uber.org/zap/options.go +140 -0
- data/vendor/go.uber.org/zap/sink.go +161 -0
- data/vendor/go.uber.org/zap/stacktrace.go +85 -0
- data/vendor/go.uber.org/zap/sugar.go +304 -0
- data/vendor/go.uber.org/zap/time.go +27 -0
- data/vendor/go.uber.org/zap/writer.go +99 -0
- data/vendor/go.uber.org/zap/zapcore/console_encoder.go +161 -0
- data/vendor/go.uber.org/zap/zapcore/core.go +113 -0
- data/vendor/go.uber.org/zap/zapcore/doc.go +24 -0
- data/vendor/go.uber.org/zap/zapcore/encoder.go +443 -0
- data/vendor/go.uber.org/zap/zapcore/entry.go +264 -0
- data/vendor/go.uber.org/zap/zapcore/error.go +115 -0
- data/vendor/go.uber.org/zap/zapcore/field.go +227 -0
- data/vendor/go.uber.org/zap/zapcore/hook.go +68 -0
- data/vendor/go.uber.org/zap/zapcore/increase_level.go +66 -0
- data/vendor/go.uber.org/zap/zapcore/json_encoder.go +534 -0
- data/vendor/go.uber.org/zap/zapcore/level.go +175 -0
- data/vendor/go.uber.org/zap/zapcore/level_strings.go +46 -0
- data/vendor/go.uber.org/zap/zapcore/marshaler.go +61 -0
- data/vendor/go.uber.org/zap/zapcore/memory_encoder.go +179 -0
- data/vendor/go.uber.org/zap/zapcore/sampler.go +208 -0
- data/vendor/go.uber.org/zap/zapcore/tee.go +81 -0
- data/vendor/go.uber.org/zap/zapcore/write_syncer.go +123 -0
- data/vendor/golang.org/x/net/AUTHORS +3 -0
- data/vendor/golang.org/x/net/CONTRIBUTORS +3 -0
- data/vendor/golang.org/x/net/LICENSE +27 -0
- data/vendor/golang.org/x/net/PATENTS +22 -0
- data/vendor/golang.org/x/net/context/context.go +56 -0
- data/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go +71 -0
- data/vendor/golang.org/x/net/context/go17.go +73 -0
- data/vendor/golang.org/x/net/context/go19.go +21 -0
- data/vendor/golang.org/x/net/context/pre_go17.go +301 -0
- data/vendor/golang.org/x/net/context/pre_go19.go +110 -0
- data/vendor/golang.org/x/oauth2/.travis.yml +13 -0
- data/vendor/golang.org/x/oauth2/AUTHORS +3 -0
- data/vendor/golang.org/x/oauth2/CONTRIBUTING.md +26 -0
- data/vendor/golang.org/x/oauth2/CONTRIBUTORS +3 -0
- data/vendor/golang.org/x/oauth2/LICENSE +27 -0
- data/vendor/golang.org/x/oauth2/README.md +36 -0
- data/vendor/golang.org/x/oauth2/go.mod +9 -0
- data/vendor/golang.org/x/oauth2/go.sum +361 -0
- data/vendor/golang.org/x/oauth2/internal/client_appengine.go +14 -0
- data/vendor/golang.org/x/oauth2/internal/doc.go +6 -0
- data/vendor/golang.org/x/oauth2/internal/oauth2.go +37 -0
- data/vendor/golang.org/x/oauth2/internal/token.go +294 -0
- data/vendor/golang.org/x/oauth2/internal/transport.go +33 -0
- data/vendor/golang.org/x/oauth2/oauth2.go +381 -0
- data/vendor/golang.org/x/oauth2/token.go +178 -0
- data/vendor/golang.org/x/oauth2/transport.go +89 -0
- data/vendor/google.golang.org/appengine/LICENSE +202 -0
- data/vendor/google.golang.org/appengine/internal/api.go +678 -0
- data/vendor/google.golang.org/appengine/internal/api_classic.go +169 -0
- data/vendor/google.golang.org/appengine/internal/api_common.go +123 -0
- data/vendor/google.golang.org/appengine/internal/app_id.go +28 -0
- data/vendor/google.golang.org/appengine/internal/base/api_base.pb.go +308 -0
- data/vendor/google.golang.org/appengine/internal/base/api_base.proto +33 -0
- data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.pb.go +4367 -0
- data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.proto +551 -0
- data/vendor/google.golang.org/appengine/internal/identity.go +55 -0
- data/vendor/google.golang.org/appengine/internal/identity_classic.go +61 -0
- data/vendor/google.golang.org/appengine/internal/identity_flex.go +11 -0
- data/vendor/google.golang.org/appengine/internal/identity_vm.go +134 -0
- data/vendor/google.golang.org/appengine/internal/internal.go +110 -0
- data/vendor/google.golang.org/appengine/internal/log/log_service.pb.go +1313 -0
- data/vendor/google.golang.org/appengine/internal/log/log_service.proto +150 -0
- data/vendor/google.golang.org/appengine/internal/main.go +16 -0
- data/vendor/google.golang.org/appengine/internal/main_common.go +7 -0
- data/vendor/google.golang.org/appengine/internal/main_vm.go +69 -0
- data/vendor/google.golang.org/appengine/internal/metadata.go +60 -0
- data/vendor/google.golang.org/appengine/internal/net.go +56 -0
- data/vendor/google.golang.org/appengine/internal/regen.sh +40 -0
- data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.pb.go +361 -0
- data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto +44 -0
- data/vendor/google.golang.org/appengine/internal/transaction.go +115 -0
- data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.pb.go +527 -0
- data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.proto +64 -0
- data/vendor/google.golang.org/appengine/urlfetch/urlfetch.go +210 -0
- data/vendor/google.golang.org/protobuf/AUTHORS +3 -0
- data/vendor/google.golang.org/protobuf/CONTRIBUTORS +3 -0
- data/vendor/google.golang.org/protobuf/LICENSE +27 -0
- data/vendor/google.golang.org/protobuf/PATENTS +22 -0
- data/vendor/google.golang.org/protobuf/encoding/prototext/decode.go +773 -0
- data/vendor/google.golang.org/protobuf/encoding/prototext/doc.go +7 -0
- data/vendor/google.golang.org/protobuf/encoding/prototext/encode.go +371 -0
- data/vendor/google.golang.org/protobuf/encoding/protowire/wire.go +538 -0
- data/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go +318 -0
- data/vendor/google.golang.org/protobuf/internal/descopts/options.go +29 -0
- data/vendor/google.golang.org/protobuf/internal/detrand/rand.go +69 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go +213 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/messageset/messageset.go +241 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/tag/tag.go +207 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode.go +665 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_number.go +190 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_string.go +161 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_token.go +373 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/doc.go +29 -0
- data/vendor/google.golang.org/protobuf/internal/encoding/text/encode.go +265 -0
- data/vendor/google.golang.org/protobuf/internal/errors/errors.go +89 -0
- data/vendor/google.golang.org/protobuf/internal/errors/is_go112.go +39 -0
- data/vendor/google.golang.org/protobuf/internal/errors/is_go113.go +12 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/build.go +158 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc.go +631 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_init.go +471 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_lazy.go +704 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list.go +450 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list_gen.go +356 -0
- data/vendor/google.golang.org/protobuf/internal/filedesc/placeholder.go +107 -0
- data/vendor/google.golang.org/protobuf/internal/filetype/build.go +297 -0
- data/vendor/google.golang.org/protobuf/internal/flags/flags.go +24 -0
- data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_disable.go +9 -0
- data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_enable.go +9 -0
- data/vendor/google.golang.org/protobuf/internal/genid/any_gen.go +34 -0
- data/vendor/google.golang.org/protobuf/internal/genid/api_gen.go +106 -0
- data/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +829 -0
- data/vendor/google.golang.org/protobuf/internal/genid/doc.go +11 -0
- data/vendor/google.golang.org/protobuf/internal/genid/duration_gen.go +34 -0
- data/vendor/google.golang.org/protobuf/internal/genid/empty_gen.go +19 -0
- data/vendor/google.golang.org/protobuf/internal/genid/field_mask_gen.go +31 -0
- data/vendor/google.golang.org/protobuf/internal/genid/goname.go +25 -0
- data/vendor/google.golang.org/protobuf/internal/genid/map_entry.go +16 -0
- data/vendor/google.golang.org/protobuf/internal/genid/source_context_gen.go +31 -0
- data/vendor/google.golang.org/protobuf/internal/genid/struct_gen.go +116 -0
- data/vendor/google.golang.org/protobuf/internal/genid/timestamp_gen.go +34 -0
- data/vendor/google.golang.org/protobuf/internal/genid/type_gen.go +184 -0
- data/vendor/google.golang.org/protobuf/internal/genid/wrappers.go +13 -0
- data/vendor/google.golang.org/protobuf/internal/genid/wrappers_gen.go +175 -0
- data/vendor/google.golang.org/protobuf/internal/impl/api_export.go +177 -0
- data/vendor/google.golang.org/protobuf/internal/impl/checkinit.go +141 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go +223 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_field.go +830 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_gen.go +5637 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_map.go +388 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go111.go +37 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go112.go +11 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_message.go +217 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_messageset.go +123 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_reflect.go +209 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_tables.go +557 -0
- data/vendor/google.golang.org/protobuf/internal/impl/codec_unsafe.go +17 -0
- data/vendor/google.golang.org/protobuf/internal/impl/convert.go +496 -0
- data/vendor/google.golang.org/protobuf/internal/impl/convert_list.go +141 -0
- data/vendor/google.golang.org/protobuf/internal/impl/convert_map.go +121 -0
- data/vendor/google.golang.org/protobuf/internal/impl/decode.go +276 -0
- data/vendor/google.golang.org/protobuf/internal/impl/encode.go +201 -0
- data/vendor/google.golang.org/protobuf/internal/impl/enum.go +21 -0
- data/vendor/google.golang.org/protobuf/internal/impl/extension.go +156 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_enum.go +219 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_export.go +92 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_extension.go +176 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_file.go +81 -0
- data/vendor/google.golang.org/protobuf/internal/impl/legacy_message.go +558 -0
- data/vendor/google.golang.org/protobuf/internal/impl/merge.go +176 -0
- data/vendor/google.golang.org/protobuf/internal/impl/merge_gen.go +209 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message.go +276 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message_reflect.go +465 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_field.go +543 -0
- data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_gen.go +249 -0
- data/vendor/google.golang.org/protobuf/internal/impl/pointer_reflect.go +178 -0
- data/vendor/google.golang.org/protobuf/internal/impl/pointer_unsafe.go +174 -0
- data/vendor/google.golang.org/protobuf/internal/impl/validate.go +576 -0
- data/vendor/google.golang.org/protobuf/internal/impl/weak.go +74 -0
- data/vendor/google.golang.org/protobuf/internal/order/order.go +89 -0
- data/vendor/google.golang.org/protobuf/internal/order/range.go +115 -0
- data/vendor/google.golang.org/protobuf/internal/pragma/pragma.go +29 -0
- data/vendor/google.golang.org/protobuf/internal/set/ints.go +58 -0
- data/vendor/google.golang.org/protobuf/internal/strs/strings.go +196 -0
- data/vendor/google.golang.org/protobuf/internal/strs/strings_pure.go +27 -0
- data/vendor/google.golang.org/protobuf/internal/strs/strings_unsafe.go +94 -0
- data/vendor/google.golang.org/protobuf/internal/version/version.go +79 -0
- data/vendor/google.golang.org/protobuf/proto/checkinit.go +71 -0
- data/vendor/google.golang.org/protobuf/proto/decode.go +278 -0
- data/vendor/google.golang.org/protobuf/proto/decode_gen.go +603 -0
- data/vendor/google.golang.org/protobuf/proto/doc.go +94 -0
- data/vendor/google.golang.org/protobuf/proto/encode.go +319 -0
- data/vendor/google.golang.org/protobuf/proto/encode_gen.go +97 -0
- data/vendor/google.golang.org/protobuf/proto/equal.go +167 -0
- data/vendor/google.golang.org/protobuf/proto/extension.go +92 -0
- data/vendor/google.golang.org/protobuf/proto/merge.go +139 -0
- data/vendor/google.golang.org/protobuf/proto/messageset.go +93 -0
- data/vendor/google.golang.org/protobuf/proto/proto.go +43 -0
- data/vendor/google.golang.org/protobuf/proto/proto_methods.go +19 -0
- data/vendor/google.golang.org/protobuf/proto/proto_reflect.go +19 -0
- data/vendor/google.golang.org/protobuf/proto/reset.go +43 -0
- data/vendor/google.golang.org/protobuf/proto/size.go +97 -0
- data/vendor/google.golang.org/protobuf/proto/size_gen.go +55 -0
- data/vendor/google.golang.org/protobuf/proto/wrappers.go +29 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go +276 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go +248 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_resolve.go +286 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_validate.go +374 -0
- data/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go +252 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/methods.go +77 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go +504 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go +128 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +461 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go +665 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go +285 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_pure.go +59 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go +411 -0
- data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go +98 -0
- data/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go +869 -0
- data/vendor/google.golang.org/protobuf/runtime/protoiface/legacy.go +15 -0
- data/vendor/google.golang.org/protobuf/runtime/protoiface/methods.go +167 -0
- data/vendor/google.golang.org/protobuf/runtime/protoimpl/impl.go +44 -0
- data/vendor/google.golang.org/protobuf/runtime/protoimpl/version.go +56 -0
- data/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go +4039 -0
- data/vendor/modules.txt +79 -0
- metadata +495 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2018 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
//go:build appengine
|
|
6
|
+
// +build appengine
|
|
7
|
+
|
|
8
|
+
package internal
|
|
9
|
+
|
|
10
|
+
import "google.golang.org/appengine/urlfetch"
|
|
11
|
+
|
|
12
|
+
func init() {
|
|
13
|
+
appengineClientHook = urlfetch.Client
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright 2014 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
package internal
|
|
6
|
+
|
|
7
|
+
import (
|
|
8
|
+
"crypto/rsa"
|
|
9
|
+
"crypto/x509"
|
|
10
|
+
"encoding/pem"
|
|
11
|
+
"errors"
|
|
12
|
+
"fmt"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// ParseKey converts the binary contents of a private key file
|
|
16
|
+
// to an *rsa.PrivateKey. It detects whether the private key is in a
|
|
17
|
+
// PEM container or not. If so, it extracts the the private key
|
|
18
|
+
// from PEM container before conversion. It only supports PEM
|
|
19
|
+
// containers with no passphrase.
|
|
20
|
+
func ParseKey(key []byte) (*rsa.PrivateKey, error) {
|
|
21
|
+
block, _ := pem.Decode(key)
|
|
22
|
+
if block != nil {
|
|
23
|
+
key = block.Bytes
|
|
24
|
+
}
|
|
25
|
+
parsedKey, err := x509.ParsePKCS8PrivateKey(key)
|
|
26
|
+
if err != nil {
|
|
27
|
+
parsedKey, err = x509.ParsePKCS1PrivateKey(key)
|
|
28
|
+
if err != nil {
|
|
29
|
+
return nil, fmt.Errorf("private key should be a PEM or plain PKCS1 or PKCS8; parse error: %v", err)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
parsed, ok := parsedKey.(*rsa.PrivateKey)
|
|
33
|
+
if !ok {
|
|
34
|
+
return nil, errors.New("private key is invalid")
|
|
35
|
+
}
|
|
36
|
+
return parsed, nil
|
|
37
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// Copyright 2014 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
package internal
|
|
6
|
+
|
|
7
|
+
import (
|
|
8
|
+
"context"
|
|
9
|
+
"encoding/json"
|
|
10
|
+
"errors"
|
|
11
|
+
"fmt"
|
|
12
|
+
"io"
|
|
13
|
+
"io/ioutil"
|
|
14
|
+
"math"
|
|
15
|
+
"mime"
|
|
16
|
+
"net/http"
|
|
17
|
+
"net/url"
|
|
18
|
+
"strconv"
|
|
19
|
+
"strings"
|
|
20
|
+
"sync"
|
|
21
|
+
"time"
|
|
22
|
+
|
|
23
|
+
"golang.org/x/net/context/ctxhttp"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
// Token represents the credentials used to authorize
|
|
27
|
+
// the requests to access protected resources on the OAuth 2.0
|
|
28
|
+
// provider's backend.
|
|
29
|
+
//
|
|
30
|
+
// This type is a mirror of oauth2.Token and exists to break
|
|
31
|
+
// an otherwise-circular dependency. Other internal packages
|
|
32
|
+
// should convert this Token into an oauth2.Token before use.
|
|
33
|
+
type Token struct {
|
|
34
|
+
// AccessToken is the token that authorizes and authenticates
|
|
35
|
+
// the requests.
|
|
36
|
+
AccessToken string
|
|
37
|
+
|
|
38
|
+
// TokenType is the type of token.
|
|
39
|
+
// The Type method returns either this or "Bearer", the default.
|
|
40
|
+
TokenType string
|
|
41
|
+
|
|
42
|
+
// RefreshToken is a token that's used by the application
|
|
43
|
+
// (as opposed to the user) to refresh the access token
|
|
44
|
+
// if it expires.
|
|
45
|
+
RefreshToken string
|
|
46
|
+
|
|
47
|
+
// Expiry is the optional expiration time of the access token.
|
|
48
|
+
//
|
|
49
|
+
// If zero, TokenSource implementations will reuse the same
|
|
50
|
+
// token forever and RefreshToken or equivalent
|
|
51
|
+
// mechanisms for that TokenSource will not be used.
|
|
52
|
+
Expiry time.Time
|
|
53
|
+
|
|
54
|
+
// Raw optionally contains extra metadata from the server
|
|
55
|
+
// when updating a token.
|
|
56
|
+
Raw interface{}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// tokenJSON is the struct representing the HTTP response from OAuth2
|
|
60
|
+
// providers returning a token in JSON form.
|
|
61
|
+
type tokenJSON struct {
|
|
62
|
+
AccessToken string `json:"access_token"`
|
|
63
|
+
TokenType string `json:"token_type"`
|
|
64
|
+
RefreshToken string `json:"refresh_token"`
|
|
65
|
+
ExpiresIn expirationTime `json:"expires_in"` // at least PayPal returns string, while most return number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func (e *tokenJSON) expiry() (t time.Time) {
|
|
69
|
+
if v := e.ExpiresIn; v != 0 {
|
|
70
|
+
return time.Now().Add(time.Duration(v) * time.Second)
|
|
71
|
+
}
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type expirationTime int32
|
|
76
|
+
|
|
77
|
+
func (e *expirationTime) UnmarshalJSON(b []byte) error {
|
|
78
|
+
if len(b) == 0 || string(b) == "null" {
|
|
79
|
+
return nil
|
|
80
|
+
}
|
|
81
|
+
var n json.Number
|
|
82
|
+
err := json.Unmarshal(b, &n)
|
|
83
|
+
if err != nil {
|
|
84
|
+
return err
|
|
85
|
+
}
|
|
86
|
+
i, err := n.Int64()
|
|
87
|
+
if err != nil {
|
|
88
|
+
return err
|
|
89
|
+
}
|
|
90
|
+
if i > math.MaxInt32 {
|
|
91
|
+
i = math.MaxInt32
|
|
92
|
+
}
|
|
93
|
+
*e = expirationTime(i)
|
|
94
|
+
return nil
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// RegisterBrokenAuthHeaderProvider previously did something. It is now a no-op.
|
|
98
|
+
//
|
|
99
|
+
// Deprecated: this function no longer does anything. Caller code that
|
|
100
|
+
// wants to avoid potential extra HTTP requests made during
|
|
101
|
+
// auto-probing of the provider's auth style should set
|
|
102
|
+
// Endpoint.AuthStyle.
|
|
103
|
+
func RegisterBrokenAuthHeaderProvider(tokenURL string) {}
|
|
104
|
+
|
|
105
|
+
// AuthStyle is a copy of the golang.org/x/oauth2 package's AuthStyle type.
|
|
106
|
+
type AuthStyle int
|
|
107
|
+
|
|
108
|
+
const (
|
|
109
|
+
AuthStyleUnknown AuthStyle = 0
|
|
110
|
+
AuthStyleInParams AuthStyle = 1
|
|
111
|
+
AuthStyleInHeader AuthStyle = 2
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
// authStyleCache is the set of tokenURLs we've successfully used via
|
|
115
|
+
// RetrieveToken and which style auth we ended up using.
|
|
116
|
+
// It's called a cache, but it doesn't (yet?) shrink. It's expected that
|
|
117
|
+
// the set of OAuth2 servers a program contacts over time is fixed and
|
|
118
|
+
// small.
|
|
119
|
+
var authStyleCache struct {
|
|
120
|
+
sync.Mutex
|
|
121
|
+
m map[string]AuthStyle // keyed by tokenURL
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ResetAuthCache resets the global authentication style cache used
|
|
125
|
+
// for AuthStyleUnknown token requests.
|
|
126
|
+
func ResetAuthCache() {
|
|
127
|
+
authStyleCache.Lock()
|
|
128
|
+
defer authStyleCache.Unlock()
|
|
129
|
+
authStyleCache.m = nil
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// lookupAuthStyle reports which auth style we last used with tokenURL
|
|
133
|
+
// when calling RetrieveToken and whether we have ever done so.
|
|
134
|
+
func lookupAuthStyle(tokenURL string) (style AuthStyle, ok bool) {
|
|
135
|
+
authStyleCache.Lock()
|
|
136
|
+
defer authStyleCache.Unlock()
|
|
137
|
+
style, ok = authStyleCache.m[tokenURL]
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// setAuthStyle adds an entry to authStyleCache, documented above.
|
|
142
|
+
func setAuthStyle(tokenURL string, v AuthStyle) {
|
|
143
|
+
authStyleCache.Lock()
|
|
144
|
+
defer authStyleCache.Unlock()
|
|
145
|
+
if authStyleCache.m == nil {
|
|
146
|
+
authStyleCache.m = make(map[string]AuthStyle)
|
|
147
|
+
}
|
|
148
|
+
authStyleCache.m[tokenURL] = v
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// newTokenRequest returns a new *http.Request to retrieve a new token
|
|
152
|
+
// from tokenURL using the provided clientID, clientSecret, and POST
|
|
153
|
+
// body parameters.
|
|
154
|
+
//
|
|
155
|
+
// inParams is whether the clientID & clientSecret should be encoded
|
|
156
|
+
// as the POST body. An 'inParams' value of true means to send it in
|
|
157
|
+
// the POST body (along with any values in v); false means to send it
|
|
158
|
+
// in the Authorization header.
|
|
159
|
+
func newTokenRequest(tokenURL, clientID, clientSecret string, v url.Values, authStyle AuthStyle) (*http.Request, error) {
|
|
160
|
+
if authStyle == AuthStyleInParams {
|
|
161
|
+
v = cloneURLValues(v)
|
|
162
|
+
if clientID != "" {
|
|
163
|
+
v.Set("client_id", clientID)
|
|
164
|
+
}
|
|
165
|
+
if clientSecret != "" {
|
|
166
|
+
v.Set("client_secret", clientSecret)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
req, err := http.NewRequest("POST", tokenURL, strings.NewReader(v.Encode()))
|
|
170
|
+
if err != nil {
|
|
171
|
+
return nil, err
|
|
172
|
+
}
|
|
173
|
+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
174
|
+
if authStyle == AuthStyleInHeader {
|
|
175
|
+
req.SetBasicAuth(url.QueryEscape(clientID), url.QueryEscape(clientSecret))
|
|
176
|
+
}
|
|
177
|
+
return req, nil
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
func cloneURLValues(v url.Values) url.Values {
|
|
181
|
+
v2 := make(url.Values, len(v))
|
|
182
|
+
for k, vv := range v {
|
|
183
|
+
v2[k] = append([]string(nil), vv...)
|
|
184
|
+
}
|
|
185
|
+
return v2
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string, v url.Values, authStyle AuthStyle) (*Token, error) {
|
|
189
|
+
needsAuthStyleProbe := authStyle == 0
|
|
190
|
+
if needsAuthStyleProbe {
|
|
191
|
+
if style, ok := lookupAuthStyle(tokenURL); ok {
|
|
192
|
+
authStyle = style
|
|
193
|
+
needsAuthStyleProbe = false
|
|
194
|
+
} else {
|
|
195
|
+
authStyle = AuthStyleInHeader // the first way we'll try
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
req, err := newTokenRequest(tokenURL, clientID, clientSecret, v, authStyle)
|
|
199
|
+
if err != nil {
|
|
200
|
+
return nil, err
|
|
201
|
+
}
|
|
202
|
+
token, err := doTokenRoundTrip(ctx, req)
|
|
203
|
+
if err != nil && needsAuthStyleProbe {
|
|
204
|
+
// If we get an error, assume the server wants the
|
|
205
|
+
// clientID & clientSecret in a different form.
|
|
206
|
+
// See https://code.google.com/p/goauth2/issues/detail?id=31 for background.
|
|
207
|
+
// In summary:
|
|
208
|
+
// - Reddit only accepts client secret in the Authorization header
|
|
209
|
+
// - Dropbox accepts either it in URL param or Auth header, but not both.
|
|
210
|
+
// - Google only accepts URL param (not spec compliant?), not Auth header
|
|
211
|
+
// - Stripe only accepts client secret in Auth header with Bearer method, not Basic
|
|
212
|
+
//
|
|
213
|
+
// We used to maintain a big table in this code of all the sites and which way
|
|
214
|
+
// they went, but maintaining it didn't scale & got annoying.
|
|
215
|
+
// So just try both ways.
|
|
216
|
+
authStyle = AuthStyleInParams // the second way we'll try
|
|
217
|
+
req, _ = newTokenRequest(tokenURL, clientID, clientSecret, v, authStyle)
|
|
218
|
+
token, err = doTokenRoundTrip(ctx, req)
|
|
219
|
+
}
|
|
220
|
+
if needsAuthStyleProbe && err == nil {
|
|
221
|
+
setAuthStyle(tokenURL, authStyle)
|
|
222
|
+
}
|
|
223
|
+
// Don't overwrite `RefreshToken` with an empty value
|
|
224
|
+
// if this was a token refreshing request.
|
|
225
|
+
if token != nil && token.RefreshToken == "" {
|
|
226
|
+
token.RefreshToken = v.Get("refresh_token")
|
|
227
|
+
}
|
|
228
|
+
return token, err
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
func doTokenRoundTrip(ctx context.Context, req *http.Request) (*Token, error) {
|
|
232
|
+
r, err := ctxhttp.Do(ctx, ContextClient(ctx), req)
|
|
233
|
+
if err != nil {
|
|
234
|
+
return nil, err
|
|
235
|
+
}
|
|
236
|
+
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1<<20))
|
|
237
|
+
r.Body.Close()
|
|
238
|
+
if err != nil {
|
|
239
|
+
return nil, fmt.Errorf("oauth2: cannot fetch token: %v", err)
|
|
240
|
+
}
|
|
241
|
+
if code := r.StatusCode; code < 200 || code > 299 {
|
|
242
|
+
return nil, &RetrieveError{
|
|
243
|
+
Response: r,
|
|
244
|
+
Body: body,
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var token *Token
|
|
249
|
+
content, _, _ := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
|
250
|
+
switch content {
|
|
251
|
+
case "application/x-www-form-urlencoded", "text/plain":
|
|
252
|
+
vals, err := url.ParseQuery(string(body))
|
|
253
|
+
if err != nil {
|
|
254
|
+
return nil, err
|
|
255
|
+
}
|
|
256
|
+
token = &Token{
|
|
257
|
+
AccessToken: vals.Get("access_token"),
|
|
258
|
+
TokenType: vals.Get("token_type"),
|
|
259
|
+
RefreshToken: vals.Get("refresh_token"),
|
|
260
|
+
Raw: vals,
|
|
261
|
+
}
|
|
262
|
+
e := vals.Get("expires_in")
|
|
263
|
+
expires, _ := strconv.Atoi(e)
|
|
264
|
+
if expires != 0 {
|
|
265
|
+
token.Expiry = time.Now().Add(time.Duration(expires) * time.Second)
|
|
266
|
+
}
|
|
267
|
+
default:
|
|
268
|
+
var tj tokenJSON
|
|
269
|
+
if err = json.Unmarshal(body, &tj); err != nil {
|
|
270
|
+
return nil, err
|
|
271
|
+
}
|
|
272
|
+
token = &Token{
|
|
273
|
+
AccessToken: tj.AccessToken,
|
|
274
|
+
TokenType: tj.TokenType,
|
|
275
|
+
RefreshToken: tj.RefreshToken,
|
|
276
|
+
Expiry: tj.expiry(),
|
|
277
|
+
Raw: make(map[string]interface{}),
|
|
278
|
+
}
|
|
279
|
+
json.Unmarshal(body, &token.Raw) // no error checks for optional fields
|
|
280
|
+
}
|
|
281
|
+
if token.AccessToken == "" {
|
|
282
|
+
return nil, errors.New("oauth2: server response missing access_token")
|
|
283
|
+
}
|
|
284
|
+
return token, nil
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
type RetrieveError struct {
|
|
288
|
+
Response *http.Response
|
|
289
|
+
Body []byte
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
func (r *RetrieveError) Error() string {
|
|
293
|
+
return fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", r.Response.Status, r.Body)
|
|
294
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2014 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
package internal
|
|
6
|
+
|
|
7
|
+
import (
|
|
8
|
+
"context"
|
|
9
|
+
"net/http"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// HTTPClient is the context key to use with golang.org/x/net/context's
|
|
13
|
+
// WithValue function to associate an *http.Client value with a context.
|
|
14
|
+
var HTTPClient ContextKey
|
|
15
|
+
|
|
16
|
+
// ContextKey is just an empty struct. It exists so HTTPClient can be
|
|
17
|
+
// an immutable public variable with a unique type. It's immutable
|
|
18
|
+
// because nobody else can create a ContextKey, being unexported.
|
|
19
|
+
type ContextKey struct{}
|
|
20
|
+
|
|
21
|
+
var appengineClientHook func(context.Context) *http.Client
|
|
22
|
+
|
|
23
|
+
func ContextClient(ctx context.Context) *http.Client {
|
|
24
|
+
if ctx != nil {
|
|
25
|
+
if hc, ok := ctx.Value(HTTPClient).(*http.Client); ok {
|
|
26
|
+
return hc
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if appengineClientHook != nil {
|
|
30
|
+
return appengineClientHook(ctx)
|
|
31
|
+
}
|
|
32
|
+
return http.DefaultClient
|
|
33
|
+
}
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
// Copyright 2014 The Go Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
// Package oauth2 provides support for making
|
|
6
|
+
// OAuth2 authorized and authenticated HTTP requests,
|
|
7
|
+
// as specified in RFC 6749.
|
|
8
|
+
// It can additionally grant authorization with Bearer JWT.
|
|
9
|
+
package oauth2 // import "golang.org/x/oauth2"
|
|
10
|
+
|
|
11
|
+
import (
|
|
12
|
+
"bytes"
|
|
13
|
+
"context"
|
|
14
|
+
"errors"
|
|
15
|
+
"net/http"
|
|
16
|
+
"net/url"
|
|
17
|
+
"strings"
|
|
18
|
+
"sync"
|
|
19
|
+
|
|
20
|
+
"golang.org/x/oauth2/internal"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
// NoContext is the default context you should supply if not using
|
|
24
|
+
// your own context.Context (see https://golang.org/x/net/context).
|
|
25
|
+
//
|
|
26
|
+
// Deprecated: Use context.Background() or context.TODO() instead.
|
|
27
|
+
var NoContext = context.TODO()
|
|
28
|
+
|
|
29
|
+
// RegisterBrokenAuthHeaderProvider previously did something. It is now a no-op.
|
|
30
|
+
//
|
|
31
|
+
// Deprecated: this function no longer does anything. Caller code that
|
|
32
|
+
// wants to avoid potential extra HTTP requests made during
|
|
33
|
+
// auto-probing of the provider's auth style should set
|
|
34
|
+
// Endpoint.AuthStyle.
|
|
35
|
+
func RegisterBrokenAuthHeaderProvider(tokenURL string) {}
|
|
36
|
+
|
|
37
|
+
// Config describes a typical 3-legged OAuth2 flow, with both the
|
|
38
|
+
// client application information and the server's endpoint URLs.
|
|
39
|
+
// For the client credentials 2-legged OAuth2 flow, see the clientcredentials
|
|
40
|
+
// package (https://golang.org/x/oauth2/clientcredentials).
|
|
41
|
+
type Config struct {
|
|
42
|
+
// ClientID is the application's ID.
|
|
43
|
+
ClientID string
|
|
44
|
+
|
|
45
|
+
// ClientSecret is the application's secret.
|
|
46
|
+
ClientSecret string
|
|
47
|
+
|
|
48
|
+
// Endpoint contains the resource server's token endpoint
|
|
49
|
+
// URLs. These are constants specific to each server and are
|
|
50
|
+
// often available via site-specific packages, such as
|
|
51
|
+
// google.Endpoint or github.Endpoint.
|
|
52
|
+
Endpoint Endpoint
|
|
53
|
+
|
|
54
|
+
// RedirectURL is the URL to redirect users going through
|
|
55
|
+
// the OAuth flow, after the resource owner's URLs.
|
|
56
|
+
RedirectURL string
|
|
57
|
+
|
|
58
|
+
// Scope specifies optional requested permissions.
|
|
59
|
+
Scopes []string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// A TokenSource is anything that can return a token.
|
|
63
|
+
type TokenSource interface {
|
|
64
|
+
// Token returns a token or an error.
|
|
65
|
+
// Token must be safe for concurrent use by multiple goroutines.
|
|
66
|
+
// The returned Token must not be modified.
|
|
67
|
+
Token() (*Token, error)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Endpoint represents an OAuth 2.0 provider's authorization and token
|
|
71
|
+
// endpoint URLs.
|
|
72
|
+
type Endpoint struct {
|
|
73
|
+
AuthURL string
|
|
74
|
+
TokenURL string
|
|
75
|
+
|
|
76
|
+
// AuthStyle optionally specifies how the endpoint wants the
|
|
77
|
+
// client ID & client secret sent. The zero value means to
|
|
78
|
+
// auto-detect.
|
|
79
|
+
AuthStyle AuthStyle
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// AuthStyle represents how requests for tokens are authenticated
|
|
83
|
+
// to the server.
|
|
84
|
+
type AuthStyle int
|
|
85
|
+
|
|
86
|
+
const (
|
|
87
|
+
// AuthStyleAutoDetect means to auto-detect which authentication
|
|
88
|
+
// style the provider wants by trying both ways and caching
|
|
89
|
+
// the successful way for the future.
|
|
90
|
+
AuthStyleAutoDetect AuthStyle = 0
|
|
91
|
+
|
|
92
|
+
// AuthStyleInParams sends the "client_id" and "client_secret"
|
|
93
|
+
// in the POST body as application/x-www-form-urlencoded parameters.
|
|
94
|
+
AuthStyleInParams AuthStyle = 1
|
|
95
|
+
|
|
96
|
+
// AuthStyleInHeader sends the client_id and client_password
|
|
97
|
+
// using HTTP Basic Authorization. This is an optional style
|
|
98
|
+
// described in the OAuth2 RFC 6749 section 2.3.1.
|
|
99
|
+
AuthStyleInHeader AuthStyle = 2
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
var (
|
|
103
|
+
// AccessTypeOnline and AccessTypeOffline are options passed
|
|
104
|
+
// to the Options.AuthCodeURL method. They modify the
|
|
105
|
+
// "access_type" field that gets sent in the URL returned by
|
|
106
|
+
// AuthCodeURL.
|
|
107
|
+
//
|
|
108
|
+
// Online is the default if neither is specified. If your
|
|
109
|
+
// application needs to refresh access tokens when the user
|
|
110
|
+
// is not present at the browser, then use offline. This will
|
|
111
|
+
// result in your application obtaining a refresh token the
|
|
112
|
+
// first time your application exchanges an authorization
|
|
113
|
+
// code for a user.
|
|
114
|
+
AccessTypeOnline AuthCodeOption = SetAuthURLParam("access_type", "online")
|
|
115
|
+
AccessTypeOffline AuthCodeOption = SetAuthURLParam("access_type", "offline")
|
|
116
|
+
|
|
117
|
+
// ApprovalForce forces the users to view the consent dialog
|
|
118
|
+
// and confirm the permissions request at the URL returned
|
|
119
|
+
// from AuthCodeURL, even if they've already done so.
|
|
120
|
+
ApprovalForce AuthCodeOption = SetAuthURLParam("prompt", "consent")
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
// An AuthCodeOption is passed to Config.AuthCodeURL.
|
|
124
|
+
type AuthCodeOption interface {
|
|
125
|
+
setValue(url.Values)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type setParam struct{ k, v string }
|
|
129
|
+
|
|
130
|
+
func (p setParam) setValue(m url.Values) { m.Set(p.k, p.v) }
|
|
131
|
+
|
|
132
|
+
// SetAuthURLParam builds an AuthCodeOption which passes key/value parameters
|
|
133
|
+
// to a provider's authorization endpoint.
|
|
134
|
+
func SetAuthURLParam(key, value string) AuthCodeOption {
|
|
135
|
+
return setParam{key, value}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// AuthCodeURL returns a URL to OAuth 2.0 provider's consent page
|
|
139
|
+
// that asks for permissions for the required scopes explicitly.
|
|
140
|
+
//
|
|
141
|
+
// State is a token to protect the user from CSRF attacks. You must
|
|
142
|
+
// always provide a non-empty string and validate that it matches the
|
|
143
|
+
// the state query parameter on your redirect callback.
|
|
144
|
+
// See http://tools.ietf.org/html/rfc6749#section-10.12 for more info.
|
|
145
|
+
//
|
|
146
|
+
// Opts may include AccessTypeOnline or AccessTypeOffline, as well
|
|
147
|
+
// as ApprovalForce.
|
|
148
|
+
// It can also be used to pass the PKCE challenge.
|
|
149
|
+
// See https://www.oauth.com/oauth2-servers/pkce/ for more info.
|
|
150
|
+
func (c *Config) AuthCodeURL(state string, opts ...AuthCodeOption) string {
|
|
151
|
+
var buf bytes.Buffer
|
|
152
|
+
buf.WriteString(c.Endpoint.AuthURL)
|
|
153
|
+
v := url.Values{
|
|
154
|
+
"response_type": {"code"},
|
|
155
|
+
"client_id": {c.ClientID},
|
|
156
|
+
}
|
|
157
|
+
if c.RedirectURL != "" {
|
|
158
|
+
v.Set("redirect_uri", c.RedirectURL)
|
|
159
|
+
}
|
|
160
|
+
if len(c.Scopes) > 0 {
|
|
161
|
+
v.Set("scope", strings.Join(c.Scopes, " "))
|
|
162
|
+
}
|
|
163
|
+
if state != "" {
|
|
164
|
+
// TODO(light): Docs say never to omit state; don't allow empty.
|
|
165
|
+
v.Set("state", state)
|
|
166
|
+
}
|
|
167
|
+
for _, opt := range opts {
|
|
168
|
+
opt.setValue(v)
|
|
169
|
+
}
|
|
170
|
+
if strings.Contains(c.Endpoint.AuthURL, "?") {
|
|
171
|
+
buf.WriteByte('&')
|
|
172
|
+
} else {
|
|
173
|
+
buf.WriteByte('?')
|
|
174
|
+
}
|
|
175
|
+
buf.WriteString(v.Encode())
|
|
176
|
+
return buf.String()
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// PasswordCredentialsToken converts a resource owner username and password
|
|
180
|
+
// pair into a token.
|
|
181
|
+
//
|
|
182
|
+
// Per the RFC, this grant type should only be used "when there is a high
|
|
183
|
+
// degree of trust between the resource owner and the client (e.g., the client
|
|
184
|
+
// is part of the device operating system or a highly privileged application),
|
|
185
|
+
// and when other authorization grant types are not available."
|
|
186
|
+
// See https://tools.ietf.org/html/rfc6749#section-4.3 for more info.
|
|
187
|
+
//
|
|
188
|
+
// The provided context optionally controls which HTTP client is used. See the HTTPClient variable.
|
|
189
|
+
func (c *Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error) {
|
|
190
|
+
v := url.Values{
|
|
191
|
+
"grant_type": {"password"},
|
|
192
|
+
"username": {username},
|
|
193
|
+
"password": {password},
|
|
194
|
+
}
|
|
195
|
+
if len(c.Scopes) > 0 {
|
|
196
|
+
v.Set("scope", strings.Join(c.Scopes, " "))
|
|
197
|
+
}
|
|
198
|
+
return retrieveToken(ctx, c, v)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Exchange converts an authorization code into a token.
|
|
202
|
+
//
|
|
203
|
+
// It is used after a resource provider redirects the user back
|
|
204
|
+
// to the Redirect URI (the URL obtained from AuthCodeURL).
|
|
205
|
+
//
|
|
206
|
+
// The provided context optionally controls which HTTP client is used. See the HTTPClient variable.
|
|
207
|
+
//
|
|
208
|
+
// The code will be in the *http.Request.FormValue("code"). Before
|
|
209
|
+
// calling Exchange, be sure to validate FormValue("state").
|
|
210
|
+
//
|
|
211
|
+
// Opts may include the PKCE verifier code if previously used in AuthCodeURL.
|
|
212
|
+
// See https://www.oauth.com/oauth2-servers/pkce/ for more info.
|
|
213
|
+
func (c *Config) Exchange(ctx context.Context, code string, opts ...AuthCodeOption) (*Token, error) {
|
|
214
|
+
v := url.Values{
|
|
215
|
+
"grant_type": {"authorization_code"},
|
|
216
|
+
"code": {code},
|
|
217
|
+
}
|
|
218
|
+
if c.RedirectURL != "" {
|
|
219
|
+
v.Set("redirect_uri", c.RedirectURL)
|
|
220
|
+
}
|
|
221
|
+
for _, opt := range opts {
|
|
222
|
+
opt.setValue(v)
|
|
223
|
+
}
|
|
224
|
+
return retrieveToken(ctx, c, v)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Client returns an HTTP client using the provided token.
|
|
228
|
+
// The token will auto-refresh as necessary. The underlying
|
|
229
|
+
// HTTP transport will be obtained using the provided context.
|
|
230
|
+
// The returned client and its Transport should not be modified.
|
|
231
|
+
func (c *Config) Client(ctx context.Context, t *Token) *http.Client {
|
|
232
|
+
return NewClient(ctx, c.TokenSource(ctx, t))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// TokenSource returns a TokenSource that returns t until t expires,
|
|
236
|
+
// automatically refreshing it as necessary using the provided context.
|
|
237
|
+
//
|
|
238
|
+
// Most users will use Config.Client instead.
|
|
239
|
+
func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource {
|
|
240
|
+
tkr := &tokenRefresher{
|
|
241
|
+
ctx: ctx,
|
|
242
|
+
conf: c,
|
|
243
|
+
}
|
|
244
|
+
if t != nil {
|
|
245
|
+
tkr.refreshToken = t.RefreshToken
|
|
246
|
+
}
|
|
247
|
+
return &reuseTokenSource{
|
|
248
|
+
t: t,
|
|
249
|
+
new: tkr,
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// tokenRefresher is a TokenSource that makes "grant_type"=="refresh_token"
|
|
254
|
+
// HTTP requests to renew a token using a RefreshToken.
|
|
255
|
+
type tokenRefresher struct {
|
|
256
|
+
ctx context.Context // used to get HTTP requests
|
|
257
|
+
conf *Config
|
|
258
|
+
refreshToken string
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// WARNING: Token is not safe for concurrent access, as it
|
|
262
|
+
// updates the tokenRefresher's refreshToken field.
|
|
263
|
+
// Within this package, it is used by reuseTokenSource which
|
|
264
|
+
// synchronizes calls to this method with its own mutex.
|
|
265
|
+
func (tf *tokenRefresher) Token() (*Token, error) {
|
|
266
|
+
if tf.refreshToken == "" {
|
|
267
|
+
return nil, errors.New("oauth2: token expired and refresh token is not set")
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
tk, err := retrieveToken(tf.ctx, tf.conf, url.Values{
|
|
271
|
+
"grant_type": {"refresh_token"},
|
|
272
|
+
"refresh_token": {tf.refreshToken},
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
if err != nil {
|
|
276
|
+
return nil, err
|
|
277
|
+
}
|
|
278
|
+
if tf.refreshToken != tk.RefreshToken {
|
|
279
|
+
tf.refreshToken = tk.RefreshToken
|
|
280
|
+
}
|
|
281
|
+
return tk, err
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// reuseTokenSource is a TokenSource that holds a single token in memory
|
|
285
|
+
// and validates its expiry before each call to retrieve it with
|
|
286
|
+
// Token. If it's expired, it will be auto-refreshed using the
|
|
287
|
+
// new TokenSource.
|
|
288
|
+
type reuseTokenSource struct {
|
|
289
|
+
new TokenSource // called when t is expired.
|
|
290
|
+
|
|
291
|
+
mu sync.Mutex // guards t
|
|
292
|
+
t *Token
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Token returns the current token if it's still valid, else will
|
|
296
|
+
// refresh the current token (using r.Context for HTTP client
|
|
297
|
+
// information) and return the new one.
|
|
298
|
+
func (s *reuseTokenSource) Token() (*Token, error) {
|
|
299
|
+
s.mu.Lock()
|
|
300
|
+
defer s.mu.Unlock()
|
|
301
|
+
if s.t.Valid() {
|
|
302
|
+
return s.t, nil
|
|
303
|
+
}
|
|
304
|
+
t, err := s.new.Token()
|
|
305
|
+
if err != nil {
|
|
306
|
+
return nil, err
|
|
307
|
+
}
|
|
308
|
+
s.t = t
|
|
309
|
+
return t, nil
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// StaticTokenSource returns a TokenSource that always returns the same token.
|
|
313
|
+
// Because the provided token t is never refreshed, StaticTokenSource is only
|
|
314
|
+
// useful for tokens that never expire.
|
|
315
|
+
func StaticTokenSource(t *Token) TokenSource {
|
|
316
|
+
return staticTokenSource{t}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// staticTokenSource is a TokenSource that always returns the same Token.
|
|
320
|
+
type staticTokenSource struct {
|
|
321
|
+
t *Token
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
func (s staticTokenSource) Token() (*Token, error) {
|
|
325
|
+
return s.t, nil
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// HTTPClient is the context key to use with golang.org/x/net/context's
|
|
329
|
+
// WithValue function to associate an *http.Client value with a context.
|
|
330
|
+
var HTTPClient internal.ContextKey
|
|
331
|
+
|
|
332
|
+
// NewClient creates an *http.Client from a Context and TokenSource.
|
|
333
|
+
// The returned client is not valid beyond the lifetime of the context.
|
|
334
|
+
//
|
|
335
|
+
// Note that if a custom *http.Client is provided via the Context it
|
|
336
|
+
// is used only for token acquisition and is not used to configure the
|
|
337
|
+
// *http.Client returned from NewClient.
|
|
338
|
+
//
|
|
339
|
+
// As a special case, if src is nil, a non-OAuth2 client is returned
|
|
340
|
+
// using the provided context. This exists to support related OAuth2
|
|
341
|
+
// packages.
|
|
342
|
+
func NewClient(ctx context.Context, src TokenSource) *http.Client {
|
|
343
|
+
if src == nil {
|
|
344
|
+
return internal.ContextClient(ctx)
|
|
345
|
+
}
|
|
346
|
+
return &http.Client{
|
|
347
|
+
Transport: &Transport{
|
|
348
|
+
Base: internal.ContextClient(ctx).Transport,
|
|
349
|
+
Source: ReuseTokenSource(nil, src),
|
|
350
|
+
},
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ReuseTokenSource returns a TokenSource which repeatedly returns the
|
|
355
|
+
// same token as long as it's valid, starting with t.
|
|
356
|
+
// When its cached token is invalid, a new token is obtained from src.
|
|
357
|
+
//
|
|
358
|
+
// ReuseTokenSource is typically used to reuse tokens from a cache
|
|
359
|
+
// (such as a file on disk) between runs of a program, rather than
|
|
360
|
+
// obtaining new tokens unnecessarily.
|
|
361
|
+
//
|
|
362
|
+
// The initial token t may be nil, in which case the TokenSource is
|
|
363
|
+
// wrapped in a caching version if it isn't one already. This also
|
|
364
|
+
// means it's always safe to wrap ReuseTokenSource around any other
|
|
365
|
+
// TokenSource without adverse effects.
|
|
366
|
+
func ReuseTokenSource(t *Token, src TokenSource) TokenSource {
|
|
367
|
+
// Don't wrap a reuseTokenSource in itself. That would work,
|
|
368
|
+
// but cause an unnecessary number of mutex operations.
|
|
369
|
+
// Just build the equivalent one.
|
|
370
|
+
if rt, ok := src.(*reuseTokenSource); ok {
|
|
371
|
+
if t == nil {
|
|
372
|
+
// Just use it directly.
|
|
373
|
+
return rt
|
|
374
|
+
}
|
|
375
|
+
src = rt.new
|
|
376
|
+
}
|
|
377
|
+
return &reuseTokenSource{
|
|
378
|
+
t: t,
|
|
379
|
+
new: src,
|
|
380
|
+
}
|
|
381
|
+
}
|