Skip to content

Commit 8d22176

Browse files
committed
add optional repo credentials
1 parent 0c7d60a commit 8d22176

11 files changed

+108
-67
lines changed

.github/workflows/ci.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
strategy:
1313
matrix:
14-
ruby: ["2.7", "3.0", "3.1", "3.2"]
14+
ruby: ["3.0", "3.1", "3.2", "3.3"]
1515

1616
name: ${{ matrix.ruby }}
1717

@@ -24,7 +24,3 @@ jobs:
2424
bundler-cache: true
2525

2626
- run: bundle exec rake
27-
28-
# - uses: coverallsapp/github-action@v1.1.2
29-
# with:
30-
# github-token: ${{ secrets.GITHUB_TOKEN }}

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ inherit_gem:
33

44
AllCops:
55
DisplayCopNames: true
6-
TargetRubyVersion: 2.7
6+
TargetRubyVersion: 3.0
77
Include:
88
- bin/console
99
- Gemfile

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RUN apk add --update --no-cache ruby git colordiff
44

55
WORKDIR /wd
66

7-
COPY --from=ghcr.io/helmfile/helmfile:v0.149.0 /usr/local/bin/helmfile /usr/local/bin/helmfile
7+
COPY --from=ghcr.io/helmfile/helmfile /usr/local/bin/helmfile /usr/local/bin/helmfile
88
COPY . .
99

1010
RUN gem install colorize && gem build && gem install helmsnap --local

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ gem "pry"
88
gem "rake"
99
gem "rspec"
1010
gem "rubocop"
11+
gem "rubocop-config-umbrellio"

Gemfile.lock

+69-51
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,105 @@
11
PATH
22
remote: .
33
specs:
4-
helmsnap (1.0.2)
4+
helmsnap (1.1.0)
55
colorize
66

