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

Added support for webhook_url dynamic overriding using annotations (issue 1083) #1476

Merged
merged 13 commits into from
Jul 7, 2024

Conversation

itisallgood
Copy link
Contributor

@itisallgood itisallgood commented Jun 29, 2024

Introduced the webhook_override attribute for ms_teams_sink, enabling the use of annotations from YAML files to dynamically override the webhook_url.

Issue #1083.

sinksConfig:
- ms_teams_sink:
    name: main_ms_teams_sink
    webhook_url: teams-incoming-webhook 
    webhook_override: "annotations.msteams"

If no such annotation exists, the default webhook will be used. If the annotation is found but its value
does not contain a valid URL, the system will search for an environmental variable with the name of the value in the additional_env_vars section of your generated_values.yaml file.

Reason for using annotations instead of labels:

Annotations are used instead of labels because URLs can't be passed to labels (see comment for MsTeamsWebhookUrlTransformer in src/robusta/core/sinks/msteams/msteams_webhook_tranformer.py )

* Created MsTeamsWebhookUrlTransformer to enable overriding the webhook_url using annotations from yaml files

* Enhanced MsTeamsSender.send_finding_to_ms_teams to support overriding the webhook_url

* Moved shared methods and logic from ChannelTransformer to BaseChannelTransformer
@itisallgood itisallgood added the enhancement New feature or request label Jun 29, 2024
@itisallgood itisallgood requested a review from RoiGlinik June 29, 2024 23:31
@itisallgood itisallgood self-assigned this Jun 29, 2024
@CLAassistant
Copy link

CLAassistant commented Jun 29, 2024

CLA assistant check
All committers have signed the CLA.

@itisallgood itisallgood removed the enhancement New feature or request label Jul 2, 2024
@itisallgood itisallgood requested review from pavangudiwada and removed request for pavangudiwada July 2, 2024 15:17
def validate_url_or_get_env(cls, webhook_url: str, default_webhook_url: str) -> str:
if URL_PATTERN.match(webhook_url):
return webhook_url
env_value = os.getenv(webhook_url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add info logs here, in case the url matching is failed?

Also is there any reference to this url pattern ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RoiGlinik There is no reference to this url pattern as I composed it from different resources, but I added pytests with different valid and invalid urls.

@RoiGlinik RoiGlinik merged commit 5a960e1 into master Jul 7, 2024
8 checks passed
@RoiGlinik RoiGlinik deleted the issue-1083-dynamic-ms-teams-sink branch July 7, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants