Skip to content
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

Moved the business logic of the configuration steps in the specific steps #64

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ inspect-tags:

.PHONY: test
test: venv-tools
@if test -d "./packages/flare/tests" ; then \
venv-tools/bin/pytest ./packages/flare/tests/**/*.py -vv ; \
fi
venv-tools/bin/pytest ./packages/flare/tests/**/*.py -vv ;

.PHONY: format setup-web
format: venv-tools
Expand Down
4 changes: 3 additions & 1 deletion packages/flare/bin/cron_job_ingest_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ def fetch_feed(
start_date = get_start_date(kvstore=kvstore)
logger.info(f"Fetching {tenant_id=}, {next=}, {start_date=}")
for event_next in flare_api.fetch_feed_events(
next=next, start_date=start_date, ingest_metadata_only=ingest_metadata_only
next=next,
start_date=start_date,
ingest_metadata_only=ingest_metadata_only,
):
yield event_next
except Exception as e:
Expand Down
5 changes: 5 additions & 0 deletions packages/flare/bin/flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def _fetch_full_event_from_uid(self, *, uid: str) -> dict:
self.logger.debug(event)
return event

def fetch_api_key_validation(self) -> requests.Response:
return self.flare_client.get(
url="/tokens/test",
)

def fetch_tenants(self) -> requests.Response:
return self.flare_client.get(
url="/firework/v2/me/tenants",
Expand Down
30 changes: 22 additions & 8 deletions packages/flare/bin/flare_external_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,32 @@
from logger import Logger


class FlareValidateApiKey(splunk.rest.BaseRestHandler):
def handle_POST(self) -> None:
payload = self.request["payload"]
params = parse.parse_qs(payload)

if "apiKey" not in params:
raise Exception("API Key is required")

flare_api = FlareAPI(api_key=params["apiKey"][0])
flare_api.fetch_api_key_validation()
self.response.setHeader("Content-Type", "application/json")
self.response.write(json.dumps({}))


class FlareUserTenants(splunk.rest.BaseRestHandler):
def handle_POST(self) -> None:
logger = Logger(class_name=__file__)
payload = self.request["payload"]
params = parse.parse_qs(payload)

if "apiKey" in params:
flare_api = FlareAPI(api_key=params["apiKey"][0])
user_tenants_response = flare_api.fetch_tenants()
tenants_response = user_tenants_response.json()
logger.debug(tenants_response)
self.response.setHeader("Content-Type", "application/json")
self.response.write(json.dumps(tenants_response))
else:
if "apiKey" not in params:
raise Exception("API Key is required")

flare_api = FlareAPI(api_key=params["apiKey"][0])
response = flare_api.fetch_tenants()
response_json = response.json()
logger.debug(f"FlareUserTenants: {response_json}")
self.response.setHeader("Content-Type", "application/json")
self.response.write(json.dumps(response_json))
5 changes: 5 additions & 0 deletions packages/flare/src/main/resources/splunk/default/restmap.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[script:flare_external_requests_api_key_validation]
match=/fetch_api_key_validation
handler=flare_external_requests.FlareValidateApiKey
python.version = python3

[script:flare_external_requests_user_tenants]
match=/fetch_user_tenants
handler=flare_external_requests.FlareUserTenants
Expand Down
4 changes: 4 additions & 0 deletions packages/flare/src/main/resources/splunk/default/web.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[expose:flare_external_requests_api_key_validation]
pattern=fetch_api_key_validation
methods=POST

[expose:flare_external_requests_user_tenants]
pattern=fetch_user_tenants
methods=POST
19 changes: 13 additions & 6 deletions packages/flare/tests/bin/test_flare_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def test_flare_full_data_without_metadata(

events: list[dict] = []
for event, next_token in flare_api.fetch_feed_events(
next=None, start_date=None, ingest_metadata_only=True
next=None,
start_date=None,
ingest_metadata_only=True,
):
assert next_token == expected_return_value["next"]
events.append(event)
Expand Down Expand Up @@ -100,7 +102,9 @@ def test_flare_full_data_with_metadata(

events: list[dict] = []
for event, next_token in flare_api.fetch_feed_events(
next=None, start_date=None, ingest_metadata_only=False
next=None,
start_date=None,
ingest_metadata_only=False,
):
assert next_token == expected_return_value["next"]
events.append(event)
Expand Down Expand Up @@ -138,9 +142,12 @@ def test_flare_full_data_with_metadata_and_exception(
flare_api = FlareAPI(api_key="some_key", tenant_id=111)

with pytest.raises(KeyError, match="metadata"):
for _, _ in flare_api.fetch_feed_events(
next=None, start_date=None, ingest_metadata_only=False
):
pass
next(
TyMarc marked this conversation as resolved.
Show resolved Hide resolved
flare_api.fetch_feed_events(
next=None,
start_date=None,
ingest_metadata_only=False,
)
)

fetch_event_feed_metadata_mock.assert_called_once()
6 changes: 3 additions & 3 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"license": "UNLICENSED",
"scripts": {
"build": "node build.js build",
"eslint": "eslint src --ext \".js,.tsx,.ts\"",
"eslint:fix": "eslint src --ext \".js,.tsx,.ts\" --fix",
"eslint": "eslint src --ext \".tsx,.ts\"",
"eslint:fix": "eslint src --ext \".tsx,.ts\" --fix",
"lint": "yarn run eslint && yarn run stylelint",
"lint:ci": "yarn run eslint:ci && yarn run stylelint",
"start": "webpack --watch",
"stylelint": "stylelint \"src/**/*.{js,jsx}\" --config stylelint.config.js"
"stylelint": "stylelint \"src/**/*.{ts,tsx}\" --config stylelint.config.js"
},
"exports": {
"./configuration-screen": "./ConfigurationScreen.js",
Expand Down
1 change: 1 addition & 0 deletions packages/react-components/src/ConfigurationScreen.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
width: 800px;
gap: 1.5rem;
align-self: center;
padding-bottom: 2rem;
}

.content-step {
Expand Down
Loading