Skip to content

Commit

Permalink
Merge pull request #13 from bennypowers/master
Browse files Browse the repository at this point in the history
aws-cognito and other changes
  • Loading branch information
gjdenhertog authored May 10, 2017
2 parents a08d488 + f718673 commit 85614eb
Show file tree
Hide file tree
Showing 14 changed files with 2,055 additions and 212 deletions.
32 changes: 32 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": ["eslint:recommended", "google"],
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"browser": true,
"es6": true
},
"plugins": [
"html"
],
"rules": {
"brace-style": "off",
"new-cap": ["error", { "capIsNewExceptions": ["Polymer"] }],
"no-var": "off",
"require-jsdoc": "off",
"max-len": ["warn", {
"ignoreTemplateLiterals": true,
"ignoreStrings": true,
"ignoreTrailingComments": true,
"ignoreComments": true,
"ignoreUrls": true
}]
},
"globals": {
"Polymer": true,
"PolymerElements": true,
"AWS": true,
"AWSCognito": true
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
wct.conf.js
npm-debug.log
bower_components
bower_components
node_modules
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2016 gjdenhertog
Portions Copyright (c) 2016 gjdenhertog
Portions Copyright (c) 2017 Benny Powers and Aaron Attar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
65 changes: 35 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,59 @@

## \<aws-app\>

The aws-app element is used for initializing and configuring your
connection to AWS.
`<aws-app>` initializes and configures your connection to AWS.
The app is permanently initialized once attached and should not be dynamically bound.

Example usage:

```html
<aws-app region="eu-west-1"></aws-app>
```

## \<aws-cognito\>

`<aws-cognito>` provides API wrapping and Polymer data binding for Amazon's
Cognito service.

Example usage:

```html
<aws-app region="us-east-1"></aws-app>
<aws-cognito id="cognito"
user-pool-id="us-east-1_XXXXXXXXX"
client-id="3XXXXXfea3nXXX0k3XXXXXX9p5"
identity-pool-id="us-east-1:XXXXXXXX-XXXX-XXXX-XXXX-XXXXAXXXXXXX"
></aws-cognito>
```

## \<aws-dynamodb\>

The `aws-dynamodb` element is an easy way to interact with a AWS DynamoDB
database. as an object and expose it to the Polymer databinding system.
`<aws-dynamodb>` provides an easy way to retrieve and update AWS DynamoDB data.

Example usage:

```html
<aws-app
region="eu-west-1">
</aws-app>
<aws-app region="eu-west-1"></aws-app>
<aws-dynamodb
table-name="notes"
data="{{data}}">
</aws-dynamodb>
data="{{data}}"
></aws-dynamodb>
```

This fetches the `data` object from the `notes` table in the DynamoDB
database and exposes it to the Polymer databinding system. Changes to
`data` will likewise be sent back and stored.

This fetches the `data` object from the `notes` table in the DynamoDB database
and exposes it to the Polymer data binding system. Changes to `data` are
likewise sent back and stored.

## \<aws-lambda\>

The `aws-lambda` element is an easy way to invoke a AWS Lambda function.
`<aws-lambda>` provides an easy way to invoke a AWS Lambda function.

Example usage:

```html
<aws-app
region="eu-west-1">
</aws-app>
<aws-lambda
id="transformNotes"
<aws-app region="eu-west-1"></aws-app>
<aws-lambda id="transformNotes"
function-name="transformNotes"
on-response="handleResponse">
</aws-lambda>
```

The `aws-app` element initializes `AWS` in `aws-lambda`.

JavaScript invoke calls can then be made to the `aws-lambda` object to invoke
the Lambda function.

```javascript
this.$.transformNotes.invoke();
on-response="handleResponse"
></aws-lambda>
```
57 changes: 31 additions & 26 deletions aws-app.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<!DOCTYPE html>

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../log-behavior/log-behavior.html">
<link rel="import" href="aws-sdk-script.html">

<!--
`aws-app`
Polymer Web Components for AWS
`<aws-app>` initializes and configures your connection to AWS.
It is permanently initialized once attached and should not be dynamically bound.
Example usage:
```html
<aws-app region="eu-west-1"></aws-app>
```
-->

<dom-module id="aws-app">
<script>
(function () {
(function() {
'use strict';

/**
* The aws-app element is used for initializing and configuring your
* connection to AWS. It is permanently initialized once attached and
* should not be dynamically bound.
*
* Example usage:
*
* ```html
* <aws-app region="eu-west-1"></aws-app>
* ```
*/
Polymer({
is: 'aws-app',

Expand All @@ -33,7 +30,7 @@
*/
region: {
type: String,
observer: '_updateRegion'
observer: '_updateRegion',
},

/**
Expand All @@ -43,7 +40,7 @@
* the preferred method for authentication is using Cognito identity.
*/
accessKeyId: {
type: String
type: String,
},

/**
Expand All @@ -54,7 +51,7 @@
* Cognito identity.
*/
secretAccessKey: {
type: String
type: String,
},

/**
Expand All @@ -63,30 +60,38 @@
sslDisabled: {
type: Boolean,
value: false,
observer: '_updateSSLSetting'
}
observer: '_updateSSLSetting',
},
},

behaviors: [
PolymerElements.LogBehavior,
],

ready: function() {
this._log.debug(this.localName + ' is ready');
},

observers: [
'_authenticateIAmUser(accessKeyId, secretAccessKey)'
'_authenticateIAmUser(accessKeyId, secretAccessKey)',
],

_authenticateIAmUser: function (accessKeyId, secretAccessKey) {
_authenticateIAmUser: function(accessKeyId, secretAccessKey) {
if (accessKeyId && secretAccessKey) {
AWS.config.update({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey
secretAccessKey: secretAccessKey,
});
}
},

_updateRegion: function (region) {
_updateRegion: function(region) {
AWS.config.region = region;
},

_updateSSLSetting: function (sslDisabled) {
_updateSSLSetting: function(sslDisabled) {
AWS.config.sslEnabled = !sslDisabled;
}
},
});
})();
</script>
Expand Down
4 changes: 4 additions & 0 deletions aws-cognito-script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>

<script src="../amazon-cognito-identity-js/dist/aws-cognito-sdk.min.js"></script>
<script src="../amazon-cognito-identity-js/dist/amazon-cognito-identity.min.js"></script>
Loading

0 comments on commit 85614eb

Please sign in to comment.