Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Commit 5334ea2

Browse files
authored
Merge pull request #95 from zalando-nakadi/event_auth_field
Add support for event_owner_selector
2 parents 6488228 + 5e2a241 commit 5334ea2

File tree

6 files changed

+196
-5
lines changed

6 files changed

+196
-5
lines changed

client/Pages/EventTypeCreate/Models.elm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Stores.EventType
1313
, categories
1414
, cleanupPolicies
1515
, compatibilityModes
16+
, emptyEventOwnerSelector
1617
, partitionStrategies
1718
)
1819
import Stores.Partition
@@ -38,6 +39,9 @@ type Field
3839
| FieldSchema
3940
| FieldEnvelope
4041
| FieldAudience
42+
| FieldEventOwnerSelectorType
43+
| FieldEventOwnerSelectorName
44+
| FieldEventOwnerSelectorValue
4145
| FieldCleanupPolicy
4246
| FieldSql
4347
| FieldPartitionCompactionKeyField
@@ -100,6 +104,9 @@ defaultValues =
100104
, ( FieldEnvelope, boolToString True )
101105
, ( FieldCompatibilityMode, compatibilityModes.forward )
102106
, ( FieldAudience, "" )
107+
, ( FieldEventOwnerSelectorType, "" )
108+
, ( FieldEventOwnerSelectorName, "" )
109+
, ( FieldEventOwnerSelectorValue, "" )
103110
, ( FieldCleanupPolicy, cleanupPolicies.delete )
104111
, ( FieldPartitionCompactionKeyField, emptyString )
105112
]
@@ -120,6 +127,10 @@ loadValues eventType =
120127
|> Basics.ceiling
121128
|> Basics.clamp 2 4
122129
|> String.fromInt
130+
131+
ownerField =
132+
eventType.event_owner_selector
133+
|> Maybe.withDefault emptyEventOwnerSelector
123134
in
124135
defaultValues
125136
|> setValue FieldName eventType.name
@@ -132,6 +143,9 @@ loadValues eventType =
132143
|> setValue FieldSchema eventType.schema.schema
133144
|> setValue FieldRetentionTime retentionTime
134145
|> maybeSetValue FieldAudience eventType.audience
146+
|> setValue FieldEventOwnerSelectorType ownerField.type_
147+
|> setValue FieldEventOwnerSelectorName ownerField.name
148+
|> setValue FieldEventOwnerSelectorValue ownerField.value
135149
|> setValue FieldCleanupPolicy eventType.cleanup_policy
136150

137151

client/Pages/EventTypeCreate/Update.elm

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,34 @@ submitCreate model =
372372
|> String.trim
373373
|> Json.string
374374

375+
isEmptyString field =
376+
model.values
377+
|> getValue field
378+
|> String.trim
379+
|> String.isEmpty
380+
375381
auth =
376382
AccessEditor.unflatten model.accessEditor.authorization
377383
|> Stores.Authorization.encoder
378384

385+
event_owner_selector =
386+
if
387+
isEmptyString FieldEventOwnerSelectorName
388+
&& isEmptyString FieldEventOwnerSelectorValue
389+
&& isEmptyString FieldEventOwnerSelectorType
390+
then
391+
[]
392+
393+
else
394+
[ ( "event_owner_selector"
395+
, Json.object
396+
[ ( "type", asString FieldEventOwnerSelectorType )
397+
, ( "name", asString FieldEventOwnerSelectorName )
398+
, ( "value", asString FieldEventOwnerSelectorValue )
399+
]
400+
)
401+
]
402+
379403
fields =
380404
[ ( "name", asString FieldName )
381405
, ( "owning_application", asString FieldOwningApplication )
@@ -419,7 +443,7 @@ submitCreate model =
419443
]
420444

421445
body =
422-
Json.object (List.concat [ fields, enrichment ])
446+
Json.object (List.concat [ fields, enrichment, event_owner_selector ])
423447
in
424448
post body
425449

@@ -457,10 +481,34 @@ submitUpdate model =
457481
|> String.trim
458482
|> Json.string
459483

484+
isEmptyString field =
485+
model.values
486+
|> getValue field
487+
|> String.trim
488+
|> String.isEmpty
489+
460490
auth =
461491
AccessEditor.unflatten model.accessEditor.authorization
462492
|> Stores.Authorization.encoder
463493

