pechkin 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a2ecda5dd85e6cb2dd48ccb18eb1966559fa8d6539239b1e6def0377324c765
4
- data.tar.gz: 9be0c8e01ceec5f0e19f2c44a9a7d10a2c09c32ddcec26d5fba5d43f808eaec2
3
+ metadata.gz: 3fa8abd425ad6a776104aabeeb6916d4b8b4d77ae0f0d7e24b75f102bb70b016
4
+ data.tar.gz: 1b5b43910b029f8553f54ddfa5d70a7195b2db86d35a38ba1fcffc37521b7d4b
5
5
  SHA512:
6
- metadata.gz: 2bdf5bd548de267c3cfc9a7a45be9a451df75bf288e9403dfe1ed9e3f748318fd1acd85f5070f310890b5947b3f478ea4cdab817b8cba9902cf5f23ad35cd431
7
- data.tar.gz: c18c214ef31484ccc3dd79af5c55270f1fdcea84ee198e7ef5c3adc39b76496914ba703bc2d5e7f45beec62fb25dd71942cdf323a82b02a35d641a6aec420d6c
6
+ metadata.gz: d636b920cb207c03ce1f96ceeb47ec478214743e0ef4f49895c07982fcf68d2b724d4006058ef00de6903c986c6f40e8678ebbb7ccdaa681d6b552cfb70111a1
7
+ data.tar.gz: 5254cb1f323cb46af16b889d82ffd565a9a0f30e5665cc6c5487e59926f25e66b8a573e004ffcf4c2a34b8f17187b0e67443ef5bf5ffec3b8e2a68e079557def
@@ -15,9 +15,7 @@ module Pechkin
15
15
  use Prometheus::Middleware::Collector, registry: prometheus
16
16
  # Add Auth check if found htpasswd file or it was excplicitly provided
17
17
  # See CLI class for configuration details
18
- if options.htpasswd
19
- use Pechkin::Auth::Middleware, auth_file: options.htpasswd
20
- end
18
+ use Pechkin::Auth::Middleware, auth_file: options.htpasswd if options.htpasswd
21
19
  use Prometheus::Middleware::Exporter, registry: prometheus
22
20
 
23
21
  run app
@@ -34,7 +32,7 @@ module Pechkin
34
32
  file = File.open(log_file, File::WRONLY | File::APPEND)
35
33
  Logger.new(file)
36
34
  else
37
- Logger.new(STDOUT)
35
+ Logger.new($stdout)
38
36
  end
39
37
  end
40
38
  end
@@ -2,7 +2,7 @@ module Pechkin
2
2
  # Http requests handler. We need fresh instance per each request. To keep
3
3
  # internal state isolated
4
4
  class RequestHandler
5
- REQ_PATH_PATTERN = %r{^/(.+)/([^/]+)/?$}
5
+ REQ_PATH_PATTERN = %r{^/(.+)/([^/]+)/?$}.freeze
6
6
 
7
7
  attr_reader :req, :handler,
8
8
  :channel_id, :message_id,
data/lib/pechkin/auth.rb CHANGED
@@ -5,6 +5,7 @@ module Pechkin
5
5
  # Utility class for altering htpasswd files
6
6
  class Manager
7
7
  attr_reader :htpasswd
8
+
8
9
  def initialize(htpasswd)
9
10
  @htpasswd = htpasswd
10
11
  end
@@ -3,7 +3,7 @@ module Pechkin
3
3
  class Chanel
4
4
  attr_accessor :logger
5
5
 
6
- def initialize(connector, channel_list, logger = ::Logger.new(STDOUT))
6
+ def initialize(connector, channel_list, logger = ::Logger.new($stdout))
7
7
  @connector = connector
8
8
  @channel_list = channel_list
9
9
  @channel_list = [channel_list] unless channel_list.is_a?(Array)
data/lib/pechkin/cli.rb CHANGED
@@ -13,7 +13,7 @@ module Pechkin
13
13
  # @opt names [Array<String>] list of command line keys
