rake_fly 2.10.0.pre.2 → 2.10.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby_fly'
2
4
  require 'rake_factory'
3
5
  require 'concourse'
@@ -13,14 +15,15 @@ module RakeFly
13
15
 
14
16
  def execute(task)
15
17
  RubyFly.login(
16
- target: task.target,
17
- concourse_url: task.concourse_url,
18
- username: task.username,
19
- password: task.password,
20
- team: task.team,
21
- environment: {
22
- "HOME" => task.home_directory
23
- })
18
+ target: task.target,
19
+ concourse_url: task.concourse_url,
20
+ username: task.username,
21
+ password: task.password,
22
+ team: task.team,
23
+ environment: {
24
+ 'HOME' => task.home_directory
25
+ }
26
+ )
24
27
  end
25
28
  end
26
29
 
@@ -30,12 +33,22 @@ module RakeFly
30
33
  end
31
34
 
32
35
  def execute(task)
33
- client = Concourse::Client.new(
34
- url: task.concourse_url)
35
- token = client.for_skymarshal.create_token(
36
+ save_target(task, fetch_token(task))
37
+ end
38
+
39
+ private
40
+
41
+ def fetch_token(task)
42
+ Concourse::Client
43
+ .new(url: task.concourse_url)
44
+ .for_skymarshal
45
+ .create_token(
36
46
  username: task.username,
37
- password: task.password)
47
+ password: task.password
48
+ )
49
+ end
38
50
 
51
+ def save_target(task, token)
39
52
  rc = RubyFly::RC.load(home: task.home_directory)
40
53
  rc.add_or_update_target(task.target) do |target|
41
54
  target.api = task.concourse_url
@@ -47,15 +60,15 @@ module RakeFly
47
60
  end
48
61
 
49
62
  default_name :login
50
- default_prerequisites RakeFactory::DynamicValue.new { |t|
63
+ default_prerequisites(RakeFactory::DynamicValue.new do |t|
51
64
  t.backend.new.resolve_prerequisites(t)
52
- }
53
- default_description RakeFactory::DynamicValue.new { |t|
65
+ end)
66
+ default_description(RakeFactory::DynamicValue.new do |t|
54
67
  concourse_url = t.concourse_url || '<derived>'
55
68
  target = t.target || '<derived>'
56
69
 
57
70
  "Login to #{concourse_url} as target #{target}"
58
- }
71
+ end)
59
72
 
60
73
  parameter :concourse_url, required: true
61
74
  parameter :team, default: 'main'
@@ -66,15 +79,17 @@ module RakeFly
66
79
  parameter :backend, default: ApiBackend
67
80
 
68
81
  parameter :home_directory,
69
- default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
82
+ default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
70
83
 
71
- parameter :fly_ensure_task_name, :default => :'fly:ensure'
84
+ parameter :fly_ensure_task_name, default: :'fly:ensure'
72
85
 
73
86
  action do |t|
74
- puts "Logging in to #{t.concourse_url} as target #{t.target}..."
87
+ $stdout.puts(
88
+ "Logging in to #{t.concourse_url} as target #{t.target}..."
89
+ )
75
90
  t.backend.new.execute(t)
76
91
  end
77
92
  end
78
93
  end
79
94
  end
80
- end
95
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby_fly'
2
4
  require 'rake_factory'
3
5
 
@@ -6,41 +8,44 @@ module RakeFly
6
8
  module Pipeline
7
9
  class Destroy < RakeFactory::Task
8
10
  default_name :destroy
9
- default_prerequisites RakeFactory::DynamicValue.new { |t|
11
+ default_prerequisites(RakeFactory::DynamicValue.new do |t|
10
12
  [t.fly_ensure_task_name, t.authentication_ensure_task_name]
11
- }
12
- default_description RakeFactory::DynamicValue.new { |t|
13
+ end)
14
+ default_description(RakeFactory::DynamicValue.new do |t|
13
15
  pipeline = t.pipeline || '<derived>'
14
16
  target = t.target || '<derived>'
15
-
17
+
16
18
  "Destroy pipeline #{pipeline} for target #{target}"
17
- }
18
-
19
- parameter :target, :required => true
19
+ end)
20
+
21
+ parameter :target, required: true
20
22
  parameter :team
