-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create opensearch_external_url_formatter.py
- Loading branch information
1 parent
f06ef4b
commit 42762f9
Showing
1 changed file
with
35 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import boto3 | ||
import os | ||
from urllib.parse import parse_qsl, urlencode, urljoin, urlparse, urlsplit, urlunsplit | ||
|
||
import requests | ||
from requests import RequestException | ||
from requests.auth import AuthBase, HTTPBasicAuth | ||
|
||
from elastalert.auth import RefeshableAWSRequestsAuth | ||
from elastalert.util import EAException | ||
|
||
class OpensearchExternalUrlFormatter: | ||
'''Interface for formatting external Opensearch urls''' | ||
|
||
def format(self, relative_url: str) -> str: | ||
raise NotImplementedError() | ||
|
||
class AbsoluteOpensearchExternalUrlFormatter(OpensearchExternalUrlFormatter): | ||
'''Formats absolute external Opensearch urls''' | ||
|
||
def __init__(self, base_url: str) -> None: | ||
self.base_url = base_url | ||
|
||
def format(self, relative_url: str) -> str: | ||
url = urljoin(self.base_url, relative_url) | ||
return url | ||
|
||
def create_opensearch_external_url_formatter( | ||
rule | ||
) -> OpensearchExternalUrlFormatter: | ||
'''Creates a Opensearch external url formatter''' | ||
|
||
base_url = rule.get('opensearch_url') | ||
|
||
return AbsoluteKibanaExternalUrlFormatter(base_url) |