notifications

command module
v0.0.0-...-2dc3ea6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2014 License: Apache-2.0 Imports: 1 Imported by: 0

README

Notifications

A notifications component that parts of CF can use to send email to end users

UAA Client

Notifications itself needs the following UAA client in order to retrieve arbitrary users' email addresses and check the members of arbitrary spaces:

properties:
  uaa:
    clients:
      notifications:
        secret: my-secret
        authorities: cloud_controller.admin,scim.read
        authorized-grant-types: client_credentials
Client Configurations
Send Notifications

The following client configurations are needed for sending messages to individual users, users in a specific space and arbitrary email addresses.

To send non-critical notifications, notifications.write scope is required. Sending critical notifications requires critical_notifications.write scope. To send notifications to an arbitrary email address requires emails.write scope.

notifications-client-name:
  scope: uaa.none
  resource_ids: none
  authorized_grant_types: client_credentials
  authorities: notifications.write critical_notifications.write emails.write
  autoapprove:
View and Edit User Preferences

To view and edit a user's preferences for receiving non-critical notifications, a client will need to be configured with notification_preferences.read scope and notification_preferences.write scope.

A client with notification_preferences.admin scope has the ability to retrieve an arbitrary user's preferences.

notifications-client-name:
  scope: notification_preferences.read notification_preferences.write openid
  resource_ids: none
  authorized_grant_types: authorization_code client_credentials refresh_token
  redirect_uri: http://example.com/sessions/create
  authorities: notification_preferences.admin
  autoapprove: 

If you are unfamiliar with UAA consult the UAA token overview.

##Configuring Environment Variables

Variable Description Default
CC_HOST* Cloud Controller Host <none>
CORS_ORIGIN Value to use for CORS Origin Header *
DB_LOGGING_ENABLED Logs DB interactions when set to true false
DATABASE_URL* URL to your Database <none>
ENCRYPTION_KEY* Key used to encrypt the unsubscribe ID <none>
GOBBLE_MIGRATIONS_DIR* Location of the gobble migrations directory <none>
PORT Port that application will bind to 3000
ROOT_PATH* Root path of your application <none>
SMTP_LOGGING_ENABLED Logs SMTP interactions when set to true <none>
SMTP_HOST* SMTP Host <none>
SMTP_PASS SMTP Password <none>
SMTP_PORT* SMTP Port <none>
SMTP_TLS Use TLS when talking to SMTP server true
SMTP_USER SMTP Username <none>
SENDER* Emails are sent from this address <none>
TEST_MODE Run in test mode false
UAA_CLIENT_ID* The UAA client ID <none>
UAA_CLIENT_SECRET* The UAA client secret <none>
UAA_HOST* The UAA Host <none>
VERIFY_SSL Verifies SSL true

* required

Posting to a notifications endpoint

Notifications currently supports two different types of messages. Messages to individual users and messages to spaces.

Users are messaged via the /users/id endpoint and spaces are messaged via /spaces/id endpoint.

Both endpoints expect a json body to be posted with following keys:

Key Description
kind_id* a key to identify the type of email to be sent
text** the text version of the email
html** the html version of the email
kind_description a description of the kind_id
subject the text of the subject
reply_to the Reply-To address for the email
source_description a description of the sender

* required

** either text or html have to be set, not both

Further API Documentation

Configuring Email Templates

The default templates are located in ./templates. The templates directory should look similar to this:

overrides/
user_body.text
user_body.html
space_body.text
space_body.html
organization_body.text
organization_body.html
email_body.text
email_body.html
subject.missing
subject.provided

When emailing a single user, user_body.html and user_body.text are used as templates in the email body for the html and plaintext, respectively. When emailing a space, space_body.html and space_body.text are used as templates in the email body for the html and plaintext, respectively. When emailing an organization, organization_body.html and organization_body.text are used as templates in the email body for the html and plaintext, respectively.

When the subject is provided, the default subject template is found in subject.provided, while subject.missing is used when the email subject is not provided.

When using the /emails endpoint, email_body.html and email_body.text are used as templates in the email body for the html and plaintext, respectively.

