From a3f8c3a0c499c2858b6cb1df2929679ab3b85601 Mon Sep 17 00:00:00 2001 From: Tim Burks Date: Wed, 30 Sep 2020 10:33:31 -0700 Subject: [PATCH] README updates + auth script clarifications --- CONTRIBUTING.md | 28 +++++++ LICENSE | 202 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 152 +++++++++++++++++++++++------------ auth/CLOUDRUN.sh | 4 + auth/ENVOY.sh | 4 + auth/LOCAL.sh | 8 +- gapic/README.md | 4 + rpc/README.md | 4 + 8 files changed, 353 insertions(+), 53 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 gapic/README.md create mode 100644 rpc/README.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..6c9207f26 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,28 @@ +# How to Contribute + +We'd love to accept your patches and contributions to this project. There are +just a few small guidelines you need to follow. + +## Contributor License Agreement + +Contributions to this project must be accompanied by a Contributor License +Agreement. You (or your employer) retain the copyright to your contribution; +this simply gives us permission to use and redistribute your contributions as +part of the project. Head over to to see +your current agreements on file or to sign a new one. + +You generally only need to submit a CLA once, so if you've already submitted +one (even if it was for a different project), you probably don't need to do it +again. + +## Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests. + +## Community Guidelines + +This project follows +[Google's Open Source Community Guidelines](https://opensource.google/conduct/). diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..7a4a3ea24 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor 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, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 544e3f849..297141a48 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # Registry API Reference Implementation -This directory contains a reference implementation of the Registry API. +This repository contains a reference implementation of the Registry API. ## The Registry API The Registry API allows teams to upload and share machine-readable descriptions of APIs that are in use and in development. These descriptions include API -specifications in standard formats like OpenAPI and Protocol Buffers. These +specifications in standard formats like OpenAPI and Protocol Buffers. These API specifications can be used by tools like linters, browsers, documentation generators, test runners, proxies, and API client and server generators. The -API itself can be seen as a machine-readable enterprise API catalog that can be -used to back online directories, portals, and workflow managers. +Registry API itself can be seen as a machine-readable enterprise API catalog +designed to back online directories, portals, and workflow managers. The Registry API is formally described by the Protocol Buffer source files in [google/cloud/apigee/registry/v1alpha1](google/cloud/apigee/registry/v1alpha1). @@ -21,36 +21,43 @@ production Google API. ## This Implementation This reference implementation is a [gRPC](https://grpc.io) service written in -Go. It can be deployed in a container using +Go. It can be run locally or deployed in a container using services including [Google Cloud Run](https://cloud.google.com/run). It stores data using the -[Google Cloud Datastore API](https://cloud.google.com/datastore) Alternate -storage backends can also be specified with a configuration file. Currently -SQLite and PostgreSQL are supported (see [config](config) for details). +[Google Cloud Datastore API](https://cloud.google.com/datastore) or a +configurable relational backend that currently supports +[PostgreSQL](https://www.postgresql.org/) and [SQLite](https://www.sqlite.org/) +(see [config](config) for details). -The service is annotated to support +The Registry API service is annotated to support [gRPC HTTP/JSON transcoding](https://aip.dev/127), which allows it to be automatically published as a JSON REST API using a proxy. Proxies also enable [gRPC web](https://github.com/grpc/grpc-web), which allows gRPC calls to be directly made from browser-based applications. A configuration for the -[Envoy](https://www.envoyproxy.io/) proxy is included along with scripts to -build and deploy the service and a proxy in a single container on Google Cloud -Run. +[Envoy](https://www.envoyproxy.io/) proxy is included +([deployments/envoy/envoy.yaml](deployments/envoy/envoy.yaml)) along with +scripts to build and deploy the Registry API server and a proxy in a single +container on Google Cloud Run. -The reference API is also configured to support +The Registry API protos also include configuration to support [generated API clients (GAPICS)](https://googleapis.github.io/gapic-generators/), which allow idiomatic API usage from a variety of languages. A Go GAPIC library is generated as part of the build process using [gapic-generator-go](https://github.com/googleapis/gapic-generator-go). A -sample Go-based client is in [examples/grpc-client](examples/grpc-client). -[cmd/apg](cmd/apg) contains a command-line interface that is automatically -generated from the API description using the -[protoc-gen-go_cli](https://github.com/googleapis/gapic-generator-go/tree/master/cmd/protoc-gen-go_cli) -tool in [gapic-generator-go](https://github.com/googleapis/gapic-generator-go). -Along with this automatically-generated CLI, the [cmd/registry](cmd/registry) -directory contains a hand-written command-line tool that uses the Go GAPIC -library to support additional API management tasks. +sample Go GAPIC-based client is in +[examples/gapic-client](examples/gapic-client). -The Registry API server itself is `registry-server`. +Two command-line interfaces are included: + +- [cmd/apg](cmd/apg), automatically generated from the API description using + the + [protoc-gen-go_cli](https://github.com/googleapis/gapic-generator-go/tree/master/cmd/protoc-gen-go_cli) + tool in + [gapic-generator-go](https://github.com/googleapis/gapic-generator-go). +- [cmd/registry](cmd/registry), a hand-written command-line tool that uses the + Go GAPIC library to support additional API management tasks. + +The entry point for the Registry API server itself is +[cmd/registry-server](cmd/registry-server). ## Build Instructions @@ -68,62 +75,93 @@ that build and deploy the API on ## Generated Components -Several directories of generated code are created during the build process (see +Several directories of generated code are produced by the build process (see the [COMPILE-PROTOS.sh](tools/COMPILE-PROTOS.sh) script for details). These include: -- **`rpc`** containing generated Protocol Buffer support code (in Go). -- **`gapic`** containing the Go GAPIC (generated API client) library. -- **`cmd/apg`** containing a generated command-line interface. +- [rpc](rpc), containing generated Go Protocol Buffer support code. +- [gapic](gapic), containing the Go GAPIC (generated API client) library. +- [cmd/apg](cmd/apg), containing a generated command-line interface. + +## Quickstart + +The easiest way to try the Registry API is to run `registry-server` locally +using the SQLite backend. + +`registry-server -c config/sqlite.yml` + +Next, in a separate terminal, configure your environment to point to this +server with the following: + +`source auth/LOCAL.sh` + +Now you can check your server and configuration with the +automatically-generated `apg` client: + +`apg registry get-status` + +Next run a suite of tests with `make test` and see a corresponding demo of API +features in [tests/demo/walkthrough.sh](tests/demo/walkthrough.sh). ## Enabling the Google Cloud Datastore API -The reference implementation uses the +For deployments, we recommend using the [Google Cloud Datastore API](https://cloud.google.com/datastore). This must be enabled for a Google Cloud project and appropriate credentials must be available to `registry-server`. One way to get credentials is to use [Application Default Credentials](https://cloud.google.com/docs/authentication/production). To get set up, just run `gcloud auth application-default login` and sign in. Then make sure that your project id is set to the project that is enabled to -use the Google Cloud Datastore API. (Note that you only need to do this when -you are running the server locally. When `registry-server` is run with Google -Cloud Run, credentials are automatically provided by the environment.) +use the Google Cloud Datastore API. -Please note: this project's Datastore usage is equivalent to -[running Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs). +Notes: -The reference implementation requires indexes in its Datastore instance. To -create them, use the `gcloud` command in the root of this repository: - -``` -gcloud datastore indexes create server/datastore/index.yaml -``` +- You only need to get credentials when you are running the server locally. + When `registry-server` is run with Google Cloud Run, credentials are + automatically provided by the environment.) +- When enabling the Datastore API, you might be asked to select a storage mode. + This project's Datastore API usage is equivalent to + [running Cloud Firestore in Datastore mode](https://cloud.google.com/datastore/docs). +- The reference implementation requires indexes in its Datastore instance. To + create these indexes, use the `gcloud` command in the root of this + repository: `gcloud datastore indexes create server/datastore/index.yaml` ## Running the API Locally +### Running the Registry API server + Running `source auth/LOCAL.sh` will configure your environment for the Registry API server (`registry-server`) and for the clients to call your local instance. -Start the server by running `registry-server`. +Start the server by running `registry-server`. (Recall that by default, this +uses the Cloud Datastore API, a remote service). -## Proxying a Local Service with Envoy +### Optional: Proxying a local service with Envoy `registry-server` provides a gRPC service only. For a transcoded HTTP/JSON -interface, run the [envoy](https://www.envoyproxy.io) proxy locally using the +interface, run the [Envoy](https://www.envoyproxy.io) proxy locally using the configuration in the [deployments/envoy](deployments/envoy) directory. With a -local installation of `envoy`, this can be done by running the following inside +local installation of Envoy, this can be done by running the following inside the [deployments/envoy](deployments/envoy) directory. -``` -envoy -c envoy.yaml -``` +`envoy -c envoy.yaml` + +### Optional: Local authorization with authz-server + +The included Envoy configuration uses Envoy's +[ext_authz_filter](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/ext_authz_filter) +to validate requests using a simple authorization server in +[cmd/authz-server](cmd/authz-server). You can start this server with the +following: + +`authz-server -c cmd/authz-server/authz.yaml` ## Running the API with Google Cloud Run -This API is designed to be easily deployed on -[Google Cloud Run](https://cloud.google.com/run). To support this, the Makefile -contains targets that build a Docker image and deploy it to Google Cloud Run. -Both use the `gcloud` command, which should be authenticated and configured for -the project where the services should be run. +The Registry API server is designed to be easily deployed on +[Google Cloud Run](https://cloud.google.com/run). To support this, the +[Makefile](Makefile) contains targets that build a Docker image and that deploy +it to Google Cloud Run. Both use the `gcloud` command, which should be +authenticated and configured for the project where the services should be run. Requirements: @@ -136,7 +174,7 @@ Requirements: set your project ID to the one where you plan to host your servce. - The Makefile gets your project ID from the `REGISTRY_PROJECT_IDENTIFIER` - environment variable. It can be set automatically by running + environment variable. This can be set automatically by running `source auth/CLOUDRUN.sh`. `make build` uses [Google Cloud Build](https://cloud.google.com/cloud-build) to @@ -154,7 +192,7 @@ questions, including this one: If you answer "y", you will be able to make calls without authentication. This is the easiest way to test the API, but it's not necessary - running `source auth/CLOUDRUN.sh` configures your environment so that the Registry CLI -and other tools will authenticate with your user ID. +and other tools will authenticate using your user ID. Now you can call the API with your generated CLI. @@ -172,3 +210,13 @@ Auth tokens are short-lived. When your token expires, your calls will return a message like this: `rpc error: code = Unauthenticated desc = Unauthorized: HTTP status code 401`. To generate a new token, rerun `source auth/CLOUDRUN.sh`. + +## LICENSE + +This software is licensed under the Apache License, Version 2.0. See +[LICENSE](LICENSE) for the full license text. + +## CONTRIBUTING + +Please see [CONTRIBUTING](CONTRIBUTING.md) for notes on how to contribute to +this project. diff --git a/auth/CLOUDRUN.sh b/auth/CLOUDRUN.sh index de85ae1a2..9d1ca9438 100755 --- a/auth/CLOUDRUN.sh +++ b/auth/CLOUDRUN.sh @@ -22,6 +22,10 @@ # gcloud project is the one with your Cloud Run instance. # +if ! [ -x "$(command -v gcloud)" ]; then + echo 'ERROR: This script requires the gcloud command. Please install it to continue.' >&2; return +fi + ### SERVER CONFIGURATION # This is used in the Makefile to build and publish your server image. diff --git a/auth/ENVOY.sh b/auth/ENVOY.sh index 0d6170596..f3ef4c0da 100644 --- a/auth/ENVOY.sh +++ b/auth/ENVOY.sh @@ -19,6 +19,10 @@ # Configure an environment to run Registry clients with a local server through a local Envoy proxy. # +if ! [ -x "$(command -v gcloud)" ]; then + echo 'ERROR: This script requires the gcloud command. Please install it to continue.' >&2; return +fi + ### SERVER CONFIGURATION # These steps are needed to enable local calls to the Cloud Datastore API. diff --git a/auth/LOCAL.sh b/auth/LOCAL.sh index b01336d2d..f4d0abe05 100644 --- a/auth/LOCAL.sh +++ b/auth/LOCAL.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Copyright 2020 Google LLC. All Rights Reserved. # @@ -21,6 +21,11 @@ ### SERVER CONFIGURATION +if ! [ -x "$(command -v gcloud)" ]; then + echo 'WARNING: The gcloud command is not installed.' >&2 + echo ' Without it, we are unable to automatically set REGISTRY_PROJECT_IDENTIFIER.' >&2 + echo ' As a result, local registry-server processes will be unable to use the Cloud Datastore API.' >&2 +else # These steps are needed to enable local calls to the Cloud Datastore API. # This is required when the registry-server is run locally. @@ -29,6 +34,7 @@ # This assumes that the current gcloud project is the one where data is stored. export REGISTRY_PROJECT_IDENTIFIER=$(gcloud config list --format 'value(core.project)') +fi ### CLIENT CONFIGURATION diff --git a/gapic/README.md b/gapic/README.md new file mode 100644 index 000000000..260c6932e --- /dev/null +++ b/gapic/README.md @@ -0,0 +1,4 @@ +# gapic + +This directory contains a client library for the Registry API that is +automatically generated at build time. diff --git a/rpc/README.md b/rpc/README.md new file mode 100644 index 000000000..88765de95 --- /dev/null +++ b/rpc/README.md @@ -0,0 +1,4 @@ +# rpc + +This directory contains support code for the Registry API that is automatically +generated at build time.