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
b0e19b3c
Commit
b0e19b3c
authored
Feb 24, 2020
by
Matt Kasa
Committed by
Grzegorz Bizon
Feb 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganize API::Entities::Internal into directories
Relates to
https://gitlab.com/gitlab-org/gitlab/issues/195964
parent
e7bf99b5
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
260 additions
and
13 deletions
+260
-13
app/finders/serverless_domain_finder.rb
app/finders/serverless_domain_finder.rb
+1
-1
app/models/serverless/lookup_path.rb
app/models/serverless/lookup_path.rb
+30
-0
app/models/serverless/virtual_domain.rb
app/models/serverless/virtual_domain.rb
+22
-0
lib/api/entities/internal/pages/lookup_path.rb
lib/api/entities/internal/pages/lookup_path.rb
+0
-5
lib/api/entities/internal/pages/virtual_domain.rb
lib/api/entities/internal/pages/virtual_domain.rb
+14
-0
lib/api/entities/internal/serverless/lookup_path.rb
lib/api/entities/internal/serverless/lookup_path.rb
+13
-0
lib/api/entities/internal/serverless/virtual_domain.rb
lib/api/entities/internal/serverless/virtual_domain.rb
+14
-0
lib/api/internal/pages.rb
lib/api/internal/pages.rb
+18
-5
spec/finders/serverless_domain_finder_spec.rb
spec/finders/serverless_domain_finder_spec.rb
+24
-2
spec/fixtures/api/schemas/internal/serverless/lookup_path.json
...fixtures/api/schemas/internal/serverless/lookup_path.json
+28
-0
spec/fixtures/api/schemas/internal/serverless/virtual_domain.json
...tures/api/schemas/internal/serverless/virtual_domain.json
+14
-0
spec/requests/api/internal/pages_spec.rb
spec/requests/api/internal/pages_spec.rb
+82
-0
No files found.
app/finders/serverless_domain_finder.rb
View file @
b0e19b3c
...
...
@@ -11,7 +11,7 @@ class ServerlessDomainFinder
return
unless
serverless?
@serverless_domain_cluster
=
::
Serverless
::
DomainCluster
.
for_uuid
(
serverless_domain_cluster_uuid
)
return
unless
serverless_domain_cluster
return
unless
serverless_domain_cluster
&
.
knative
&
.
external_ip
@environment
=
::
Environment
.
for_id_and_slug
(
match
[
:environment_id
].
to_i
(
16
),
match
[
:environment_slug
])
return
unless
environment
...
...
app/models/serverless/lookup_path.rb
0 → 100644
View file @
b0e19b3c
# frozen_string_literal: true
module
Serverless
class
LookupPath
attr_reader
:serverless_domain
delegate
:serverless_domain_cluster
,
to: :serverless_domain
delegate
:knative
,
to: :serverless_domain_cluster
delegate
:certificate
,
to: :serverless_domain_cluster
delegate
:key
,
to: :serverless_domain_cluster
def
initialize
(
serverless_domain
)
@serverless_domain
=
serverless_domain
end
def
source
{
type:
'serverless'
,
service:
serverless_domain
.
knative_uri
.
host
,
cluster:
{
hostname:
knative
.
hostname
,
address:
knative
.
external_ip
,
port:
443
,
cert:
certificate
,
key:
key
}
}
end
end
end
app/models/serverless/virtual_domain.rb
0 → 100644
View file @
b0e19b3c
# frozen_string_literal: true
module
Serverless
class
VirtualDomain
attr_reader
:serverless_domain
delegate
:serverless_domain_cluster
,
to: :serverless_domain
delegate
:pages_domain
,
to: :serverless_domain_cluster
delegate
:certificate
,
to: :pages_domain
delegate
:key
,
to: :pages_domain
def
initialize
(
serverless_domain
)
@serverless_domain
=
serverless_domain
end
def
lookup_paths
[
::
Serverless
::
LookupPath
.
new
(
serverless_domain
)
]
end
end
end
lib/api/entities/internal.rb
→
lib/api/entities/internal
/pages/lookup_path
.rb
View file @
b0e19b3c
...
...
@@ -8,11 +8,6 @@ module API
expose
:project_id
,
:access_control
,
:source
,
:https_only
,
:prefix
end
class
VirtualDomain
<
Grape
::
Entity
expose
:certificate
,
:key
expose
:lookup_paths
,
using:
LookupPath
end
end
end
end
...
...
lib/api/entities/internal/pages/virtual_domain.rb
0 → 100644
View file @
b0e19b3c
# frozen_string_literal: true
module
API
module
Entities
module
Internal
module
Pages
class
VirtualDomain
<
Grape
::
Entity
expose
:certificate
,
:key
expose
:lookup_paths
,
using:
LookupPath
end
end
end
end
end
lib/api/entities/internal/serverless/lookup_path.rb
0 → 100644
View file @
b0e19b3c
# frozen_string_literal: true
module
API
module
Entities
module
Internal
module
Serverless
class
LookupPath
<
Grape
::
Entity
expose
:source
end
end
end
end
end
lib/api/entities/internal/serverless/virtual_domain.rb
0 → 100644
View file @
b0e19b3c
# frozen_string_literal: true
module
API
module
Entities
module
Internal
module
Serverless
class
VirtualDomain
<
Grape
::
Entity
expose
:certificate
,
:key
expose
:lookup_paths
,
using:
LookupPath
end
end
end
end
end
lib/api/internal/pages.rb
View file @
b0e19b3c
...
...
@@ -24,13 +24,26 @@ module API
requires
:host
,
type:
String
,
desc:
'The host to query for'
end
get
"/"
do
host
=
Namespace
.
find_by_pages_host
(
params
[
:host
])
||
PagesDomain
.
find_by_domain
(
params
[
:host
])
no_content!
unless
host
serverless_domain_finder
=
ServerlessDomainFinder
.
new
(
params
[
:host
])
if
serverless_domain_finder
.
serverless?
# Handle Serverless domains
serverless_domain
=
serverless_domain_finder
.
execute
no_content!
unless
serverless_domain
virtual_domain
=
host
.
pages_virtual_domain
no_content!
unless
virtual_domain
virtual_domain
=
Serverless
::
VirtualDomain
.
new
(
serverless_domain
)
no_content!
unless
virtual_domain
present
virtual_domain
,
with:
Entities
::
Internal
::
Pages
::
VirtualDomain
present
virtual_domain
,
with:
Entities
::
Internal
::
Serverless
::
VirtualDomain
else
# Handle Pages domains
host
=
Namespace
.
find_by_pages_host
(
params
[
:host
])
||
PagesDomain
.
find_by_domain
(
params
[
:host
])
no_content!
unless
host
virtual_domain
=
host
.
pages_virtual_domain
no_content!
unless
virtual_domain
present
virtual_domain
,
with:
Entities
::
Internal
::
Pages
::
VirtualDomain
end
end
end
end
...
...
spec/finders/serverless_domain_finder_spec.rb
View file @
b0e19b3c
...
...
@@ -5,12 +5,34 @@ require 'spec_helper'
describe
ServerlessDomainFinder
do
let
(
:function_name
)
{
'test-function'
}
let
(
:pages_domain_name
)
{
'serverless.gitlab.io'
}
let
(
:pages_domain
)
{
create
(
:pages_domain
,
:instance_serverless
,
domain:
pages_domain_name
)
}
let!
(
:serverless_domain_cluster
)
{
create
(
:serverless_domain_cluster
,
uuid:
'abcdef12345678'
,
pages_domain:
pages_domain
)
}
let
(
:valid_cluster_uuid
)
{
'aba1cdef123456f278'
}
let
(
:invalid_cluster_uuid
)
{
'aba1cdef123456f178'
}
let!
(
:environment
)
{
create
(
:environment
,
name:
'test'
)
}
let
(
:pages_domain
)
do
create
(
:pages_domain
,
:instance_serverless
,
domain:
pages_domain_name
)
end
let
(
:knative_with_ingress
)
do
create
(
:clusters_applications_knative
,
external_ip:
'10.0.0.1'
)
end
let!
(
:serverless_domain_cluster
)
do
create
(
:serverless_domain_cluster
,
uuid:
'abcdef12345678'
,
pages_domain:
pages_domain
,
knative:
knative_with_ingress
)
end
let
(
:valid_uri
)
{
"https://
#{
function_name
}
-
#{
valid_cluster_uuid
}#{
"%x"
%
environment
.
id
}
-
#{
environment
.
slug
}
.
#{
pages_domain_name
}
"
}
let
(
:valid_fqdn
)
{
"
#{
function_name
}
-
#{
valid_cluster_uuid
}#{
"%x"
%
environment
.
id
}
-
#{
environment
.
slug
}
.
#{
pages_domain_name
}
"
}
let
(
:invalid_uri
)
{
"https://
#{
function_name
}
-
#{
invalid_cluster_uuid
}#{
"%x"
%
environment
.
id
}
-
#{
environment
.
slug
}
.
#{
pages_domain_name
}
"
}
...
...
spec/fixtures/api/schemas/internal/serverless/lookup_path.json
0 → 100644
View file @
b0e19b3c
{
"type"
:
"object"
,
"required"
:
[
"source"
],
"properties"
:
{
"source"
:
{
"type"
:
"object"
,
"required"
:
[
"type"
,
"service"
,
"cluster"
],
"properties"
:
{
"type"
:
{
"type"
:
"string"
,
"enum"
:
[
"serverless"
]
},
"service"
:
{
"type"
:
"string"
},
"cluster"
:
{
"type"
:
"object"
,
"required"
:
[
"hostname"
,
"address"
,
"port"
,
"cert"
,
"key"
],
"properties"
:
{
"hostname"
:
{
"type"
:
"string"
},
"address"
:
{
"type"
:
"string"
},
"port"
:
{
"type"
:
"integer"
},
"cert"
:
{
"type"
:
"string"
},
"key"
:
{
"type"
:
"string"
}
},
"additionalProperties"
:
false
}
},
"additionalProperties"
:
false
}
},
"additionalProperties"
:
false
}
spec/fixtures/api/schemas/internal/serverless/virtual_domain.json
0 → 100644
View file @
b0e19b3c
{
"type"
:
"object"
,
"required"
:
[
"lookup_paths"
,
"certificate"
,
"key"
],
"properties"
:
{
"certificate"
:
{
"type"
:
[
"string"
,
"null"
]
},
"key"
:
{
"type"
:
[
"string"
,
"null"
]
},
"lookup_paths"
:
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"lookup_path.json"
}
}
},
"additionalProperties"
:
false
}
spec/requests/api/internal/pages_spec.rb
View file @
b0e19b3c
...
...
@@ -56,6 +56,88 @@ describe API::Internal::Pages do
end
end
context
'serverless domain'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'gitlab-org'
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
namespace
,
name:
'gitlab-ce'
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:pages_domain
)
{
create
(
:pages_domain
,
domain:
'serverless.gitlab.io'
)
}
let
(
:knative_without_ingress
)
{
create
(
:clusters_applications_knative
)
}
let
(
:knative_with_ingress
)
{
create
(
:clusters_applications_knative
,
external_ip:
'10.0.0.1'
)
}
context
'without a knative ingress gateway IP'
do
let!
(
:serverless_domain_cluster
)
do
create
(
:serverless_domain_cluster
,
uuid:
'abcdef12345678'
,
pages_domain:
pages_domain
,
knative:
knative_without_ingress
)
end
let
(
:serverless_domain
)
do
create
(
:serverless_domain
,
serverless_domain_cluster:
serverless_domain_cluster
,
environment:
environment
)
end
it
'responds with 204 no content'
do
query_host
(
serverless_domain
.
uri
.
host
)
expect
(
response
).
to
have_gitlab_http_status
(
:no_content
)
expect
(
response
.
body
).
to
be_empty
end
end
context
'with a knative ingress gateway IP'
do
let!
(
:serverless_domain_cluster
)
do
create
(
:serverless_domain_cluster
,
uuid:
'abcdef12345678'
,
pages_domain:
pages_domain
,
knative:
knative_with_ingress
)
end
let
(
:serverless_domain
)
do
create
(
:serverless_domain
,
serverless_domain_cluster:
serverless_domain_cluster
,
environment:
environment
)
end
it
'responds with proxy configuration'
do
query_host
(
serverless_domain
.
uri
.
host
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
match_response_schema
(
'internal/serverless/virtual_domain'
)
expect
(
json_response
[
'certificate'
]).
to
eq
(
pages_domain
.
certificate
)
expect
(
json_response
[
'key'
]).
to
eq
(
pages_domain
.
key
)
expect
(
json_response
[
'lookup_paths'
]).
to
eq
(
[
{
'source'
=>
{
'type'
=>
'serverless'
,
'service'
=>
"test-function.
#{
project
.
name
}
-
#{
project
.
id
}
-
#{
environment
.
slug
}
.
#{
serverless_domain_cluster
.
knative
.
hostname
}
"
,
'cluster'
=>
{
'hostname'
=>
serverless_domain_cluster
.
knative
.
hostname
,
'address'
=>
serverless_domain_cluster
.
knative
.
external_ip
,
'port'
=>
443
,
'cert'
=>
serverless_domain_cluster
.
certificate
,
'key'
=>
serverless_domain_cluster
.
key
}
}
}
]
)
end
end
end
context
'custom domain'
do
let
(
:namespace
)
{
create
(
:namespace
,
name:
'gitlab-org'
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
namespace
,
name:
'gitlab-ce'
)
}
...
...
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