chatopsify 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 216f9a98d4907836c37bfc4454f177b1ba57acdf83e24b84e800c8d67f1c5d9c
4
- data.tar.gz: d493671383220e3df3d80cc07627bd31ab27c3fc9ab8e23a3bad49ecfdd215ba
3
+ metadata.gz: 14141a20c1a8a4cfda8993608f336919ef400ad96644ca994658fd215b494a8b
4
+ data.tar.gz: dbf4b8583120ec65a00d0e47fa82e469ed4fd80e27644d1d9def262c9e8849fb
5
5
  SHA512:
6
- metadata.gz: f035c97f0c8449746fb3ea2f16361736d2841e162e4b965a5f63037931216e53b6949631cd66a857d4e749341faf31ff97d202539396e90e2b658ab1cd03c982
7
- data.tar.gz: d3d04ec37b3683597cc7a530314947cbc3ea086522c1993589579d9a3804c2cffcfb835160285327a7adc37e0108841b206ff65f910876097009d626c914a80b
6
+ metadata.gz: 690503d6828f98cd64ce2e90540c6adcdcaccfcc59093ad195f887ee5893c549b8ffd87f6a94e9f2985826cbd12bb8bc63ab6da54b52fdba8137c88ed49465c9
7
+ data.tar.gz: 29c67e0bed4b61b825c49a4e903fc1643516a9d14279bf12b0547e04a3a802b0de0fb80fccc2dce17af082fa0bb4e3675ec185aed0796761aee8f604c82065cb
@@ -8,20 +8,17 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
 
10
10
  steps:
11
- - uses: actions/checkout@v2
12
- - name: Set up Ruby 2.6 is
13
- uses: actions/setup-ruby@v1
11
+ - uses: actions/checkout@v4
12
+ - name: Set up Ruby 2.6.4
13
+ uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 2.6.x
16
- - uses: actions/cache@v1
17
- with:
18
- path: vendor/bundle
19
- key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
20
- restore-keys: |
21
- ${{ runner.os }}-gems-
15
+ ruby-version: 2.6.4
16
+ # - uses: ruby/setup-ruby@v1
17
+ # with:
18
+ # bundler-cache: true
22
19
  - name: Run Rubocop linter
23
20
  run: |
24
- gem install bundler
21
+ gem install bundler -v 2.4.22
25
22
  bundle config path vendor/bundle
26
23
  bundle install --jobs 4 --retry 3
27
24
  bundle exec rubocop
@@ -8,20 +8,14 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
 
10
10
  steps:
11
- - uses: actions/checkout@v2
12
- - name: Set up Ruby 2.6 is
13
- uses: actions/setup-ruby@v1
11
+ - uses: actions/checkout@v4
12
+ - name: Set up Ruby 2.6.4
13
+ uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 2.6.x
16
- - uses: actions/cache@v1
17
- with:
18
- path: vendor/bundle
19
- key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
20
- restore-keys: |
21
- ${{ runner.os }}-gems-
15
+ ruby-version: 2.6.4
22
16
  - name: Run test suite
23
17
  run: |
24
- gem install bundler
18
+ gem install bundler -v 2.4.22
25
19
  bundle config path vendor/bundle
26
20
  bundle install --jobs 4 --retry 3
27
21
  bundle exec rake test
data/.rubocop.yml CHANGED
@@ -6,8 +6,14 @@ Style/StringLiteralsInInterpolation:
6
6
  Enabled: true
7
7
  EnforcedStyle: single_quotes
8
8
 
9
+ Metrics/AbcSize:
10
+ Enabled: false
11
+
9
12
  Layout/LineLength:
10
13
  Max: 120
14
+ Metrics/MethodLength:
15
+ Max: 120
16
+
11
17
 
12
18
  AllCops:
13
19
  NewCops: enable
data/Gemfile CHANGED
@@ -5,8 +5,7 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in Chatopsify.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 13.0'
9
-
8
+ gem 'bundler', '~> 2'
10
9
  gem 'minitest', '~> 5.0'
11
-
10
+ gem 'rake', '~> 13.0'
12
11
  gem 'rubocop', '~> 1.21'
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Chatopsify
2
2
 
