-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added support for SesAccount (#54) Also updated Feature to be simple string for future plugin easy addition [Tests] Added unit tests for SesAccount Updated Unit tests for changes Signed-off-by: @akbhatta * Adds legacy chime, slack, custom webhook messages, request/response f (#53) * Adds legacy chime, slack, custom webhook messages, request/response for publishing legacy notifications, and method for executing transport action Signed-off-by: Drew Baugher <[email protected]> * Fixes import and removes username/password that is not used by ISM Signed-off-by: Drew Baugher <[email protected]> * Throws error for toXContent for legacy notification response Signed-off-by: Drew Baugher <[email protected]> * Renames legacy destination types to have legacy prefix Signed-off-by: Drew Baugher <[email protected]> * Obfuscates message to remove from logs in toString method Signed-off-by: Drew Baugher <[email protected]> * Makes destinationt type private and updates places to use getter Signed-off-by: Drew Baugher <[email protected]> * Inlines destination type Signed-off-by: Drew Baugher <[email protected]> * Makes base message content final Signed-off-by: Drew Baugher <[email protected]> * Requires url to be defined in LegacyCustomWebhookMessage for use across transport wire and only writes the full url instead of each individual part Signed-off-by: Drew Baugher <[email protected]> Co-authored-by: Drew Baugher <[email protected]>
- Loading branch information
Showing
44 changed files
with
2,012 additions
and
333 deletions.
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 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() { | ||
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 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() { | ||
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.