xaases 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eb9556e3367b7df995d7252a29fdae6c57250841715979f3f8675246725241b7
4
+ data.tar.gz: c2acf6a3e7ebace685157d21aedd8598d340dbf3a05581f0b502aba0a115955f
5
+ SHA512:
6
+ metadata.gz: 7ac3daed57eca40918178850922fca759bc42922a4050ccd881d99e4bedb2d7bdd5daffb841a98df3eb55be3bfb5c6f0c776f3a801d45c72d8c89430d54ec88a
7
+ data.tar.gz: 453bd28db844b82204810e1eeb913ea02f0c4301d665c48c028a0f3f4c6129b41c7c228b1fb7d9eb56da298c22641904779e532348c9dae00972f0830aafc706
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ # package directories
2
+ node_modules
3
+ jspm_packages
4
+ pkg
5
+
6
+ # Serverless directories
7
+ serverless.yml
8
+ xaases.yml
9
+ .serverless
10
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in xaases.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xaases (0.1.0)
5
+ highline (~> 2.0, >= 2.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ highline (2.0.0)
11
+ rake (10.5.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.16)
18
+ rake (~> 10.0)
19
+ xaases!
20
+
21
+ BUNDLED WITH
22
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 myun2
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Xaases
2
+
3
+ **Serverless** wrapper.
4
+
5
+ ## Installation
6
+
7
+ Need install node, npm and serverless.
8
+
9
+ and install from ruby gem
10
+
11
+ ```
12
+ $ gem install xaases
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ First, in project directory, run command
18
+
19
+ ```
20
+ $ xaases init
21
+ ```
22
+
23
+ is create `xaases.yml`.
24
+
25
+ ### Add resource
26
+
27
+ ```
28
+ $ xaases add <tablename> <columns...>
29
+ ```
30
+
31
+ ### Deploy to AWS
32
+
33
+ Edit `serverless.yml`
34
+
35
+ ```
36
+ provider:
37
+ name: aws
38
+ region: <region>
39
+ ```
40
+
41
+ and run `sls deploy`
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xaases.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "xaases"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const AWS = require('aws-sdk'),
4
+ db = new AWS.DynamoDB(),
5
+ TABLE_NAME = 'event-store';
6
+
7
+ const indexQueryParams = (organization) => (
8
+ {
9
+ TableName: TABLE_NAME,
10
+ Item: event
11
+ }
12
+ );
13
+
14
+ module.exports.create = (event, context, callback) => {
15
+ console.log(event)
16
+ db.put(putParams(event), (err, data) => {
17
+ if (err) {
18
+ callback(err);
19
+ }
20
+ else {
21
+ callback(null, { statusCode: 200, body: 'OK' });
22
+ }
23
+ });
24
+ };
@@ -0,0 +1,47 @@
1
+ service: event-store
2
+ provider:
3
+ name: aws
4
+ runtime: nodejs6.10
5
+ region: ap-northeast-1
6
+ profile: serverless-deploy
7
+ iamRoleStatements:
8
+ - Effect: Allow
9
+ Action:
10
+ - dynamodb:DescribeTable
11
+ - dynamodb:Query
12
+ - dynamodb:Scan
13
+ - dynamodb:GetItem
14
+ - dynamodb:PutItem
15
+ - dynamodb:UpdateItem
16
+ - dynamodb:DeleteItem
17
+ Resource: "arn:aws:dynamodb:ap-northeast-1:*:table/event-store*"
18
+ resources:
19
+ Resources:
20
+ ActivitiesDynamoDbTable:
21
+ Type: 'AWS::DynamoDB::Table'
22
+ Properties:
23
+ TableName: event-store
24
+ AttributeDefinitions:
25
+ -
26
+ AttributeName: resource_name
27
+ AttributeType: S
28
+ -
29
+ AttributeName: resource_id
30
+ AttributeType: S
31
+ KeySchema:
32
+ -
33
+ AttributeName: resource_name
34
+ KeyType: HASH
35
+ -
36
+ AttributeName: resource_id
37
+ KeyType: RANGE
38
+ ProvisionedThroughput:
39
+ ReadCapacityUnits: 1
40
+ WriteCapacityUnits: 1
41
+ functions:
42
+ root:
43
+ handler: events.create
44
+ events:
45
+ - http:
46
+ path: /events
47
+ method: post
data/exe/xaases ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "xaases/cli"
@@ -0,0 +1,46 @@
1
+ module Xaases
2
+ module Aws
3
+ class Dynamodb
4
+ attr_reader :name, :keys
5
+ def initialize(name, *keys)
6
+ @name = name
7
+ @keys = keys
8
+ end
9
+
10
+ def attribute_definitions
11
+ keys.map do |key, type|
12
+ {
13
+ "AttributeName" => key,
14
+ "AttributeType" => (type == 'integer' ? 'N' : 'S')
15
+ }
16
+ end
17
+ end
18
+
19
+ def key_schema
20
+ i = 0
21
+ keys.map do |key, type|
22
+ i += 1
23
+ {
24
+ "AttributeName" => key,
25
+ "KeyType" => (i == 1 ? 'HASH' : 'RANGE')
26
+ }
27
+ end
28
+ end
29
+
30
+ def to_hash
31
+ {
32
+ "Type" => 'AWS::DynamoDB::Table',
33
+ "Properties" => {
34
+ "TableName" => name,
35
+ "AttributeDefinitions" => attribute_definitions,
36
+ "KeySchema" => key_schema,
37
+ "ProvisionedThroughput" => {
38
+ "ReadCapacityUnits" => 1,
39
+ "WriteCapacityUnits" => 1
40
+ }
41
+ }
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
data/lib/xaases/aws.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Xaases
2
+ module Aws
3
+ def self.arn(*rs)
4
+ (%w{arn aws} + rs).join(':')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ require 'highline'
2
+
3
+ module Xaases
4
+ module Color
5
+ @@highline = HighLine.new
6
+
7
+ def self.warn(s = nil)
8
+ puts @@highline.color s || self, :yellow
9
+ end
10
+
11
+ def self.yellow(s = nil)
12
+ @@highline.color s || self, :yellow
13
+ end
14
+
15
+ def self.failure(s = nil)
16
+ puts @@highline.color s || self, :red
17
+ end
18
+
19
+ def self.red(s = nil)
20
+ @@highline.color s || self, :red
21
+ end
22
+ end
23
+ end
24
+ String.include Xaases::Color
25
+
26
+ @highline = HighLine.new
27
+
28
+ def attempt(s)
29
+ puts @highline.color s, :yellow
30
+ end
@@ -0,0 +1,5 @@
1
+ puts <<-EOS
2
+ usage: #{Xaases::NAME} <command> [options]
3
+ init
4
+ add <name> <columns...>
5
+ EOS
@@ -0,0 +1,5 @@
1
+ require 'fileutils'
2
+ TMPL_NAME = Xaases::NAME + '.yml'
3
+ FileUtils.touch(TMPL_NAME)
4
+
5
+ attempt "Created #{TMPL_NAME}"
data/lib/xaases/cli.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'xaases/cli/color'
2
+ require 'xaases/conf'
3
+ require 'xaases/serverless'
4
+ require 'xaases/aws/dynamodb'
5
+
6
+ cmd = ARGV.first
7
+ options = ARGV.slice(1..-1)
8
+
9
+ begin
10
+ case cmd
11
+ when 'add'
12
+ Xaases.add *options
13
+ sls = Xaases::Serverless::Yaml.new('serverless.yml', 'xaases')
14
+ name = options.first + 'DynamoDbTable'
15
+ sls.add_resource name, Xaases::Aws::Dynamodb.new(*options).to_hash
16
+ sls.write
17
+ #`sls deploy`
18
+ when 'init', 'touch'
19
+ require 'xaases/cli/init'
20
+ else
21
+ require 'xaases/cli/help'
22
+ end
23
+ rescue => e
24
+ Xaases::Color.failure e.message
25
+ end
@@ -0,0 +1,30 @@
1
+ require 'yaml'
2
+
3
+ module Xaases
4
+ CONF_NAME = NAME + '.yml'
5
+
6
+ def self.load
7
+ begin
8
+ @@config = YAML.load_file(CONF_NAME) || {}
9
+ rescue Errno::ENOENT
10
+ raise "Require '#{CONF_NAME}' file, you need run at 'xaases init' command."
11
+ end
12
+ end
13
+
14
+ def self.dump
15
+ YAML.dump @@config, File.open(CONF_NAME, 'w')
16
+ end
17
+
18
+ def self.edit(&block)
19
+ self.load
20
+ yield @@config
21
+ dump
22
+ end
23
+
24
+ def self.add name, *columns
25
+ edit do |c|
26
+ puts Color.yellow "Add #{name}"
27
+ c[name] = columns
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Xaases
2
+ NAME = 'xaases'
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+
3
+ module Xaases
4
+ module Serverless
5
+ class Yaml
6
+ attr_writer :data
7
+
8
+ def initialize(filename, name = nil)
9
+ @filename = filename
10
+ begin
11
+ @data = YAML.load_file filename
12
+ rescue Errno::ENOENT
13
+ @data = {
14
+ 'service' => name,
15
+ 'provider' => {},
16
+ 'resources' => {'Resources' => {}},
17
+ 'functions' => {}
18
+ }
19
+ end
20
+ end
21
+
22
+ def provider=(prov)
23
+ @data['provider'] = prov
24
+ end
25
+
26
+ def add_resource(name, rs)
27
+ @data['resources']['Resources'][name] = rs
28
+ end
29
+
30
+ def functions=(fns)
31
+ @data['functions'] = fns
32
+ end
33
+
34
+ def write
35
+ YAML.dump @data, File.open(@filename, 'w')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1 @@
1
+ require 'xaases/serverless/yaml'
@@ -0,0 +1,3 @@
1
+ module Xaases
2
+ VERSION = "0.1.0"
3
+ end
data/lib/xaases.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "xaases/version"
2
+
3
+ module Xaases
4
+ # Your code goes here...
5
+ end
data/xaases.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "xaases/name"
4
+ require "xaases/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = Xaases::NAME
8
+ spec.version = Xaases::VERSION
9
+ spec.authors = ["myun2"]
10
+ spec.email = ["myun2@nwhite.info"]
11
+
12
+ spec.summary = 'Serverless wrapper'
13
+ spec.description = 'Serverless wrapper'
14
+ spec.homepage = 'https://github.com/myun2/Xaases'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ #end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_runtime_dependency "highline", '~> 2.0', '>= 2.0.0'
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xaases
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - myun2
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.16'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.16'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: Serverless wrapper
62
+ email:
63
+ - myun2@nwhite.info
64
+ executables:
65
+ - xaases
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/console
76
+ - bin/setup
77
+ - event-store/events.js
78
+ - event-store/serverless.yml
79
+ - exe/xaases
80
+ - lib/xaases.rb
81
+ - lib/xaases/aws.rb
82
+ - lib/xaases/aws/dynamodb.rb
83
+ - lib/xaases/cli.rb
84
+ - lib/xaases/cli/color.rb
85
+ - lib/xaases/cli/help.rb
86
+ - lib/xaases/cli/init.rb
87
+ - lib/xaases/conf.rb
88
+ - lib/xaases/name.rb
89
+ - lib/xaases/serverless.rb
90
+ - lib/xaases/serverless/yaml.rb
91
+ - lib/xaases/version.rb
92
+ - xaases.gemspec
93
+ homepage: https://github.com/myun2/Xaases
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.7.7
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Serverless wrapper
117
+ test_files: []