21
- parameter :pipeline, :required => true
23
+ parameter :pipeline, required: true
22
24
 
23
25
  parameter :non_interactive
24
26
 
25
27
  parameter :home_directory,
26
- default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
28
+ default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
27
29
 
28
- parameter :fly_ensure_task_name, :default => :'fly:ensure'
30
+ parameter :fly_ensure_task_name, default: :'fly:ensure'
29
31
  parameter :authentication_ensure_task_name,
30
- :default => :'authentication:ensure'
31
-
32
+ default: :'authentication:ensure'
33
+
32
34
  action do |t|
33
- puts "Destroying pipeline #{t.pipeline} for target #{t.target}..."
35
+ $stdout.puts(
36
+ "Destroying pipeline #{t.pipeline} for target #{t.target}..."
37
+ )
34
38
  RubyFly.destroy_pipeline(
35
- target: t.target,
36
- team: t.team,
37
- pipeline: t.pipeline,
38
- non_interactive: t.non_interactive,
39
- environment: {
40
- "HOME" => t.home_directory
41
- })
39
+ target: t.target,
40
+ team: t.team,
41
+ pipeline: t.pipeline,
42
+ non_interactive: t.non_interactive,
43
+ environment: {
44
+ 'HOME' => t.home_directory
45
+ }
46
+ )
42
47
  end
43
48
  end
44
49
  end
45
50
  end
46
- end
51
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby_fly'
2
4
  require 'rake_factory'
3
5
 
@@ -6,36 +8,39 @@ module RakeFly
6
8
  module Pipeline
7
9
  class Get < RakeFactory::Task
8
10
  default_name :get
9
- default_prerequisites RakeFactory::DynamicValue.new { |t|
11
+ default_prerequisites(RakeFactory::DynamicValue.new do |t|
10
12
  [t.fly_ensure_task_name, t.authentication_ensure_task_name]
11
- }
12
- default_description RakeFactory::DynamicValue.new { |t|
13
+ end)
14
+ default_description(RakeFactory::DynamicValue.new do |t|
13
15
  pipeline = t.pipeline || '<derived>'
14
16
  target = t.target || '<derived>'
15
-
17
+
16
18
  "Get pipeline #{pipeline} for target #{target}"
17
- }
18
-
19
- parameter :target, :required => true
20
- parameter :pipeline, :required => true
19
+ end)
20
+
21
+ parameter :target, required: true
22
+ parameter :pipeline, required: true
21
23
 
22
24
  parameter :home_directory,
23
- default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
25
+ default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
24
26
 
25
- parameter :fly_ensure_task_name, :default => :'fly:ensure'
27
+ parameter :fly_ensure_task_name, default: :'fly:ensure'
26
28
  parameter :authentication_ensure_task_name,
27
- :default => :'authentication:ensure'
28
-
29
+ default: :'authentication:ensure'
30
+
29
31
  action do |t|
30
- puts "Getting pipeline #{t.pipeline} for target #{t.target}..."
32
+ $stdout.puts(
33
+ "Getting pipeline #{t.pipeline} for target #{t.target}..."
34
+ )
31
35
  RubyFly.get_pipeline(
32
- target: t.target,
33
- pipeline: t.pipeline,
34
- environment: {
35
- "HOME" => t.home_directory
36
- })
36
+ target: t.target,
37
+ pipeline: t.pipeline,
38
+ environment: {
39
+ 'HOME' => t.home_directory
40
+ }
41
+ )
37
42
  end
38
43
  end
39
44
  end
40
45
  end
41
- end
46
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby_fly'
2
4
  require 'rake_factory'
3
5
 
@@ -6,25 +8,25 @@ module RakeFly
6
8
  module Pipeline
7
9
  class Push < RakeFactory::Task
8
10
  default_name :push
9
- default_description RakeFactory::DynamicValue.new { |t|
11
+ default_description(RakeFactory::DynamicValue.new do |t|
10
12
  pipeline = t.pipeline || '<derived>'
11
13
  target = t.target || '<derived>'
12
14
 
13
15
  "Push pipeline #{pipeline} to target #{target}"
14
- }
16
+ end)
15
17
 
