├── requirements.txt ├── pubsub-sendmail.png ├── CONTRIBUTING.md ├── deploy-pubsub-sendmail.sh ├── main.py ├── README.md └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | flask==2.2.2 2 | google-cloud-error-reporting==1.1.1 3 | click==8.0 4 | -------------------------------------------------------------------------------- /pubsub-sendmail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleCloudPlatform/cloud-pubsub-sendmail/HEAD/pubsub-sendmail.png -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows [Google's Open Source Community 28 | Guidelines](https://opensource.google/conduct/). 29 | -------------------------------------------------------------------------------- /deploy-pubsub-sendmail.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2021 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an 'AS IS' BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # deploy-pubsub-sendmail 18 | # 19 | # This shell script deploys the pubsub_sendmail Google Cloud Function. 20 | # The Cloud Function receives a Cloud Pub/Sub event and sends 21 | # an email message. 22 | 23 | # Set these variables as appropriate: 24 | 25 | # MAIL_FROM = Email address of the sender (e.g. user@example.com). 26 | # MAIL_TO = Email address of the recipient (e.g. user@example.com). 27 | # MAIL_SERVER = Host:tcpport of email server (e.g. mail.example.com:587). 28 | # If unspecified, the default port is 25. 29 | # MAIL_SUBJECT = Email subject (e.g. "Pub/Sub Email"). 30 | # MAIL_FORCE_TLS = Force TLS encryption. TRUE | FALSE. 31 | # If not TRUE, encryption is opportunistic. 32 | # MAIL_LOCAL_HOST = Domain to use for EHLO/HELO command. 33 | # This is needed because Cloud Functions have no hostname. 34 | # MAIL_DEBUG = Enable debug info in Cloud Functions log: TRUE | FALSE. 35 | # If unspecified or not TRUE, debugging is disabled. 36 | # FN_PUBSUB_TOPIC = Cloud Function Pub/Sub topic. 37 | # FN_REGION = Region to deploy the function. 38 | # FN_SOURCE_DIR = Source directory for the function code. 39 | # FN_SA = Service Account to run the function. 40 | # FN_VPC_CONN = VPC Connector to use. 41 | # 42 | # If you are a Google Workspace customer and want to use the Google SMTP relay 43 | # here are two options: 44 | # 45 | # If you configure the relay to require TLS, set these two variables: 46 | # 47 | # MAIL_SERVER="smtp-relay.gmail.com:465" 48 | # MAIL_FORCE_TLS="TRUE" 49 | # 50 | # If you configure the relay to not require TLS, set these two variables: 51 | # 52 | # MAIL_SERVER="smtp-relay.gmail.com:587" 53 | # MAIL_FORCE_TLS="FALSE" 54 | 55 | # Enable the services in case they are not enabled 56 | gcloud services enable cloudbuild.googleapis.com cloudfunctions.googleapis.com 57 | 58 | MAIL_FROM="fromuser@example.com" 59 | MAIL_TO="touser@example.com" 60 | # MAIL_SERVER="smtp-relay.gmail.com:465" 61 | MAIL_SUBJECT="Cloud Pub/Sub Email" 62 | MAIL_LOCAL_HOST="pubsub-sendmail-nat.example.com" 63 | MAIL_DEBUG="TRUE" 64 | MAIL_SERVER="smtp-relay.gmail.com:587" 65 | MAIL_FORCE_TLS="FALSE" 66 | FN_PUBSUB_TOPIC="pubsub-sendmail" 67 | FN_REGION="us-central1" 68 | FN_SOURCE_DIR="./" 69 | FN_SA="pubsub-sendmail@PROJECTID.iam.gserviceaccount.com" 70 | FN_VPC_CONN="pubsub-sendmail" 71 | 72 | ENVVARS_FILE=/tmp/send_mail_envvars.$$ 73 | 74 | cat <$ENVVARS_FILE 75 | MAIL_FROM: "$MAIL_FROM" 76 | MAIL_TO: "$MAIL_TO" 77 | MAIL_SERVER: "$MAIL_SERVER" 78 | MAIL_SUBJECT: "$MAIL_SUBJECT" 79 | MAIL_LOCAL_HOST: "$MAIL_LOCAL_HOST" 80 | MAIL_FORCE_TLS: "$MAIL_FORCE_TLS" 81 | MAIL_DEBUG: "$MAIL_DEBUG" 82 | EOF 83 | 84 | echo 85 | echo Here is the environment variables file: 86 | echo 87 | cat $ENVVARS_FILE 88 | echo 89 | 90 | if [ -z "$FN_VPC_CONN" ] 91 | then 92 | gcloud functions deploy pubsub_sendmail \ 93 | --region $FN_REGION \ 94 | --runtime python38 \ 95 | --trigger-topic $FN_PUBSUB_TOPIC \ 96 | --service-account "$FN_SA" \ 97 | --env-vars-file $ENVVARS_FILE \ 98 | --source $FN_SOURCE_DIR 99 | else 100 | gcloud functions deploy pubsub_sendmail \ 101 | --region $FN_REGION \ 102 | --runtime python38 \ 103 | --trigger-topic $FN_PUBSUB_TOPIC \ 104 | --service-account "$FN_SA" \ 105 | --env-vars-file $ENVVARS_FILE \ 106 | --vpc-connector $FN_VPC_CONN \ 107 | --egress-settings all \ 108 | --source $FN_SOURCE_DIR 109 | fi 110 | 111 | rm $ENVVARS_FILE 112 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # pubsub_sendmail 16 | # 17 | # This is a Google Cloud Function which sends a Google Cloud Pub/Sub event 18 | # and forwards the event to an e-mail address. 19 | # 20 | # The following environment variables must be defined in the function deployment: 21 | # 22 | # MAIL_FROM = Email address of the sender (e.g. user@example.com). 23 | # MAIL_TO = Email address of the recipient (e.g. user@example.com). 24 | # MAIL_SERVER = Host:tcpport of email server (e.g. mail.example.com:587). 25 | # If unspecified, the default port is 25. 26 | # MAIL_SUBJECT = Email subject (e.g. "Pub/Sub Email"). 27 | # MAIL_FORCE_TLS = Force TLS encryption. TRUE | FALSE. 28 | # If not TRUE, encryption is opportunistic. 29 | # MAIL_LOCAL_HOST = Domain to use for EHLO/HELO command. 30 | # This is needed because Cloud Functions have no hostname. 31 | # MAIL_DEBUG = Generate debug info in Cloud Functions log: TRUE | FALSE. 32 | # If unspecified or not TRUE, debugging is disabled. 33 | # 34 | # (1) You may need to customize this based on the configuration of your 35 | # mail relay (for example, to support mandatory TLS, authentication, etc.). 36 | # (2) If you want your mail to come from a static IP address use a 37 | # VPC connector with a static NAT. 38 | 39 | def pubsub_sendmail(event, context): 40 | import base64 41 | import os 42 | import smtplib 43 | from email.message import EmailMessage 44 | 45 | # Log the message ID and timestamp. 46 | 47 | print('BEGIN messageId {} published at {}'.format(context.event_id, context.timestamp)) 48 | 49 | # Fetch environment variables and set to '' if they are not present. 50 | # Remove leading and trailing spaces. 51 | 52 | mailFrom = os.environ.get('MAIL_FROM', '').strip() 53 | mailTo = os.environ.get('MAIL_TO', '').strip() 54 | mailSubject = os.environ.get('MAIL_SUBJECT', '').strip() 55 | mailServer = os.environ.get('MAIL_SERVER', '').strip() 56 | mailLocalHost = os.environ.get('MAIL_LOCAL_HOST', '').strip() 57 | mailForceTls = os.environ.get('MAIL_FORCE_TLS', '').strip() 58 | mailDebug = os.environ.get('MAIL_DEBUG', '').strip() 59 | 60 | # Fetch the pub/sub message and set to '' if not present. 61 | 62 | if 'data' in event: 63 | mailMessageBody = base64.b64decode(event['data']).decode('utf-8') 64 | else: 65 | mailMessageBody = '' 66 | 67 | debugFlag = mailDebug == "TRUE" 68 | forceTlsFlag = mailForceTls == "TRUE" 69 | 70 | # Log all of the environment variables. 71 | 72 | if debugFlag: 73 | print('Mail from: {}'.format(mailFrom)) 74 | print('Mail to: {}'.format(mailTo)) 75 | print('Mail subject: {}'.format(mailSubject)) 76 | print('Mail server: {}'.format(mailServer)) 77 | print('Mail local host: {}'.format(mailLocalHost)) 78 | print('Mail force TLS: {}'.format(mailForceTls)) 79 | print('Mail message body: {}'.format(mailMessageBody)) 80 | 81 | # Create EmailMessage object for eventual transmission. 82 | 83 | outboundMessage = EmailMessage() 84 | outboundMessage.set_content(mailMessageBody) 85 | outboundMessage['Subject'] = mailSubject 86 | outboundMessage['From'] = mailFrom 87 | outboundMessage['To'] = mailTo 88 | 89 | # You may need to customize this flow to support your mail relay configuration. 90 | # Examples may include authentication, encryption, etc. 91 | 92 | if forceTlsFlag: 93 | smtpServer = smtplib.SMTP_SSL(host=mailServer, local_hostname=mailLocalHost) 94 | else: 95 | smtpServer = smtplib.SMTP(host=mailServer, local_hostname=mailLocalHost) 96 | 97 | if debugFlag: 98 | smtpServer.set_debuglevel(2) 99 | 100 | if (not forceTlsFlag) and smtpServer.has_extn('STARTTLS'): 101 | smtpServer.starttls() 102 | smtpServer.ehlo() 103 | 104 | smtpServer.send_message(outboundMessage) 105 | smtpServer.quit() 106 | 107 | # Log end of Cloud Function. 108 | 109 | print('END messageId {}'.format(context.event_id)) 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pubsub_sendmail - Send emails from Google Cloud Pub/Sub events 2 | ## Overview 3 | 4 | pubsub_sendmail is a Google [Cloud Function](https://cloud.google.com/functions) that can be triggered by a Google Cloud [Pub/Sub](https://cloud.google.com/pubsub) which then sends an email using Python [smtplib](https://docs.python.org/3/library/smtplib.html) to the desired recipient. You can also have the email come from a static IP address by using a [VPC Access Connector](https://cloud.google.com/vpc/docs/configure-serverless-vpc-access) along with [Cloud NAT](https://cloud.google.com/nat/docs/overview). 5 | 6 | pubsub_sendmail is configured using environment variables in the deployment shell script. These environment variables are described in a later section of this document. Revisions or bug fixes are welcome. You can also of course adapt the code to any use cases that are not covered. 7 | 8 | SMTP is very flexible but that flexibility can be challenging to deal with from a configuration perspective. The best way to deal with problems in the configuration is to do incremental testing and look at the [Cloud Functions Logs](https://cloud.google.com/functions/docs/monitoring/logging). 9 | 10 | ## Why was this written? 11 | 12 | Google Cloud normally recommends using tools such as [SendGrid to send emails from Cloud Functions triggered by Cloud Pub/Sub](https://cloud.google.com/security-command-center/docs/how-to-enable-real-time-notifications). Services such as SendGrid offer many production level features at various service tiers and are supported by the service vendors. If your mail volume is relatively low but you need send email from a static IP, using a native Cloud Function like pubsub_sendmail is another option. The tradeoff is that you must implement and support the Cloud Function. The pubsub_sendmail function supports the use of a static IP using the VPC Access Connector along with Cloud NAT. 13 | 14 | ## Diagram 15 | 16 | Here is a diagram of how a message issued from Cloud Pub/Sub would travel through the Cloud Function and then generate an e-mail. 17 | 18 | ![pubsub-sendmail diagram](https://github.com/GoogleCloudPlatform/cloud-pubsub-sendmail/blob/main/pubsub-sendmail.png) 19 | 20 | ## Concepts 21 | 22 | ### Encryption - Forced, Opportunistic, or None 23 | 24 | It is important to understand the various modes email encryption modes. With *forced encryption* (also called *implicit*), the entire session with the mail server is encrypted from start to end. Nothing is in plaintext. With *opportunistic encryption* (also called *explicit*) the session begins in plaintext but is subsequently elevated to encrypted by sending a STARTTLS command. Said differently, if encryption is *allowed* (but not *required*) by the server it is *opportunistic*. If it is required by the server it is *forced*. When no encryption is supported, the entire session is in plaintext (highly unlikely). 25 | 26 | ## Costs 27 | 28 | You are responsible for the costs associated with this implementation. The costs include but are not limited to the following: 29 | 30 | 1. the Cloud Function 31 | 2. the VPC Access Connector 32 | 3. Cloud NAT (if you need a static IP) 33 | 4. Data egress charges 34 | 35 | ## Installation 36 | 37 | Here are the high level steps that are needed to deploy pubsub_sendmail. This will be expanded over time. 38 | 39 | 1. Identify the following information regarding the mail server. The mail server provider may not have all of this information up front but gather what you can. 40 | 41 | * Server name 42 | 43 | * Server port? 44 | 45 | >Note: Google Cloud does not allow egress on port 25. If you are told to use this port, there is often an alternative, typically 587. 46 | 47 | * Encryption mode (Forced, Opportunistic, none)? 48 | 49 | * Do you need to register an IP address with the mail server or the network firewall protecting it? 50 | 51 | * Does the server need to do a DNS lookup on the hostname provided during initialization (EHLO, HELO)? 52 | 53 | 2. Identify the additional Google Cloud information. 54 | 55 | * In which [region](https://cloud.google.com/functions/docs/locations) do you want to deploy the function? 56 | 57 | 3. Gather additional information regarding the transmission of e-mail. If you want to determine this information dynamically you will need to modify the code to gather this information. 58 | 59 | * What email address should be used for the sender? 60 | 61 | * What email address should be used for the recipient? 62 | 63 | * What subject should be used for the message? 64 | 65 | * What fully qualified domain name ("FQDN") do you want to pass to the mail server as the hostname of pubsub_sendmail? This is referred to as the *local host*. This is for the EHLO/HELO dialog. You can try leaving it blank and see what your mail server does with the default generated by smtplib. Keep in mind that the Cloud Function will have no knowledge of the sender's domain unless you choose to assign this value. 66 | 67 | 68 | 4. If you want the egress traffic from pubsub_sendmail to come from a static IP: 69 | 70 | * Select an existing VPC or create a new VPC. 71 | 72 | * Create a /28 subnet in the VPC in the desired region for the VPC Access Connector. 73 | 74 | * Create a VPC Access Conncetor using the /28 you created. 75 | 76 | * Create a Cloud NAT for the VPC if one does not already exist. The Cloud NAT must be configured to receive traffic sent through the VPC Access Connnector subnet. Assign a static IP address to the Cloud NAT. 77 | 78 | * If the mail server does a DNS lookup of the *local host* value, you may need to assign a DNS A record to it. Try the deployment without creating an A record first. 79 | 80 | 5. Create a service account for the Cloud Function. The service account itself needs no specific permissions but will be an alternative to the default service account whose permissions are not needed. When you deploy pubsub_sendmail, you must have the Service Account User permission on this service account so you can "act as" the service account during the deploment. 81 | 82 | 6. Clone or download this repository. 83 | 84 | 7. Edit the deploy-pubsub-sendmail file and make the changes below to the environment variables. 85 | 86 | * MAIL_FROM - Set this to the email address of the sender (e.g. user@example.com). 87 | 88 | * MAIL_TO - Set this to the email address of the recipient (e.g. user@example.com). 89 | 90 | * MAIL_SERVER - Set this to the host and TCP port of email server (e.g. mail.example.com:587). If the port number is not specified and MAIL_FORCE_TLS is set to TRUE then the port defaults to 465. Otherwise the port defaults to 25. Note that Google Cloud blocks egress to port 25. Port 587 is often used as an alternative for opportunistic or no encryption. 91 | 92 | * MAIL_SUBJECT - Set this to the email subject (e.g. "Pub/Sub Email"). 93 | 94 | * MAIL_FORCE_TLS - Set this to TRUE for forced (also known as implicit) encryption. If unset or set to any other value then encryption is opportunistic (also known as explicit). 95 | 96 | * MAIL_LOCAL_HOST - Set this to the fully qualified domain to use for the EHLO/HELO SMTP command. A Cloud Function does not have a host name that is associated with your mail ddomain. The mail server may be fine without that. The smtplib functions will generate a default hostname. You can try this default if you wish but it may not behave as expected. 97 | 98 | * MAIL_DEBUG - Set this to TRUE to generate additional debugging info in the Cloud Functions log. If unset or set to anything other than TRUE then no additional debugging info is generated. 99 | 100 | * FN_PUBSUB_TOPIC - Set this to the Cloud Function Pub/Sub from which pubsub_sendmail will receive events. 101 | 102 | * FN_REGION - Set this to the Google Cloud region in which to deploy the function. Note that Cloud Functions must be supported in this region. 103 | 104 | * FN_SOURCE_DIR - Set this to the source directory for the function code, the directory that contains the main.py file. 105 | 106 | * FN_SA - Set this to the service account to use for the pubsub_sendmail Cloud Function. Use the complete email address of the service account. 107 | 108 | * FN_VPC_CONN - Set this to the VPC Connector to use. If not set, then egress traffic from pubsub_sendmail will go out over the internet directly. 109 | 110 | 8. Deploy the pubsub_sendmail function. 111 | 112 | ``` 113 | chmod 755 deploy-pubsub-sendmail 114 | ./deploy-pubsub-sendmail.sh 115 | ``` 116 | ## Testing the Cloud Function 117 | 118 | 1. To test pubsub_sendmail, just publish a message to your topic using this command (substituting the name of your Pub/Sub topic for $FN_PUBSUB_TOPIC): 119 | 120 | ``` 121 | gcloud pubsub topics publish $FN_PUBSUB_TOPIC --message "This is a test" 122 | ``` 123 | 124 | ## Common connection problems and ways to address them 125 | 126 | 1. When you are deploying pubsub_sendmail to a new server, set MAIL_DEBUG to TRUE to put additional information into the logs. 127 | 128 | > Note: The error messages in the logs are not always accurate. 129 | 130 | 2. Many connection problems arise from a mismatch between the client (pubsub_senndmail in this case) and the mail server/port which is specified in the MAIL_SERVER environment variable. Make sure you know the correct server name, port, and encryption mode (forced, opportunistic, or none at all). 131 | 132 | 3. Remember that Google Cloud blocks outbound connections to port 25 - the default port for opportunistic connections. For opportunistic encryption connections, you will likely use port 587. You must specifically include this port number in MAIL_SERVER (e.g. mail.example.com:587). 133 | 134 | 4. If a message in the Cloud Function logs says something like "Wrong Encryption Mode," it usually means that there is a conflict between the mail server and pubsub_sendmail. If the server is supposed to be enforcing encryption, try connecting to it with telnet on the desitred port (assuming your IP is not blocked) and see if any plaintext message appears. If plaintext appears (e.g. "Hello...."), then encryption s likely opportunistic on that port. The server may provide forced encryption at a different server or port. If encryption is required, make sure you set MAIL_FORCE_TLS to TRUE. If you need to use a port other than 25, you must specify it in MAIL_SERVER. 135 | 136 | 5. If you want the emails to come from a static IP address, you must set the "FN_VPC_CONN" to the name of the VPC connector to use and also assign a Cloud NAT to the VPC and attach a static IP address to the Cloud NAT. 137 | 138 | 6. If a message in the Cloud Function logs says something like "IP not registered," it often (but not always) means that pubsub_sendmail is not connecting on a registered IP address. If a static IP is required, make sure a static IP address is configured on the Cloud NAT and that it has been registered with the mail server. This error message may also mean that the encryption mode is incorrect. 139 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Google LLC 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------