14
14
  # @opt desc [String] option description
15
15
  # @opt type [Class] argument type to parse from command line, e.g. Integer
16
- def opt(name, default: nil, names:, desc: '', type: nil)
16
+ def opt(name, names:, default: nil, desc: '', type: nil)
17
17
  @cli_options ||= []
18
18
 
19
19
  # raise ':names is nil or empty' if names.nil? || names.empty?
@@ -9,7 +9,7 @@ module Pechkin
9
9
  # command behaviour
10
10
  # @opt stdout [IO] IO object which represents STDOUT
11
11
  # @opt stderr [IO] IO object which represents STDERR
12
- def initialize(options, stdout: STDOUT, stderr: STDERR)
12
+ def initialize(options, stdout: $stdout, stderr: $stderr)
13
13
  @options = options
14
14
  @stdout = stdout
15
15
  @stderr = stderr
@@ -29,6 +29,7 @@ module Pechkin
29
29
  d = if data.start_with?('@')
30
30
  file = data[1..-1]
31
31
  raise "File not found #{file}" unless File.exist?(file)
32
+
32
33
  IO.read(file)
33
34
  else
34
35
  data
@@ -17,7 +17,7 @@ module Pechkin
17
17
  when 'slack'
18
18
  Connector::Slack.new(bot.token, bot.name)
19
19
  else
20
- raise 'Unknown connector ' + bot.connector + ' for ' + bot.name
20
+ raise "Unknown connector #{bot.connector} for #{bot.name}"
21
21
  end
22
22
  end
23
23
 
@@ -15,9 +15,7 @@ module Pechkin
15
15
  def load_bots_configuration(working_dir, bots)
16
16
  bots_dir = File.join(working_dir, 'bots')
17
17
 
18
- unless File.directory?(bots_dir)
19
- raise ConfigurationError, "'#{bots_dir}' is not a directory"
20
- end
18
+ raise ConfigurationError, "'#{bots_dir}' is not a directory" unless File.directory?(bots_dir)
21
19
 
22
20
  Dir["#{bots_dir}/*.yml"].each do |bot_file|
23
21
  name = File.basename(bot_file, '.yml')
@@ -22,9 +22,7 @@ module Pechkin
22
22
  def load_channels_configuration(working_dir, channels)
23
23
  channels_dir = File.join(working_dir, 'channels')
24
24
 
25
- unless File.directory?(channels_dir)
26
- raise ConfigurationError, "'#{channels_dir}' is not a directory"
27
- end
25
+ raise ConfigurationError, "'#{channels_dir}' is not a directory" unless File.directory?(channels_dir)
28
26
 
29
27
  Dir["#{channels_dir}/*"].each do |channel_dir|
30
28
  next unless File.directory?(channel_dir)
@@ -63,9 +61,7 @@ module Pechkin
63
61
  message_config = YAML.safe_load(IO.read(file))
64
62
  name = File.basename(file, '.yml')
65
63
 
66
- if message_config.key?('template')
67
- message_config['template'] = get_template(message_config['template'])
68
- end
64
+ message_config['template'] = get_template(message_config['template']) if message_config.key?('template')
69
65
 
70
66
  messages[name] = message_config
71
67
  end
@@ -15,9 +15,7 @@ module Pechkin
15
15
  def load_views_configuration(working_dir, views)
16
16
  views_dir = File.join(working_dir, 'views')
17
17
 
18
- unless File.directory?(views_dir)
19
- raise ConfigurationError, "'#{views_dir}' is not a directory"
20
- end
18
+ raise ConfigurationError, "'#{views_dir}' is not a directory" unless File.directory?(views_dir)
21
19
 
22
20
  Dir["#{views_dir}/**/*.erb"].each do |f|
23
21
  relative_path = f["#{views_dir}/".length..-1]
@@ -4,6 +4,8 @@ module Pechkin
4
4
  attr_reader :name
