Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5b797471
Commit
5b797471
authored
Mar 16, 2020
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move files into Terraform module
- Model - Uploader - Tests
parent
24002101
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
92 additions
and
70 deletions
+92
-70
app/models/terraform.rb
app/models/terraform.rb
+7
-0
app/models/terraform/state.rb
app/models/terraform/state.rb
+23
-0
app/models/terraform_state.rb
app/models/terraform_state.rb
+0
-21
app/uploaders/terraform/state_uploader.rb
app/uploaders/terraform/state_uploader.rb
+44
-0
app/uploaders/terraform_state_uploader.rb
app/uploaders/terraform_state_uploader.rb
+0
-42
spec/factories/terraform/state.rb
spec/factories/terraform/state.rb
+11
-0
spec/fixtures/terraform/terraform.tfstate
spec/fixtures/terraform/terraform.tfstate
+0
-0
spec/models/terraform/state_spec.rb
spec/models/terraform/state_spec.rb
+3
-3
spec/uploaders/terraform/state_uploader_spec.rb
spec/uploaders/terraform/state_uploader_spec.rb
+4
-4
No files found.
app/models/terraform.rb
0 → 100644
View file @
5b797471
# frozen_string_literal: true
module
Terraform
def
self
.
table_name_prefix
'terraform_'
end
end
app/models/terraform/state.rb
0 → 100644
View file @
5b797471
# frozen_string_literal: true
module
Terraform
class
State
<
ApplicationRecord
belongs_to
:project
validates
:project_id
,
presence:
true
after_save
:update_file_store
,
if: :saved_change_to_file?
mount_uploader
:file
,
StateUploader
def
update_file_store
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
self
.
update_column
(
:file_store
,
file
.
object_store
)
end
def
file_store
super
||
StateUploader
.
default_store
end
end
end
app/models/terraform_state.rb
deleted
100644 → 0
View file @
24002101
# frozen_string_literal: true
class
TerraformState
<
ApplicationRecord
belongs_to
:project
validates
:project_id
,
presence:
true
after_save
:update_file_store
,
if: :saved_change_to_file?
mount_uploader
:file
,
TerraformStateUploader
def
update_file_store
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
self
.
update_column
(
:file_store
,
file
.
object_store
)
end
def
file_store
super
||
TerraformStateUploader
.
default_store
end
end
app/uploaders/terraform/state_uploader.rb
0 → 100644
View file @
5b797471
# frozen_string_literal: true
module
Terraform
class
StateUploader
<
GitlabUploader
include
ObjectStorage
::
Concern
storage_options
Gitlab
.
config
.
terraform_state
delegate
:project_id
,
to: :model
# Use Lockbox to encrypt/decrypt the stored file (registers CarrierWave callbacks)
encrypt
(
key: :key
)
def
filename
"
#{
model
.
id
}
.tfstate"
end
def
store_dir
project_id
.
to_s
end
def
key
OpenSSL
::
HMAC
.
digest
(
'SHA256'
,
Gitlab
::
Application
.
secrets
.
db_key_base
,
project_id
.
to_s
)
end
class
<<
self
def
direct_upload_enabled?
false
end
def
background_upload_enabled?
false
end
def
proxy_download_enabled?
true
end
def
default_store
object_store_enabled?
?
ObjectStorage
::
Store
::
REMOTE
:
ObjectStorage
::
Store
::
LOCAL
end
end
end
end
app/uploaders/terraform_state_uploader.rb
deleted
100644 → 0
View file @
24002101
# frozen_string_literal: true
class
TerraformStateUploader
<
GitlabUploader
include
ObjectStorage
::
Concern
storage_options
Gitlab
.
config
.
terraform_state
delegate
:project_id
,
to: :model
# Use Lockbox to encrypt/decrypt the stored file (registers CarrierWave callbacks)
encrypt
(
key: :key
)
def
filename
"
#{
model
.
id
}
.tfstate"
end
def
store_dir
project_id
.
to_s
end
def
key
OpenSSL
::
HMAC
.
digest
(
'SHA256'
,
Gitlab
::
Application
.
secrets
.
db_key_base
,
project_id
.
to_s
)
end
class
<<
self
def
direct_upload_enabled?
false
end
def
background_upload_enabled?
false
end
def
proxy_download_enabled?
true
end
def
default_store
object_store_enabled?
?
ObjectStorage
::
Store
::
REMOTE
:
ObjectStorage
::
Store
::
LOCAL
end
end
end
spec/factories/terraform
_
state.rb
→
spec/factories/terraform
/
state.rb
View file @
5b797471
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:terraform_state
do
factory
:terraform_state
,
class:
'Terraform::State'
do
project
{
create
(
:project
)
}
trait
:with_file
do
file
{
fixture_file_upload
(
'spec/fixtures/terraform.tfstate'
)
}
file
{
fixture_file_upload
(
'spec/fixtures/terraform
/terraform
.tfstate'
)
}
end
end
end
spec/fixtures/terraform.tfstate
→
spec/fixtures/terraform
/terraform
.tfstate
View file @
5b797471
File moved
spec/models/terraform
_
state_spec.rb
→
spec/models/terraform
/
state_spec.rb
View file @
5b797471
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
TerraformState
do
describe
Terraform
::
State
do
subject
{
create
(
:terraform_state
,
:with_file
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
...
...
@@ -10,14 +10,14 @@ describe TerraformState do
it
{
is_expected
.
to
validate_presence_of
(
:project_id
)
}
before
do
stub_terraform_state_object_storage
(
TerraformStateUploader
)
stub_terraform_state_object_storage
(
Terraform
::
StateUploader
)
end
describe
'#file_store'
do
context
'when no value is set'
do
it
'returns the default store of the uploader'
do
[
ObjectStorage
::
Store
::
LOCAL
,
ObjectStorage
::
Store
::
REMOTE
].
each
do
|
store
|
expect
(
TerraformStateUploader
).
to
receive
(
:default_store
).
and_return
(
store
)
expect
(
Terraform
::
StateUploader
).
to
receive
(
:default_store
).
and_return
(
store
)
expect
(
described_class
.
new
.
file_store
).
to
eq
(
store
)
end
end
...
...
spec/uploaders/terraform
_
state_uploader_spec.rb
→
spec/uploaders/terraform
/
state_uploader_spec.rb
View file @
5b797471
...
...
@@ -2,10 +2,10 @@
require
'spec_helper'
describe
TerraformStateUploader
do
describe
Terraform
::
StateUploader
do
subject
{
terraform_state
.
file
}
let
(
:terraform_state
)
{
create
(
:terraform_state
,
file:
fixture_file_upload
(
'spec/fixtures/terraform.tfstate'
))
}
let
(
:terraform_state
)
{
create
(
:terraform_state
,
file:
fixture_file_upload
(
'spec/fixtures/terraform
/terraform
.tfstate'
))
}
before
do
stub_terraform_state_object_storage
...
...
@@ -36,11 +36,11 @@ describe TerraformStateUploader do
describe
'encryption'
do
it
'encrypts the stored file'
do
expect
(
subject
.
file
.
read
).
not_to
eq
(
fixture_file
(
'terraform.tfstate'
))
expect
(
subject
.
file
.
read
).
not_to
eq
(
fixture_file
(
'terraform
/terraform
.tfstate'
))
end
it
'decrypts the file when reading'
do
expect
(
subject
.
read
).
to
eq
(
fixture_file
(
'terraform.tfstate'
))
expect
(
subject
.
read
).
to
eq
(
fixture_file
(
'terraform
/terraform
.tfstate'
))
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment