Skip to content

Conversation

migmartri
Copy link
Member

@migmartri migmartri commented Jun 15, 2023

Extension that leverages Discord webhooks to send attestations.

The inputs at registration time are a required webhook URL and an optional username override

$ chainloop integration available describe --id discord-webhook

Available integrations ready to be used during registration
┌─────────────────┬─────────┬──────────────────────────────┐
│ ID              │ VERSION │ DESCRIPTION                  │
├─────────────────┼─────────┼──────────────────────────────┤
│ discord-webhook │ 0.1     │ Send attestations to Discord │
└─────────────────┴─────────┴──────────────────────────────┘
┌───────────────────────────────────────────────────────────────────────────────────────┐
│ Registration inputs                                                                   │
├──────────┬──────────────┬──────────┬──────────────────────────────────────────────────┤
│ FIELD    │ TYPE         │ REQUIRED │ DESCRIPTION                                      │
├──────────┼──────────────┼──────────┼──────────────────────────────────────────────────┤
│ username │ string       │ no       │ Override the default username of the webhook     │
│ webhook  │ string (uri) │ yes      │ URL of the discord webhook                       │
└──────────┴──────────────┴──────────┴──────────────────────────────────────────────────┘

The result is a message that includes some metadata in the content body and an attached intoto attestation.

image

This patch also includes some improvements in the sdk. we now inject additional workflow information (name, project) as well as the runnerURL. refs #174 cc/ @danlishka

That new data is used to craft the resulting message.

Another interesting aspect about the implementation, is that during registration I fetch information about the webhook itself (i.e name set in discord) so we can clearly differentiate them.

$ chainloop integration registered list                        
┌──────────────────────────────────────┬─────────────────┬─────────────────┬──────────────────────────────────────────────────────────────────────────────────────┬─────────────────────┐
│ ID                                   │ DESCRIPTION     │ KIND            │ CONFIG                                                                               │ CREATED AT          │
├──────────────────────────────────────┼─────────────────┼─────────────────┼──────────────────────────────────────────────────────────────────────────────────────┼─────────────────────┤
│ 16fff68c-a017-46fe-8937-df7b7c9d7d20 │                 │ discord-webhook │ name: Chainloop webhook                                                              │ 15 Jun 23 15:19 UTC │
│                                      │                 │                 │ owner: migmartri                                                                     │                     │
│                                      │                 │                 │ username: miguel-test                                                                │                     │
├──────────────────────────────────────┼─────────────────┼─────────────────┼────────────────────────────────────────────

Closes #176

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri requested a review from danlishka June 15, 2023 16:37

// Merge attachment and integration configs
// If there are not attachment configuration then create an empty map
if attachment.Config == nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed that this code was buggy when the registration didn't have any metadata.

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
Copy link
Member

@danlishka danlishka left a comment

Choose a reason for hiding this comment

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

LGTM!

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri changed the title feat(extensions): add discord extension feat(extensions): add discord extension and additional metadata Jun 15, 2023
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri changed the title feat(extensions): add discord extension and additional metadata feat(extensions): add Discord ™️ extension and additional metadata Jun 15, 2023
@migmartri migmartri changed the title feat(extensions): add Discord ™️ extension and additional metadata feat(extensions): add Discord extension and additional metadata Jun 15, 2023
@migmartri migmartri requested a review from danlishka June 15, 2023 18:42
wf := attachment.Workflow
integration := attachment.Integration

// Merge attachment and integration configs
Copy link
Member

Choose a reason for hiding this comment

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

Are we merging integration and attachment configs or we are merging configurations provided during registration and attachment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi.

Not sure I understand the difference, but we are showing together both registration and attachment configuration states. Does it make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I am nitpicking here a bit, but I was not sure at first what you mean by the integration config here.

continue
}
options = append(options, fmt.Sprintf("%s: %v", k, v))
maps.Copy(attachment.Config, integration.Config)
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not correct. We are overwriting the configuration provided at the attachment state, and I think we should either show both (attachment and registration configs) or use the attachment value instead in case the keys are the same.

Copy link
Member

Choose a reason for hiding this comment

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

To give you an example, imagine I want to add another To field at the attachment stage in the smtp extension because today the to field in the registration is more like a default value and I may want to have different values for different workflows (set via attachment).

--- a/app/controlplane/extensions/core/smtp/v1/extension.go
+++ b/app/controlplane/extensions/core/smtp/v1/extension.go
@@ -49,10 +49,12 @@ type registrationState struct {
 }

 type attachmentRequest struct {
+       To string `json:"to,omitempty" jsonschema:"format=email,description=The email address to send the ema
il to."`
        CC string `json:"cc,omitempty" jsonschema:"format=email,description=The email address of the carbon c
opy recipient."`
 }

 type attachmentState struct {
+       To string `json:"to"`

Does it make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good point. I updated it to instead use the attachment config in the case of a conflict.

Thanks!


```console
$ chainloop integration registered add discord-webhook --opt webhook=[webhookURL]
```
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we should mention anything about the way we store webhooks? We treat them like credentials, which may be worth mentioning here.

Copy link
Member Author

Choose a reason for hiding this comment

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

as an user I don't see value on mentioning it, or do you think that it could help with adoption?

Copy link
Member

Choose a reason for hiding this comment

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

ok. I would like to know that this is stored securely without looking into the code.

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri merged commit 59caa39 into chainloop-dev:main Jun 16, 2023
@migmartri migmartri deleted the add-discord branch June 16, 2023 06:24
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.

[extension] add Discord extension
2 participants