mina-infinum 2.2.0 → 2.4.0

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: b9e1081ff27138ce5b9264ec25ed270c8e394ffd35ee7272e9a60897a4e87a3b
4
- data.tar.gz: 81e98a8aaeceefbef746339be9ad07860a8ae11eff653131832b84444960312d
3
+ metadata.gz: 7d08049d5114d7747bbad76c04cec40f51f95b55b1741b79fc57fc3fa96d7419
4
+ data.tar.gz: 25e29db32a826f58bb8fc530f8ae9fea7fbd159a0f8880dab2b02c9003365978
5
5
  SHA512:
6
- metadata.gz: 6e4863e6edadd84172c87cc34d043b4db4445be056373d1b1ba8b6982e839a205e3c9390bc84050d0f9ded00911440e0ac541bedadeb396d26282369f84db0d8
7
- data.tar.gz: d02cb8f73830e4e4f5436d0e25a5eb5ae842543c8c55887e3ce739208780c3ba6309560abae8f04b14a26e0d28e762a290b467ae1a2f4326c93f50bb2a45aea0
6
+ metadata.gz: f3b0043ceea5b17160fc4b164fad29948cb4e910d479b8e591935cf2be740545f92af8ebf1c4a94ed209fb7a92c4b830f8632b6f7bc0422397800f2cb839ec00
7
+ data.tar.gz: 488b575896cbb2d8be5efac54f71cb6bf5a639492b877bca0ca92d974f78e23d7d0001bdd9b4e838f19a06ec13ff495b1f24accd2e0e1369d22c08ba44722201
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [v2.4.0](https://github.com/infinum/mina-infinum/tree/v-2.4.0) (2025-10-14)
4
+ [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.3.0...v2.4.0)
5
+
6
+ ### Enhancements
7
+
8
+ - Add `skip_profile` flag to call AWS CLI commands without a `--profile` flag [\#9](https://github.com/infinum/mina-infinum/pull/9)
9
+ - Add path param to params:pull task [\#10](https://github.com/infinum/mina-infinum/pull/10)
10
+
11
+ ## [v2.3.0](https://github.com/infinum/mina-infinum/tree/v-2.3.0) (2025-10-02)
12
+ [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.2.0...v2.3.0)
13
+
14
+ ### Enhancements
15
+
16
+ - Add logs and logs:tail AWS tasks [\#8](https://github.com/infinum/mina-infinum/pull/8)
17
+
3
18
  ## [v2.2.0](https://github.com/infinum/mina-infinum/tree/v-2.2.0) (2025-07-25)
4
19
  [Full Changelog](https://github.com/infinum/mina-infinum/compare/v2.1.0...v2.2.0)
5
20
 
@@ -70,3 +70,7 @@ Starting session with SessionId: botocore-session-12345
70
70
  Port 9999 opened for sessionId botocore-session-12345.
71
71
  Waiting for connections...
72
72
  ```
73
+
74
+ ## Skip profile
75
+
76
+ To execute AWS CLI commands without the `--profile` flag, append `skip_profile=true` to your commands, e.g.: `bundle exec mina staging params:pull skip_profile=true`.
@@ -43,6 +43,8 @@ namespace :aws do
43
43
 
44
44
  namespace :profile do
45
45
  task :check do
46
+ next if fetch(:skip_profile)
47
+
46
48
  ensure!(:aws_profile)
47
49
 
48
50
  unless profile_exists?(fetch(:aws_profile))
@@ -92,5 +94,9 @@ def profile_exists?(profile)
92
94
  profiles.split("\n").include?(profile)
93
95
  end
94
96
 
97
+ def aws_cli_profile_flag
98
+ fetch(:aws_profile) && !fetch(:skip_profile) ? "--profile #{fetch(:aws_profile)}" : ''
99
+ end
100
+
95
101
  desc 'Alias for aws:login'
96
102
  task :login => 'aws:login'
@@ -15,7 +15,6 @@ namespace :db do
15
15
  ensure!(:aws_jump_server_id)
16
16
  ensure!(:db_host)
17
17
 
18
- profile = fetch(:aws_profile)
19
18
  jump_server_id = fetch(:aws_jump_server_id)
20
19
  host = fetch(:db_host)
21
20
  remote_port = fetch(:db_port, 5432)
@@ -26,7 +25,7 @@ namespace :db do
26
25
  --target #{jump_server_id}
27
26
  --document-name AWS-StartPortForwardingSessionToRemoteHost
28
27
  --parameters host="#{host}",portNumber="#{remote_port}",localPortNumber="#{local_port}"
29
- --profile #{profile}
28
+ #{aws_cli_profile_flag}
30
29
  #{'--debug' if debug?}
31
30
  CMD
32
31
  end
@@ -24,7 +24,7 @@ namespace :ecs do
24
24
  --task #{task_arn}
25
25
  --command \"#{command}\"
26
26
  --cluster #{fetch(:cluster)}
27
- --profile #{fetch(:aws_profile)}
27
+ #{aws_cli_profile_flag}
28
28
  --interactive
29
29
  #{'--debug' if debug?}
30
30
  CMD
@@ -48,7 +48,7 @@ def find_task_arn
48
48
  --output json
49
49
  --cluster #{fetch(:cluster)}
50
50
  --service #{fetch(:service)}
51
- --profile #{fetch(:aws_profile)}
51
+ #{aws_cli_profile_flag}
52
52
  #{'--debug' if debug?}
53
53
  CMD
54
54
 
@@ -0,0 +1,112 @@
1
+ require 'time'
2
+ require 'mina/infinum/ecs/aws'
3
+
4
+ desc <<~TXT
5
+ Print logs from CloudWatch
6
+
7
+ Logs are printed from :log_group, which is a CloudWatch log group name.
8
+
9
+ Logs are fetched in range :since to :until (both inclusive). Both values must be
10
+ parseable by `Time.parse` (e.g. ISO8601 timestamps). :since is required,
11
+ :until is optional (if omitted, value will be current time).
12
+
13
+ If date is ommitted in either value, the current date is assumed.
14
+
15
+ Examples:
16
+ # logs since 26.9.2025. 14:00 in local time zone
17
+ $ mina logs since="2025-09-26 14:00"
18
+
19
+ # logs on 26.9.2025. between 14:00 and 15:00 in local time zone
20
+ $ mina logs since="2025-09-26 14:00" until="2025-09-26 15:00"
21
+
22
+ # logs between 14:00 and 15:00 today in local time zone
23
+ $ mina logs since="14:00" until="15:00"
24
+
25
+ # logs between 14:00 and 15:00 today in UTC
26
+ $ mina logs since="14:00Z" until="15:00Z"
27
+
28
+ # logs since 26.9.2025. 14:00 in UTC (ISO 8601 format)
29
+ $ mina logs since="2025-09-26T14:00Z"
30
+ TXT
31
+ task logs: ['aws:profile:check'] do
32
+ ensure!(:log_group)
33
+ ensure!(:since)
34
+
35
+ since_time = Time.parse(fetch(:since))
36
+ until_time = fetch(:until) ? Time.parse(fetch(:until)) : Time.now
37
+
38
+ puts "Printing logs from #{fetch(:log_group)} in range [#{since_time.iso8601},#{until_time.iso8601}]"
39
+ raw_logs = run_cmd squish(<<~CMD)
40
+ aws logs filter-log-events
41
+ --log-group-name #{fetch(:log_group)}
42
+ #{aws_cli_profile_flag}
43
+ --start-time #{since_time.strftime('%s%L')}
44
+ --end-time #{until_time.strftime('%s%L')}
45
+ --output json
46
+ --query "events[].{timestamp: timestamp, message: message}"
47
+ CMD
48
+
49
+ next if raw_logs.empty? # response can be empty due to auth issues, user will see error in terminal
50
+
51
+ logs = JSON.parse(raw_logs)
52
+ if logs.any?
53
+ logs.each do |log|
54
+ time = Time.at(0, log.fetch('timestamp'), :millisecond)
55
+ puts "#{green_text(time.utc.iso8601)} #{log.fetch('message')}"
56
+ end
57
+ else
58
+ puts 'There are no logs'
59
+ end
60
+ end
61
+
62
+ namespace :logs do
63
+ desc <<~TXT
64
+ Tail logs from CloudWatch
65
+
66
+ Logs are tailed from :log_group, which is a CloudWatch log group name.
67
+
68
+ Before new logs are tailed, recent logs are first printed. You can control
69
+ from what time recent logs are printed with :since. The value can be absolute
70
+ time parseable by `Time.parse`, or relative time.
71
+
72
+ If date is ommitted in absolute time, the current date is assumed.
73
+
74
+ Examples:
75
+ # tail logs since 26.9.2025. 14:00 in local time zone
76
+ $ mina logs:tail since="2025-09-26 14:00"
77
+
78
+ # tail logs since 14:00 today in local time zone
79
+ $ mina logs:tail since="14:00"
80
+
81
+ # tail logs since 26.9.2025. 14:00 in UTC (ISO 8601 format)
82
+ $ mina logs:tail since="2025-09-26T14:00Z"
83
+
84
+ # tail logs since 5 minutes ago
85
+ $ mina logs:tail since="5m"
86
+
87
+ For more info on accepted :since values, see --since options
88
+ https://docs.aws.amazon.com/cli/latest/reference/logs/tail.html#options
89
+ TXT
90
+ task tail: ['aws:profile:check'] do
91
+ ensure!(:log_group)
92
+
93
+ since_time = fetch(:since)&.strip
94
+
95
+ if since_time && !since_time.empty? && !since_time.match?(/\A\d+\w\z/)
96
+ since_time = Time.parse(since_time).iso8601
97
+ end
98
+
99
+ puts "Tailing logs from #{fetch(:log_group)}"
100
+ run_cmd squish(<<~CMD), exec: true
101
+ aws logs tail #{fetch(:log_group)}
102
+ #{aws_cli_profile_flag}
103
+ --follow
104
+ --format short
105
+ #{"--since #{since_time}" if since_time}
106
+ CMD
107
+ end
108
+ end
109
+
110
+ def green_text(text)
111
+ "\e[32m#{text}\e[0m"
112
+ end
@@ -15,13 +15,19 @@ namespace :params do
15
15
  end
16
16
 
17
17
  desc <<~TXT
18
- Save AWS Param Store params to .env file
18
+ Save AWS Param Store params to a file
19
+
20
+ Params are by default stored to .env file, you can override
21
+ the location with :path. For example:
22
+ $ mina params:pull path=.env.local
19
23
 
20
24
  See params:read documentation for details on how params
21
25
  are fetched.
22
26
  TXT
23
27
  task pull: ['aws:profile:check'] do
24
- env_file_path = File.join(Dir.pwd, '.env')
28
+ path = fetch(:path) || '.env'
29
+
30
+ env_file_path = File.join(Dir.pwd, path)
25
31
 
26
32
  File.write(env_file_path, get_params.map(&:as_env).join("\n"))
27
33
  end
@@ -55,7 +61,7 @@ def get_params_from_aws
55
61
  --path #{params_path}
56
62
  --with-decryption
57
63
  --recursive
58
- --profile #{fetch(:aws_profile)}
64
+ #{aws_cli_profile_flag}
59
65
  #{'--debug' if debug?}
60
66
  CMD
61
67
 
@@ -1,5 +1,6 @@
1
1
  require 'mina/default'
2
2
  require 'mina/infinum/ecs/rails'
3
+ require 'mina/infinum/ecs/logs'
3
4
  require 'mina/infinum/ecs/db'
4
5
  require 'mina/infinum/ecs/params'
5
6
 
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Infinum
3
- VERSION = '2.2.0'.freeze
3
+ VERSION = '2.4.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-infinum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stjepan Hadjic
@@ -145,6 +145,7 @@ files:
145
145
  - lib/mina/infinum/ecs/aws.rb
146
146
  - lib/mina/infinum/ecs/db.rb
147
147
  - lib/mina/infinum/ecs/ecs.rb
148
+ - lib/mina/infinum/ecs/logs.rb
148
149
  - lib/mina/infinum/ecs/params.rb
149
150
  - lib/mina/infinum/ecs/rails.rb
150
151
  - lib/mina/infinum/helpers.rb