16
- parameter :target, :required => true
17
- parameter :pipeline, :required => true
18
+ parameter :target, required: true
19
+ parameter :pipeline, required: true
18
20
 
19
- parameter :get_task_name, :default => :get
20
- parameter :set_task_name, :default => :set
21
- parameter :unpause_task_name, :default => :unpause
21
+ parameter :get_task_name, default: :get
22
+ parameter :set_task_name, default: :set
23
+ parameter :unpause_task_name, default: :unpause
22
24
 
23
25
  action do |t, args|
24
26
  [
25
- t.application[t.set_task_name, t.scope],
26
- t.application[t.get_task_name, t.scope],
27
- t.application[t.unpause_task_name, t.scope]
27
+ t.application[t.set_task_name, t.scope],
28
+ t.application[t.get_task_name, t.scope],
29
+ t.application[t.unpause_task_name, t.scope]
28
30
  ].each do |task|
29
31
  task.invoke(*args)
30
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby_fly'
2
4
  require 'rake_factory'
3
5
 
@@ -6,45 +8,48 @@ module RakeFly
6
8
  module Pipeline
7
9
  class Set < RakeFactory::Task
8
10
  default_name :set
9
- default_prerequisites RakeFactory::DynamicValue.new { |t|
11
+ default_prerequisites(RakeFactory::DynamicValue.new do |t|
10
12
  [t.fly_ensure_task_name, t.authentication_ensure_task_name]
11
- }
12
- default_description RakeFactory::DynamicValue.new { |t|
13
+ end)
14
+ default_description(RakeFactory::DynamicValue.new do |t|
13
15
  pipeline = t.pipeline || '<derived>'
14
16
  target = t.target || '<derived>'
15
17
 
16
18
  "Set pipeline #{pipeline} for target #{target}"
17
- }
19
+ end)
18
20
 
19
- parameter :target, :required => true
21
+ parameter :target, required: true
20
22
  parameter :team
21
- parameter :pipeline, :required => true
22
- parameter :config, :required => true
23
+ parameter :pipeline, required: true
24
+ parameter :config, required: true
23
25
 
24
26
  parameter :vars
25
27
  parameter :var_files
26
28
  parameter :non_interactive
27
29
 
28
30
  parameter :home_directory,
29
- default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
31
+ default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
30
32
 
31
- parameter :fly_ensure_task_name, :default => :'fly:ensure'
33
+ parameter :fly_ensure_task_name, default: :'fly:ensure'
32
34
  parameter :authentication_ensure_task_name,
33
- :default => :'authentication:ensure'
35
+ default: :'authentication:ensure'
34
36
 
35
37
  action do |t|
36
- puts "Setting pipeline #{t.pipeline} for target #{t.target}..."
38
+ $stdout.puts(
39
+ "Setting pipeline #{t.pipeline} for target #{t.target}..."
40
+ )
37
41
  RubyFly.set_pipeline(
38
- target: t.target,
39
- team: t.team,
40
- pipeline: t.pipeline,
41
- config: t.config,
42
- vars: t.vars,
43
- var_files: t.var_files,
44
- non_interactive: t.non_interactive,
45
- environment: {
46
- "HOME" => t.home_directory
47
- })
42
+ target: t.target,
43
+ team: t.team,
44
+ pipeline: t.pipeline,
45
+ config: t.config,
46
+ vars: t.vars,
47
+ var_files: t.var_files,
48
+ non_interactive: t.non_interactive,
49
+ environment: {
50
+ 'HOME' => t.home_directory
51
+ }
52
+ )
48
53
  end
49
54
  end
50
55
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby_fly'
2
4
  require 'rake_factory'
3
5
 
@@ -6,36 +8,39 @@ module RakeFly
6
8
  module Pipeline
7
9
  class Unpause < RakeFactory::Task
8
10
  default_name :unpause
9
- default_prerequisites RakeFactory::DynamicValue.new { |t|
11
+ default_prerequisites(RakeFactory::DynamicValue.new do |t|
10
12
  [t.fly_ensure_task_name, t.authentication_ensure_task_name]
11
- }
12
- default_description RakeFactory::DynamicValue.new { |t|
13
+ end)
14
+ default_description(RakeFactory::DynamicValue.new do |t|
13
15
  pipeline = t.pipeline || '<derived>'
14
16
  target = t.target || '<derived>'
15
17
 
16
18
  "Unpause pipeline #{pipeline} for target #{target}"
17
- }
19
+ end)
18
20
 