77
GEM
88
remote: https://rubygems.org/
99
specs:
10-
activesupport (7.0.4)
11-
concurrent-ruby (~> 1.0, >= 1.0.2)
10+
activesupport (7.2.1)
11+
base64
12+
bigdecimal
13+
concurrent-ruby (~> 1.0, >= 1.3.1)
14+
connection_pool (>= 2.2.5)
15+
drb
1216
i18n (>= 1.6, < 2)
17+
logger (>= 1.4.2)
1318
minitest (>= 5.1)
14-
tzinfo (~> 2.0)
19+
securerandom (>= 0.3)
20+
tzinfo (~> 2.0, >= 2.0.5)
1521
ast (2.4.2)
22+
base64 (0.2.0)
23+
bigdecimal (3.1.8)
1624
coderay (1.1.3)
17-
colorize (0.8.1)
18-
concurrent-ruby (1.1.10)
19-
diff-lcs (1.5.0)
20-
i18n (1.12.0)
25+
colorize (1.1.0)
26+
concurrent-ruby (1.3.4)
27+
connection_pool (2.4.1)
28+
diff-lcs (1.5.1)
29+
drb (2.2.1)
30+
i18n (1.14.6)
2131
concurrent-ruby (~> 1.0)
22-
json (2.6.3)
23-
method_source (1.0.0)
24-
minitest (5.17.0)
25-
parallel (1.22.1)
26-
parser (3.2.0.0)
32+
json (2.7.2)
33+
language_server-protocol (3.17.0.3)
34+
logger (1.6.1)
35+
method_source (1.1.0)
36+
minitest (5.25.1)
37+
parallel (1.26.3)
38+
parser (3.3.5.0)
2739
ast (~> 2.4.1)
40+
racc
2841
pry (0.14.2)
2942
coderay (~> 1.1)
3043
method_source (~> 1.0)
31-
rack (3.0.3)
44+
racc (1.8.1)
45+
rack (3.1.8)
3246
rainbow (3.1.1)
33-
rake (13.0.6)
34-
regexp_parser (2.6.1)
35-
rexml (3.2.5)
36-
rspec (3.12.0)
37-
rspec-core (~> 3.12.0)
38-
rspec-expectations (~> 3.12.0)
39-
rspec-mocks (~> 3.12.0)
40-
rspec-core (3.12.0)
41-
rspec-support (~> 3.12.0)
42-
rspec-expectations (3.12.2)
47+
rake (13.2.1)
48+
regexp_parser (2.9.2)
49+
rspec (3.13.0)
50+
rspec-core (~> 3.13.0)
51+
rspec-expectations (~> 3.13.0)
52+
rspec-mocks (~> 3.13.0)
53+
rspec-core (3.13.1)
54+
rspec-support (~> 3.13.0)
55+
rspec-expectations (3.13.3)
4356
diff-lcs (>= 1.2.0, < 2.0)
44-
rspec-support (~> 3.12.0)
45-
rspec-mocks (3.12.2)
57+
rspec-support (~> 3.13.0)
58+
rspec-mocks (3.13.2)
4659
diff-lcs (>= 1.2.0, < 2.0)
47-
rspec-support (~> 3.12.0)
48-
rspec-support (3.12.0)
49-
rubocop (1.43.0)
60+
rspec-support (~> 3.13.0)
61+
rspec-support (3.13.1)
62+
rubocop (1.66.1)
5063
json (~> 2.3)
64+
language_server-protocol (>= 3.17.0)
5165
parallel (~> 1.10)
52-
parser (>= 3.2.0.0)
66+
parser (>= 3.3.0.2)
5367
rainbow (>= 2.2.2, < 4.0)
54-
regexp_parser (>= 1.8, < 3.0)
55-
rexml (>= 3.2.5, < 4.0)
56-
rubocop-ast (>= 1.24.1, < 2.0)
68+
regexp_parser (>= 2.4, < 3.0)
69+
rubocop-ast (>= 1.32.2, < 2.0)
5770
ruby-progressbar (~> 1.7)
5871
unicode-display_width (>= 2.4.0, < 3.0)
59-
rubocop-ast (1.24.1)
60-
parser (>= 3.1.1.0)
61-
rubocop-config-umbrellio (1.43.0.81)
62-
rubocop (~> 1.43.0)
63-
rubocop-performance (~> 1.15.0)
64-
rubocop-rails (~> 2.17.0)
72+
rubocop-ast (1.32.3)
73+
parser (>= 3.3.1.0)
74+
rubocop-config-umbrellio (1.66.0.99)
75+
rubocop (~> 1.66.0)
76+
rubocop-factory_bot (~> 2.26.0)
77+
rubocop-performance (~> 1.22.0)
78+
rubocop-rails (~> 2.26.0)
6579
rubocop-rake (~> 0.6.0)
66-
rubocop-rspec (~> 2.16.0)
80+
rubocop-rspec (~> 3.0.0)
6781
rubocop-sequel (~> 0.3.3)
68-
rubocop-performance (1.15.2)
69-
rubocop (>= 1.7.0, < 2.0)
70-
rubocop-ast (>= 0.4.0)
71-
rubocop-rails (2.17.4)
82+
rubocop-factory_bot (2.26.1)
83+
rubocop (~> 1.61)
84+
rubocop-performance (1.22.1)
85+
rubocop (>= 1.48.1, < 2.0)
86+
rubocop-ast (>= 1.31.1, < 2.0)
87+
rubocop-rails (2.26.2)
7288
activesupport (>= 4.2.0)
7389
rack (>= 1.1)
74-
rubocop (>= 1.33.0, < 2.0)
90+
rubocop (>= 1.52.0, < 2.0)
91+
rubocop-ast (>= 1.31.1, < 2.0)
7592
rubocop-rake (0.6.0)
7693
rubocop (~> 1.0)
77-
rubocop-rspec (2.16.0)
78-
rubocop (~> 1.33)
94+
rubocop-rspec (3.0.5)
95+
rubocop (~> 1.61)
7996
rubocop-sequel (0.3.4)
8097
rubocop (~> 1.0)
81-
ruby-progressbar (1.11.0)
82-
tzinfo (2.0.5)
98+
ruby-progressbar (1.13.0)
99+
securerandom (0.3.1)
100+
tzinfo (2.0.6)
83101
concurrent-ruby (~> 1.0)
84-
unicode-display_width (2.4.2)
102+
unicode-display_width (2.6.0)
85103

86104
PLATFORMS
87105
arm64-darwin-21
@@ -98,4 +116,4 @@ DEPENDENCIES
98116
rubocop-config-umbrellio
99117

100118
BUNDLED WITH
101-
2.4.3
119+
2.5.21

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You can also override configuration file location using `--config` option.
4949

5050
## Dependencies
5151

