-
Notifications
You must be signed in to change notification settings - Fork 108
Adds legacy chime, slack, custom webhook messages, request/response f #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ff9165a
Adds legacy chime, slack, custom webhook messages, request/response f…
dbbaughe b77a4dc
Fixes import and removes username/password that is not used by ISM
dbbaughe 6f083e6
Throws error for toXContent for legacy notification response
dbbaughe e962667
Renames legacy destination types to have legacy prefix
dbbaughe d839f89
Obfuscates message to remove from logs in toString method
dbbaughe d5a38f5
Makes destinationt type private and updates places to use getter
dbbaughe 0b8488a
Inlines destination type
dbbaughe 8875a87
Makes base message content final
dbbaughe c530c44
Requires url to be defined in LegacyCustomWebhookMessage for use acro…
dbbaughe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
src/main/java/org/opensearch/commons/destination/message/LegacyBaseMessage.java
This file contains hidden or 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,128 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| /* | ||
| * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package org.opensearch.commons.destination.message; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.http.client.utils.URIBuilder; | ||
| import org.opensearch.common.Strings; | ||
| import org.opensearch.common.io.stream.StreamInput; | ||
| import org.opensearch.common.io.stream.StreamOutput; | ||
| import org.opensearch.common.io.stream.Writeable; | ||
|
|
||
| /** | ||
| * This class holds the generic parameters required for a | ||
| * message. | ||
| */ | ||
| public abstract class LegacyBaseMessage implements Writeable { | ||
|
|
||
| private final LegacyDestinationType destinationType; | ||
| protected String destinationName; | ||
| protected String url; | ||
| private final String content; | ||
|
|
||
| LegacyBaseMessage(final LegacyDestinationType destinationType, final String destinationName, final String content) { | ||
| if (destinationType == null) { | ||
| throw new IllegalArgumentException("Channel type must be defined"); | ||
| } | ||
| if (!Strings.hasLength(destinationName)) { | ||
| throw new IllegalArgumentException("Channel name must be defined"); | ||
| } | ||
| this.destinationType = destinationType; | ||
| this.destinationName = destinationName; | ||
| this.content = content; | ||
| } | ||
|
|
||
| LegacyBaseMessage(final LegacyDestinationType destinationType, final String destinationName, final String content, final String url) { | ||
| this(destinationType, destinationName, content); | ||
| if (url == null) { | ||
| throw new IllegalArgumentException("url is invalid or empty"); | ||
| } | ||
| this.url = url; | ||
| } | ||
|
|
||
| LegacyBaseMessage(StreamInput streamInput) throws IOException { | ||
| this.destinationType = streamInput.readEnum(LegacyDestinationType.class); | ||
| this.destinationName = streamInput.readString(); | ||
| this.url = streamInput.readOptionalString(); | ||
| this.content = streamInput.readString(); | ||
| } | ||
|
|
||
| public void setUrl(String url) { | ||
| this.url = url; | ||
| } | ||
|
|
||
| public LegacyDestinationType getChannelType() { | ||
| return destinationType; | ||
| } | ||
|
|
||
| public String getChannelName() { | ||
| return destinationName; | ||
| } | ||
|
|
||
| public String getMessageContent() { | ||
| return content; | ||
| } | ||
|
|
||
| public String getUrl() { | ||
| return url; | ||
| } | ||
|
|
||
| public URI getUri() { | ||
|
dbbaughe marked this conversation as resolved.
|
||
| return buildUri(getUrl().trim(), null, null, -1, null, null); | ||
| } | ||
|
|
||
| protected URI buildUri(String endpoint, String scheme, String host, int port, String path, Map<String, String> queryParams) { | ||
| try { | ||
| if (Strings.isNullOrEmpty(endpoint)) { | ||
| if (Strings.isNullOrEmpty(scheme)) { | ||
| scheme = "https"; | ||
| } | ||
| URIBuilder uriBuilder = new URIBuilder(); | ||
| if (queryParams != null) { | ||
| for (Map.Entry<String, String> e : queryParams.entrySet()) | ||
| uriBuilder.addParameter(e.getKey(), e.getValue()); | ||
| } | ||
| return uriBuilder.setScheme(scheme).setHost(host).setPort(port).setPath(path).build(); | ||
| } | ||
| return new URIBuilder(endpoint).build(); | ||
| } catch (URISyntaxException exception) { | ||
| throw new IllegalStateException("Error creating URI"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput streamOutput) throws IOException { | ||
| streamOutput.writeEnum(destinationType); | ||
| streamOutput.writeString(destinationName); | ||
| streamOutput.writeOptionalString(url); | ||
| streamOutput.writeString(content); | ||
| } | ||
| } | ||
91 changes: 91 additions & 0 deletions
91
src/main/java/org/opensearch/commons/destination/message/LegacyChimeMessage.java
This file contains hidden or 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,91 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| /* | ||
| * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package org.opensearch.commons.destination.message; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.opensearch.common.Strings; | ||
| import org.opensearch.common.io.stream.StreamInput; | ||
|
|
||
| /** | ||
| * This class holds the contents of an Chime message | ||
| */ | ||
| public class LegacyChimeMessage extends LegacyBaseMessage { | ||
| private final String message; | ||
|
|
||
| private LegacyChimeMessage(final String destinationName, final String url, final String message) { | ||
| super(LegacyDestinationType.LEGACY_CHIME, destinationName, message, url); | ||
|
|
||
| if (Strings.isNullOrEmpty(message)) { | ||
| throw new IllegalArgumentException("Message content is missing"); | ||
| } | ||
|
|
||
| this.message = message; | ||
| } | ||
|
|
||
| public LegacyChimeMessage(StreamInput streamInput) throws IOException { | ||
| super(streamInput); | ||
| this.message = super.getMessageContent(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
|
dbbaughe marked this conversation as resolved.
|
||
| return "DestinationType: " + getChannelType() + ", DestinationName:" + destinationName + ", Url: " + url + ", Message: <...>"; | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private String message; | ||
| private final String destinationName; | ||
| private String url; | ||
|
|
||
| public Builder(String destinationName) { | ||
| this.destinationName = destinationName; | ||
| } | ||
|
|
||
| public LegacyChimeMessage.Builder withMessage(String message) { | ||
| this.message = message; | ||
| return this; | ||
| } | ||
|
|
||
| public LegacyChimeMessage.Builder withUrl(String url) { | ||
| this.url = url; | ||
| return this; | ||
| } | ||
|
|
||
| public LegacyChimeMessage build() { | ||
| return new LegacyChimeMessage(this.destinationName, this.url, this.message); | ||
| } | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
|
|
||
| public String getUrl() { | ||
| return url; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.