cloudwatch_logs_insights_url_builder 0.0.1

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
+ SHA256:
3
+ metadata.gz: 76f321c616c87f935c6698cd13d763fea55e3ded22ceeccc7bf3ce9e4444d644
4
+ data.tar.gz: 55a903d5832dae43ec348b7c35df2bf3f9cd4a5a7212fa09db2c0f61e3c245c9
5
+ SHA512:
6
+ metadata.gz: 443eebdfe8bf3530385502ae71a20c824ae80237feeb74c8072967cbe2a23e35851a35b3587cecf20ac455c1278c6b2701bff9c4054940bba4e1dcc9beef017e
7
+ data.tar.gz: 6faec77bd5a6bed72d28e6a417ad7dfe1495cb9b602f922bdca2abf279b2c1858aa47cb18ee97cdc50fb1b4963e29d11bcda243fc391ef4003e504488b3726b5
@@ -0,0 +1,25 @@
1
+ name: rspec
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ rspec:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Checkout code
12
+ uses: actions/checkout@v3
13
+
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ bundler-cache: true
18
+
19
+ - name: Bundler and gem install
20
+ run: |
21
+ gem install bundler
22
+ bundle install --jobs 4
23
+
24
+ - name: Run rspec
25
+ run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ AllCops:
2
+ SuggestExtensions: false
3
+
4
+ Layout/LineLength:
5
+ Exclude:
6
+ - 'spec/**/*'
7
+
8
+ Metrics/AbcSize:
9
+ Max: 32
10
+
11
+ Metrics/BlockLength:
12
+ Exclude:
13
+ - 'spec/**/*'
14
+
15
+ Metrics/MethodLength:
16
+ Max: 16
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Style/FrozenStringLiteralComment:
22
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.0
@@ -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 n.yamakita@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cloudwatch_logs_insights_url_builder (0.0.4)
5
+ url
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ diff-lcs (1.5.0)
12
+ docile (1.4.0)
13
+ json (2.6.3)
14
+ parallel (1.22.1)
15
+ parser (3.2.0.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.1.1)
18
+ rake (13.0.6)
19
+ regexp_parser (2.6.2)
20
+ rexml (3.2.5)
21
+ rspec (3.12.0)
22
+ rspec-core (~> 3.12.0)
23
+ rspec-expectations (~> 3.12.0)
24
+ rspec-mocks (~> 3.12.0)
25
+ rspec-core (3.12.0)
26
+ rspec-support (~> 3.12.0)
27
+ rspec-expectations (3.12.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-mocks (3.12.3)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-support (3.12.0)
34
+ rubocop (1.44.1)
35
+ json (~> 2.3)
36
+ parallel (~> 1.10)
37
+ parser (>= 3.2.0.0)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ regexp_parser (>= 1.8, < 3.0)
40
+ rexml (>= 3.2.5, < 4.0)
41
+ rubocop-ast (>= 1.24.1, < 2.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 2.4.0, < 3.0)
44
+ rubocop-ast (1.24.1)
45
+ parser (>= 3.1.1.0)
46
+ ruby-progressbar (1.11.0)
47
+ simplecov (0.22.0)
48
+ docile (~> 1.1)
49
+ simplecov-html (~> 0.11)
50
+ simplecov_json_formatter (~> 0.1)
51
+ simplecov-html (0.12.3)
52
+ simplecov_json_formatter (0.1.4)
53
+ unicode-display_width (2.4.2)
54
+ url (0.3.2)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ cloudwatch_logs_insights_url_builder!
61
+ rake
62
+ rspec
63
+ rubocop
64
+ simplecov
65
+
66
+ BUNDLED WITH
67
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Naomichi Yamakita
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # cloudwatch_logs_url_builder
2
+
3
+ ![rspec](https://github.com/naomichi-y/cloudwatch_logs_url_builder/actions/workflows/rspec.yml/badge.svg)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Generate AWS Console URL for Amazon CloudWatch.
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ gem 'cloudwatch_logs_insights_url_builder'
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ require 'cloudwatch_logs_insights_url_builder'
18
+
19
+ builder = CloudWatchLogsInsightsUrlBuilder.new
20
+ builder.time_type = 'ABSOLUTE'
21
+ builder.start_time = 24 * 3600
22
+ builder.end_time = 0
23
+
24
+ query = 'fields @timestamp, @message, @logStream, @log\n| sort @timestamp desc\n| limit 2'
25
+ log_groups = ['/aws/cloudtrail']
26
+
27
+ # https://us-east-1.console.aws.amazon.com/cloudwatch/home?...
28
+ builder.log_insights_url(query, log_groups)
29
+ ```
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require './lib/cloudwatch_logs_url_builder'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,32 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'cloudwatch_logs_insights_url_builder'
3
+ spec.version = '0.0.1'
4
+ spec.authors = ['naomichi-y']
5
+ spec.email = ['n.yamakita@gmail.com']
6
+
7
+ spec.summary = 'Generate AWS Console URL for Amazon CloudWatch.'
8
+ spec.description = 'Specify log groups and filters to generate URLs accessible to the AWS Console.'
9
+ spec.homepage = 'https://github.com/naomichi-y/cloudwatch_logs_insights_url_builder'
10
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
11
+
12
+ spec.metadata['homepage_uri'] = spec.homepage
13
+ spec.metadata['source_code_uri'] = spec.homepage
14
+ spec.metadata['changelog_uri'] = spec.homepage
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'simplecov'
30
+
31
+ spec.add_dependency 'url'
32
+ end
@@ -0,0 +1,39 @@
1
+ class CloudWatchLogsInsightsUrlBuilder
2
+ class Criteria
3
+ def initialize
4
+ @conditions = []
5
+ end
6
+
7
+ def add(key, value)
8
+ case value
9
+ when Array
10
+ result = +encode_key("~#{key}~(")
11
+
12
+ value.each do |v|
13
+ result << "#{encode_key("~'")}#{encode_value(v)}"
14
+ end
15
+
16
+ @conditions << result + encode_key(')')
17
+
18
+ when String
19
+ @conditions << "#{encode_key("~#{key}~'")}#{encode_value(value)}"
20
+ else
21
+ @conditions << "#{encode_key("~#{key}~")}#{encode_value(value)}"
22
+ end
23
+ end
24
+
25
+ def build
26
+ "#{encode_key('~(')}#{@conditions.join.delete_prefix(encode_key('~'))}#{encode_key(')')}"
27
+ end
28
+
29
+ private
30
+
31
+ def encode_key(key)
32
+ URI.encode_www_form_component(URI.encode_www_form_component(key)).gsub('%', '$')
33
+ end
34
+
35
+ def encode_value(value)
36
+ URI.encode_www_form_component(value).gsub('%', '*')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require 'url'
2
+ require 'cloudwatch_logs_insights_url_builder/criteria'
3
+
4
+ class CloudWatchLogsInsightsUrlBuilder
5
+ attr_accessor :time_type, :timezone, :start_time, :end_time
6
+
7
+ STRING_TIME_FORMAT = '%Y-%m-%dT%T.000Z'.freeze
8
+
9
+ def initialize(region)
10
+ @region = region
11
+ @time_type = 'RELATIVE'
12
+ @timezone = 'Local'
13
+ @unit = 'minutes'
14
+ @start_time = -86_400
15
+ @end_time = 0
16
+ end
17
+
18
+ def log_insights_url(query, log_groups = [])
19
+ url = +"https://#{@region}.console.aws.amazon.com/cloudwatch/home?region=#{@region}#logsV2:logs-insights"
20
+ url << URI.encode_www_form_component('?queryDetail=').gsub('%', '$')
21
+
22
+ start_time = @start_time.is_a?(Time) ? @start_time.strftime(STRING_TIME_FORMAT) : @start_time
23
+ end_time = @end_time.is_a?(Time) ? @end_time.strftime(STRING_TIME_FORMAT) : @end_time
24
+
25
+ builder = CloudWatchLogsInsightsUrlBuilder::Criteria.new
26
+ builder.add('end', end_time)
27
+ builder.add('start', start_time)
28
+ builder.add('timeType', @time_type)
29
+ builder.add('unit', 'seconds') if @time_type == 'RELATIVE'
30
+ builder.add('tz', @timezone)
31
+ builder.add('editorString', query)
32
+ builder.add('isLiveTail', false)
33
+ builder.add('source', log_groups) if log_groups.size.positive?
34
+
35
+ url << builder.build
36
+ url
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudwatch_logs_insights_url_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - naomichi-y
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
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: url
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Specify log groups and filters to generate URLs accessible to the AWS
84
+ Console.
85
+ email:
86
+ - n.yamakita@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".github/workflows/rspec.yml"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".ruby-version"
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - LICENSE
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - cloudwatch_logs_ingihts_url_builder.gemspec
105
+ - lib/cloudwatch_logs_insights_url_builder.rb
106
+ - lib/cloudwatch_logs_insights_url_builder/criteria.rb
107
+ homepage: https://github.com/naomichi-y/cloudwatch_logs_insights_url_builder
108
+ licenses: []
109
+ metadata:
110
+ homepage_uri: https://github.com/naomichi-y/cloudwatch_logs_insights_url_builder
111
+ source_code_uri: https://github.com/naomichi-y/cloudwatch_logs_insights_url_builder
112
+ changelog_uri: https://github.com/naomichi-y/cloudwatch_logs_insights_url_builder
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 2.6.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.0.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Generate AWS Console URL for Amazon CloudWatch.
132
+ test_files: []