52-
- Ruby 2.7+.
52+
- Ruby 3.0+.
5353
- [Helmfile](https://github.com/roboll/helmfile), which in turn relies on [Helm](https://github.com/helm/helm).
5454
- Colordiff or diff utility.
5555

helmsnap.gemspec

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
1111
spec.summary = "A tool for creating and checking helm chart snapshots."
1212
spec.homepage = "https://github.com/tycooon/helmsnap"
1313
spec.license = "MIT"
14-
spec.required_ruby_version = ">= 2.7.0"
14+
spec.required_ruby_version = ">= 3.0.0"
1515

1616
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
1717
spec.metadata["homepage_uri"] = spec.homepage
@@ -31,6 +31,4 @@ Gem::Specification.new do |spec|
3131
spec.require_paths = ["lib"]
3232

3333
spec.add_dependency "colorize"
34-
35-
spec.add_development_dependency "rubocop-config-umbrellio"
3634
end

lib/helmsnap/args_parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Helmsnap::ArgsParser
66
Args = Struct.new(:config_path)
77

88
DEFAULT_CONFIG_PATH = Pathname.new(".helmsnap.yaml")
9-
CONFIG_PATH_HELP = %{Path to config (default: "#{DEFAULT_CONFIG_PATH}")}
9+
CONFIG_PATH_HELP = %{Path to config (default: "#{DEFAULT_CONFIG_PATH}")}.freeze
1010
BANNER = "Usage: helmsnap CMD [options]"
1111

1212
def initialize(options)

lib/helmsnap/config.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# frozen_string_literal: true
22

33
class Helmsnap::Config
4-
attr_reader :envs, :snapshots_path
4+
Credentials = Struct.new(:username, :password)
5+
6+
attr_reader :envs, :snapshots_path, :credentials
57

68
DEFAULT_ENV = "default"
79
DEFAULT_SNAPSHOTS_PATH = "helm/snapshots"
@@ -15,11 +17,12 @@ def initialize(config_path)
1517

1618
self.envs = parse_envs(yaml)
1719
self.snapshots_path = parse_snaphots_path(yaml)
20+
self.credentials = parse_credentials(yaml)
1821
end
1922

2023
private
2124

22-
attr_writer :envs, :snapshots_path
25+
attr_writer :envs, :snapshots_path, :credentials
2326

2427
def parse_envs(yaml)
2528
value = yaml.fetch("envs", [DEFAULT_ENV])
@@ -29,4 +32,10 @@ def parse_envs(yaml)
2932
def parse_snaphots_path(yaml)
3033
Pathname.new(yaml.fetch("snapshotsPath", DEFAULT_SNAPSHOTS_PATH))
3134
end
35+
36+
def parse_credentials(yaml)
37+
yaml.fetch("credentials", []).each_with_object({}) do |obj, credentials|
38+
credentials[obj["repo"]] = Credentials.new(obj["username"], obj["password"])
39+
end
40+
end
3241
end

lib/helmsnap/setup_dependencies.rb

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# frozen_string_literal: true
22

33
class Helmsnap::SetupDependencies < Helmsnap::Service
4+
REPO_NAME_PREFIX = "helmsnap-"
5+
46
def initialize(config)
57
super()
68
self.config = config
79
self.processed_paths = Set.new
810
end
911

1012
def call
13+
clear_existing_repos!
14+
1115
config.envs.flat_map(&:release_paths).each do |chart_path|
1216
setup!(chart_path)
1317
end
@@ -17,6 +21,14 @@ def call
1721

1822
attr_accessor :config, :processed_paths
1923

24+
def clear_existing_repos!
25+
result = run_cmd("helm", "repo", "ls").output
26+
27+
result.scan(/#{REPO_NAME_PREFIX}\S+/o) do |repo_name|
28+
run_cmd("helm", "repo", "remove", repo_name)
29+
end
30+
end
31+
2032
def setup!(chart_path)
2133
normalized_path = chart_path.expand_path
2234
return if processed_paths.include?(normalized_path)
@@ -30,7 +42,14 @@ def setup!(chart_path)
3042
end
3143

3244
dep_list.scan(%r{(https?://.+?)\s}) do |dep_path|
33-
run_cmd("helm", "repo", "add", Digest::MD5.hexdigest(dep_path.first), dep_path.first)
45+
url = dep_path.first
46+
47+
if (credentials = config.credentials[url])
48+
extra_args = ["--username", credentials.username, "--password", credentials.password]
49+
end
50+
51+
repo_name = "#{REPO_NAME_PREFIX}#{Digest::MD5.hexdigest(url)}"
52+
run_cmd("helm", "repo", "add", repo_name, url, *extra_args)
3453
end
3554

3655
update_deps!(chart_path)

lib/helmsnap/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Helmsnap
4-
VERSION = "1.0.2"
4+
VERSION = "1.1.0"
55
end

0 commit comments

Comments
 (0)