Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cerebro
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
cerebro
Commits
37907772
Commit
37907772
authored
7 years ago
by
Leonardo Menezes
Browse files
Options
Downloads
Patches
Plain Diff
allow providing known host auth through request
parent
922a161d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/models/CerebroRequest.scala
+14
-13
14 additions, 13 deletions
app/models/CerebroRequest.scala
with
14 additions
and
13 deletions
app/models/CerebroRequest.scala
+
14
−
13
View file @
37907772
...
...
@@ -4,7 +4,7 @@ import controllers.auth.AuthRequest
import
exceptions.
{
MissingRequiredParamException
,
MissingTargetHostException
}
import
play.api.libs.json.
{
JsArray
,
JsObject
,
JsValue
}
class
CerebroRequest
(
val
target
:
ElasticServer
,
body
:
JsValue
,
val
user
:
Option
[
User
])
{
case
class
CerebroRequest
(
val
target
:
ElasticServer
,
body
:
JsValue
,
val
user
:
Option
[
User
])
{
def
get
(
name
:
String
)
=
(
body
\
name
).
asOpt
[
String
].
getOrElse
(
throw
MissingRequiredParamException
(
name
))
...
...
@@ -36,22 +36,23 @@ class CerebroRequest(val target: ElasticServer, body: JsValue, val user: Option[
object
CerebroRequest
{
def
apply
(
request
:
AuthRequest
[
JsValue
],
hosts
:
Hosts
)
=
{
def
apply
(
request
:
AuthRequest
[
JsValue
],
hosts
:
Hosts
)
:
CerebroRequest
=
{
val
body
=
request
.
body
val
host
=
(
body
\
"host"
).
asOpt
[
String
].
getOrElse
(
throw
MissingTargetHostException
)
val
knownHost
=
hosts
.
getServer
(
host
)
val
cluster
=
knownHost
.
getOrElse
{
val
username
=
(
body
\
"username"
).
asOpt
[
String
]
val
password
=
(
body
\
"password"
).
asOpt
[
String
]
if
(
username
.
isDefined
&&
password
.
isDefined
)
{
val
auth
=
ESAuth
(
username
.
get
,
password
.
get
)
ElasticServer
(
host
,
Some
(
auth
))
}
else
{
ElasticServer
(
host
,
None
)
val
requestAuth
=
(
username
,
password
)
match
{
case
(
Some
(
u
),
Some
(
p
))
=>
Some
(
ESAuth
(
u
,
p
))
case
_
=>
None
}
val
server
=
hosts
.
getServer
(
host
)
match
{
case
Some
(
ElasticServer
(
h
,
a
))
=>
ElasticServer
(
h
,
a
.
orElse
(
requestAuth
))
case
None
=>
ElasticServer
(
host
,
requestAuth
)
}
new
CerebroRequest
(
clust
er
,
body
,
request
.
user
)
CerebroRequest
(
serv
er
,
body
,
request
.
user
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment