ecsort 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f03e5a08c2c08cd5ed466c2df7bcb8b0bbc80c8b40bb12e35cad57e5e405d40
4
+ data.tar.gz: b0045b3ce5ae5ce71dcd530e8e98ca88cbb0c8138de716b749947c9f9e45a9c4
5
+ SHA512:
6
+ metadata.gz: bdce44daa15a86f7e4bcdacbd547e9d344ba3f5b52bbc8fefe9ddc3dc3bbc76e25ef37b544176855e46bbed516f0c3ef5ffa4b6e4b66623e7836f5098757c7cb
7
+ data.tar.gz: 83c6533d3d77871b9e104160938476f78109521f3095f01fcab7fa2d66137be56ca8b11cf00e93587d5c0856c757810947e92bb1808a01da63ccf5af3c944ec8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
@@ -0,0 +1,18 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "rdbg",
9
+ "name": "Debug RSpec",
10
+ "request": "launch",
11
+ "cwd": "${workspaceFolder}",
12
+ "command": "${workspaceFolder}/bin/rspec",
13
+ "script": "${file}",
14
+ "args": [],
15
+ "askParameters": false
16
+ },
17
+ ]
18
+ }
data/CHANGELOG.md ADDED
File without changes
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 shmokmt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # ecsort
2
+
3
+ It's a lightweight tool that sorts environments and secrets used in Amazon ECS Task Definitions by name.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install specific_install
9
+ gem specific_install -l 'https://github.com/shmokmt/ecsort'
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```bash
15
+ Usage: ecsort [--recursive, -r] [target]
16
+ --recursive, -r
17
+ Also process files in subdirectories. By default, only the given directroy (or current directroy) is processed.
18
+ ```
19
+
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shmokmt/ecsort.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec]
data/exe/ecsort ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "ecsort"
4
+
5
+ Ecsort::CLI.new.run
data/lib/ecsort/cli.rb ADDED
@@ -0,0 +1,76 @@
1
+ require "json"
2
+ require "optparse"
3
+
4
+ module Ecsort
5
+ class CLI
6
+ def initialize
7
+ @options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = <<~BANNER
10
+ Usage: ecsort [--recursive, -r] [target]
11
+ --recursive, -r
12
+ Also process files in subdirectories. By default, only the given directroy (or current directroy) is processed.
13
+ BANNER
14
+
15
+ opts.on("-r", "--recursive", "Process directories recursively") do |r|
16
+ @options[:recursive] = r
17
+ end
18
+ end.parse!
19
+
20
+ @path = ARGV[0]
21
+ @recursive = @options[:recursive] || false
22
+ end
23
+
24
+ def run
25
+ @path = "." if @path.nil?
26
+
27
+ if File.directory?(@path)
28
+ process_directory(@path)
29
+ elsif File.file?(@path)
30
+ process_file(@path)
31
+ else
32
+ raise InvalidPathError
33
+ end
34
+ end
35
+
36
+ def process_directory(directory_path)
37
+ pattern = if directory_path == "."
38
+ "*.json"
39
+ elsif @recursive
40
+ File.join(directory_path, "**", "*.json")
41
+ else
42
+ File.join(directory_path, "*.json")
43
+ end
44
+ Dir.glob(pattern).each do |file|
45
+ process_file(file)
46
+ end
47
+ end
48
+
49
+ def process_file(file_path)
50
+ file_content = File.read(file_path)
51
+ sorted_content = Ecsort.sort_ecs_task_definition(file_content)
52
+ File.write(file_path, sorted_content)
53
+ puts file_path if file_content != sorted_content
54
+ rescue JSON::ParserError
55
+ puts "Skipping invalid JSON file: #{file_path}"
56
+ rescue StandardError => e
57
+ puts "Error processing file: #{file_path}, Error: #{e.message}"
58
+ end
59
+ end
60
+
61
+ def self.sort_ecs_task_definition(json_input)
62
+ ecs_task_definition = JSON.parse(json_input)
63
+
64
+ if ecs_task_definition["containerDefinitions"]
65
+ ecs_task_definition["containerDefinitions"].each do |container|
66
+ if container["environment"]
67
+ container["environment"] = container["environment"].sort_by { |entry| entry["name"] }
68
+ end
69
+
70
+ container["secrets"] = container["secrets"].sort_by { |entry| entry["name"] } if container["secrets"]
71
+ end
72
+ end
73
+
74
+ JSON.pretty_generate(ecs_task_definition)
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ecsort
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ecsort.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ecsort/version"
4
+ require_relative "ecsort/cli"
5
+
6
+ module Ecsort
7
+ class InvalidPathError < StandardError; end
8
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ecsort
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shmokmt
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-01-12 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: It's a lightweight tool that sorts environments and secrets used in Amazon
13
+ ECS Task Definitions by name.
14
+ email:
15
+ - 32533860+shmokmt@users.noreply.github.com
16
+ executables:
17
+ - ecsort
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - ".vscode/launch.json"
24
+ - CHANGELOG.md
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - exe/ecsort
29
+ - lib/ecsort.rb
30
+ - lib/ecsort/cli.rb
31
+ - lib/ecsort/version.rb
32
+ homepage: https://github.com/shmokmt/ecsort
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ rubygems_mfa_required: 'true'
38
+ homepage_uri: https://github.com/shmokmt/ecsort
39
+ source_code_uri: https://github.com/shmokmt/ecsort
40
+ changelog_uri: https://github.com/shmokmt/ecsort/tree/main/CHANGELOG.md
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 3.0.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.6.2
56
+ specification_version: 4
57
+ summary: It's a lightweight tool that sorts environments and secrets used in Amazon
58
+ ECS Task Definitions by name.
59
+ test_files: []