lita-yandex-domains 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
+ SHA1:
3
+ metadata.gz: fc217e9272589c57bae5d1c92afeba46dfe55275
4
+ data.tar.gz: 2bffa086fafacd6bd8b82c6f371c3e7adf11f281
5
+ SHA512:
6
+ metadata.gz: 8e23c5407b2eb05ff525858854b44a8f1f8bea5508b295bacd05a7a2d6c15eae787e482ad4077e0929745fc50d940e7bb9c5dbc3eede4a8b7768351a30b6bab1
7
+ data.tar.gz: 2f2be7c5110f34b7d249699a1dd8925839c16419367a7be3550eb7bd7c904cf3a04d8dea2e0ac6aeb06b4d820bb404581bc152d511bd25c18ea95d6d0c4c7a88
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
9
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # lita-yandex-domains
2
+
3
+ [![Build Status](https://travis-ci.org/DevicoSolutions/lita-yandex-domains.svg?branch=master)](https://travis-ci.org/DevicoSolutions/lita-yandex-domains)
4
+ [![Coverage Status](https://coveralls.io/repos/github/DevicoSolutions/lita-yandex-domains/badge.svg?branch=master)](https://coveralls.io/github/DevicoSolutions/lita-yandex-domains?branch=master)
5
+
6
+ Lita handler to interact with yandex domain API
7
+
8
+ ## Installation
9
+
10
+ Add lita-yandex-domains to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem 'lita-yandex-domains'
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ ### Required attributes
19
+
20
+ [How to get PDD token](https://tech.yandex.com/domain/doc/concepts/access-docpage/)
21
+
22
+ * `pdd_token` (String) - Yandex PDD Token. Default: `nil`.
23
+
24
+ * `domain` (String) - Your domain name that is linked to yandex domain service. Default: `nil`.
25
+
26
+ ### Example
27
+
28
+ ``` ruby
29
+ Lita.configure do |config|
30
+ config.handlers.yandex_domains.pdd_token = 'XXXXXXX'
31
+ config.handlers.yandex_domains.domain = 'example.com'
32
+ config.robot.yandex_admins = ["XXXXX"]
33
+ end
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ Please note
39
+
40
+ ```
41
+ yandex show all human emails - Show all emails that not include mailing lists
42
+ yandex show all maillists - Show all maillists
43
+ yandex add email <email> - Add email with random generated password
44
+ yandex delete email <email> - Delete user email
45
+ yandex add maillist <email> - Add maillist
46
+ yandex delete maillist <email> - Delete maillist
47
+ yandex add <email> to maillist <email> - Add subcriber to maillist
48
+ yandex delete <email> from maillist <email> - Remove subcriber from maillist
49
+ ```
50
+
51
+ *Note:* The above commands except show commands require that the user be a member of the `:yandex_admins` authorization group.
52
+
53
+ ## License
54
+
55
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ require 'lita'
2
+
3
+ require 'yandexhelper/regex'
4
+ require 'yandex-pdd-2'
5
+
6
+ Lita.load_locales Dir[File.expand_path(
7
+ File.join("..", "..", "locales", "*.yml"), __FILE__
8
+ )]
9
+
10
+ require 'lita/handlers/yandex_domains'
11
+
12
+ Lita::Handlers::YandexDomains.template_root File.expand_path(
13
+ File.join("..", "..", "templates"),
14
+ __FILE__
15
+ )
@@ -0,0 +1,181 @@
1
+ module Lita
2
+ module Handlers
3
+ class YandexDomains < Handler
4
+
5
+ config :pdd_token, required: false, type: String, default: 'NAHCRSUVLHFRSILELDIJGPK2KTAWD5K7RTKYKPOG2XIB462LKTRQ'
6
+ config :domain, required: false, type: String, default: 'devico.io'
7
+
8
+ include ::YandexHelper::Regex
9
+
10
+ def yandex_client
11
+ @yandex_client ||= Yandex::Pdd::Client.new(config.pdd_token)
12
+ end
13
+
14
+ route(
15
+ /^yandex\screate\semail\s#{EMAIL_PATTERN}$/,
16
+ :create_email,
17
+ command: true,
18
+ restrict_to: :yandex_admins,
19
+ help: {
20
+ t('help.create_email.syntax') => t('help.create_email.desc')
21
+ }
22
+ )
23
+
24
+ route(
25
+ /^yandex\sdelete\semail\s#{EMAIL_PATTERN}$/,
26
+ :delete_email,
27
+ command: true,
28
+ restrict_to: :yandex_admins,
29
+ help: {
30
+ t('help.delete_email.syntax') => t('help.delete_email.desc')
31
+ }
32
+ )
33
+
34
+ route(
35
+ /^yandex\sshow\sall\shuman\semails$/,
36
+ :show_all_emails,
37
+ command: true,
38
+ help: {
39
+ t('help.show_human_emails.syntax') => t('help.show_human_emails.desc')
40
+ }
41
+ )
42
+
43
+ route(
44
+ /^yandex\screate\smaillist\s#{MAILLIST_PATTERN}$/,
45
+ :create_maillist,
46
+ command: true,
47
+ restrict_to: :yandex_admins,
48
+ help: {
49
+ t('help.create_maillist.syntax') => t('help.create_maillist.desc')
50
+ }
51
+ )
52
+
53
+ route(
54
+ /^yandex\sdelete\smaillist\s#{MAILLIST_PATTERN}$/,
55
+ :delete_maillist,
56
+ command: true,
57
+ restrict_to: :yandex_admins,
58
+ help: {
59
+ t('help.delete_maillist.syntax') => t('help.delete_maillist.desc')
60
+ }
61
+ )
62
+
63
+ route(
64
+ /^yandex\sshow\sall\smaillists$/,
65
+ :show_all_maillists,
66
+ command: true,
67
+ help: {
68
+ t('help.show_maillists.syntax') => t('help.show_maillists.desc')
69
+ }
70
+ )
71
+
72
+ route(
73
+ /^yandex\sadd\s#{EMAIL_PATTERN}\sto\smaillist\s#{MAILLIST_PATTERN}$/,
74
+ :add_subscriber,
75
+ command: true,
76
+ restrict_to: :yandex_admins,
77
+ help: {
78
+ t('help.add_subscriber.syntax') => t('help.add_subscriber.desc')
79
+ }
80
+ )
81
+
82
+ route(
83
+ /^yandex\sdelete\s#{EMAIL_PATTERN}\sfrom\smaillist\s#{MAILLIST_PATTERN}$/,
84
+ :remove_subscriber,
85
+ command: true,
86
+ restrict_to: :yandex_admins,
87
+ help: {
88
+ t('help.delete_subscriber.syntax') => t('help.delete_subscriber.desc')
89
+ }
90
+ )
91
+
92
+ def create_email(response)
93
+ email = response.match_data['email']
94
+ domain = email.split('@').last
95
+ if domain == config.domain
96
+ password = generate_passwd
97
+ status = yandex_client.mailbox_add(options = { domain: config.domain, login: email, password: password })
98
+ if status['success'] == 'error'
99
+ message = status
100
+ else
101
+ message = "Email #{email} with password #{password} was successfully created. Please login to mailbox using https//mail.#{domain}"
102
+ end
103
+ else
104
+ message = error_message(domain)
105
+ end
106
+ response.reply(message)
107
+ end
108
+
109
+ def delete_email(response)
110
+ email = response.match_data['email']
111
+ message = yandex_client.mailbox_delete(options = { domain: config.domain, login: email })
112
+ response.reply(message)
113
+ end
114
+
115
+ def show_all_emails(response)
116
+ show_emails(response, maillist='no')
117
+ end
118
+
119
+ def create_maillist(response)
120
+ email = response.match_data['maillist']
121
+ domain = email.split('@').last
122
+ message = nil
123
+ if domain == config.domain
124
+ status = yandex_client.maillist_add(options = { domain: config.domain, login: email })
125
+ message = status if status['success'] == 'error'
126
+ else
127
+ message = error_message(domain)
128
+ end
129
+ response.reply(message)
130
+ end
131
+
132
+ def delete_maillist(response)
133
+ email = response.match_data['maillist']
134
+ message = yandex_client.maillist_delete(options = { domain: config.domain, maillist: email })
135
+ response.reply(message)
136
+ end
137
+
138
+ def show_all_maillists(response)
139
+ show_emails(response, maillist='yes')
140
+ end
141
+
142
+ def add_subscriber(response)
143
+ email = response.match_data['email']
144
+ maillist = response.match_data['maillist']
145
+ message = yandex_client.subscription_add(options = { domain: config.domain, maillist: maillist, subscriber: email })
146
+ response.reply(message)
147
+ end
148
+
149
+ def remove_subscriber(response)
150
+ email = response.match_data['email']
151
+ maillist = response.match_data['maillist']
152
+ message = yandex_client.subscription_destroy(options = { domain: config.domain, maillist: maillist, subscriber: email })
153
+ response.reply(message)
154
+ end
155
+
156
+
157
+ Lita.register_handler(self)
158
+
159
+ private
160
+
161
+ def show_emails(response, maillist)
162
+ emails = []
163
+ accounts = yandex_client.mailbox_list(config.domain, page=1, on_page=500)
164
+ accounts['accounts'].each do |account|
165
+ emails.push(account['login']) if account['maillist'] == maillist
166
+ end
167
+ response.reply(emails)
168
+ end
169
+
170
+ def error_message(domain)
171
+ "Domain '#{domain}' is not valid. You authorize to manage emails only for #{config.domain} domain"
172
+ end
173
+
174
+ def generate_passwd(length=8)
175
+ chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789'
176
+ Array.new(length) { chars[rand(chars.length)].chr }.join
177
+ end
178
+
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,7 @@
1
+ module YandexHelper
2
+ module Regex
3
+ EMAIL_PATTERN = /(?<email>[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+)/i
4
+ MAILLIST_PATTERN = /(?<maillist>[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+)/i
5
+
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-yandex-domains"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Devico Solutions"]
5
+ spec.email = ["info@devico.io"]
6
+ spec.description = "Lita handler to interact with yandex domain API"
7
+ spec.summary = ""
8
+ spec.homepage = "https://github.com/DevicoSolutions/lita-yandex-domains"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.required_ruby_version = '>= 2.3.0'
18
+
19
+ spec.add_runtime_dependency 'lita', '>= 4.7'
20
+ spec.add_runtime_dependency 'yandex-pdd-2', '~> 0.1.3'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'pry-byebug'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rack-test'
26
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
27
+ spec.add_development_dependency 'simplecov'
28
+ spec.add_development_dependency 'coveralls'
29
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,29 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ yandex_domains:
5
+ help:
6
+ show_human_emails:
7
+ syntax: yandex show all human emails
8
+ desc: Show all emails that not include mailing lists
9
+ show_maillists:
10
+ syntax: yandex show all maillists
11
+ desc: Show all maillists
12
+ create_email:
13
+ syntax: yandex add email <email>
14
+ desc: Add email with random generated password
15
+ delete_email:
16
+ syntax: yandex delete email <email>
17
+ desc: Delete user email
18
+ create_maillist:
19
+ syntax: yandex add maillist <email>
20
+ desc: Add maillist
21
+ delete_maillist:
22
+ syntax: yandex delete maillist <email>
23
+ desc: Delete maillist
24
+ add_subscriber:
25
+ syntax: yandex add <email> to maillist <email>
26
+ desc: Add subcriber to maillist
27
+ delete_subscriber:
28
+ syntax: yandex delete <email> from maillist <email>
29
+ desc: Remove subcriber from maillist
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::YandexDomains, lita_handler: true do
4
+
5
+ before do
6
+ robot.auth.add_user_to_group!(user, :yandex_admins)
7
+ end
8
+
9
+ describe 'lita routes' do
10
+ it { is_expected.to route_command('yandex create email test@test.com').to(:create_email).with_authorization_for(:yandex_admins) }
11
+ it { is_expected.to route_command('yandex delete email test@test.com').to(:delete_email).with_authorization_for(:yandex_admins) }
12
+ it { is_expected.to route_command('yandex show all human emails').to(:show_all_emails) }
13
+ it { is_expected.to route_command('yandex create maillist maillist@test.com').to(:create_maillist).with_authorization_for(:yandex_admins) }
14
+ it { is_expected.to route_command('yandex delete maillist maillist@test.com').to(:delete_maillist).with_authorization_for(:yandex_admins) }
15
+ it { is_expected.to route_command('yandex show all maillists').to(:show_all_maillists) }
16
+ it { is_expected.to route_command('yandex add test@devico.io to maillist maillist@test.com').to(:add_subscriber).with_authorization_for(:yandex_admins) }
17
+ it { is_expected.to route_command('yandex delete test@devico.io from maillist maillist@test.com').to(:remove_subscriber).with_authorization_for(:yandex_admins) }
18
+ end
19
+
20
+ end
@@ -0,0 +1,14 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-yandex-domains"
10
+ require "lita/rspec"
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-yandex-domains
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Devico Solutions
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yandex-pdd-2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Lita handler to interact with yandex domain API
140
+ email:
141
+ - info@devico.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - Gemfile
149
+ - README.md
150
+ - Rakefile
151
+ - lib/lita-yandex-domains.rb
152
+ - lib/lita/handlers/yandex_domains.rb
153
+ - lib/yandexhelper/regex.rb
154
+ - lita-yandex-domains.gemspec
155
+ - locales/en.yml
156
+ - spec/lita/handlers/yandex_domains_spec.rb
157
+ - spec/spec_helper.rb
158
+ - templates/.gitkeep
159
+ homepage: https://github.com/DevicoSolutions/lita-yandex-domains
160
+ licenses:
161
+ - MIT
162
+ metadata:
163
+ lita_plugin_type: handler
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 2.3.0
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.5.1
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: ''
184
+ test_files:
185
+ - spec/lita/handlers/yandex_domains_spec.rb
186
+ - spec/spec_helper.rb