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
bd18aa43
Commit
bd18aa43
authored
Jan 17, 2020
by
David Fernandez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add seed for the license file
Use a common rake task between the development and production seed
parent
e2b86d1d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
62 deletions
+103
-62
ee/db/fixtures/development/10_license_file.rb
ee/db/fixtures/development/10_license_file.rb
+5
-0
ee/db/fixtures/production/010_license.rb
ee/db/fixtures/production/010_license.rb
+1
-16
ee/lib/tasks/gitlab/license.rake
ee/lib/tasks/gitlab/license.rake
+27
-0
ee/spec/db/production/license_spec.rb
ee/spec/db/production/license_spec.rb
+3
-46
ee/spec/tasks/gitlab/license_rake_spec.rb
ee/spec/tasks/gitlab/license_rake_spec.rb
+67
-0
No files found.
ee/db/fixtures/development/10_license_file.rb
0 → 100644
View file @
bd18aa43
# frozen_string_literal: true
Gitlab
::
Seeder
.
quiet
do
Rake
::
Task
[
'gitlab:license:load'
].
invoke
(
'verbose'
)
end
ee/db/fixtures/production/010_license.rb
View file @
bd18aa43
# frozen_string_literal: true
default_license_file
=
Settings
.
source
.
dirname
+
'Gitlab.gitlab-license'
license_file
=
Pathname
.
new
(
ENV
.
fetch
(
'GITLAB_LICENSE_FILE'
,
default_license_file
))
# Do not fail if the license was not specified in configuration or a file
# placed at the expected locations.
if
license_file
.
exist?
if
::
License
.
new
(
data:
license_file
.
read
).
save
puts
"License Added:
\n\n
FilePath:
#{
license_file
}
"
.
color
(
:green
)
else
puts
"License Invalid:
\n\n
FilePath:
#{
license_file
}
"
.
color
(
:red
)
raise
"License Invalid"
end
elsif
!
ENV
[
'GITLAB_LICENSE_FILE'
].
blank?
puts
"License File Missing:
\n\n
FilePath:
#{
license_file
}
"
.
color
(
:red
)
raise
"License File Missing"
end
Rake
::
Task
[
'gitlab:license:load'
].
invoke
ee/lib/tasks/gitlab/license.rake
View file @
bd18aa43
...
...
@@ -12,5 +12,32 @@ namespace :gitlab do
puts
"License valid from:
#{
license
[
:license_starts_at
]
}
to
#{
license
[
:license_expires_at
]
}
"
puts
"Email associated with license:
#{
license
[
:licensee
][
'Email'
]
}
"
end
task
:load
,
[
:mode
]
=>
:environment
do
|
_
,
args
|
args
.
with_defaults
(
mode:
'default'
)
verbose
=
args
[
:mode
]
==
'verbose'
flag
=
'GITLAB_LICENSE_FILE'
if
ENV
[
flag
].
blank?
&&
verbose
puts
"Skipped. Use the `
#{
flag
}
` environment variable to seed the License file of the given path."
next
end
default_license_file
=
Settings
.
source
.
dirname
+
'Gitlab.gitlab-license'
license_file
=
ENV
.
fetch
(
flag
,
default_license_file
)
if
File
.
file?
(
license_file
)
if
::
License
.
create
(
data:
File
.
read
(
license_file
))
puts
"License Added:
\n\n
FilePath:
#{
license_file
}
"
.
color
(
:green
)
else
puts
"License Invalid:
\n\n
FilePath:
#{
license_file
}
"
.
color
(
:red
)
raise
"License Invalid"
end
elsif
!
ENV
[
flag
].
blank?
puts
"License File Missing:
\n\n
FilePath:
#{
license_file
}
"
.
color
(
:red
)
raise
"License File Missing"
end
end
end
end
ee/spec/db/production/license_spec.rb
View file @
bd18aa43
...
...
@@ -4,52 +4,9 @@ require 'spec_helper'
describe
'Automated License Installation'
do
subject
{
load
Rails
.
root
.
join
(
'ee'
,
'db'
,
'fixtures'
,
'production'
,
'010_license.rb'
)
}
it
'works when no license to be installed'
do
expect
{
subject
}.
not_to
raise_error
end
context
'when GITLAB_LICENSE_FILE env variable is set'
do
let
(
:license_path
)
{
'arbitrary_file_name'
}
before
do
stub_env
(
'GITLAB_LICENSE_FILE'
,
license_path
)
end
it
'fails when the file does not exist'
do
license_file
=
double
(
'Pathname'
,
exist?:
false
)
allow
(
Pathname
).
to
receive
(
:new
).
and_call_original
expect
(
Pathname
).
to
receive
(
:new
).
with
(
license_path
).
and_return
(
license_file
)
expect
{
subject
}.
to
raise_error
(
RuntimeError
,
"License File Missing"
)
end
context
'when the file does exist'
do
before
do
license_file
=
double
(
'Pathname'
,
exist?:
true
,
read:
license_file_contents
)
allow
(
Pathname
).
to
receive
(
:new
).
and_call_original
expect
(
Pathname
).
to
receive
(
:new
).
with
(
license_path
).
and_return
(
license_file
)
end
context
'and contains a valid license'
do
let
(
:license_file_contents
)
{
'valid contents'
}
it
'executes the gitlab:license:load task'
do
expect
(
Rake
::
Task
).
to
receive
(
:[]
).
with
(
'gitlab:license:load'
).
and_return
(
OpenStruct
.
new
(
invoke:
true
))
it
'succeeds in adding the license'
do
license
=
double
(
'License'
,
save:
true
)
expect
(
License
).
to
receive
(
:new
).
with
(
data:
license_file_contents
).
and_return
(
license
)
expect
{
subject
}.
not_to
raise_error
end
end
context
'but does not contain a valid license'
do
let
(
:license_file_contents
)
{
'invalid contents'
}
it
'fails to add the license'
do
license
=
double
(
'License'
,
save:
false
)
expect
(
License
).
to
receive
(
:new
).
with
(
data:
license_file_contents
).
and_return
(
license
)
expect
{
subject
}.
to
raise_error
(
RuntimeError
,
"License Invalid"
)
end
end
end
subject
end
end
ee/spec/tasks/gitlab/license_rake_spec.rb
0 → 100644
View file @
bd18aa43
# frozen_string_literal: true
require
'rake_helper'
describe
'gitlab:license namespace rake tasks'
do
before
do
Rake
.
application
.
rake_require
'tasks/gitlab/license'
end
describe
'load'
do
let_it_be
(
:license_path
)
{
'arbitrary_file_name'
}
let
(
:mode
)
{
'default'
}
subject
{
run_rake_task
'gitlab:license:load'
,
[
mode
]
}
it
'works when no license to be installed'
do
expect
{
subject
}.
not_to
raise_error
end
context
'when GITLAB_LICENSE_FILE env variable is set'
do
before
do
stub_env
(
'GITLAB_LICENSE_FILE'
,
license_path
)
end
it
'fails when the file does not exist'
do
expect
(
File
).
to
receive
(
:file?
).
with
(
license_path
).
and_return
(
false
)
expect
{
subject
}.
to
raise_error
(
RuntimeError
,
"License File Missing"
)
end
context
'when the file does exist'
do
before
do
expect
(
File
).
to
receive
(
:file?
).
with
(
license_path
).
and_return
(
true
)
end
context
'and contains a valid license'
do
let
(
:license_file_contents
)
{
'valid contents'
}
it
'succeeds in adding the license'
do
expect
(
File
).
to
receive
(
:read
).
with
(
license_path
).
and_return
(
license_file_contents
)
expect
(
License
).
to
receive
(
:create
).
with
(
data:
license_file_contents
).
and_return
(
true
)
expect
{
subject
}.
not_to
raise_error
end
end
context
'but does not contain a valid license'
do
let
(
:license_file_contents
)
{
'invalid contents'
}
it
'fails to add the license'
do
expect
(
File
).
to
receive
(
:read
).
with
(
license_path
).
and_return
(
license_file_contents
)
expect
(
License
).
to
receive
(
:create
).
with
(
data:
license_file_contents
).
and_return
(
false
)
expect
{
subject
}.
to
raise_error
(
RuntimeError
,
"License Invalid"
)
end
end
end
end
context
'running in mode verbose'
do
let
(
:mode
)
{
'verbose'
}
it
'outputs a the help message'
do
expect
{
subject
}.
to
output
(
/environment variable to seed the License file of the given path/
).
to_stdout
end
end
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