The files located in the templates directory are defaults and will be used if there is no override of the same name.

Overriding default templates

There are three types of overrides.

Type Effect
global applies to any email sent, has least precedence
client specific applies to any email sent by a client, higher precedence than global
client and kind specific applies to any email sent by a client with the kind_id, has highest precedence

All types of overrides have access to the same variables described in global overrides. The only difference is which email types they are applied to.

global overrides

Any file that exists in ./templates can be overriden by placing a file of the same name in ./templates/overrides.

The templates are go templates. The templates have access to the following variables:

Variable Description
KindDescription Pulled from json posted to endpoint under: kind_description, falls back to kind if not set
From Which account is in the from field of the email
ReplyTo The address is in the reply to field of the email
To The address the email is going to
Subject Pulled from json posted to endpoint under: subject
Text Pulled from json posted to endpoint under: text
HTML Pulled from json posted to endpoint under: html
SourceDescription Pulled from json posted to endpoint under: source_description, falls back to ClientID if not set
ClientID The access token of the user requesting the email be sent
MessageID Unique id for the email being sent
UserGUID Unique id for the user the email is sent to
Organization The name of the organization of the space (used for emails to spaces)
OrganizationGUID The guid of the organization of the space (used for emails to spaces)
Space The name of the space (used for emails to spaces)
SpaceGUID The guid of the space (used for emails to spaces)
UnsubscribeID The id for unsubscribing a user from a notification. See here for details
Example: Overriding space_body.text

To override the plain text template in the email body, write the following in ./templates/overrides/space_body.text:

You are receiving this electronic mail because you are a member of {{.Space}}

All apps in {{.Space}} have had an emergency of type {{.KindDescription}}
overriding by clientID

To override a template for a client with id banana. You would place a file in the ./templates/overrides directory with the following name scheme:

clientID.templateName.templateExtension

So to override the subject.missing the file name would be:

banana.subject.missing

This override would only be applied to emails sent by the client banana.

overriding by clientID and kind_id

To override a template for client banana with the kind_id damage you would place a file in the ./templates/overrides directory with the following name scheme:

clientID.kind_id.templateName.templateExtension

So to override the user_body.text template the file name would be:

banana.damage.user_body.text

This override only applies to requests that match both the clientId and the kind. This has the most precedence and overrides all other overrides.

Further Template API Documentation

UnsubscribeID

AES Encryption is used to encrypt a token value for unsubscribing a user from a notification. The format of the token is the user_guid|client_id|kind_id. The key used to instantiate a cipher is a 16 byte MD5 sum of the text given to the ENCRYPTION_KEY environment variable.

Encrypting:

  1. Concatenate user GUID, client ID, and kind ID into a single string, delimited by a | character.
  2. Base64 encode the concatenated string.
  3. Encrypt the encoded text using AES cipher in CFB mode.
  4. Base64 encode the cipher text.

Decrypting:

  1. Base64 decode the unsubscribe token.
  2. Decrypt the decoded text using AES cipher in CFB mode.
  3. Base64 decode the decrypted text.
  4. Split the text at the | characters.
Development
Running locally

