cognito-sync-service 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dab3b324ec56e6518a5c3af477244a9bf1fe92939b0d927a582dd9b9d0cb7801
4
+ data.tar.gz: ded8d0b4ce96d6c7da81d1b3ddff11971a4be261cac4376a3ad28aa53ef272a4
5
+ SHA512:
6
+ metadata.gz: c31322de7e67b21c293b15cce43377878ce6742fec4802dc99be44453686d6c6263eac22f4a6ddaf598b207a07a3d041a6cdcdbf2871837bbfbc1fe0f7f6964f
7
+ data.tar.gz: f29cd5e9b55eed76b9d5e282876dc773fce58ab8f202b83c5fb58d6748ccac2c93d9588ea76533d492a8400e3ef1d4f85c3c6ba042761fb619e3750749531510
@@ -0,0 +1,7 @@
1
+ development:
2
+ aws:
3
+ access_key_id: "access_key_id"
4
+ secret_access_key: "secret_access_key"
5
+ web_pool: "web_pool"
6
+ region: "region"
7
+ client_id: "client_id"
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /pkg/
6
+ /spec/reports/
7
+ /tmp/
8
+
9
+ .evn
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .idea/
14
+ /spec/support/spec_credentials.yml
15
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,58 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/*'
4
+ - '*.gemspec'
5
+ - 'Rakefile'
6
+
7
+ ModuleLength:
8
+ Enabled: false
9
+
10
+ LineLength:
11
+ Enabled: false
12
+
13
+ StringLiterals:
14
+ EnforcedStyle: single_quotes
15
+ Enabled: false
16
+
17
+ Layout/DotPosition:
18
+ EnforcedStyle: leading
19
+ Enabled: true
20
+
21
+ Documentation:
22
+ Enabled: false
23
+
24
+ Naming/MemoizedInstanceVariableName:
25
+ Enabled: false
26
+
27
+ Metrics/AbcSize:
28
+ Max: 40
29
+ Enabled: true
30
+
31
+ Metrics/BlockLength:
32
+ CountComments: false
33
+ Max: 300
34
+ Enabled: true
35
+
36
+ Metrics/ClassLength:
37
+ CountComments: false
38
+ Max: 320
39
+ Enabled: true
40
+
41
+ Metrics/PerceivedComplexity:
42
+ Max: 12
43
+ Enabled: true
44
+
45
+ Metrics/CyclomaticComplexity:
46
+ Max: 12
47
+ Enabled: true
48
+
49
+ Metrics/ParameterLists:
50
+ Max: 10
51
+
52
+ Metrics/MethodLength:
53
+ CountComments: false
54
+ Max: 30
55
+ Enabled: true
56
+
57
+ Naming/UncommunicativeMethodParamName:
58
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mark.osipenko@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1 @@
1
+ run `spec` and `rubocop`
@@ -0,0 +1,4 @@
1
+
2
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
3
+
4
+ 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).
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ group :development, :test do
6
+ # aws
7
+ gem 'aws-sdk-cognitoidentity', '~> 1.0.0.rc7'
8
+ gem 'aws-sdk-cognitoidentityprovider', '~> 1.12'
9
+ gem 'aws-sdk-cognitosync', '~> 1.6'
10
+ gem 'aws-sdk-ec2', '~> 1'
11
+ gem 'aws-sdk-s3', '~> 1'
12
+ gem 'aws-sdk-ses', '~> 1.6'
13
+
14
+ gem 'pry', '~> 0.10', require: false
15
+ gem 'pry-byebug', '~> 3.4'
16
+ gem 'pry-doc', '~> 1.0.0', require: false
17
+ gem 'rb-readline'
18
+
19
+ gem 'factory_bot', '~> 4.8'
20
+ gem 'rspec', '~> 3.6'
21
+ gem 'rubocop', require: false
22
+ gem 'rubocop-rspec', require: false
23
+ end
24
+
25
+ group :test do
26
+ gem 'rspec-its', '~> 1.2'
27
+ gem 'rspec-simplecov', '~> 0.2'
28
+ gem 'simplecov', '~> 0.14'
29
+ gem 'simplecov-console'
30
+ end
@@ -0,0 +1,138 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (5.2.3)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 0.7, < 2)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ ansi (1.5.0)
10
+ ast (2.4.0)
11
+ aws-eventstream (1.0.3)
12
+ aws-partitions (1.190.0)
13
+ aws-sdk-cognitoidentity (1.0.1)
14
+ aws-sdk-core (~> 3)
15
+ aws-sigv4 (~> 1.0)
16
+ aws-sdk-cognitoidentityprovider (1.24.0)
17
+ aws-sdk-core (~> 3, >= 3.58.0)
18
+ aws-sigv4 (~> 1.1)
19
+ aws-sdk-cognitosync (1.14.0)
20
+ aws-sdk-core (~> 3, >= 3.58.0)
21
+ aws-sigv4 (~> 1.1)
22
+ aws-sdk-core (3.59.0)
23
+ aws-eventstream (~> 1.0, >= 1.0.2)
24
+ aws-partitions (~> 1.0)
25
+ aws-sigv4 (~> 1.1)
26
+ jmespath (~> 1.0)
27
+ aws-sdk-ec2 (1.99.0)
28
+ aws-sdk-core (~> 3, >= 3.58.0)
29
+ aws-sigv4 (~> 1.1)
30
+ aws-sdk-kms (1.23.0)
31
+ aws-sdk-core (~> 3, >= 3.58.0)
32
+ aws-sigv4 (~> 1.1)
33
+ aws-sdk-s3 (1.45.0)
34
+ aws-sdk-core (~> 3, >= 3.58.0)
35
+ aws-sdk-kms (~> 1)
36
+ aws-sigv4 (~> 1.1)
37
+ aws-sdk-ses (1.24.0)
38
+ aws-sdk-core (~> 3, >= 3.58.0)
39
+ aws-sigv4 (~> 1.1)
40
+ aws-sigv4 (1.1.0)
41
+ aws-eventstream (~> 1.0, >= 1.0.2)
42
+ byebug (11.0.1)
43
+ coderay (1.1.2)
44
+ concurrent-ruby (1.1.5)
45
+ diff-lcs (1.3)
46
+ docile (1.3.2)
47
+ factory_bot (4.11.1)
48
+ activesupport (>= 3.0.0)
49
+ i18n (1.6.0)
50
+ concurrent-ruby (~> 1.0)
51
+ jaro_winkler (1.5.3)
52
+ jmespath (1.4.0)
53
+ json (2.2.0)
54
+ method_source (0.9.2)
55
+ minitest (5.11.3)
56
+ parallel (1.17.0)
57
+ parser (2.6.3.0)
58
+ ast (~> 2.4.0)
59
+ pry (0.12.2)
60
+ coderay (~> 1.1.0)
61
+ method_source (~> 0.9.0)
62
+ pry-byebug (3.7.0)
63
+ byebug (~> 11.0)
64
+ pry (~> 0.10)
65
+ pry-doc (1.0.0)
66
+ pry (~> 0.11)
67
+ yard (~> 0.9.11)
68
+ rainbow (3.0.0)
69
+ rb-readline (0.5.5)
70
+ rspec (3.8.0)
71
+ rspec-core (~> 3.8.0)
72
+ rspec-expectations (~> 3.8.0)
73
+ rspec-mocks (~> 3.8.0)
74
+ rspec-core (3.8.2)
75
+ rspec-support (~> 3.8.0)
76
+ rspec-expectations (3.8.4)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-its (1.3.0)
80
+ rspec-core (>= 3.0.0)
81
+ rspec-expectations (>= 3.0.0)
82
+ rspec-mocks (3.8.1)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.8.0)
85
+ rspec-simplecov (0.2.2)
86
+ rspec-support (3.8.2)
87
+ rubocop (0.73.0)
88
+ jaro_winkler (~> 1.5.1)
89
+ parallel (~> 1.10)
90
+ parser (>= 2.6)
91
+ rainbow (>= 2.2.2, < 4.0)
92
+ ruby-progressbar (~> 1.7)
93
+ unicode-display_width (>= 1.4.0, < 1.7)
94
+ rubocop-rspec (1.33.0)
95
+ rubocop (>= 0.60.0)
96
+ ruby-progressbar (1.10.1)
97
+ simplecov (0.17.0)
98
+ docile (~> 1.1)
99
+ json (>= 1.8, < 3)
100
+ simplecov-html (~> 0.10.0)
101
+ simplecov-console (0.5.0)
102
+ ansi
103
+ simplecov
104
+ terminal-table
105
+ simplecov-html (0.10.2)
106
+ terminal-table (1.8.0)
107
+ unicode-display_width (~> 1.1, >= 1.1.1)
108
+ thread_safe (0.3.6)
109
+ tzinfo (1.2.5)
110
+ thread_safe (~> 0.1)
111
+ unicode-display_width (1.6.0)
112
+ yard (0.9.20)
113
+
114
+ PLATFORMS
115
+ ruby
116
+
117
+ DEPENDENCIES
118
+ aws-sdk-cognitoidentity (~> 1.0.0.rc7)
119
+ aws-sdk-cognitoidentityprovider (~> 1.12)
120
+ aws-sdk-cognitosync (~> 1.6)
121
+ aws-sdk-ec2 (~> 1)
122
+ aws-sdk-s3 (~> 1)
123
+ aws-sdk-ses (~> 1.6)
124
+ factory_bot (~> 4.8)
125
+ pry (~> 0.10)
126
+ pry-byebug (~> 3.4)
127
+ pry-doc (~> 1.0.0)
128
+ rb-readline
129
+ rspec (~> 3.6)
130
+ rspec-its (~> 1.2)
131
+ rspec-simplecov (~> 0.2)
132
+ rubocop
133
+ rubocop-rspec
134
+ simplecov (~> 0.14)
135
+ simplecov-console
136
+
137
+ BUNDLED WITH
138
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Mark Osipenko
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.
@@ -0,0 +1,68 @@
1
+ # CognitoSyncService
2
+
3
+ Aws Cognito user pool synchronizer
4
+
5
+ - [CognitoSyncService](#cognitoSyncService)
6
+ - [Installation](#installation)
7
+ - [Usage](#usage)
8
+ - [Development](#development)
9
+ - [Contributing](#contributing)
10
+ - [Contacts](#contacts)
11
+ - [License](#license)
12
+ - [Status](#status)
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'cognito-sync-service'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install cognito-sync-service
29
+
30
+ ## Usage
31
+
32
+ [AWS Cognito](https://aws.amazon.com/ru/cognito/) let use [list of methods](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/index.html) or this [SDK methods for ruby](https://docs.aws.amazon.com/sdkforruby/api/Aws/CognitoIdentity/Client.html).
33
+
34
+ In common case you need __CRUD__ functionality, __synchronization__, between you DB and Cognito pools and __handling authorization__.
35
+
36
+ #### With this gem you can implement:
37
+ 1. __CRUD__ functionality from you application
38
+ 2. `(WIP)` __Synchronize__ you database users with user_pools
39
+ 3. `(WIP)`__Handling authorization__
40
+ *methods naming:*
41
+
42
+ `ca`_action => `cognito_admin`_action
43
+
44
+ `c`_action => `cognito`_action
45
+
46
+ ## Development
47
+
48
+ See [DEVELOPMENT.md](https://github.com/MarkOsipenko/cognito-sync-service/blob/master/DEVELOPMENT.md).
49
+
50
+ ## Contributing
51
+
52
+ See [CONTRIBUTING.md](https://github.com/MarkOsipenko/cognito-sync-service/blob/master/CONTRIBUTING.md).
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
57
+
58
+ ## Code of Conduct
59
+
60
+ Everyone interacting in the CognitoSyncService project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/MarkOsipenko/cognito_sync_service/blob/master/CODE_OF_CONDUCT.md).
61
+ ## Contacts
62
+
63
+ https://t.me/hakmatmao
64
+
65
+
66
+ ## Status
67
+ [![Maintainability](https://api.codeclimate.com/v1/badges/b90c232e049a226e25d9/maintainability)](https://codeclimate.com/github/MarkOsipenko/cognito-sync-service/maintainability)
68
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/b90c232e049a226e25d9/test_coverage)](https://codeclimate.com/github/MarkOsipenko/cognito-sync-service/test_coverage)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'cognito_sync_service'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -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,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'cognito_sync_service/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'cognito-sync-service'
9
+ spec.version = CognitoSyncService::VERSION
10
+ spec.authors = ['Mark Osipenko']
11
+ spec.email = ['mark.osipenko@gmail.com']
12
+
13
+ spec.summary = 'Aws Cognito user pool synchronizer'
14
+ spec.description = 'Aws Cognito user pool synchronizer'
15
+ spec.homepage = 'https://github.com/MarkOsipenko/cognito-sync-service'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org.
19
+ # To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata['homepage_uri'] = spec.homepage
23
+ spec.metadata['source_code_uri'] = 'https://github.com/MarkOsipenko/cognito-sync-service'
24
+ spec.metadata['changelog_uri'] = 'https://github.com/MarkOsipenko/cognito-sync-service'
25
+ else
26
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ 'public gem pushes.'
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = 'exe'
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ['lib']
38
+
39
+ spec.add_development_dependency 'bundler', '~> 2.0'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ end
@@ -0,0 +1,37 @@
1
+ # CognitoSyncService
2
+
3
+ __*#ca_create!(username)*__
4
+
5
+ > In order to create user on Cognito
6
+ > - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
7
+ >
8
+ > Also check this doc [admin-create-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-create-user.html) method
9
+
10
+ ## Usage
11
+
12
+ ```ruby
13
+ class UserExample
14
+ extend ::CognitoSyncService
15
+ end
16
+
17
+ attrs = {
18
+ { email: 'useremail@example.com' },
19
+ { phone_number: '+1111111111' }
20
+ }
21
+
22
+ UserExample.ca_create!(attrs, attrs[:phone_number])
23
+ ```
24
+
25
+ __Output__
26
+
27
+ ```ruby
28
+ {
29
+ "username"=>"fd99f027-bebf-4f43-abf9-24829f45107f",
30
+ "user_create_date"=>2019-07-26 16:27:14 +0300,
31
+ "user_last_modified_date"=>2019-07-26 16:27:14 +0300,
32
+ "enabled"=>true,
33
+ "user_status"=>"FORCE_CHANGE_PASSWORD",
34
+ "phone_number"=>"+3333333333"
35
+ }
36
+
37
+ ```
@@ -0,0 +1,23 @@
1
+ # CognitoSyncService
2
+
3
+ __*#ca_delete!(username)*__
4
+
5
+ > Delete user from cognito pool.
6
+ >
7
+ > Also check this doc [admin-delete-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-delete-user.html) method
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ class UserExample
13
+ extend ::CognitoSyncService
14
+ end
15
+
16
+ UserExample.ca_delete!(username) =>
17
+ ```
18
+
19
+ __Output__
20
+
21
+ ```ruby
22
+ {}
23
+ ```
@@ -0,0 +1,23 @@
1
+ # CognitoSyncService
2
+
3
+ __*#ca_disable!(username)*__
4
+
5
+ > Disable user in cognito pool.
6
+ >
7
+ > Also check this doc [admin-disable-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-disable-user.html) method
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ class UserExample
13
+ extend ::CognitoSyncService
14
+ end
15
+
16
+ UserExample.ca_disable!(username) =>
17
+ ```
18
+
19
+ __Output__
20
+
21
+ ```ruby
22
+ {}
23
+ ```
@@ -0,0 +1,50 @@
1
+ # CognitoSyncService
2
+
3
+ __*#ca_find!(username)*__
4
+
5
+ > In order to find user on Cognito pool
6
+ > - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
7
+
8
+ Cognito return data in format with __user_attributes__ key
9
+ # cognito-idp example
10
+ ```
11
+ <struct Aws::CognitoIdentityProvider::Types::AdminGetUserResponse
12
+ username="98fa7330-a5bb-4aed-a89a-17eed002f238",
13
+ user_attributes= [
14
+ #<struct Aws::CognitoIdentityProvider::Types::AttributeType name="sub", value="98fa7330-a5bb-4aed-a89a-17eed002f238">,
15
+ #<struct Aws::CognitoIdentityProvider::Types::AttributeType name="phone_number", value="+3333333333">
16
+ ],
17
+ user_create_date=2019-07-29 13:06:30 +0300,
18
+ user_last_modified_date=2019-07-29 13:06:30 +0300,
19
+ enabled=true,
20
+ user_status="FORCE_CHANGE_PASSWORD",
21
+ mfa_options=nil,
22
+ preferred_mfa_setting=nil,
23
+ user_mfa_setting_list=nil>
24
+
25
+ ```
26
+ >
27
+ >
28
+ > Also check this doc [admin-get-user](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-get-user.html) method
29
+
30
+ ## Usage
31
+
32
+ ```ruby
33
+ class UserExample
34
+ extend CognitoSyncService
35
+ end
36
+
37
+ UserExample.ca_find!('+123456789')
38
+ ```
39
+
40
+ __Output__
41
+
42
+ ```ruby
43
+ {
44
+ "enabled"=>true,
45
+ "phone_number"=>"+123456789",
46
+ "user_create_date"=>2019-07-26 15:48:06.130000114 +0300,
47
+ "user_status"=>"FORCE_CHANGE_PASSWORD",
48
+ "username"=>"dae4900d-0984-4ac0-9ab0-14505e52d50c"
49
+ }
50
+ ```
@@ -0,0 +1,41 @@
1
+ # CognitoSyncService
2
+
3
+ __*#ca_update!(username)*__
4
+
5
+ > In order to update user on Cognito
6
+ > - Username should be equal __email/phone_number/random_uniq_string__ depend on you cognito user pool settings - [cognito username attribute doc](https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-usernames)
7
+ >
8
+ > Also check this doc [admin-update-user-attributes](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/admin-update-user-attributes.html) method
9
+
10
+ ## Usage
11
+
12
+ `Attention!!!`
13
+ changing username (alias for you login) not tested yet
14
+
15
+ ```ruby
16
+ class UserExample
17
+ extend ::CognitoSyncService
18
+ end
19
+
20
+ attrs = {
21
+ { email: 'usernewemail@example.com' },
22
+ { phone_number: '+1111111111' }
23
+ }
24
+
25
+ UserExample.ca_update!(attrs, attrs[:phone_number])
26
+ ```
27
+
28
+ __Output__
29
+
30
+ ```ruby
31
+ {
32
+ "email"=>"example2@gmail.com",
33
+ "username"=>"01f29e86-f9ff-4b30-a8d6-977e07d07abb",
34
+ "user_create_date"=>2019-07-29 17:14:44 +0300,
35
+ "user_last_modified_date"=>2019-07-29 17:15:04 +0300,
36
+ "enabled"=>true,
37
+ "user_status"=>"FORCE_CHANGE_PASSWORD",
38
+ "phone_number"=>"+111111111"
39
+ }
40
+
41
+ ```
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CognitoAttributesConverter
4
+ def convert_to_cognito(attrs)
5
+ cognito_attrs = attrs.map { |k, v| [k, v] }.to_h
6
+
7
+ cognito_attrs.map do |k, v|
8
+ { name: cognito_key_name(k), value: v } if cognito_key?(k) && v
9
+ end.compact
10
+ end
11
+
12
+ # name of attribute in cognito pool
13
+ def cognito_key_name(key)
14
+ return "custom:#{key}" if list_cognito_custom_attr_keys.include?(key.to_s)
15
+
16
+ key.to_s
17
+ end
18
+
19
+ def convert_from_cognito(user_struct)
20
+ cognito_attrs = user_struct.to_h
21
+
22
+ user_attributes(cognito_attrs)
23
+ end
24
+
25
+ def user_attributes(cognito_attrs)
26
+ if cognito_attrs.key?(:user_attributes)
27
+ user_attrs = cognito_attrs.delete(:user_attributes)
28
+ common_attrs = cognito_attrs
29
+ elsif cognito_attrs.key?(:attributes)
30
+ user_attrs = cognito_attrs.delete(:attributes)
31
+ common_attrs = cognito_attrs
32
+ end
33
+
34
+ list_cognito_attr_keys.map do |key|
35
+ (user_attrs.find do |a|
36
+ common_attrs[key.to_s] = a[:value] if a[:name] == cognito_key_name(key)
37
+ end)
38
+ end
39
+
40
+ Hash[common_attrs.map { |k, v| [k.to_s, v] }]
41
+ end
42
+
43
+ def cognito_key?(key)
44
+ list_cognito_attr_keys.include?(key.to_s)
45
+ end
46
+
47
+ def list_cognito_attr_keys
48
+ list_cognito_default_attr_keys + list_cognito_custom_attr_keys
49
+ end
50
+
51
+ def list_cognito_default_attr_keys
52
+ cognito_default_attr_keys.map(&:to_s)
53
+ end
54
+
55
+ def list_cognito_custom_attr_keys
56
+ cognito_custom_attr_keys.map(&:to_s)
57
+ end
58
+
59
+ # redefine this methods in you model if you want to store special attributes
60
+ def cognito_default_attr_keys
61
+ %w[email phone_number]
62
+ end
63
+
64
+ # redefine this methods in you model if you want to store special custom attributes
65
+ def cognito_custom_attr_keys
66
+ %w[]
67
+ end
68
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TODO: add to credentials
4
+ # aws:
5
+ # development:
6
+ # web_pool: "web_pool_id"
7
+ # web_client_id: "web_client_id"
8
+
9
+ module CognitoPoolsInitializer
10
+ def web_pool_id(env_key = 'development')
11
+ @web_pool_id ||= ENV[env_key]['aws']['web_pool']
12
+ end
13
+
14
+ def web_client_id(env_key = 'development')
15
+ @web_client_id ||= ENV[env_key]['aws']['web_client_id']
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TODO: add to credentials on ENV
4
+ # development:
5
+ # aws:
6
+ # access_key_id: "access_key_id"
7
+ # secret_access_key: "secret_access_key"
8
+ # region: "region"
9
+
10
+ require 'aws-sdk-cognitoidentityprovider'
11
+
12
+ module CognitoProvider
13
+ def cognito_provider(env_key = 'development')
14
+ ::Aws::CognitoIdentityProvider::Client.new(
15
+ access_key_id: ENV[env_key]['aws']['access_key_id'],
16
+ secret_access_key: ENV[env_key]['aws']['secret_access_key'],
17
+ region: ENV[env_key]['aws']['region']
18
+ )
19
+ end
20
+ # If you store you env variables in credentials file for rails you should redefine cognito_provider like example bellow
21
+
22
+ # def cognito_provider
23
+ # ::Aws::CognitoIdentityProvider::Client.new(
24
+ # access_key_id: Rails.application.credentials.dig(:aws, :access_key_id),
25
+ # secret_access_key: Rails.application.credentials.dig(:aws, :secret_access_key),
26
+ # region: Rails.application.credentials.dig(:aws, Rails.env.to_sym, :region)
27
+ # )
28
+ # end
29
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cognito_sync_service/version'
4
+ require 'cognito_attributes_converter.rb'
5
+ require 'cognito_pools_initializer.rb'
6
+ require 'cognito_provider.rb'
7
+
8
+ module CognitoSyncService
9
+ include ::CognitoAttributesConverter
10
+ include ::CognitoPoolsInitializer
11
+ include ::CognitoProvider
12
+
13
+ # username - can be email, phone_number or custom string depend on you cognito pool settings
14
+ # attrs - hash of user attributes which will be saved in cognito pool
15
+ # attrs = { email: 'qwe@qwe,com', phone_number: '+12......0'}
16
+ def ca_create!(attrs, username)
17
+ c_attributes = convert_to_cognito(attrs)
18
+ user = cognito_provider.admin_create_user(user_pool_id: web_pool_id, username: username, user_attributes: c_attributes).user
19
+ convert_from_cognito(user)
20
+ end
21
+
22
+ # user can be delete by email or phone_number depend on cognito pool settings
23
+ def ca_delete!(username)
24
+ cognito_provider.admin_delete_user(user_pool_id: web_pool_id, username: username)
25
+ end
26
+
27
+ # user can be find by email or phone_number depend on cognito pool settings
28
+ def ca_find!(username)
29
+ user = cognito_provider.admin_get_user(user_pool_id: web_pool_id, username: username)
30
+ convert_from_cognito(user)
31
+ end
32
+
33
+ # username - can be email, phone_number or custom string depend on you cognito pool settings
34
+ # attrs - hash of user attributes which will be saved in cognito pool
35
+ # attrs = { email: 'qwe@qwe,com', phone_number: '+12......0'}
36
+ def ca_update!(attrs, username)
37
+ c_attributes = convert_to_cognito(attrs)
38
+ cognito_provider.admin_update_user_attributes(user_pool_id: web_pool_id, username: username, user_attributes: c_attributes)
39
+ ca_find!(username)
40
+ end
41
+
42
+ # user can be disable by email or phone_number depend on cognito pool settings
43
+ def ca_disable!(username)
44
+ cognito_provider.admin_disable_user(user_pool_id: web_pool_id, username: username)
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CognitoSyncService
4
+ VERSION = '0.2.0'
5
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cognito-sync-service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Osipenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Aws Cognito user pool synchronizer
56
+ email:
57
+ - mark.osipenko@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".env.example"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".travis.yml"
67
+ - CODE_OF_CONDUCT.md
68
+ - CONTRIBUTING.md
69
+ - DEVELOPMENT.md
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/console
76
+ - bin/setup
77
+ - cognito-sync-service-0.1.0.gem
78
+ - cognito_sync_service.gemspec
79
+ - doc/ca_create!.md
80
+ - doc/ca_delete!.md
81
+ - doc/ca_disable!.md
82
+ - doc/ca_find!.md
83
+ - doc/ca_update!.md
84
+ - lib/cognito_attributes_converter.rb
85
+ - lib/cognito_pools_initializer.rb
86
+ - lib/cognito_provider.rb
87
+ - lib/cognito_sync_service.rb
88
+ - lib/cognito_sync_service/version.rb
89
+ homepage: https://github.com/MarkOsipenko/cognito-sync-service
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ homepage_uri: https://github.com/MarkOsipenko/cognito-sync-service
94
+ source_code_uri: https://github.com/MarkOsipenko/cognito-sync-service
95
+ changelog_uri: https://github.com/MarkOsipenko/cognito-sync-service
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.7.6
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Aws Cognito user pool synchronizer
116
+ test_files: []