5
5
 
6
6
  def initialize(bot_token, name)
7
+ super()
8
+
7
9
  @headers = { 'Authorization' => "Bearer #{bot_token}" }
8
10
  @name = name
9
11
  end
@@ -4,6 +4,8 @@ module Pechkin
4
4
  attr_reader :name
5
5
 
6
6
  def initialize(bot_token, name)
7
+ super()
8
+
7
9
  @bot_token = bot_token
8
10
  @name = name
9
11
  end
@@ -4,7 +4,10 @@ module Pechkin
4
4
  super("No such channel #{channel_name}")
5
5
  end
6
6
  end
7
+
7
8
  class MessageNotFoundError < StandardError; end
9
+
8
10
  class MessageContentIsEmptyError < StandardError; end
11
+
9
12
  class ConfigurationError < StandardError; end
10
13
  end
@@ -5,7 +5,7 @@ module Pechkin
5
5
  attr_reader :channels, :message_matcher
6
6
  attr_accessor :logger
7
7
 
8
- def initialize(channels, stdout = STDOUT, stderr = STDERR)
8
+ def initialize(channels, stdout = $stdout, stderr = $stderr)
9
9
  @channels = channels
10
10
  # Create empty logger by default
11
11
  @logger = Logger.new(IO::NULL)
@@ -1,5 +1,6 @@
1
1
  module Pechkin
2
2
  class MessageMatchError < StandardError; end
3
+
3
4
  # Allows to match message configuration against received data.
4
5
  #
5
6
  # Data is checked againts either allow or forbid rules. But not both at the
@@ -51,11 +52,12 @@ module Pechkin
51
52
  # can take one field in rule and check it separately as new rule. If all
52
53
  # fields are passed check then whole rule passed.
53
54
  def check_rule(top_rule, sub_rule, data)
54
- result = if sub_rule.is_a?(Hash)
55
+ result = case sub_rule
56
+ when Hash
55
57
  check_hash_rule(top_rule, sub_rule, data)
56
- elsif sub_rule.is_a?(Array)
58
+ when Array
57
59
  check_array_rule(top_rule, sub_rule, data)
58
- elsif sub_rule.is_a?(String)
60
+ when String
59
61
  check_string_rule(top_rule, sub_rule, data)
60
62
  else
61
63
  sub_rule.eql?(data)
@@ -1,7 +1,7 @@
1
1
  module Pechkin
2
2
  # Keeps actual version
3
3
  module Version
4
- VERSION = [1, 3, 2].freeze
4
+ VERSION = [1, 4, 0].freeze
5
5
  class << self
6
6
  def version_string
7
7
  VERSION.join('.')
data/lib/pechkin.rb CHANGED
@@ -28,8 +28,8 @@ module Pechkin # :nodoc:
28
28
  cmd = Command::Dispatcher.new(options).dispatch
29
29
  cmd.execute
30
30
  rescue StandardError => e
31
- warn 'Error: ' + e.message
32
- warn "\t" + e.backtrace.reverse.join("\n\t") if options.debug?
31
+ warn "Error: #{e.message}"
32
+ warn "\t#{e.backtrace.reverse.join("\n\t")}" if options.debug?
33
33
  exit 2
34
34
  end
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pechkin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Arkhanhelsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-10 00:00:00.000000000 Z
11
+ date: 2021-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htauth
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 2.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: 2.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: powerpack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.0.8
61
+ version: 2.2.3
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.0.8
68
+ version: 2.2.3
69
69
  description:
70
70
  email: ilya.arkhanhelsky at gmail.com
71
71
  executables:
@@ -117,16 +117,16 @@ require_paths:
117
117
  - lib
118
118
  required_ruby_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - ">="
120
+ - - ">"
121
121
  - !ruby/object:Gem::Version
122
- version: '0'
122
+ version: '2.5'
123
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.0.3
129
+ rubygems_version: 3.2.22
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Web service to proxy webhooks to Telegram Bot API