-
Notifications
You must be signed in to change notification settings - Fork 80
Add logged-on User details to the Monitor and Destination #255
Conversation
…tination response, 3/ handle null in GetMonitorRequest
Codecov Report
@@ Coverage Diff @@
## master #255 +/- ##
============================================
+ Coverage 77.31% 77.53% +0.21%
- Complexity 187 198 +11
============================================
Files 137 138 +1
Lines 4466 4522 +56
Branches 594 614 +20
============================================
+ Hits 3453 3506 +53
+ Misses 701 691 -10
- Partials 312 325 +13
Continue to review full report at Codecov.
|
if (srcContext != null) { | ||
out.writeBoolean(true) | ||
srcContext?.writeTo(out) | ||
srcContext.writeTo(out) | ||
} else { | ||
out.writeBoolean(false) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Maybe cleaner?
out.writeBoolean(srcContext != null)
srcContext?.writeTo(out)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like it 👍
@@ -117,8 +122,15 @@ data class Monitor( | |||
|
|||
override fun fromDocument(id: String, version: Long): Monitor = copy(id = id, version = version) | |||
|
|||
private fun XContentBuilder.optionalUserField(user: User?): XContentBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Move to ElasticExtensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -131,6 +143,12 @@ data class Monitor( | |||
schedule.writeTo(out) | |||
out.writeInstant(lastUpdateTime) | |||
out.writeOptionalInstant(enabledTime) | |||
if (user != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Same as above
out.writeBoolean(user != null)
user?.writeTo(out)
@@ -0,0 +1,92 @@ | |||
package com.amazon.opendistroforelasticsearch.alerting.model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing License
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput): this( | ||
sin.readString(), // name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I prefer using the named arguments instead of comments
i.e.
@Throws(IOException::class)
constructor(sin: StreamInput): this(
name = sin.readString(),
backendRoles = sin.readStringList(),
roles = sin.readStringList(),
customAttNames = sin.readStringList()
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Still kotlin newbie
} | ||
} | ||
} | ||
return User(name, backendRoles, roles, customAttNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want any validation of the values here? Or is a User("", listOf(), listOf(), listOf())
a valid user?
@@ -164,6 +182,14 @@ fun Monitor.toJsonString(): String { | |||
return this.toXContent(builder).string() | |||
} | |||
|
|||
fun randomUser(): User { | |||
return User("joe", listOf("ops", "backup"), listOf("all_access"), listOf("test_attr=test")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't really seem random 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
randomized
import org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken | ||
import java.io.IOException | ||
|
||
data class User( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression we wanted to decouple the roles
from the user when storing this on the Monitor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having name, roles, backend_roles as user (sub) object is much clean. Checks are simpler. monitor.user
"type" : "text", | ||
"fields" : { | ||
"keyword" : { | ||
"type" : "text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be type keyword? Same with below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Yes it has to be keyword. Merged old version.
"type" : "text", | ||
"fields" : { | ||
"keyword" : { | ||
"type" : "text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as below.
val ranStrGen = RandomStringGenerator.Builder().build() | ||
val randomUser = ranStrGen.generate(5) | ||
val bckEndRole1 = ranStrGen.generate(10) | ||
val bckEndRole2 = ranStrGen.generate(10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are already provided helper methods for generating random values, e.g. ESRestTestCase.randomAlphaOfLength(10)
} else { | ||
out.writeBoolean(false) | ||
} | ||
out.writeBoolean(srcContext != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me.
8e1092f
Issue #, if available:
#6
#215
Description of changes:
Add logged-on User details to the Monitor and Destination
This one of PR's for adding security to alerting.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.