3
- ![Gem](https://img.shields.io/gem/v/Chatopsify?color=%234cc61f&label=Gem%20version&logo=ruby&logoColor=red)
4
- ![Gem](https://img.shields.io/gem/dt/Chatopsify?color=%2330c754&label=Downloads&logo=rubygems&logoColor=red)
5
- ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/rs-phunt/Chatopsify/Tests%20%F0%9F%A7%AA?label=Tests&logo=github)
6
- ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/rs-phunt/Chatopsify/Rubocop%20Lint?label=Rubocop&logo=github)
3
+ ![Gem](https://img.shields.io/gem/v/chatopsify?color=%25234cc61f&label=Gem%20version&logo=ruby&logoColor=red&link=https%3A%2F%2Frubygems.org%2Fgems%2Fchatopsify)
4
+ ![Gem](https://img.shields.io/gem/dt/chatopsify?color=%2330c754&label=Downloads&logo=rubygems&logoColor=red&link=https%3A%2F%2Frubygems.org%2Fgems%2Fchatopsify)
5
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/papakvy/chatopsify/run_rubocop.yml?branch=main&logo=rubocop&logoColor=red&label=Rubocop%20Lint)
6
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/papakvy/chatopsify/run_tests.yml?branch=main&logo=rubocop&logoColor=red&label=Tests%20%F0%9F%A7%AA)
7
+ <!-- ![GitHub Repo stars](https://img.shields.io/github/stars/papakvy/chatopsify?logoColor=red) -->
7
8
 
8
9
  ## Installation
9
10
 
@@ -29,19 +30,22 @@ Require the gem in your `Capfile`:
29
30
 
30
31
  ## Configuration
31
32
 
32
- ### Puts `CHATOPS_API_KEY` into your ENV
33
-
34
- - Export to your `bash`: `export CHATOPS_API_KEY=xxx`
35
-
36
- - Add to `.env` if you're using `dotenv` gem
33
+ ### Using ENV (or `.env`)
37
34
 
35
+ ```bash
36
+ export CHATOPS_URI='your_chatops_uri'
37
+ export CHATOPS_API_KEY='your_chatops_api_key'
38
+ export CHATOPS_CHANNEL_ID='your_channel_id'
39
+ ```
38
40
 
39
- ### Puts `CHATOPS_CHANNEL_ID` into your ENV or custom in `config/deploy`
41
+ ### Using `config/deploy`
40
42
 
41
43
  ```ruby
42
44
  # config/deploy.rb
43
45
  ...
44
- set :chatops_channel_id, 'xxx'
46
+ set :chatops_uri, 'your_chatops_uri'
47
+ set :chatops_api_key, 'your_chatops_api_key'
48
+ set :chatops_channel_id, 'your_channel_id'
45
49
  ...
46
50
  ```
47
51
 
data/chatopsify.gemspec CHANGED
@@ -12,15 +12,15 @@ Gem::Specification.new do |spec|
12
12
  spec.email = ['phunt@runsystem.net']
13
13
 
14
14
  spec.summary = 'Publish deployment notifications to ChatOps via the API'
15
- spec.description = 'Publish deployment notifications to ChatOps via the API'
15
+ spec.description = 'chatopsify = ChatOps + Capistrano notifications via API'
16
16
  spec.homepage = 'https://github.com/papakvy/chatopsify'
17
17
  spec.license = 'MIT'
18
18
  spec.required_ruby_version = '>= 2.6'
19
19
 
20
20
  # spec.metadata['allowed_push_host'] = 'TODO: Set to your gem server 'https://example.com''
21
21
  spec.metadata['rubygems_mfa_required'] = 'true'
22
- spec.metadata['homepage_uri'] = spec.homepage
23
- spec.metadata['source_code_uri'] = 'https://github.com/papakvy/chatopsify'
22
+ # spec.metadata['homepage_uri'] = spec.homepage
23
+ # spec.metadata['source_code_uri'] = 'https://github.com/papakvy/chatopsify'
24
24
  spec.metadata['changelog_uri'] = 'https://github.com/papakvy/chatopsify/blob/master/CHANGELOG.md'
25
25
 
26
26
  spec.files = `git ls-files -z`.split("\x0")
@@ -31,9 +31,6 @@ Gem::Specification.new do |spec|
31
31
  # Uncomment to register a new dependency of your gem
32
32
 
33
33
  spec.add_dependency 'capistrano', '~> 3.2', '>= 3.2.0'
34
- spec.add_dependency 'tzinfo', '~> 1.1'
35
- spec.add_development_dependency 'bundler', '~> 2'
36
- spec.add_development_dependency 'rake', '~> 1'
37
34
 
38
35
  # For more information and examples about making a new gem, checkout our
39
36
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,11 +1,15 @@
1
1
  namespace :chatops do
2
2
  desc "Notify ChatOps Started"
3
3
  task :notify_started do
4
- # return
5
4
  set :chatops_time_started, Time.now
6
5
  run_locally do
7
6
  if fetch(:chatops_notify_events).include? :started
8
- Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:starting))
7
+ info 'Notifying ChatOps of deploy started'
8
+ begin
9
+ Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:starting))
10
+ rescue StandardError => e
11
+ info "ERROR notify_started: #{e}"
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -18,7 +22,11 @@ namespace :chatops do
18
22
  run_locally do
19
23
  if fetch(:chatops_notify_events).include? :finished
20
24
  info 'Notifying ChatOps of deploy finished'
21
- Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:success))
25
+ begin
26
+ Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:success))
27
+ rescue StandardError => e
28
+ info "ERROR notify_finished: #{e}"
29
+ end
22
30
  end
23
31
  end
24
32
  end
@@ -31,7 +39,11 @@ namespace :chatops do
31
39
  run_locally do
32
40
  if fetch(:chatops_notify_events).include? :failed
33
41
  info 'Notifying ChatOps of deploy failed'
34
- Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:failed))
42
+ begin
43
+ Chatopsify::Co.call.process(Chatopsify::CoLib.msg_fmt(:failed))
44
+ rescue StandardError => e
45
+ info "ERROR notify_failed: #{e}"
46
+ end
35
47
  end
36
48
  end
37
49
  end
@@ -51,7 +63,7 @@ namespace :load do
51
63
  servers.map{ |e| ["#{e.hostname} (#{e.properties.fetch(:my_property)&.upcase!})"]}.join(', ')
52
64
  }
53
65
  set :chatops_deploy_starting_text, ->{
54
- "### :zap: ⎡#{fetch(:application)}⎦ is deploying by ⎡*#{fetch(:local_user)}*⎦: Starting •••"
66
+ "### :zap: ⎡#{fetch(:application)}⎦ is being deployed by ⎡*#{fetch(:local_user)}*⎦: Starting •••"
55
67
  }
56
68
  set :chatops_deploy_succeed_text, ->{
57
69
  time_elapsed = Integer(fetch(:chatops_time_finished, 0).to_i - fetch(:chatops_time_started, 0).to_i)
@@ -61,7 +73,7 @@ namespace :load do
61
73
  set :chatops_deploy_failed_text, ->{
62
74
  time_elapsed = Integer(fetch(:chatops_time_finished, 0).to_i - fetch(:chatops_time_started, 0).to_i)
63
75
  "### :sos: ⎡#{fetch(:application)}⎦ was deployed by ⎡#{fetch(:local_user)}⎦: " \
64
- "*failed* in **#{time_elapsed}** seconds."
76
+ "*failed* within **#{time_elapsed}** seconds."
65
77
  }
66
78
  set :chatops_notify_events, [:started, :finished, :failed]
67
79
  end
data/lib/chatopsify/co.rb CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'json'
4
4
  require 'net/http'
5
- require 'tzinfo'
6
5
 
7
6
  module Chatopsify
8
- # ChatOps service
7
+ # ChatOps services
9
8
  class Co
10
9
  def initialize(api_key = nil)
11
10
  @api_key = api_key || load_api_key
@@ -25,8 +24,8 @@ module Chatopsify
25
24
  puts e.message
26
25
  end
27
26
 
28
- def call_get(id = nil)
29
- send_get_request(id)
27
+ def call_delete(id = nil)
28
+ send_delete_request(id)
30
29
  rescue StandardError => e
31
30
  puts e.message
32
31
  end
@@ -67,11 +66,10 @@ module Chatopsify
67
66
  puts "Response: #{res.code} #{res.body}"
68
67
  end
69
68
 
70
- def send_get_request(id = nil)
69
+ def send_delete_request(id = nil)
71
70
  uri = URI(@uri)
72
71
  uri.path += "/#{id}" if id
73
72
 
74
- # req = Net::HTTP::Get.new(co_uri)
75
73
  req = Net::HTTP::Delete.new(uri)
76
74
  req['authorization'] = "Bearer #{o_api_key}"
77
75
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
@@ -97,20 +95,23 @@ module Chatopsify
97
95
  end
98
96
  end
99
97
 
98
+ # rubocop:disable Lint/TripleQuotes, Style/StringLiterals, Layout/IndentationWidth
100
99
  def msg_fmt(status = nil)
101
100
  """#{text(status)}
102
101
  | TITLE | CONTENTS |
103
102
  |----------:|:-------------|
104
- | Stage | #{fetch(:stage).upcase!} |
105
- | Server | #{fetch(:ip_address) }|
103
+ | Stage | #{fetch(:stage)&.upcase!} |
104
+ | Server | #{fetch(:ip_address)}|
106
105
  | Branch | #{fetch(:branch)} |
107
106
  | Revision | #{fetch(:current_revision) || '<empty>'} |
108
- | Timestamp | #{TZInfo::Timezone.get('Asia/Ho_Chi_Minh')&.now || Time.now} |
107
+ | Timestamp | #{Time.now.getlocal('+07:00') || Time.now} |
109
108
  """
110
109
  end
110
+ # rubocop:enable Lint/TripleQuotes, Style/StringLiterals, Layout/IndentationWidth
111
111
  end
112
112
  end
113
113
 
114
+ # CoSecurity service
114
115
  class CoSecurity
115
116
  require 'openssl'
116
117
  require 'securerandom'
@@ -124,44 +125,40 @@ module Chatopsify
124
125
  end
125
126
 
126
127
  def encrypt_string
127
- begin
128
- cipher = OpenSSL::Cipher::AES256.new(:CBC)
129
- cipher.encrypt
130
- salt = SecureRandom.random_bytes(16)
131
- key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
132
- key = key_iv[0, cipher.key_len]
133
- iv = key_iv[cipher.key_len, cipher.iv_len]
134
-
135
- cipher.key = key
136
- cipher.iv = iv
137
-
138
- encrypted = cipher.update(@str) + cipher.final
139
- (salt + encrypted).unpack1('H*')
140
- rescue => e
141
- false
142
- end
128
+ cipher = OpenSSL::Cipher.new('aes-256-cbc')
129
+ cipher.encrypt
130
+ salt = SecureRandom.random_bytes(16)
131
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
132
+ key = key_iv[0, cipher.key_len]
133
+ iv = key_iv[cipher.key_len, cipher.iv_len]
134
+
135
+ cipher.key = key
136
+ cipher.iv = iv
137
+
138
+ encrypted = cipher.update(@str) + cipher.final
139
+ (salt + encrypted).unpack1('H*')
140
+ rescue StandardError => e
141
+ puts e.message
143
142
  end
144
143
 
145
144
  def decrypt_string
146
- begin
147
- encrypted = [@str].pack('H*')
148
- cipher = OpenSSL::Cipher::AES256.new(:CBC)
149
- cipher.decrypt
145
+ encrypted = [@str].pack('H*')
146
+ cipher = OpenSSL::Cipher.new('aes-256-cbc')
147
+ cipher.decrypt
150
148
 
151
- salt = encrypted[0, 16]
152
- encrypted_data = encrypted[16..-1]
149
+ salt = encrypted[0, 16]
150
+ encrypted_data = encrypted[16..]
153
151
 
154
- key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
155
- key = key_iv[0, cipher.key_len]
156
- iv = key_iv[cipher.key_len, cipher.iv_len]
152
+ key_iv = OpenSSL::PKCS5.pbkdf2_hmac_sha1(generate_pwd, salt, 2000, cipher.key_len + cipher.iv_len)
153
+ key = key_iv[0, cipher.key_len]
154
+ iv = key_iv[cipher.key_len, cipher.iv_len]
157
155
 
158
- cipher.key = key
159
- cipher.iv = iv
156
+ cipher.key = key
157
+ cipher.iv = iv
160
158
 
161
- cipher.update(encrypted_data) + cipher.final
162
- rescue => e
163
- false
164
- end
159
+ cipher.update(encrypted_data) + cipher.final
160
+ rescue StandardError => e
161
+ puts e.message
165
162
  end
166
163
 
167
164
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chatopsify
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.6'
5
5
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
- require 'Chatopsify'
4
+ require 'chatopsify'
5
5
 
6
6
  require 'minitest/autorun'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatopsify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - phunt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-16 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -30,49 +30,7 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.2.0
33
- - !ruby/object:Gem::Dependency
34
- name: tzinfo
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '1.1'
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '1.1'
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '2'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '2'
61
- - !ruby/object:Gem::Dependency
62
- name: rake
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1'
75
- description: Publish deployment notifications to ChatOps via the API
33
+ description: chatopsify = ChatOps + Capistrano notifications via API
76
34
  email:
77
35
  - phunt@runsystem.net
78
36
  executables: []
@@ -96,18 +54,15 @@ files:
96
54
  - lib/capistrano/tasks/chatopsify.cap
97
55
  - lib/chatopsify.rb
98
56
  - lib/chatopsify/co.rb
99
- - lib/chatopsify/co_service.rb
100
57
  - lib/chatopsify/version.rb
101
58
  - lib/core_ext/custom_lib.rb
102
- - test/chatworkify_test.rb
59
+ - test/chatopsify_test.rb
103
60
  - test/test_helper.rb
104
61
  homepage: https://github.com/papakvy/chatopsify
105
62
  licenses:
106
63
  - MIT
107
64
  metadata:
108
65
  rubygems_mfa_required: 'true'
109
- homepage_uri: https://github.com/papakvy/chatopsify
110
- source_code_uri: https://github.com/papakvy/chatopsify
111
66
  changelog_uri: https://github.com/papakvy/chatopsify/blob/master/CHANGELOG.md
112
67
  post_install_message:
113
68
  rdoc_options: []
@@ -1,10 +0,0 @@
1
- module Chatopsify
2
- class CoService
3
- CO_URI = 'https://chat.runsystem.vn/api/v4/posts'.freeze
4
-
5
- def initialize(api_key, channel_id)
6
- @api_key = api_key
7
- @channel_id = channel_id
8
- end
9
- end
10
- end
File without changes