494+
event_owner_selector =
495+
if
496+
isEmptyString FieldEventOwnerSelectorName
497+
&& isEmptyString FieldEventOwnerSelectorValue
498+
&& isEmptyString FieldEventOwnerSelectorType
499+
then
500+
[]
501+
502+
else
503+
[ ( "event_owner_selector"
504+
, Json.object
505+
[ ( "type", asString FieldEventOwnerSelectorType )
506+
, ( "name", asString FieldEventOwnerSelectorName )
507+
, ( "value", asString FieldEventOwnerSelectorValue )
508+
]
509+
)
510+
]
511+
464512
fields =
465513
[ ( "name", asString FieldName )
466514
, ( "owning_application", asString FieldOwningApplication )
@@ -496,7 +544,7 @@ submitUpdate model =
496544
]
497545

498546
body =
499-
Json.object (List.concat [ fields, enrichment ])
547+
Json.object (List.concat [ fields, enrichment, event_owner_selector ])
500548
in
501549
put body (getValue FieldName model.values)
502550

client/Pages/EventTypeCreate/View.elm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Stores.EventType
2222
, allCategories
2323
, allCleanupPolicies
2424
, allModes
25+
, allOwnerSelectorTypes
2526
, categories
2627
, cleanupPolicies
2728
, compatibilityModes
@@ -265,6 +266,41 @@ viewForm model setup =
265266
Required
266267
Enabled
267268
("" :: allAudiences)
269+
, div [ class "dc-row form-create__input-row" ]
270+
[ selectInput formModel
271+
FieldEventOwnerSelectorType
272+
OnInput
273+
"Event Owner Selector Type"
274+
""
275+
Help.eventOwnerSelector
276+
Optional
277+
Enabled
278+
("" :: allOwnerSelectorTypes)
279+
, div
280+
[ class "dc-column" ]
281+
[ textInput formModel
282+
FieldEventOwnerSelectorName
283+
OnInput
284+
"Event Owner Selector Name"
285+
"Example: retailer_id"
286+
""
287+
Help.eventOwnerSelector
288+
Optional
289+
Enabled
290+
]
291+
, div
292+
[ class "dc-column" ]
293+
[ textInput formModel
294+
FieldEventOwnerSelectorValue
295+
OnInput
296+
"Event Owner Selector Value"
297+
"Example: security.owners"
298+
""
299+
Help.eventOwnerSelector
300+
Optional
301+
Enabled
302+
]
303+
]
268304
, selectInput formModel
269305
FieldCleanupPolicy
270306
OnInput

client/Pages/EventTypeDetails/Help.elm

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Pages.EventTypeDetails.Help exposing (audience, authorization, category, cleanupPolicy, cleanupPolicyCompact, compatibilityMode, consumers, consumingQueries, createdAt, defaultStatistic, enrichmentStrategies, envelope, eventType, options, orderingKeyFields, owningApplication, partitionCompactionKeyField, partitionKeyFields, partitionStrategy, partitions, publishers, schema, subscription, updatedAt)
1+
module Pages.EventTypeDetails.Help exposing (audience, authorization, category, cleanupPolicy, cleanupPolicyCompact, compatibilityMode, consumers, consumingQueries, createdAt, defaultStatistic, enrichmentStrategies, envelope, eventOwnerSelector, eventType, options, orderingKeyFields, owningApplication, partitionCompactionKeyField, partitionKeyFields, partitionStrategy, partitions, publishers, schema, subscription, updatedAt)
22

33
import Config exposing (appPreffix)
44
import Helpers.UI exposing (..)
@@ -414,6 +414,41 @@ audience =
414414
]
415415

416416

