Skip to content

Commit 32e4ea0

Browse files
authored
Change webhook to eventstream (#1011)
1 parent ee05401 commit 32e4ea0

File tree

64 files changed

+2055
-3410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2055
-3410
lines changed

.gitleaks.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ description = "Global Allowlist"
55
paths = [
66
'''tests\/unit\/data''',
77
'''tools\/docker\/redis-tls''',
8-
'''tests\/integration\/api\/test_webhook.py'''
8+
'''tests\/integration\/api\/test_event_stream_ecdsa.py'''
99
]

sonar-project.properties

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Complete documentation with many more options at:
2+
# https://docs.sonarqube.org/latest/analysis/analysis-parameters/
3+
4+
## The unique project identifier. This is mandatory.
5+
# Do not duplicate or reuse!
6+
# Available characters: [a-zA-Z0-9_:\.\-]
7+
# Must have least one non-digit.
8+
# Recommended format: <group>:<project>
9+
sonar.projectKey=ansible_eda-server
10+
11+
sonar.organization=ansible
12+
13+
# Customize what paths to scan. Default is .
14+
sonar.sources=.
15+
16+
# Verbose name of project displayed in WUI. Default is set to the projectKey. This field is optional.
17+
sonar.projectName=eda-server
18+
19+
# Version of project. This field is optional.
20+
#sonar.projectVersion=1.0
21+
22+
# Tell sonar scanner where coverage files exist
23+
#sonar.python.coverage.reportPaths=coverage.xml
24+
25+
sonar.issue.ignore.multicriteria=e1
26+
# Ignore "should be a variable"
27+
#sonar.issue.ignore.multicriteria.e1.ruleKey=python:S1192
28+
sonar.issue.ignore.multicriteria.e1.resourceKey=**/migrations/**/*
29+
30+
# Only scan with python3
31+
sonar.python.version=3.9,3.10,3.11
32+
33+
# Ignore code dupe for the migrations
34+
sonar.cpd.exclusions=**/migrations/*.py

src/aap_eda/api/constants.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,4 @@
1414

1515
# EDA_SERVER_VAULT_LABEL is reserved for system vault password identifiers
1616
EDA_SERVER_VAULT_LABEL = "EDA_SERVER"
17-
18-
PG_NOTIFY_TEMPLATE_RULEBOOK_NAME = "_PG_NOTIFY_TEMPLATE_RULEBOOK_"
19-
PG_NOTIFY_TEMPLATE_RULEBOOK_DATA = """
20-
---
21-
- name: PG Notify Template Event Stream
22-
hosts: all
23-
sources:
24-
- name: my_range
25-
ansible.eda.range:
26-
limit: 5
27-
complementary_source:
28-
type: ansible.eda.pg_listener
29-
name: Postgres Listener
30-
args:
31-
dsn: "{{ EDA_PG_NOTIFY_DSN }}"
32-
channels:
33-
- "{{ EDA_PG_NOTIFY_CHANNEL }}"
34-
extra_vars:
35-
EDA_PG_NOTIFY_DSN: "{{ settings.PG_NOTIFY_DSN }}"
36-
EDA_PG_NOTIFY_CHANNEL: "{{ event_stream.channel_name }}"
37-
encrypt_vars:
38-
- EDA_PG_NOTIFY_DSN
39-
rules:
40-
- name: Post event
41-
condition: true
42-
action:
43-
pg_notify:
44-
dsn: "{{ EDA_PG_NOTIFY_DSN }}"
45-
channel: "{{ EDA_PG_NOTIFY_CHANNEL }}"
46-
event: "{{ event }}"
47-
"""
48-
4917
SOURCE_MAPPING_ERROR_KEY = "rulebook"

src/aap_eda/api/webhook_authentication.py renamed to src/aap_eda/api/event_stream_authentication.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""Module providing all webhook authentication types."""
14+
"""Module providing all event stream authentication types."""
1515

1616
import base64
1717
import hashlib
@@ -37,16 +37,16 @@
3737
DEFAULT_TIMEOUT = 30
3838

3939

40-
class WebhookAuthentication(ABC):
41-
"""Base class for Webhook Authentication."""
40+
class EventStreamAuthentication(ABC):
41+
"""Base class for EventStream Authentication."""
4242

4343
@abstractmethod
4444
def authenticate(self, body: Optional[bytes]):
4545
"""Implement the authenticate maethod with body."""
4646

4747

4848
@dataclass
49-
class HMACAuthentication(WebhookAuthentication):
49+
class HMACAuthentication(EventStreamAuthentication):
5050
"""HMAC Parameters."""
5151

5252
signature: str
@@ -87,7 +87,7 @@ def authenticate(self, body: bytes):
8787

8888

8989
@dataclass
90-
class TokenAuthentication(WebhookAuthentication):
90+
class TokenAuthentication(EventStreamAuthentication):
9191
"""Token Authentication."""
9292

9393
token: str
@@ -102,7 +102,7 @@ def authenticate(self, _body=None):
102102

103103

104104
@dataclass
105-
class MTLSAuthentication(WebhookAuthentication):
105+
class MTLSAuthentication(EventStreamAuthentication):
106106
"""mTLS Authentication."""
107107

108108
subject: str
@@ -117,8 +117,8 @@ def authenticate(self, _body=None):
117117

118118

119119
@dataclass
120-
class BasicAuthentication(WebhookAuthentication):
121-
"""Token Authentication."""
120+
class BasicAuthentication(EventStreamAuthentication):
121+
"""Basic Authentication."""
122122

123123
password: str
124124
username: str
@@ -139,7 +139,7 @@ def authenticate(self, _body=None):
139139

140140

141141
@dataclass
142-
class Oauth2JwtAuthentication(WebhookAuthentication):
142+
class Oauth2JwtAuthentication(EventStreamAuthentication):
143143
"""OAuth2 JWT Authentication."""
144144

145145
jwks_url: str
@@ -187,7 +187,7 @@ def authenticate(self, _body=None):
187187

188188

189189
@dataclass
190-
class Oauth2Authentication(WebhookAuthentication):
190+
class Oauth2Authentication(EventStreamAuthentication):
191191
"""OAuth2 Authentication."""
192192

193193
introspection_url: str
@@ -225,7 +225,7 @@ def authenticate(self, _body=None):
225225

226226

227227
@dataclass
228-
class EcdsaAuthentication(WebhookAuthentication):
228+
class EcdsaAuthentication(EventStreamAuthentication):
229229
"""ECDSA Authentication."""
230230

231231
public_key: str

src/aap_eda/api/exceptions.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,38 +97,9 @@ class InvalidWebsocketHost(APIException):
9797
)
9898

9999

100-
class MissingEventStreamRulebook(APIException):
100+
class InvalidEventStreamSource(APIException):
101101
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
102102
default_detail = (
103-
"Configuration Error: Event stream template rulebook not found"
104-
)
105-
106-
107-
class MissingEventStreamRulebookKeys(APIException):
108-
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
109-
default_detail = (
110-
"Configuration Error: Event stream template rulebook is missing "
111-
"required keys in complementary_source: type, name and args"
112-
)
113-
114-
115-
class MissingEventStreamRulebookSource(APIException):
116-
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
117-
default_detail = (
118-
"Configuration Error: Event stream template rulebook is missing "
119-
"required complementary_source"
120-
)
121-
122-
123-
class InvalidEventStreamRulebook(APIException):
124-
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
125-
default_detail = (
126-
"Configuration Error: Event stream template rulebook is invalid"
127-
)
128-
129-
130-
class InvalidWebhookSource(APIException):
131-
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
132-
default_detail = (
133-
"Configuration Error: Webhook source could not be updated in ruleset"
103+
"Configuration Error: Event Stream source could not be "
104+
"updated in ruleset"
134105
)

src/aap_eda/api/filters/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
)
3232
from .team import OrganizationTeamFilter, TeamFilter
3333
from .user import UserFilter
34-
from .webhook import WebhookFilter
3534

3635
__all__ = (
3736
# project
@@ -52,13 +51,11 @@
5251
"ActivationInstanceLogFilter",
5352
# user
5453
"UserFilter",
55-
# event_stream
56-
"EventStreamFilter",
5754
# organization
5855
"OrganizationFilter",
5956
# team
6057
"TeamFilter",
6158
"OrganizationTeamFilter",
62-
# Webhook
63-
"WebhookFilter",
59+
# EventStream
60+
"EventStreamFilter",
6461
)

src/aap_eda/api/filters/event_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class EventStreamFilter(django_filters.FilterSet):
2121
name = django_filters.CharFilter(
2222
field_name="name",
2323
lookup_expr="istartswith",
24-
label="Filter by event source name.",
24+
label="Filter by event stream name.",
2525
)
2626

2727
class Meta:

src/aap_eda/api/filters/webhook.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/aap_eda/api/serializers/__init__.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@
3838
EdaCredentialCreateSerializer,
3939
EdaCredentialSerializer,
4040
)
41-
from .event_stream import (
42-
EventStreamCreateSerializer,
43-
EventStreamOutSerializer,
44-
EventStreamSerializer,
45-
)
41+
from .event_stream import EventStreamInSerializer, EventStreamOutSerializer
4642
from .organization import (
4743
OrganizationCreateSerializer,
4844
OrganizationRefSerializer,
@@ -80,7 +76,6 @@
8076
UserListSerializer,
8177
UserSerializer,
8278
)
83-
from .webhook import WebhookInSerializer, WebhookOutSerializer
8479

8580
__all__ = (
8681
# auth
@@ -123,10 +118,6 @@
123118
"EdaCredentialCreateSerializer",
124119
# decision environment
125120
"DecisionEnvironmentSerializer",
126-
# event streams
127-
"EventStreamSerializer",
128-
"EventStreamCreateSerializer",
129-
"EventStreamOutSerializer",
130121
# organizations
131122
"OrganizationSerializer",
132123
"OrganizationCreateSerializer",
@@ -138,7 +129,7 @@
138129
"TeamCreateSerializer",
139130
"TeamUpdateSerializer",
140131
"TeamDetailSerializer",
141-
# webhooks
142-
"WebhookInSerializer",
143-
"WebhookOutSerializer",
132+
# event streams
133+
"EventStreamInSerializer",
134+
"EventStreamOutSerializer",
144135
)

0 commit comments

Comments
 (0)