19
- parameter :target, :required => true
21
+ parameter :target, required: true
20
22
  parameter :team
21
- parameter :pipeline, :required => true
23
+ parameter :pipeline, required: true
22
24
 
23
25
  parameter :home_directory,
24
- default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
26
+ default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }
25
27
 
26
- parameter :fly_ensure_task_name, :default => :'fly:ensure'
28
+ parameter :fly_ensure_task_name, default: :'fly:ensure'
27
29
  parameter :authentication_ensure_task_name,
28
- :default => :'authentication:ensure'
30
+ default: :'authentication:ensure'
29
31
 
30
32
  action do |t|
31
- puts "Unpausing pipeline #{t.pipeline} for target #{t.target}..."
33
+ $stdout.puts(
34
+ "Unpausing pipeline #{t.pipeline} for target #{t.target}..."
35
+ )
32
36
  RubyFly.unpause_pipeline(
33
- target: t.target,
34
- team: t.team,
35
- pipeline: t.pipeline,
36
- environment: {
37
- "HOME" => t.home_directory
38
- })
37
+ target: t.target,
38
+ team: t.team,
39
+ pipeline: t.pipeline,
40
+ environment: {
41
+ 'HOME' => t.home_directory
42
+ }
43
+ )
39
44
  end
40
45
  end
41
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'tasks/authentication/login'
2
4
  require_relative 'tasks/authentication/ensure'
3
5
  require_relative 'tasks/pipeline/get'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFly
2
- VERSION = '2.10.0.pre.2'
4
+ VERSION = '2.10.0.pre.3'
3
5
  end
data/lib/rake_fly.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'semantic'
2
4
  require 'rake_dependencies'
3
5
  require 'ruby_fly'
@@ -11,42 +13,15 @@ module RakeFly
11
13
  ARTIFACT_FORMAT_CHANGE_VERSION = '5.0.0'
12
14
 
13
15
  def self.define_installation_tasks(opts = {})
14
- namespace = opts[:namespace] || :fly
15
- version = opts[:version] || '2.7.0'
16
- path = opts[:path] || File.join('vendor', 'fly')
17
-
18
- type = self.type(version)
19
- uri_template = self.uri_template(version)
20
- file_name_template = self.file_name_template(version)
21
- new_format = self.new_format?(version)
22
-
23
- task_set_opts = {
24
- namespace: namespace,
25
- dependency: 'fly',
26
- version: version,
27
- path: path,
28
- type: type,
29
- platform_os_names: {darwin: 'darwin', linux: 'linux'},
30
- uri_template: uri_template,
31
- file_name_template: file_name_template,
32
- needs_fetch: lambda { |t|
33
- fly_binary = File.join(t.path, t.binary_directory, 'fly')
34
-
35
- !(File.exist?(fly_binary) && RubyFly.version == version)
36
- }}
37
-
38
- unless new_format
39
- task_set_opts[:source_binary_name_template] =
40
- "fly_<%= @platform_os_name %>_amd64"
41
- task_set_opts[:target_binary_name_template] =
42
- "fly"
43
- end
16
+ option_resolver = OptionResolver.new(opts)
44
17
 
45
18
  RubyFly.configure do |c|
46
- c.binary = File.join(path, 'bin', 'fly')
19
+ c.binary = option_resolver.fly_binary_path
47
20
  end
48
21
 
49
- RakeDependencies::TaskSets::All.define(task_set_opts)
22
+ RakeDependencies::TaskSets::All.define(
23
+ option_resolver.installation_task_set_options
24
+ )
50
25
  end
51
26
 
52
27
  def self.define_authentication_tasks(opts = {}, &block)
@@ -61,37 +36,108 @@ module RakeFly
61
36
  RakeFly::TaskSets::Project.define(opts, &block)
62
37
  end
63
38
 
64
- private
39
+ class OptionResolver
40
+ attr_reader :opts
65
41
 