The application can be run locally by executing the ./bin/run script. This script will look for a file called ./bin/env/development to load environment variables. Setting the TEST_MODE env var to true will disable the requirement for a running SMTP server.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Godeps
_workspace/src/bitbucket.org/chrj/smtpd
Package smtpd implements an SMTP server with support for STARTTLS, authentication (PLAIN/LOGIN), XCLIENT and optional restrictions on the different stages of the SMTP session.
Package smtpd implements an SMTP server with support for STARTTLS, authentication (PLAIN/LOGIN), XCLIENT and optional restrictions on the different stages of the SMTP session.
_workspace/src/code.google.com/p/cascadia
The cascadia package is an implementation of CSS selectors.
The cascadia package is an implementation of CSS selectors.
_workspace/src/code.google.com/p/go.net/html
Package html implements an HTML5-compliant tokenizer and parser.
Package html implements an HTML5-compliant tokenizer and parser.
_workspace/src/code.google.com/p/go.net/html/atom
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id".
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id".
_workspace/src/code.google.com/p/go.net/html/charset
Package charset provides common text encodings for HTML documents.
Package charset provides common text encodings for HTML documents.
_workspace/src/github.com/PuerkitoBio/goquery
Package goquery implements features similar to jQuery, including the chainable syntax, to manipulate and query an HTML document.
Package goquery implements features similar to jQuery, including the chainable syntax, to manipulate and query an HTML document.
_workspace/src/github.com/coopernurse/gorp
Package gorp provides a simple way to marshal Go structs to and from SQL databases.
Package gorp provides a simple way to marshal Go structs to and from SQL databases.
_workspace/src/github.com/dgrijalva/jwt-go
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html
A useful example app.
_workspace/src/github.com/go-sql-driver/mysql
Go MySQL Driver - A MySQL-Driver for Go's database/sql package
Go MySQL Driver - A MySQL-Driver for Go's database/sql package
_workspace/src/github.com/gorilla/context
Package gorilla/context stores values shared during a request lifetime.
Package gorilla/context stores values shared during a request lifetime.
_workspace/src/github.com/gorilla/mux
Package gorilla/mux implements a request router and dispatcher.
Package gorilla/mux implements a request router and dispatcher.
_workspace/src/github.com/kylelemons/go-gypsy/yaml
Gypsy is a simplified YAML parser written in Go.
Gypsy is a simplified YAML parser written in Go.
_workspace/src/github.com/lib/pq
Package pq is a pure Go Postgres driver for the database/sql package.
Package pq is a pure Go Postgres driver for the database/sql package.
_workspace/src/github.com/lib/pq/listen_example
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
_workspace/src/github.com/lib/pq/oid
Package oid contains OID constants as defined by the Postgres server.
Package oid contains OID constants as defined by the Postgres server.
_workspace/src/github.com/nu7hatch/gouuid
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122.
This package provides immutable UUID structs and the functions NewV3, NewV4, NewV5 and Parse() for generating versions 3, 4 and 5 UUIDs as specified in RFC 4122.
_workspace/src/github.com/onsi/ginkgo
Ginkgo is a BDD-style testing framework for Golang
Ginkgo is a BDD-style testing framework for Golang
_workspace/src/github.com/onsi/ginkgo/config
Ginkgo accepts a number of configuration options.
Ginkgo accepts a number of configuration options.
The Ginkgo CLI
_workspace/src/github.com/onsi/ginkgo/internal/remote
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
Ginkgo's Default Reporter
_workspace/src/github.com/onsi/gomega
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
_workspace/src/github.com/onsi/gomega/format
Gomega's format package pretty-prints objects.
Gomega's format package pretty-prints objects.
_workspace/src/github.com/onsi/gomega/gbytes
Package gbytes provides a buffer that supports incrementally detecting input.
Package gbytes provides a buffer that supports incrementally detecting input.
_workspace/src/github.com/onsi/gomega/gexec
Package gexec provides support for testing external processes.
Package gexec provides support for testing external processes.
_workspace/src/github.com/onsi/gomega/ghttp
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
Gomega matchers
_workspace/src/github.com/pivotal-cf/uaa-sso-golang/uaa
Package to interact with Cloudfoundry UAA server.
Package to interact with Cloudfoundry UAA server.
_workspace/src/github.com/pivotal-golang/conceal
Package conceal provides the ability to encrypt/decrypt byte slices using aes encryption.
Package conceal provides the ability to encrypt/decrypt byte slices using aes encryption.
_workspace/src/github.com/rubenv/sql-migrate
SQL Schema migration tool for Go.
SQL Schema migration tool for Go.
_workspace/src/github.com/ziutek/mymysql/godrv
MySQL driver for Go database/sql package
MySQL driver for Go database/sql package
_workspace/src/github.com/ziutek/mymysql/mysql
MySQL Client API written entirely in Go without any external dependences.
MySQL Client API written entirely in Go without any external dependences.
_workspace/src/github.com/ziutek/mymysql/native
Thread unsafe engine for MyMySQL
Thread unsafe engine for MyMySQL
acceptance
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL