Skip to content

Commit aa1465d

Browse files
tarekbadrshafrittoli
authored andcommitted
Update all services
1 parent 0ec5be9 commit aa1465d

File tree

7 files changed

+137
-329
lines changed

7 files changed

+137
-329
lines changed

cli/cdevents/cli/artifact.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ def packaged(
5454
data: List[str] = None,
5555
):
5656
print_function_args()
57-
artifact_packaged_eventV1 = "cd.artifact.packaged.v1"
57+
artifact_packaged_event_v1 = "cd.artifact.packaged.v1"
5858
extensions = {
5959
"artifactid": id,
6060
"artifactname": name,
6161
"artifactversion": version,
6262
}
63+
6364
cdevents_command = CDeventsCommand()
64-
cdevents_command.run(artifact_packaged_eventV1, extensions, data)
65+
cdevents_command.run(artifact_packaged_event_v1, extensions, data)
6566

6667

6768
@click.command(help=add_disclaimer_text("Artifact Published CloudEvent."))
@@ -73,11 +74,11 @@ def published(
7374
data: List[str] = None,
7475
):
7576
print_function_args()
76-
artifact_published_eventV1 = "cd.artifact.published.v1"
77+
artifact_published_event_v1 = "cd.artifact.published.v1"
7778
extensions = {
7879
"artifactid": id,
7980
"artifactname": name,
8081
"artifactversion": version,
8182
}
8283
cdevents_command = CDeventsCommand()
83-
cdevents_command.run(artifact_published_eventV1, extensions, data)
84+
cdevents_command.run(artifact_published_event_v1, extensions, data)

cli/cdevents/cli/branch.py

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
"""Module for cli branch commands."""
22
from __future__ import annotations
33

4-
import logging
54
import os
65
from typing import List
76

87
import click
9-
import requests
10-
from cloudevents.http import CloudEvent, to_structured
118

129
from cdevents.cli.utils import add_disclaimer_text, print_function_args
13-
14-
_log = logging.getLogger(__name__)
10+
from cdevents.cli.cdevents_command import CDeventsCommand
1511

1612
# pylint: disable=unused-argument
1713
def common_branch_options(function):
1814
"""Decorator for common cli options for branch."""
19-
function = click.option(
20-
"--cde_sink",
21-
"-c",
22-
required=False,
23-
type=str,
24-
default=lambda: os.environ.get("CDE_SINK", "http://localhost:8080"),
25-
help="CDE_SINK",
26-
)(function)
2715
function = click.option(
2816
"--id",
2917
"-i",
@@ -60,51 +48,37 @@ def common_branch_options(function):
6048
@click.command(help=add_disclaimer_text("Branch Created CloudEvent."))
6149
@common_branch_options
6250
def created(
63-
cde_sink: str,
6451
id: str,
6552
name: str = None,
6653
repoid: str = None,
6754
data: List[str] = None,
6855
):
6956
print_function_args()
70-
attributes = {
71-
"type": "cd.repository.branch.created.v1",
72-
"source": "cde-cli",
73-
"extensions": {
74-
"branchid": id,
75-
"branchname": name,
76-
"branchrepositoryid": repoid,
77-
},
57+
branch_created_event_v1 = "cd.repository.branch.created.v1"
58+
extensions = {
59+
"branchid": id,
60+
"branchname": name,
61+
"branchrepositoryid": repoid,
7862
}
79-
event = CloudEvent(attributes, dict(data))
80-
headers, body = to_structured(event)
8163

82-
# send and print event
83-
result = requests.post(cde_sink, headers=headers, data=body)
84-
_log.debug(f"Response with state code {result.status_code}")
64+
cdevents_command = CDeventsCommand()
65+
cdevents_command.run(branch_created_event_v1, extensions, data)
8566

8667
@click.command(help=add_disclaimer_text("Branch Deleted CloudEvent."))
8768
@common_branch_options
8869
def deleted(
89-
cde_sink: str,
9070
id: str,
9171
name: str = None,
9272
repoid: str = None,
9373
data: List[str] = None,
9474
):
9575
print_function_args()
96-
attributes = {
97-
"type": "cd.repository.branch.deleted.v1",
98-
"source": "cde-cli",
99-
"extensions": {
100-
"branchid": id,
101-
"branchname": name,
102-
"branchrepositoryid": repoid,
103-
},
76+
branch_deleted_event_v1 = "cd.repository.branch.deleted.v1"
77+
extensions = {
78+
"branchid": id,
79+
"branchname": name,
80+
"branchrepositoryid": repoid,
10481
}
105-
event = CloudEvent(attributes, dict(data))
106-
headers, body = to_structured(event)
10782

108-
# send and print event
109-
result = requests.post(cde_sink, headers=headers, data=body)
110-
_log.debug(f"Response with state code {result.status_code}")
83+
cdevents_command = CDeventsCommand()
84+
cdevents_command.run(branch_deleted_event_v1, extensions, data)

cli/cdevents/cli/build.py

Lines changed: 22 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
"""Module for cli build commands."""
22
from __future__ import annotations
33

4-
import logging
54
import os
65
from typing import List
76

87
import click
9-
import requests
10-
from cloudevents.http import CloudEvent, to_structured
118

129
from cdevents.cli.utils import add_disclaimer_text, print_function_args
13-
14-
_log = logging.getLogger(__name__)
15-
10+
from cdevents.cli.cdevents_command import CDeventsCommand
1611

1712
# pylint: disable=unused-argument
1813
def common_build_options(function):
1914
"""Decorator for common cli options for build."""
20-
function = click.option(
21-
"--cde_sink",
22-
"-c",
23-
required=False,
24-
type=str,
25-
default=lambda: os.environ.get("CDE_SINK", "http://localhost:8080"),
26-
help="CDE_SINK",
27-
)(function)
2815
function = click.option(
2916
"--id",
3017
"-i",
@@ -62,79 +49,57 @@ def common_build_options(function):
6249
@click.command(help=add_disclaimer_text("Build Started CloudEvent."))
6350
@common_build_options
6451
def started(
65-
cde_sink: str,
6652
id: str,
6753
name: str = None,
6854
artifact: str = None,
6955
data: List[str] = None,
7056
):
7157
print_function_args()
72-
attributes = {
73-
"type": "cd.build.started.v1",
74-
"source": "cde-cli",
75-
"extensions": {
76-
"buildid": id,
77-
"buildname": name,
78-
"buildartifactid": artifact,
79-
},
58+
build_started_event_v1 = "cd.build.started.v1"
59+
extensions = {
60+
"buildid": id,
61+
"buildname": name,
62+
"buildartifactid": artifact,
8063
}
81-
event = CloudEvent(attributes, dict(data))
82-
headers, body = to_structured(event)
83-
84-
# send and print event
85-
result = requests.post(cde_sink, headers=headers, data=body)
86-
_log.debug(f"Response with state code {result.status_code}")
8764

65+
cdevents_command = CDeventsCommand()
66+
cdevents_command.run(build_started_event_v1, extensions, data)
8867

8968
@click.command(help=add_disclaimer_text("Build Finished CloudEvent."))
9069
@common_build_options
9170
def finished(
92-
cde_sink: str,
9371
id: str,
9472
name: str = None,
9573
artifact: str = None,
9674
data: List[str] = None,
9775
):
9876
print_function_args()
99-
attributes = {
100-
"type": "cd.build.finished.v1",
101-
"source": "cde-cli",
102-
"extensions": {
103-
"buildid": id,
104-
"buildname": name,
105-
"buildartifactid": artifact,
106-
},
77+
build_finished_event_v1 = "cd.build.finished.v1"
78+
extensions = {
79+
"buildid": id,
80+
"buildname": name,
81+
"buildartifactid": artifact,
10782
}
108-
event = CloudEvent(attributes, dict(data))
109-
headers, body = to_structured(event)
11083

111-
# send and print event
112-
result = requests.post(cde_sink, headers=headers, data=body)
113-
_log.debug(f"Response with state code {result.status_code}")
84+
cdevents_command = CDeventsCommand()
85+
cdevents_command.run(build_finished_event_v1, extensions, data)
11486

11587

11688
@click.command(help=add_disclaimer_text("PipelineRun Queued CloudEvent."))
11789
@common_build_options
11890
def queued(
119-
cde_sink: str,
12091
id: str,
12192
name: str = None,
12293
artifact: str = None,
12394
data: List[str] = None,
12495
):
12596
print_function_args()
126-
attributes = {
127-
"type": "cd.build.queued.v1",
128-
"source": "cde-cli",
129-
"extensions": {
130-
"buildid": id,
131-
"buildname": name,
132-
"buildartifactid": artifact,
133-
},
97+
build_queued_event_v1 = "cd.build.queued.v1"
98+
extensions = {
99+
"buildid": id,
100+
"buildname": name,
101+
"buildartifactid": artifact,
134102
}
135-
event = CloudEvent(attributes, dict(data))
136-
headers, body = to_structured(event)
137103

138-
# send and print event
139-
result = requests.post(cde_sink, headers=headers, data=body)
140-
_log.debug(f"Response with state code {result.status_code}")
104+
cdevents_command = CDeventsCommand()
105+
cdevents_command.run(build_queued_event_v1, extensions, data)

cli/cdevents/cli/env.py

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
"""Module for cli environment commands."""
22
from __future__ import annotations
33

4-
import logging
54
import os
65
from typing import List
76

87
import click
9-
import requests
10-
from cloudevents.http import CloudEvent, to_structured
118

129
from cdevents.cli.utils import add_disclaimer_text, print_function_args
13-
14-
_log = logging.getLogger(__name__)
10+
from cdevents.cli.cdevents_command import CDeventsCommand
1511

1612
# pylint: disable=unused-argument
1713
def common_env_options(function):
1814
"""Decorator for common cli options for environment."""
19-
function = click.option(
20-
"--cde_sink",
21-
"-c",
22-
required=False,
23-
type=str,
24-
default=lambda: os.environ.get("CDE_SINK", "http://localhost:8080"),
25-
help="CDE_SINK",
26-
)(function)
2715
function = click.option(
2816
"--id",
2917
"-i",
@@ -60,79 +48,58 @@ def common_env_options(function):
6048
@click.command(help=add_disclaimer_text("Environment Created CloudEvent."))
6149
@common_env_options
6250
def created(
63-
cde_sink: str,
6451
id: str,
6552
name: str = None,
6653
repo: str = None,
6754
data: List[str] = None,
6855
):
6956
print_function_args()
70-
attributes = {
71-
"type": "cd.environment.created.v1",
72-
"source": "cde-cli",
73-
"extensions": {
74-
"envId": id,
75-
"envname": name,
76-
"envrepourl": repo,
77-
},
57+
environment_created_event_v1 = "cd.environment.created.v1"
58+
extensions = {
59+
"envId": id,
60+
"envname": name,
61+
"envrepourl": repo,
7862
}
79-
event = CloudEvent(attributes, dict(data))
80-
headers, body = to_structured(event)
8163

82-
# send and print event
83-
result = requests.post(cde_sink, headers=headers, data=body)
84-
_log.debug(f"Response with state code {result.status_code}")
64+
cdevents_command = CDeventsCommand()
65+
cdevents_command.run(environment_created_event_v1, extensions, data)
8566

8667

8768
@click.command(help=add_disclaimer_text("Environment Deleted CloudEvent."))
8869
@common_env_options
8970
def deleted(
90-
cde_sink: str,
9171
id: str,
9272
name: str = None,
9373
repo: str = None,
9474
data: List[str] = None,
9575
):
9676
print_function_args()
97-
attributes = {
98-
"type": "cd.environment.deleted.v1",
99-
"source": "cde-cli",
100-
"extensions": {
101-
"envId": id,
102-
"envname": name,
103-
"envrepourl": repo,
104-
},
77+
environment_deleted_event_v1 = "cd.environment.deleted.v1"
78+
extensions = {
79+
"envId": id,
80+
"envname": name,
81+
"envrepourl": repo,
10582
}
106-
event = CloudEvent(attributes, dict(data))
107-
headers, body = to_structured(event)
10883

109-
# send and print event
110-
result = requests.post(cde_sink, headers=headers, data=body)
111-
_log.debug(f"Response with state code {result.status_code}")
84+
cdevents_command = CDeventsCommand()
85+
cdevents_command.run(environment_deleted_event_v1, extensions, data)
11286

11387

11488
@click.command(help=add_disclaimer_text("Environment Modified CloudEvent."))
11589
@common_env_options
11690
def modified(
117-
cde_sink: str,
11891
id: str,
11992
name: str = None,
12093
repo: str = None,
12194
data: List[str] = None,
12295
):
12396
print_function_args()
124-
attributes = {
125-
"type": "cd.environment.modified.v1",
126-
"source": "cde-cli",
127-
"extensions": {
128-
"envId": id,
129-
"envname": name,
130-
"envrepourl": repo,
131-
},
97+
environment_modified_event_v1 = "cd.environment.modified.v1"
98+
extensions = {
99+
"envId": id,
100+
"envname": name,
101+
"envrepourl": repo,
132102
}
133-
event = CloudEvent(attributes, dict(data))
134-
headers, body = to_structured(event)
135103

136-
# send and print event
137-
result = requests.post(cde_sink, headers=headers, data=body)
138-
_log.debug(f"Response with state code {result.status_code}")
104+
cdevents_command = CDeventsCommand()
105+
cdevents_command.run(environment_modified_event_v1, extensions, data)

0 commit comments

Comments
 (0)