aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/policies
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-08-17 13:50:34 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-28 12:54:13 +0200
commitd54a95e0f9c689f2bbaaea90a3a16a855a408823 (patch)
tree2fcd758c6eaa7bc65a9744969a506c4ed24e0365 /src/hydrilla/proxy/policies
parent2c98d04e4d4a344dc04a481b039a235678f7848e (diff)
downloadhaketilo-hydrilla-d54a95e0f9c689f2bbaaea90a3a16a855a408823.tar.gz
haketilo-hydrilla-d54a95e0f9c689f2bbaaea90a3a16a855a408823.zip
allow loading packages from zip files through web UI and listing installed mappings
Diffstat (limited to 'src/hydrilla/proxy/policies')
-rw-r--r--src/hydrilla/proxy/policies/payload.py24
-rw-r--r--src/hydrilla/proxy/policies/payload_resource.py11
2 files changed, 8 insertions, 27 deletions
diff --git a/src/hydrilla/proxy/policies/payload.py b/src/hydrilla/proxy/policies/payload.py
index 577c94e..e64653d 100644
--- a/src/hydrilla/proxy/policies/payload.py
+++ b/src/hydrilla/proxy/policies/payload.py
@@ -46,7 +46,6 @@ from . import base
@dc.dataclass(frozen=True) # type: ignore[misc]
class PayloadAwarePolicy(base.Policy):
"""...."""
- haketilo_state: state.HaketiloState
payload_data: state.PayloadData
def assets_base_url(self, request_url: ParsedUrl):
@@ -174,7 +173,7 @@ class PayloadInjectPolicy(PayloadAwarePolicy):
base_url = self.assets_base_url(url)
payload_ref = self.payload_data.payload_ref
- for path in payload_ref.get_script_paths(self.haketilo_state):
+ for path in payload_ref.get_script_paths():
yield base_url + '/'.join(('static', *path))
def _modify_body(
@@ -266,19 +265,6 @@ class AutoPayloadInjectPolicy(PayloadInjectPolicy):
"""...."""
priority: t.ClassVar[base.PolicyPriority] = base.PolicyPriority._ONE
- def _modify_body(
- self,
- url: ParsedUrl,
- body: bytes,
- encoding: t.Optional[str]
- ) -> bytes:
- """...."""
- payload_ref = self.payload_data.payload_ref
- mapping_ref = payload_ref.get_mapping(self.haketilo_state)
- mapping_ref.enable(self.haketilo_state)
-
- return super()._modify_body(url, body, encoding)
-
@dc.dataclass(frozen=True)
class PayloadSuggestPolicy(PayloadAwarePolicy):
@@ -299,20 +285,20 @@ class PayloadPolicyFactory(PayloadAwarePolicyFactory):
-> t.Optional[base.Policy]:
"""...."""
try:
- payload_data = self.payload_ref.get_data(haketilo_state)
+ payload_data = self.payload_ref.get_data()
except:
return None
if payload_data.explicitly_enabled:
- return PayloadInjectPolicy(haketilo_state, payload_data)
+ return PayloadInjectPolicy(payload_data)
mode = haketilo_state.get_settings().mapping_use_mode
if mode == state.MappingUseMode.QUESTION:
- return PayloadSuggestPolicy(haketilo_state, payload_data)
+ return PayloadSuggestPolicy(payload_data)
if mode == state.MappingUseMode.WHEN_ENABLED:
return None
# mode == state.MappingUseMode.AUTO
- return AutoPayloadInjectPolicy(haketilo_state, payload_data)
+ return AutoPayloadInjectPolicy(payload_data)
diff --git a/src/hydrilla/proxy/policies/payload_resource.py b/src/hydrilla/proxy/policies/payload_resource.py
index 3e1b31a..3aacea0 100644
--- a/src/hydrilla/proxy/policies/payload_resource.py
+++ b/src/hydrilla/proxy/policies/payload_resource.py
@@ -77,10 +77,7 @@ class PayloadResourcePolicy(PayloadAwarePolicy):
-> http_messages.ProducedResponse:
"""...."""
try:
- file_data = self.payload_data.payload_ref.get_file_data(
- self.haketilo_state,
- path
- )
+ file_data = self.payload_data.payload_ref.get_file_data(path)
except state.MissingItemError:
return resource_blocked_response
@@ -147,7 +144,7 @@ class PayloadResourcePolicyFactory(PayloadAwarePolicyFactory):
-> t.Union[PayloadResourcePolicy, BlockedResponsePolicy]:
"""...."""
try:
- payload_data = self.payload_ref.get_data(haketilo_state)
+ payload_data = self.payload_ref.get_data()
except state.MissingItemError:
return BlockedResponsePolicy()
@@ -156,6 +153,4 @@ class PayloadResourcePolicyFactory(PayloadAwarePolicyFactory):
state.MappingUseMode.AUTO:
return BlockedResponsePolicy()
- return PayloadResourcePolicy(haketilo_state, payload_data)
-
-
+ return PayloadResourcePolicy(payload_data)