417+
eventOwnerSelector : List (Html msg)
418+
eventOwnerSelector =
419+
[ text "Event Owner Selector for per-event authorization. "
420+
, text "Can be used to point to a string field in the event, which "
421+
, text "is used by Nakadi do decide if an authorized consumer "
422+
, text "can read a published event. It is optional and "
423+
, text "if not specified or field is not present/null, all "
424+
, text "authorized consumers can read the event."
425+
, newline
426+
, bold "The event_owner_selector must contain the following fields:"
427+
, newline
428+
, text "- "
429+
, mono "type"
430+
, text " Specifies the type of the selector (can be 'path' or 'static')"
431+
, newline
432+
, text "- "
433+
, mono "name"
434+
, text " Informational field specifying what type of data the field"
435+
, text " represents (eg: team/retailers, etc)"
436+
, newline
437+
, text "- "
438+
, mono "value"
439+
, text " Static value or value in dot notation pointing to a string field"
440+
, text " in an event which will be used to"
441+
, text " classify if the consumer is allowed to read the event."
442+
, newline
443+
, newline
444+
, bold "Key: "
445+
, mono "event_owner_selector"
446+
, bold "optional"
447+
, newline
448+
, man "#definition_EventOwnerSelector"
449+
]
450+
451+
417452
cleanupPolicy : List (Html msg)
418453
cleanupPolicy =
419454
[ text "Event type cleanup policy."

client/Pages/EventTypeDetails/View.elm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import Stores.ConsumingQuery exposing (ConsumingQuery)
2828
import Stores.CursorDistance
2929
import Stores.EventType
3030
exposing
31-
( EventType
31+
( EventOwnerSelector
32+
, EventType
3233
, EventTypeOptions
3334
, EventTypeStatistics
3435
, cleanupPolicies
@@ -198,6 +199,8 @@ detailsLayout typeName eventType model =
198199
none
199200
, infoField "Audience " Help.audience TopRight <|
200201
infoStringToText eventType.audience
202+
, infoField "Event Owner Selector " Help.eventOwnerSelector TopRight <|
203+
infoEventOwnerSelectorToText eventType.event_owner_selector
201204
, infoField "Created " Help.createdAt TopRight <|
202205
infoDateToText eventType.created_at
203206
, infoField "Updated " Help.updatedAt TopRight <|
@@ -380,6 +383,20 @@ infoStatisticsToText maybeStatistics =
380383
infoEmpty
381384

382385

386+
infoEventOwnerSelectorToText : Maybe EventOwnerSelector -> Html Msg
387+
infoEventOwnerSelectorToText maybeEventOwnerSelector =
388+
case maybeEventOwnerSelector of
389+
Just owner_selector ->
390+
div []
391+
[ infoSubField "Type: " owner_selector.type_
392+
, infoSubField "Name: " owner_selector.name
393+
, infoSubField "Value: " owner_selector.value
394+
]
395+
396+
Nothing ->
397+
infoEmpty
398+
399+
383400
schemaTab :
384401
JsonEditor.Model
385402
-> Stores.EventTypeSchema.Model

client/Stores/EventType.elm

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Stores.EventType exposing (EventType, EventTypeOptions, EventTypeStatistics, Model, Msg, allAudiences, allCategories, allCleanupPolicies, allModes, audiences, categories, cleanupPolicies, collectionDecoder, compatibilityModes, config, defaultStatisticDecoder, initialModel, memberDecoder, optionsDecoder, partitionStrategies, update)
1+
module Stores.EventType exposing (EventOwnerSelector, EventType, EventTypeOptions, EventTypeStatistics, Model, Msg, allAudiences, allCategories, allCleanupPolicies, allModes, allOwnerSelectorTypes, audiences, categories, cleanupPolicies, collectionDecoder, compatibilityModes, config, defaultStatisticDecoder, emptyEventOwnerSelector, initialModel, memberDecoder, optionsDecoder, partitionStrategies, update)
22

33
import Config
44
import Constants
@@ -32,6 +32,7 @@ type alias EventType =
3232
, --enum component-internal, business-unit-internal,
3333
-- company-internal, external-partner, external-public
3434
audience : Maybe String
35+
, event_owner_selector : Maybe EventOwnerSelector
3536
, created_at : Maybe String
3637
, updated_at : Maybe String
3738
}
@@ -50,6 +51,37 @@ type alias EventTypeOptions =
5051
}
5152

5253

54+
type alias EventOwnerSelector =
55+
{ type_ : String
56+
, name : String
57+
, value : String
58+
}
59+
60+
61+
emptyEventOwnerSelector =
62+
{ type_ = ""
63+
, name = ""
64+
, value = ""
65+
}
66+
67+
68+
ownerSelectorTypes :
69+
{ path : String
70+
, static : String
71+
}
72+
ownerSelectorTypes =
73+
{ path = "path"
74+
, static = "static"
75+
}
76+
77+
78+
allOwnerSelectorTypes : List String
79+
allOwnerSelectorTypes =
80+
[ ownerSelectorTypes.path
81+
, ownerSelectorTypes.static
82+
]
83+
84+
5385
type alias Model =
5486
Helpers.Store.Model EventType
5587

@@ -198,6 +230,7 @@ memberDecoder =
198230
|> optional "authorization" (nullable Stores.Authorization.collectionDecoder) Nothing
199231
|> optional "cleanup_policy" string cleanupPolicies.delete
200232
|> optional "audience" (nullable string) Nothing
233+
|> optional "event_owner_selector" (nullable eventOwnerSelectorDecoder) Nothing
201234
|> optional "created_at" (nullable string) Nothing
202235
|> optional "updated_at" (nullable string) Nothing
203236

@@ -215,3 +248,11 @@ optionsDecoder : Decoder EventTypeOptions
215248
optionsDecoder =
216249
succeed EventTypeOptions
217250
|> optional "retention_time" (nullable int) Nothing
251+
252+
253+
eventOwnerSelectorDecoder : Decoder EventOwnerSelector
254+
eventOwnerSelectorDecoder =
255+
succeed EventOwnerSelector
256+
|> required "type" string
257+
|> required "name" string
258+
|> required "value" string

0 commit comments

Comments
 (0)