This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARUHA-2344 Do not check authorization while creating system ET
- Loading branch information
Showing
10 changed files
with
148 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/org/zalando/nakadi/service/SystemEventTypeInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.zalando.nakadi.service; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.base.Charsets; | ||
import com.google.common.io.Resources; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.zalando.nakadi.domain.EventTypeBase; | ||
import org.zalando.nakadi.exceptions.runtime.DuplicatedEventTypeNameException; | ||
import org.zalando.nakadi.exceptions.runtime.NakadiBaseException; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
@Component | ||
public class SystemEventTypeInitializer { | ||
private final ObjectMapper objectMapper; | ||
private final EventTypeService eventTypeService; | ||
private static final Logger LOG = LoggerFactory.getLogger(SystemEventTypeInitializer.class); | ||
|
||
@Autowired | ||
public SystemEventTypeInitializer( | ||
final ObjectMapper objectMapper, | ||
final EventTypeService eventTypeService) { | ||
this.objectMapper = objectMapper; | ||
this.eventTypeService = eventTypeService; | ||
} | ||
|
||
public void createEventTypesFromResource( | ||
final String resourceName, | ||
final Map<String, String> nameReplacements) throws IOException { | ||
LOG.debug("Initializing event types from {}", resourceName); | ||
String eventTypesString = Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8); | ||
for (final Map.Entry<String, String> entry : nameReplacements.entrySet()) { | ||
eventTypesString = eventTypesString.replaceAll( | ||
Pattern.quote(entry.getKey()), | ||
Matcher.quoteReplacement(entry.getValue())); | ||
} | ||
|
||
final TypeReference<List<EventTypeBase>> typeReference = new TypeReference<List<EventTypeBase>>() { | ||
}; | ||
final List<EventTypeBase> eventTypes = objectMapper.readValue(eventTypesString, typeReference); | ||
|
||
eventTypes.forEach(et -> { | ||
try { | ||
eventTypeService.create(et, false); | ||
} catch (final DuplicatedEventTypeNameException e) { | ||
LOG.debug("Event type {} from {} already exists", et.getName(), resourceName); | ||
} catch (final NakadiBaseException e) { | ||
LOG.debug("Problem creating event type {} from {}", et.getName(), resourceName, e); | ||
} | ||
}); | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"name": "event_type_name_placeholder", | ||
"owning_application": "owning_application_placeholder", | ||
"category": "data", | ||
"enrichment_strategies": [ | ||
"metadata_enrichment" | ||
], | ||
"partition_strategy": "hash", | ||
"partition_key_fields": [ | ||
"resource_id" | ||
], | ||
"cleanup_policy": "delete", | ||
"ordering_key_fields": [], | ||
"ordering_instance_ids": [], | ||
"schema": { | ||
"type": "json_schema", | ||
"schema": "{\"properties\": {\"previous_object\": { \"type\": \"object\", \"description\": \"When modifying an already existent entity, its value is captured in this field as a JSON object. So, for example, when changing an Event Type attribute, this field contains the entire state before the changes are applied\"},\"previous_text\": { \"type\": \"string\", \"description\": \"Contains the same information as the field `previous_object` but as text, since the data lake stores a flat map of all the fields in the object, destroying information about its structure. Storing the text makes sure that the original data is not lost by any transformation that the data lake may apply on the data\"},\"new_object\": { \"type\": \"object\", \"description\": \"New value submitted by the user\"},\"new_text\": { \"type\": \"string\", \"description\": \"New value submitted by the user as text, in order to preserve the structure, if needed\"},\"resource_type\": { \"x-extensible-enum\": [ \"event_type\", \"subscription\", \"timeline\", \"storage\", \"feature\", \"admins\", \"cursors\", \"blacklist_entry\" ], \"type\":\"string\" },\"resource_id\": { \"description\": \"Resource identifier. Together with `resource_type` allows for the selection of a resource\", \"type\": \"string\"},\"user\": { \"description\": \"User or service that requested the changes\", \"type\": \"string\"},\"user_hash\": { \"description\": \"User hashed\", \"type\": \"string\"}},\"required\": [\"user\", \"user_hash\", \"resource_id\", \"resource_type\"]}" | ||
}, | ||
"default_statistic": { | ||
"messages_per_minute": 100, | ||
"message_size": 100, | ||
"read_parallelism": 10, | ||
"write_parallelism": 10 | ||
}, | ||
"options": { | ||
"retention_time": 345600000 | ||
}, | ||
"compatibility_mode": "forward", | ||
"audience": "company-internal", | ||
"authorization": { | ||
"admins": [ | ||
{ | ||
"data_type": "auth_data_type_placeholder", | ||
"value": "auth_value_placeholder" | ||
} | ||
], | ||
"readers": [ | ||
{ | ||
"data_type": "auth_data_type_placeholder", | ||
"value": "auth_value_placeholder" | ||
} | ||
], | ||
"writers": [ | ||
{ | ||
"data_type": "auth_data_type_placeholder", | ||
"value": "auth_value_placeholder" | ||
} | ||
] | ||
} | ||
} | ||
] |
Oops, something went wrong.