66
- def self.new_format?(version)
67
- Semantic::Version.new(version) >=
68
- Semantic::Version.new(ARTIFACT_FORMAT_CHANGE_VERSION)
69
- end
42
+ def initialize(opts)
43
+ @opts = opts
44
+ end
45
+
46
+ # rubocop:disable Metrics/MethodLength
47
+ def installation_task_set_options
48
+ task_set_opts = {
49
+ namespace: namespace,
50
+ dependency: dependency,
51
+ version: version,
52
+ path: path,
53
+ type: type,
54
+ platform_os_names: platform_os_names,
55
+ uri_template: uri_template,
56
+ file_name_template: file_name_template,
57
+ needs_fetch: needs_fetch_check_lambda
58
+ }
70
59
 
71
- def self.type(version)
72
- if self.new_format?(version)
73
- :tgz
74
- else
75
- :uncompressed
60
+ unless new_format?
61
+ task_set_opts[:source_binary_name_template] =
62
+ source_binary_name_template
63
+ task_set_opts[:target_binary_name_template] =
64
+ target_binary_name_template
65
+ end
66
+
67
+ task_set_opts
76
68
  end
77
- end
69
+ # rubocop:enable Metrics/MethodLength
78
70
 
79
- def self.uri_template(version)
80
- if new_format?(version)
81
- "https://github.com/concourse/concourse/releases/download" +
82
- "/v<%= @version %>" +
83
- "/fly-<%= @version %>-<%= @platform_os_name %>-amd64<%= @ext %>"
84
- else
85
- "https://github.com/concourse/concourse/releases/" +
86
- "download/v<%= @version %>/fly_<%= @platform_os_name %>_amd64"
71
+ def fly_binary_path
72
+ File.join(path, 'bin', 'fly')
87
73
  end
88
- end
89
74
 
90
- def self.file_name_template(version)
91
- if new_format?(version)
92
- "fly-<%= @version %>-<%= @platform_os_name %>-amd64<%= @ext %>"
93
- else
94
- "fly_<%= @platform_os_name %>_amd64"
75
+ def namespace
76
+ opts[:namespace] || :fly
77
+ end
78
+
79
+ def dependency
80
+ 'fly'
81
+ end
82
+
83
+ def version
84
+ opts[:version] || '2.7.0'
85
+ end
86
+
87
+ def path
88
+ opts[:path] || File.join('vendor', 'fly')
89
+ end
90
+
91
+ def type
92
+ if new_format?
93
+ :tgz
94
+ else
95
+ :uncompressed
96
+ end
97
+ end
98
+
99
+ def platform_os_names
100
+ { darwin: 'darwin', linux: 'linux' }
101
+ end
102
+
103
+ def uri_template
104
+ if new_format?
105
+ 'https://github.com/concourse/concourse/releases/download' \
106
+ '/v<%= @version %>' \
107
+ '/fly-<%= @version %>-<%= @platform_os_name %>-amd64<%= @ext %>'
108
+ else
109
+ 'https://github.com/concourse/concourse/releases/' \
110
+ 'download/v<%= @version %>/fly_<%= @platform_os_name %>_amd64'
111
+ end
112
+ end
113
+
114
+ def file_name_template
115
+ if new_format?
116
+ 'fly-<%= @version %>-<%= @platform_os_name %>-amd64<%= @ext %>'
117
+ else
118
+ 'fly_<%= @platform_os_name %>_amd64'
119
+ end
120
+ end
121
+
122
+ def target_binary_name_template
123
+ 'fly'
124
+ end
125
+
126
+ def source_binary_name_template
127
+ 'fly_<%= @platform_os_name %>_amd64'
128
+ end
129
+
130
+ def needs_fetch_check_lambda
131
+ lambda { |t|
132
+ fly_binary = File.join(t.path, t.binary_directory, 'fly')
133
+
134
+ !(File.exist?(fly_binary) && RubyFly.version == version)
135
+ }
136
+ end
137
+
138
+ def new_format?
139
+ Semantic::Version.new(version) >=
140
+ Semantic::Version.new(ARTIFACT_FORMAT_CHANGE_VERSION)
95
141
  end
96
142
  end
97
143
  end