File tree Expand file tree Collapse file tree 6 files changed +26
-18
lines changed Expand file tree Collapse file tree 6 files changed +26
-18
lines changed Original file line number Diff line number Diff line change @@ -64,8 +64,8 @@ def repository_data
64
64
end
65
65
66
66
def ssh_key
67
- if ssh_key = repository . settings . ssh_key . decrypt
68
- { 'source' => 'repo_settings' , 'value' => ssh_key }
67
+ if ssh_key = repository . settings . ssh_key
68
+ { 'source' => 'repo_settings' , 'value' => ssh_key . value . decrypt }
69
69
elsif ssh_key = job . ssh_key
70
70
{ 'source' => 'config' , 'value' => ssh_key }
71
71
end
Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ class EnvVar < Travis::Settings::Model
14
14
validates :name , presence : true
15
15
end
16
16
17
+ class SshKey < Travis ::Settings ::Model
18
+ attribute :description , String
19
+ attribute :value , Travis ::Settings ::EncryptedValue
20
+
21
+ validates :value , presence : true
22
+ end
23
+
17
24
class EnvVars < Collection
18
25
model EnvVar
19
26
end
@@ -24,7 +31,7 @@ class EnvVars < Collection
24
31
attribute :build_pushes , Boolean , default : true
25
32
attribute :build_pull_requests , Boolean , default : true
26
33
attribute :maximum_number_of_builds , Integer
27
- attribute :ssh_key , Travis :: Settings :: EncryptedValue
34
+ attribute :ssh_key , SshKey
28
35
29
36
def maximum_number_of_builds
30
37
super . to_i
Original file line number Diff line number Diff line change @@ -10,16 +10,7 @@ def set(instance, value)
10
10
end
11
11
12
12
def get ( instance )
13
- if type . primitive <= Travis ::Settings ::Model
14
- unless instance . instance_variable_get ( instance_variable_name )
15
- value = Travis ::Settings ::Model . new
16
- if instance . frozen?
17
- return value
18
- else
19
- set ( instance , value )
20
- end
21
- end
22
- elsif type . primitive <= Travis ::Settings ::EncryptedValue
13
+ if type . primitive <= Travis ::Settings ::EncryptedValue
23
14
unless instance . instance_variable_get ( instance_variable_name )
24
15
value = Travis ::Settings ::EncryptedValue . new ( nil )
25
16
if instance . frozen?
@@ -92,6 +83,10 @@ def model?(name)
92
83
end
93
84
end
94
85
86
+ def primitive ( name )
87
+ attribute_set [ name . to_sym ] . type . primitive
88
+ end
89
+
95
90
def get ( key )
96
91
if attribute? ( key )
97
92
self . send ( key )
@@ -107,9 +102,13 @@ def set(key, value)
107
102
private :set
108
103
109
104
def load ( hash )
105
+ return unless hash
106
+
110
107
hash . each do |key , value |
111
108
if collection? ( key ) || encrypted? ( key ) || model? ( key )
112
- get ( key ) . load ( value )
109
+ thing = get ( key )
110
+ thing = set ( key , primitive ( key ) . new ) if !thing && value
111
+ thing . load ( value ) if thing
113
112
elsif attribute? ( key )
114
113
set ( key , value )
115
114
end
Original file line number Diff line number Diff line change @@ -190,7 +190,8 @@ def stub_test(attributes = {})
190
190
finished_at : Time . now . utc ,
191
191
worker : 'ruby3.worker.travis-ci.org:travis-ruby-4' ,
192
192
tags : 'tag-a,tag-b' ,
193
- log_content : log . content
193
+ log_content : log . content ,
194
+ ssh_key : nil
194
195
)
195
196
196
197
source = stub_build ( :matrix => [ test ] )
Original file line number Diff line number Diff line change 6
6
let ( :test ) do
7
7
test = stub_test
8
8
settings = Repository ::Settings . load ( {
9
- 'ssh_key' => Travis ::Model ::EncryptedColumn . new ( use_prefix : false ) . dump ( 'an ssh key' ) ,
9
+ 'ssh_key' => {
10
+ 'value' => Travis ::Model ::EncryptedColumn . new ( use_prefix : false ) . dump ( 'an ssh key' )
11
+ } ,
10
12
'env_vars' => [ {
11
13
'name' => 'FOO' ,
12
14
'value' => Travis ::Model ::EncryptedColumn . new ( use_prefix : false ) . dump ( 'bar' )
Original file line number Diff line number Diff line change 44
44
before :each do
45
45
settings = OpenStruct . new (
46
46
restricts_number_of_builds? : false ,
47
- env_vars : [ ] ,
48
- ssh_key : Travis ::Settings ::EncryptedValue . new ( 'an ssh key' )
47
+ env_vars : [ ]
49
48
)
50
49
test . repository . stubs ( :settings ) . returns ( settings )
51
50
scope = stub ( 'scope' )
You can’t perform that action at this time.
0 commit comments