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
9b2160bd
Commit
9b2160bd
authored
May 21, 2018
by
Jacob Schatz
Committed by
Micaël Bergeron
Jun 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Static analysis pass
parent
eefea6d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
26 deletions
+20
-26
ee/lib/assets/pseudonymity_dump.yml
ee/lib/assets/pseudonymity_dump.yml
+0
-0
ee/spec/lib/gitlab/pseudonymity_spec.rb
ee/spec/lib/gitlab/pseudonymity_spec.rb
+5
-13
lib/pseudonymity/table.rb
lib/pseudonymity/table.rb
+14
-12
lib/tasks/gitlab/db.rake
lib/tasks/gitlab/db.rake
+1
-1
No files found.
lib/assets/pseudonymity_dump.yml
→
ee/
lib/assets/pseudonymity_dump.yml
View file @
9b2160bd
File moved
ee/spec/lib/gitlab/pseudo_spec.rb
→
ee/spec/lib/gitlab/pseudo
nymity
_spec.rb
View file @
9b2160bd
require
'spec_helper'
describe
Gitlab
::
Pseudonymity
do
let!
(
:project
)
{
create
(
:project
)
}
let
(
:base_dir
)
{
Dir
.
mktmpdir
}
subject
(
:pseudo
)
{
Pseudonymity
::
Table
.
new
}
...
...
@@ -16,20 +15,13 @@ describe Gitlab::Pseudonymity do
pseudo
.
config
[
"output"
][
"csv"
]
=
base_dir
pseudo
.
config
[
"tables"
]
=
{
"projects"
=>
{
"whitelist"
=>
[
"id"
,
"name"
,
"path"
,
"description"
],
"pseudo"
=>
[
"id"
]
"whitelist"
=>
%w(id name path description)
,
"pseudo"
=>
%w(id)
}
}
expect
(
pseudo
.
config
[
"output"
][
"csv"
]).
to
eq
(
base_dir
)
# grab the first table it outputs. There would only be 1.
project_table_file
=
pseudo
.
tables_to_csv
[
0
]
...
...
@@ -44,14 +36,14 @@ describe Gitlab::Pseudonymity do
if
line_num
==
0
columns
=
line
.
split
(
","
)
end
if
line_num
==
1
project_data
=
line
.
split
(
","
)
break
end
end
# check if CSV columns are correct
expect
(
columns
.
to_set
).
to
eq
(
[
"id"
,
"name"
,
"path"
,
"description
\n
"
]
.
to_set
)
expect
(
columns
.
to_set
).
to
eq
(
%W(id name path description
\n
)
.
to_set
)
# is it pseudonymous
expect
(
project_data
[
0
]).
not_to
eq
(
1
)
...
...
lib/pseudonymity/table.rb
View file @
9b2160bd
...
...
@@ -13,7 +13,7 @@ module Pseudonymity
columns
=
results
.
columns
# Assume they all have the same table
to_filter
=
@anon_fields
&
columns
Enumerator
.
new
do
|
yielder
|
Enumerator
.
new
do
|
yielder
|
results
.
each
do
|
result
|
to_filter
.
each
do
|
field
|
secret
=
Rails
.
application
.
secrets
[
:secret_key_base
]
...
...
@@ -39,10 +39,12 @@ module Pseudonymity
def
tables_to_csv
tables
=
config
[
"tables"
]
@csv_output
=
config
[
"output"
][
"csv"
]
if
!
File
.
directory?
(
@csv_output
)
unless
File
.
directory?
(
@csv_output
)
raise
"No such directory
#{
@csv_output
}
"
end
tables
.
each
do
|
k
,
v
|
tables
.
each
do
|
k
,
v
|
@schema
[
k
]
=
{}
table_to_csv
(
k
,
v
[
"whitelist"
],
v
[
"pseudo"
])
end
...
...
@@ -50,7 +52,7 @@ module Pseudonymity
file_list_to_json
end
def
get_and_log_file_name
(
ext
,
prefix
=
nil
,
filename
=
nil
)
def
get_and_log_file_name
(
ext
,
prefix
=
nil
,
filename
=
nil
)
file_timestamp
=
filename
||
"
#{
prefix
}
_
#{
Time
.
now
.
to_i
}
"
file_timestamp
=
"
#{
file_timestamp
}
.
#{
ext
}
"
@output_files
<<
file_timestamp
...
...
@@ -69,19 +71,19 @@ module Pseudonymity
def
table_to_csv
(
table
,
whitelist_columns
,
pseudonymity_columns
)
sql
=
"SELECT
#{
whitelist_columns
.
join
(
","
)
}
FROM
#{
table
}
;"
# type_sql = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '#{table}';"
results
=
ActiveRecord
::
Base
.
connection
.
exec_query
(
sql
)
# type_results = ActiveRecord::Base.connection.exec_query(type_sql)
type_results
=
ActiveRecord
::
Base
.
connection
.
columns
(
table
)
type_results
=
type_results
.
select
do
|
c
|
type_results
=
type_results
.
select
do
|
c
|
@config
[
"tables"
][
table
][
"whitelist"
].
include?
(
c
.
name
)
end
type_results
=
type_results
.
map
do
|
c
|
data_type
=
c
.
sql_type
if
@config
[
"tables"
][
table
][
"pseudo"
].
include?
(
c
.
name
)
data_type
=
"character varying"
end
{
name:
c
.
name
,
data_type:
data_type
}
end
set_schema_column_types
(
table
,
type_results
)
...
...
@@ -92,7 +94,7 @@ module Pseudonymity
end
def
set_schema_column_types
(
table
,
type_results
)
type_results
.
each
do
|
type_result
|
type_results
.
each
do
|
type_result
|
@schema
[
table
][
type_result
[
:name
]]
=
type_result
[
:data_type
]
end
# hard coded because all mapping keys in GL are id
...
...
@@ -106,16 +108,16 @@ module Pseudonymity
def
write_to_csv_file
(
title
,
contents
)
file_path
=
get_and_log_file_name
(
"csv"
,
title
)
column_names
=
contents
.
first
.
keys
contents
=
CSV
.
generate
do
|
csv
|
contents
=
CSV
.
generate
do
|
csv
|
csv
<<
column_names
contents
.
each
do
|
x
|
csv
<<
x
.
values
end
end
File
.
open
(
file_path
,
'w'
)
{
|
file
|
file
.
write
(
contents
)
}
return
file_path
file_path
end
private
:write_to_csv_file
end
end
\ No newline at end of file
end
lib/tasks/gitlab/db.rake
View file @
9b2160bd
...
...
@@ -71,7 +71,7 @@ namespace :gitlab do
end
desc
'Output pseudonymity dump of selected tables'
task
:pseudonymity_dump
=>
:environment
do
task
pseudonymity_dump:
:environment
do
table
=
Pseudonymity
::
Table
.
new
table
.
tables_to_csv
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