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
a6386bf2
Commit
a6386bf2
authored
Jun 07, 2018
by
Micaël Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added specs and renamed stuff accordingly
parent
3aef2204
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
137 additions
and
52 deletions
+137
-52
app/views/admin/application_settings/_pseudonymizer.html.haml
...views/admin/application_settings/_pseudonymizer.html.haml
+23
-0
app/views/admin/application_settings/show.html.haml
app/views/admin/application_settings/show.html.haml
+1
-1
app/workers/pseudonymizer_worker.rb
app/workers/pseudonymizer_worker.rb
+6
-6
config/gitlab.yml.example
config/gitlab.yml.example
+6
-6
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+3
-3
ee/app/controllers/ee/admin/application_settings_controller.rb
...p/controllers/ee/admin/application_settings_controller.rb
+4
-0
ee/app/models/ee/application_setting.rb
ee/app/models/ee/application_setting.rb
+1
-1
lib/pseudonymizer/dumper.rb
lib/pseudonymizer/dumper.rb
+2
-2
lib/pseudonymizer/manifest.yml
lib/pseudonymizer/manifest.yml
+0
-0
lib/pseudonymizer/options.rb
lib/pseudonymizer/options.rb
+5
-1
lib/pseudonymizer/uploader.rb
lib/pseudonymizer/uploader.rb
+22
-23
lib/tasks/gitlab/db.rake
lib/tasks/gitlab/db.rake
+6
-6
spec/lib/pseudonymizer/dumper_spec.rb
spec/lib/pseudonymizer/dumper_spec.rb
+3
-2
spec/lib/pseudonymizer/uploader_spec.rb
spec/lib/pseudonymizer/uploader_spec.rb
+44
-0
spec/support/helpers/stub_object_storage.rb
spec/support/helpers/stub_object_storage.rb
+11
-1
No files found.
app/views/admin/application_settings/_pseudonymizer.html.haml
0 → 100644
View file @
a6386bf2
=
form_for
@application_setting
,
url:
admin_application_settings_path
,
html:
{
class:
'fieldset-form'
}
do
|
f
|
=
form_errors
(
@application_setting
)
%fieldset
.form-group.row
.offset-sm-2.col-sm-10
-
is_enabled
=
@application_setting
.
pseudonymizer_enabled?
-
is_available
=
@application_setting
.
pseudonymizer_available?
.form-check
=
f
.
label
:pseudonymizer_enabled
do
=
f
.
check_box
:pseudonymizer_enabled
,
disabled:
!
is_available
Enable Pseudonymizer Cron Job
.form-text.text-muted
-
if
is_enabled
=
pseudonymizer_description_text
-
else
-
if
is_available
=
pseudonymizer_disabled_description_text
-
else
=
pseudonymizer_unavailable_description_text
=
f
.
submit
'Save changes'
,
class:
"btn btn-success"
app/views/admin/application_settings/show.html.haml
View file @
a6386bf2
...
...
@@ -237,7 +237,7 @@
.settings-content
=
render
'usage'
-
if
License
.
feature_available?
(
:pseudonymizer
)
-
if
Gitlab
::
CurrentSettings
.
pseudonymizer_can_be_configured?
%section
.settings.as-usage.no-animate
#js-elt-database-dump-settings
{
class:
(
'expanded'
if
expanded
)
}
.settings-header
%h4
...
...
app/workers/pseudonymizer_worker.rb
View file @
a6386bf2
...
...
@@ -5,16 +5,16 @@ class PseudonymizerWorker
def
perform
return
unless
Gitlab
::
CurrentSettings
.
pseudonymizer_enabled?
options
=
Pseudonymi
ty
::
Options
.
new
(
options
=
Pseudonymi
zer
::
Options
.
new
(
config:
YAML
.
load_file
(
Rails
.
root
.
join
(
Gitlab
.
config
.
pseudonymizer
.
manifest
)),
start_at:
Time
.
now
.
utc
)
table
=
Pseudonymity
::
Table
.
new
(
options
)
table
.
tables_to_csv
dumper
=
Pseudonymizer
::
Dumper
.
new
(
options
)
dumper
.
tables_to_csv
upload
=
Pseudonymity
::
UploadService
.
new
(
options
)
upload
.
upload
upload
.
cleanup
upload
er
=
Pseudonymizer
::
Uploader
.
new
(
options
)
upload
er
.
upload
upload
er
.
cleanup
end
end
config/gitlab.yml.example
View file @
a6386bf2
...
...
@@ -733,9 +733,9 @@ production: &base
pseudonymizer:
enabled: false
# Tables manifest that specifies the fields to extract and pseudonymize.
manifest: config/pseudonymizer.yml
# remote_directory: 'gitlab-elt'
manifest: lib/pseudonymizer/manifest.yml
upload:
# remote_directory: 'gitlab-elt'
# Fog storage connection settings, see http://fog.io/storage/ .
connection:
# provider: AWS
...
...
@@ -896,16 +896,16 @@ test:
path: tmp/tests/backups
pseudonymizer:
enabled: false
manifest:
config/pseudonymizer.t
est.yml
manifest:
lib/pseudonymizer/manif
est.yml
upload:
# The remote 'directory' to store the CSV files. For S3, this would be the bucket name.
remote_directory: gitlab-elt.test
# Fog storage connection settings, see http://fog.io/storage/
connection:
provider: AWS
provider: AWS # Only AWS supported at the moment
aws_access_key_id: AWS_ACCESS_KEY_ID
aws_secret_access_key: AWS_SECRET_ACCESS_KEY
region: us-east-1
aws_access_key_id: minio
aws_secret_access_key: gdk-minio
gitlab_shell:
path: tmp/tests/gitlab-shell/
hooks_path: tmp/tests/gitlab-shell/hooks/
...
...
config/initializers/1_settings.rb
View file @
a6386bf2
...
...
@@ -370,9 +370,9 @@ Settings.cron_jobs['gitlab_usage_ping_worker'] ||= Settingslogic.new({})
Settings
.
cron_jobs
[
'gitlab_usage_ping_worker'
][
'cron'
]
||=
Settings
.
__send__
(
:cron_for_usage_ping
)
Settings
.
cron_jobs
[
'gitlab_usage_ping_worker'
][
'job_class'
]
=
'GitlabUsagePingWorker'
Settings
.
cron_jobs
[
'
gitlab_elt_database_dump
'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'
gitlab_elt_database_dump
'
][
'cron'
]
||=
'0 23 * * *'
;
Settings
.
cron_jobs
[
'
gitlab_elt_database_dump'
][
'job_class'
]
||=
'GitlabEltDataDump
Worker'
;
Settings
.
cron_jobs
[
'
pseudonymizer
'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'
pseudonymizer
'
][
'cron'
]
||=
'0 23 * * *'
;
Settings
.
cron_jobs
[
'
pseudonymizer'
][
'job_class'
]
||=
'Pseudonymizer
Worker'
;
Settings
.
cron_jobs
[
'schedule_update_user_activity_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'schedule_update_user_activity_worker'
][
'cron'
]
||=
'30 0 * * *'
...
...
ee/app/controllers/ee/admin/application_settings_controller.rb
View file @
a6386bf2
...
...
@@ -20,6 +20,10 @@ module EE
attrs
<<
:email_additional_text
end
if
License
.
feature_available?
(
:pseudonymizer
)
attrs
<<
:pseudonymizer_enabled
end
attrs
end
end
...
...
ee/app/models/ee/application_setting.rb
View file @
a6386bf2
...
...
@@ -101,7 +101,7 @@ module EE
slack_app_id:
nil
,
slack_app_secret:
nil
,
slack_app_verification_token:
nil
,
pseudonymizer_enabled:
Settings
.
pseudonymizer
[
'enabled'
]
,
pseudonymizer_enabled:
Settings
.
pseudonymizer
[
'enabled'
]
)
end
end
...
...
lib/pseudonymi
ty/table
.rb
→
lib/pseudonymi
zer/dumper
.rb
View file @
a6386bf2
...
...
@@ -3,7 +3,7 @@ require 'digest'
require
'csv'
require
'yaml'
module
Pseudonymi
ty
module
Pseudonymi
zer
class
Anon
def
initialize
(
fields
)
@anon_fields
=
fields
...
...
@@ -25,7 +25,7 @@ module Pseudonymity
end
end
class
Table
class
Dumper
attr_accessor
:config
def
initialize
(
options
)
...
...
lib/pseudonymi
ty
/manifest.yml
→
lib/pseudonymi
zer
/manifest.yml
View file @
a6386bf2
File moved
lib/pseudonymi
ty
/options.rb
→
lib/pseudonymi
zer
/options.rb
View file @
a6386bf2
module
Pseudonymi
ty
module
Pseudonymi
zer
class
Options
attr_reader
:config
attr_reader
:start_at
...
...
@@ -15,5 +15,9 @@ module Pseudonymity
def
upload_dir
File
.
join
(
self
.
start_at
.
iso8601
)
end
def
object_store_credentials
config
.
upload
.
connection
.
to_hash
.
deep_symbolize_keys
end
end
end
lib/pseudonymi
ty/upload_service
.rb
→
lib/pseudonymi
zer/uploader
.rb
View file @
a6386bf2
module
Pseudonymi
ty
class
Upload
Service
module
Pseudonymi
zer
class
Upload
er
RemoteStorageUnavailableError
=
Class
.
new
(
StandardError
)
def
initialize
(
options
,
progress
=
nil
)
@progress
=
progress
||
$stdout
@config
=
options
.
config
@output_dir
=
options
.
output_dir
@upload_dir
=
options
.
upload_dir
@connection_params
=
options
.
object_store_credentials
end
def
upload
...
...
@@ -16,18 +18,6 @@ module Pseudonymity
end
end
def
upload_file
(
file
,
directory
)
progress
.
print
"
\t
#{
file
}
... "
if
directory
.
files
.
create
(
key:
File
.
join
(
@upload_dir
,
File
.
basename
(
file
)),
body:
File
.
open
(
file
),
public:
false
)
progress
.
puts
"done"
.
color
(
:green
)
else
progress
.
puts
"uploading CSV to
#{
remote_directory
}
failed"
.
color
(
:red
)
end
end
def
cleanup
progress
.
print
"Deleting tmp directory
#{
@output_dir
}
... "
return
unless
File
.
exist?
(
@output_dir
)
...
...
@@ -41,24 +31,33 @@ module Pseudonymity
private
def
config
Gitlab
.
config
.
pseudonymizer
attr_reader
:progress
def
upload_file
(
file
,
directory
)
progress
.
print
"
\t
#{
file
}
... "
if
directory
.
files
.
create
(
key:
File
.
join
(
@upload_dir
,
File
.
basename
(
file
)),
body:
File
.
open
(
file
),
public:
false
)
progress
.
puts
"done"
.
color
(
:green
)
else
progress
.
puts
"uploading CSV to
#{
remote_directory
}
failed"
.
color
(
:red
)
end
end
def
remote_directory
connection_settings
=
config
.
upload
.
connection
if
connection_settings
.
blank?
if
@connection_params
.
blank?
progress
.
puts
"Cannot upload files, make sure the `pseudonimizer.upload.connection` is set properly"
.
color
(
:red
)
raise
RemoteStorageUnavailableError
.
new
(
connection_settings
)
raise
RemoteStorageUnavailableError
.
new
(
@config
)
end
connect_to_remote_directory
(
connection_settings
)
connect_to_remote_directory
end
def
connect_to_remote_directory
(
connection_settings
)
def
connect_to_remote_directory
# our settings use string keys, but Fog expects symbols
connection
=
::
Fog
::
Storage
.
new
(
connection_settings
.
symbolize_key
s
)
remote_dir
=
config
.
upload
.
remote_directory
connection
=
::
Fog
::
Storage
.
new
(
@connection_param
s
)
remote_dir
=
@
config
.
upload
.
remote_directory
# We only attempt to create the directory for local backups. For AWS
# and other cloud providers, we cannot guarantee the user will have
...
...
lib/tasks/gitlab/db.rake
View file @
a6386bf2
...
...
@@ -78,17 +78,17 @@ namespace :gitlab do
abort
"Pseudonymizer disabled."
unless
Gitlab
::
CurrentSettings
.
pseudonymizer_enabled?
options
=
Pseudonymi
ty
::
Options
.
new
(
options
=
Pseudonymi
zer
::
Options
.
new
(
config:
YAML
.
load_file
(
Rails
.
root
.
join
(
Gitlab
.
config
.
pseudonymizer
.
manifest
)),
start_at:
Time
.
now
.
utc
)
table
=
Pseudonymity
::
Table
.
new
(
options
)
table
.
tables_to_csv
dumper
=
Pseudonymizer
::
Dumper
.
new
(
options
)
dumper
.
tables_to_csv
upload
=
Pseudonymity
::
UploadService
.
new
(
options
,
progress
)
upload
.
upload
upload
.
cleanup
upload
er
=
Pseudonymizer
::
Uploader
.
new
(
options
,
progress
)
upload
er
.
upload
upload
er
.
cleanup
end
def
progress
...
...
spec/lib/pseudonymi
ty
_spec.rb
→
spec/lib/pseudonymi
zer/dumper
_spec.rb
View file @
a6386bf2
require
'spec_helper'
describe
Gitlab
::
Pseudonymity
do
describe
Pseudonymizer
::
Dumper
do
let!
(
:project
)
{
create
(
:project
)
}
let
(
:base_dir
)
{
Dir
.
mktmpdir
}
subject
(
:pseudo
)
{
Pseudonymity
::
Table
.
new
}
let
(
:options
)
{
Pseudonymizer
::
Options
.
new
()
}
subject
(
:pseudo
)
{
described_class
.
new
(
options
)
}
after
do
FileUtils
.
rm_rf
(
base_dir
)
...
...
spec/lib/pseudonymizer/uploader_spec.rb
0 → 100644
View file @
a6386bf2
require
'spec_helper'
describe
Pseudonymizer
::
Uploader
do
let
(
:base_dir
)
{
Dir
.
mktmpdir
}
let
(
:options
)
do
Pseudonymizer
::
Options
.
new
(
config:
Gitlab
.
config
.
pseudonymizer
,
start_at:
Time
.
now
.
utc
)
end
let
(
:remote_directory
)
{
subject
.
send
(
:remote_directory
)
}
subject
{
described_class
.
new
(
options
)
}
def
mock_file
(
file_name
)
FileUtils
.
touch
(
File
.
join
(
base_dir
,
file_name
))
end
before
do
allow
(
options
).
to
receive
(
:output_dir
).
and_return
(
base_dir
)
stub_object_storage_pseudonymizer
(
options:
options
)
10
.
times
{
|
i
|
mock_file
(
"file_
#{
i
}
.test"
)}
mock_file
(
"schema.yml"
)
mock_file
(
"file_list.json"
)
end
describe
"#upload"
do
it
"upload all file in the directory"
do
subject
.
upload
expect
(
remote_directory
.
files
.
count
).
to
eq
(
12
)
end
end
describe
"#cleanup"
do
it
"cleans the directory"
do
subject
.
cleanup
expect
(
Dir
[
File
.
join
(
base_dir
,
"*"
)].
length
).
to
eq
(
0
)
end
end
after
do
FileUtils
.
rm_rf
(
base_dir
)
end
end
spec/support/helpers/stub_object_storage.rb
View file @
a6386bf2
...
...
@@ -15,9 +15,14 @@ module StubObjectStorage
return
unless
enabled
stub_object_storage
(
connection_params:
uploader
.
object_store_credentials
,
remote_directory:
remote_directory
)
end
def
stub_object_storage
(
connection_params
:,
remote_directory
:)
Fog
.
mock!
::
Fog
::
Storage
.
new
(
uploader
.
object_store_credential
s
).
tap
do
|
connection
|
::
Fog
::
Storage
.
new
(
connection_param
s
).
tap
do
|
connection
|
begin
connection
.
directories
.
create
(
key:
remote_directory
)
rescue
Excon
::
Error
::
Conflict
...
...
@@ -57,4 +62,9 @@ module StubObjectStorage
</InitiateMultipartUploadResult>
EOS
end
def
stub_object_storage_pseudonymizer
(
options
:)
stub_object_storage
(
connection_params:
options
.
object_store_credentials
,
remote_directory:
options
.
config
.
upload
.
remote_directory
)
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