Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruby: add AUTHENTICATION.md template #225

Merged
merged 5 commits into from
Apr 19, 2019

Conversation

quartzmo
Copy link
Member

@quartzmo quartzmo commented Apr 17, 2019

Add AUTHENTICATION.md for all GAPIC packages in googleapis/google-cloud-ruby.

[refs googleapis/google-cloud-ruby#2933]

Example usage in a google-cloud-ruby package:

diff --git a/google-cloud-bigquery-data_transfer/synth.py b/google-cloud-bigquery-data_transfer/synth.py
index 15fd8f222..3f1df1cd9 100644
--- a/google-cloud-bigquery-data_transfer/synth.py
+++ b/google-cloud-bigquery-data_transfer/synth.py
@@ -38,6 +38,17 @@ s.copy(v1_library / '.gitignore')
 s.copy(v1_library / '.yardopts')
 s.copy(v1_library / 'google-cloud-bigquery-data_transfer.gemspec', merge=ruby.merge_gemspec)
 
+# Copy common templates
+common_templates = gcp.CommonTemplates()
+metadata = {
+    "package_name": "google-cloud-bigquery-data_transfer",
+    "module_name": "Bigquery::DataTransfer",
+    "module_name_credentials": "Bigquery::DataTransfer::V1",
+    "constant_name": "DATA_TRANSFER",
+}
+templates = common_templates.ruby_library(metadata=metadata)
+s.copy(templates)
+
 # PERMANENT: Use custom credentials env variable names
 s.replace(
     'lib/google/cloud/bigquery/data_transfer/v1/credentials.rb',

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 17, 2019
@quartzmo
Copy link
Member Author

quartzmo commented Apr 17, 2019

To demo this template in google-cloud-ruby:

  1. Checkout the branch for this PR to synthtool.
  2. pip install -e ./synthtool
  3. cd google-cloud-ruby/google-cloud-asset
  4. python -m synthtool

@blowmage
Copy link

Is this the direction we want to take? Do we want the templates to be part of this tool? Or should the template be somewhere on the repo?

@TheRoyalTnetennba
Copy link
Contributor

Should this open with a best-practices quickstart?

@quartzmo
Copy link
Member Author

@TheRoyalTnetennba Is there one available that I can drop in? Or adapt? (If so please link)

@TheRoyalTnetennba
Copy link
Contributor

Is this the direction we want to take? Do we want the templates to be part of this tool? Or should the template be somewhere on the repo?

I have mixed feelings about this, but I think this approach works well for both split/monorepo, whereas if we ERB'd it in our own repo, we'd end up having our own separate tool in the event of a repo split (at least as I'm imaging how it would work).

@blowmage
Copy link

I definitely think generating this file in GAPIC is preferred. I guess my question is if putting the template in this tool is acceptable for the short term.

@TheRoyalTnetennba
Copy link
Contributor

TheRoyalTnetennba commented Apr 17, 2019

@quartzmo I don't know of one. I think inserting some Overview/Quickstart like the following just above Project and Credential Lookup would be nice for people just looking for a quick how-to:

Quickstart

  1. Create and download a service account
  2. Set the environment variable: export {{ metadata["constant_name"] }}_CREDENTIALS=/path/to/json
  3. Initialize client:
require "{{ metadata["package_name"].replace("-", "/") }}"

client = Google::Cloud::{{ metadata["module_name"] }}.new

@quartzmo
Copy link
Member Author

It sounds like this is the right home for the template for now, so I will update the template for @TheRoyalTnetennba's suggestions.

@quartzmo
Copy link
Member Author

I will also test synthtool's Ruby support for .repo-metadata.json, and update if needed.

Ensure that .repo-metadata.json is loaded if present.
@quartzmo
Copy link
Member Author

@TheRoyalTnetennba I updated this PR to use values from .repo-metadata.json. The values needed for the template are:

{
  "name": "google-cloud-bigquery-data_transfer",
  "name_pretty": "BigQuery Data Transfer Service",
  "module_name": "Bigquery::DataTransfer",
  "module_name_credentials": "Bigquery::DataTransfer::V1",
  "env_var_prefix": "DATA_TRANSFER"
}

This reduces the additions needed in synth.py to:

# Copy common templates
templates = gcp.CommonTemplates().ruby_library()
s.copy(templates)

Please give this comment a +1 if this sounds good to you.

@TheRoyalTnetennba
Copy link
Contributor

@quartzmo can you swap "name" for "distribution_name" throughout? The name field should should correspond to the pre-".google-apis.com" name in the googleapis/*.yaml i.e. https://github.com/googleapis/googleapis/blob/9a89b9443aa9d43ccecbd5200cb866e551bbd5e7/google/cloud/bigquery/datatransfer/datatransfer.yaml#L3 . Whereas distribution_name should be just whatever appears after gem install

Change 'name' to 'distribution_name'.
@quartzmo
Copy link
Member Author

@TheRoyalTnetennba Done. The keys needed in .repo-metadata.json now look like this:

{
  "distribution_name": "google-cloud-bigquery-data_transfer",
  "module_name": "Bigquery::DataTransfer",
  "module_name_credentials": "Bigquery::DataTransfer::V1",
  "env_var_prefix": "DATA_TRANSFER"
}

Add Quickstart section and anchor links.
@quartzmo
Copy link
Member Author

@TheRoyalTnetennba Do you know who should approve this PR for merging?

@quartzmo
Copy link
Member Author

@TheRoyalTnetennba I'll merge when you approve.

Copy link
Contributor

@TheRoyalTnetennba TheRoyalTnetennba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome

@quartzmo quartzmo self-assigned this Apr 19, 2019
@quartzmo quartzmo merged commit 50ba7c9 into googleapis:master Apr 19, 2019
@quartzmo quartzmo deleted the ruby-templates branch April 19, 2019 18:52
@quartzmo
Copy link
Member Author

When can we expect this addition to be released?

@busunkim96
Copy link
Contributor

@quartzmo Autosynth runs the synthtool at master, so a new release shouldn't be necessary. The synth.py scripts just need to be updated to copy over the templates.

templates = common_templates.ruby_library(metadata=metadata)
s.copy(templates)

@quartzmo
Copy link
Member Author

@busunkim96 Great, thanks! I'll open a PR in google-cloud-ruby to update the synth.py scripts and add the .repo-metadata.json files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants