bindings

module
v0.0.0-...-c9b6943 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: Apache-2.0

README

Knative-style Bindings

This repository contains a collection of Knative-style Bindings for accessing various services. Each of the bindings contained in this repository generally has two key parts:

  1. A Binding CRD that will augment the runtime contract of the Binding subject in some way.

  2. A small client library for consuming the runtime conract alteration to bootstrap and API client for the service being bound.

GithubBinding

The GithubBinding is intended to facilitate the consumption of the GitHub API. It has the following form:

apiVersion: bindings.mattmoor.dev/v1alpha1
kind: GithubBinding
metadata:
  name: foo-binding
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    # Either name or selector may be specified.
    selector:
      matchLabels:
        foo: bar

  secret:
    name: github-secret

The referenced secret should have a key named accessToken with the Github access token to be used with the Github API. It and any other keys are made available under /var/bindings/github/ (this is the runtime contract of the GithubBinding).

There is a helper library available to aid in the consumption of this runtime contract, which returns a github.com/google/go-github/github.Client:


import "github.com/mattmoor/bindings/pkg/github"


// Instantiate a Client from the access token made available by
// the GithubBinding.
client, err := github.New(ctx)
...

SlackBinding

The SlackBinding is intended to facilitate the consumption of the Slack API. It has the following form:

apiVersion: bindings.mattmoor.dev/v1alpha1
kind: SlackBinding
metadata:
  name: foo-binding
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    # Either name or selector may be specified.
    selector:
      matchLabels:
        foo: bar

  secret:
    name: slack-secret

The referenced secret should have a key named token with the Slack token to be used with the Slack API. It and any other keys are made available under /var/bindings/slack/ (this is the runtime contract of the SlackBinding).

There is a helper library available to aid in the consumption of this runtime contract, which returns a github.com/nlopes/slack.Client:


import "github.com/mattmoor/bindings/pkg/slack"


// Instantiate a Client from the token made available by
// the SlackBinding.
client, err := slack.New(ctx)
...

TwitterBinding

The TwitterBinding is intended to facilitate the consumption of the Twitter API. It has the following form:

apiVersion: bindings.mattmoor.dev/v1alpha1
kind: TwitterBinding
metadata:
  name: foo-binding
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    # Either name or selector may be specified.
    selector:
      matchLabels:
        foo: bar

  secret:
    name: twitter-secret

The referenced secret must have the keys: consumerKey, consumerSecretKey, which are the Twitter "Application" credentials. It may also optionally have the keys: accessToken, accessSecret in order to access the Twitter API using "User" credentials. These (and other) keys are made available under /var/bindings/twitter/ (this is the runtime contract of the TwitterBinding).

Depending on whether you want "Application" or "User" functionality (the latter requires additional secret keys), we provide a helper for each to instantiate a client compatible with github.com/dghubble/go-twitter:


import "github.com/mattmoor/bindings/pkg/twitter"


// Instantiate a Client that authenticates as an Application from
// the TwitterBinding.
client, err := twitter.NewAppClient(ctx)
...

// Instantiate a Client that authenticates as a User from
// the TwitterBinding.
client, err := twitter.NewUserClient(ctx)
...

GoogleCloudSQLBinding

The GoogleCloudSQLBinding is intended to facilitate the consumption of Google Cloud SQL instances via the proxy without manually configuring it. It has the following form:

apiVersion: bindings.mattmoor.dev/v1alpha1
kind: GoogleCloudSQLBinding
metadata:
  name: foo-binding
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    # Either name or selector may be specified.
    selector:
      matchLabels:
        foo: bar

  secret:
    name: cloudsql-secret

  instance: "project:region:name"

The referenced secret should have three parts:

  1. credentials.json: the JSON Key with the Cloud SQL "Client" IAM role.
  2. username: the database username to use when connecting.
  3. password: the database password to use when connecting.

These keys are made available under /var/bindings/cloudsql/secrets/, and a unix socket to the instance if made available under /var/bindings/cloudsql/sockets/.

There is a helper library available to facilitate consumption a database/sql.DB:


import "github.com/mattmoor/bindings/pkg/cloudsql"

// Open a connection to the named database.
db, err := cloudsql.Open(ctx, "DATABASE NAME")
...

SQLBinding

The SQLBinding is intended to facilitate the consumption of SQL instances.

apiVersion: bindings.mattmoor.dev/v1alpha1
kind: SQLBinding
metadata:
  name: foo-binding
spec:
  subject:
    apiVersion: apps/v1
    kind: Deployment
    # Either name or selector may be specified.
    selector:
      matchLabels:
        foo: bar

  secret:
    name: sql-secret

The referenced secret should have the connection string in it:

  1. connectionstr: in the format expected by the golang SQL package for your particular DB.

For example, to connect to postgres datbase called myfoodb you would specify postgres://username:password@ip:port/myfoodb

postgres://myuser:mysupersecretpassword@127.0.0.1:5432/myfoodb

This key is made available under /var/bindings/sql/ so there's a file called /var/bindings/sql/connectionstr with the connectionstr from the secret.

There is a helper library available to facilitate consumption a database/sql.DB:


import (
	"github.com/mattmoor/bindings/pkg/sql"

	// Also import your database driver, for example for postgres:
	_ "github.com/lib/pq"
)

// Open a connection to the named database.
db, err := cloudsql.Open(ctx, "postgres")
...

Directories

Path Synopsis
cmd
Package config is a placeholder that allows us to pull in config files via go mod vendor.
Package config is a placeholder that allows us to pull in config files via go mod vendor.
pkg
apis/bindings/v1alpha1
+k8s:deepcopy-gen=package +groupName=bindings.mattmoor.dev
+k8s:deepcopy-gen=package +groupName=bindings.mattmoor.dev
bindings
Package bindings holds constants and tools used by the various binding libraries.
Package bindings holds constants and tools used by the various binding libraries.
client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
client/clientset/versioned/typed/bindings/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/bindings/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.
cloudsql
Package cloudsql ...
Package cloudsql ...
github
Package github holds utilities for bootstrapping a Github API client from the metadata injected by the GithubBinding.
Package github holds utilities for bootstrapping a Github API client from the metadata injected by the GithubBinding.
slack
Package slack holds utilities for bootstrapping a Slack API client from the metadata injected by the SlackBinding.
Package slack holds utilities for bootstrapping a Slack API client from the metadata injected by the SlackBinding.
sql
twitter
Package twitter holds utilities for bootstrapping a Twitter API client from the metadata injected by the TwitterBinding.
Package twitter holds utilities for bootstrapping a Twitter API client from the metadata injected by the TwitterBinding.

Jump to

Keyboard shortcuts

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