Skip to content

Commit

Permalink
feat(gitlab-gateway): check for duplicate webhooks (#537)
Browse files Browse the repository at this point in the history
* feat(gitlab-gateway): check for duplicate webhooks

* feat(gitlab-gateway): check for duplicate webhooks
  • Loading branch information
VaibhavPage authored Mar 10, 2020
1 parent 7f3198f commit 4916c8b
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 31 deletions.
16 changes: 14 additions & 2 deletions api/event-source.html
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ <h3 id="argoproj.io/v1alpha1.EventSourceSpec">EventSourceSpec
<td>
<code>type</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.EventSourceType
Argo Events common.EventSourceType
</em>
</td>
<td>
Expand Down Expand Up @@ -1128,6 +1128,18 @@ <h3 id="argoproj.io/v1alpha1.GitlabEventSource">GitlabEventSource
<p>DeleteHookOnFinish determines whether to delete the GitLab hook for the project once the event source is stopped.</p>
</td>
</tr>
<tr>
<td>
<code>allowDuplicate</code></br>
<em>
bool
</em>
</td>
<td>
<p>AllowDuplicate allows the gateway to register the same webhook integrations for multiple event source configurations.
Defaults to false.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="argoproj.io/v1alpha1.HDFSEventSource">HDFSEventSource
Expand Down Expand Up @@ -2296,5 +2308,5 @@ <h3 id="argoproj.io/v1alpha1.StripeEventSource">StripeEventSource
<hr/>
<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
on git commit <code>ce4ab23</code>.
on git commit <code>7f3198f</code>.
</em></p>
27 changes: 24 additions & 3 deletions api/event-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,7 @@ Generic event source

<td>

<code>type</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.EventSourceType </em>
<code>type</code></br> <em> Argo Events common.EventSourceType </em>

</td>

Expand Down Expand Up @@ -2223,6 +2222,28 @@ project once the event source is stopped.

</tr>

<tr>

<td>

<code>allowDuplicate</code></br> <em> bool </em>

</td>

<td>

<p>

AllowDuplicate allows the gateway to register the same webhook
integrations for multiple event source configurations. Defaults to
false.

</p>

</td>

</tr>

</tbody>

</table>
Expand Down Expand Up @@ -4571,6 +4592,6 @@ all types of events will be processed. More info at
<p>

<em> Generated with <code>gen-crd-api-reference-docs</code> on git
commit <code>ce4ab23</code>. </em>
commit <code>7f3198f</code>. </em>

</p>
10 changes: 5 additions & 5 deletions api/gateway.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h3 id="argoproj.io/v1alpha1.Gateway">Gateway
<td>
<code>type</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.EventSourceType
Argo Events common.EventSourceType
</em>
</td>
<td>
Expand Down Expand Up @@ -186,7 +186,7 @@ <h3 id="argoproj.io/v1alpha1.Gateway">Gateway
<td>
<code>eventProtocol</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.EventProtocol
Argo Events common.EventProtocol
</em>
</td>
<td>
Expand Down Expand Up @@ -304,7 +304,7 @@ <h3 id="argoproj.io/v1alpha1.GatewaySpec">GatewaySpec
<td>
<code>type</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.EventSourceType
Argo Events common.EventSourceType
</em>
</td>
<td>
Expand Down Expand Up @@ -354,7 +354,7 @@ <h3 id="argoproj.io/v1alpha1.GatewaySpec">GatewaySpec
<td>
<code>eventProtocol</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.EventProtocol
Argo Events common.EventProtocol
</em>
</td>
<td>
Expand Down Expand Up @@ -671,5 +671,5 @@ <h3 id="argoproj.io/v1alpha1.Subscribers">Subscribers
<hr/>
<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
on git commit <code>ce4ab23</code>.
on git commit <code>7f3198f</code>.
</em></p>
16 changes: 7 additions & 9 deletions api/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ configurations for the gateway

<td>

<code>type</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.EventSourceType </em>
<code>type</code></br> <em> Argo Events common.EventSourceType </em>

</td>

Expand Down Expand Up @@ -358,8 +357,8 @@ Port on which the gateway event source processor is running on.

<td>

<code>eventProtocol</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.EventProtocol </em>
<code>eventProtocol</code></br> <em> Argo Events common.EventProtocol
</em>

</td>

Expand Down Expand Up @@ -601,8 +600,7 @@ configurations for the gateway

<td>

<code>type</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.EventSourceType </em>
<code>type</code></br> <em> Argo Events common.EventSourceType </em>

</td>

Expand Down Expand Up @@ -689,8 +687,8 @@ Port on which the gateway event source processor is running on.

<td>

<code>eventProtocol</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.EventProtocol </em>
<code>eventProtocol</code></br> <em> Argo Events common.EventProtocol
</em>

</td>

Expand Down Expand Up @@ -1323,6 +1321,6 @@ NATS refers to the subscribers over NATS protocol.
<p>

<em> Generated with <code>gen-crd-api-reference-docs</code> on git
commit <code>ce4ab23</code>. </em>
commit <code>7f3198f</code>. </em>

</p>
8 changes: 4 additions & 4 deletions api/sensor.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ <h3 id="argoproj.io/v1alpha1.ArtifactLocation">ArtifactLocation
<td>
<code>s3</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.S3Artifact
Argo Events common.S3Artifact
</em>
</td>
<td>
Expand Down Expand Up @@ -735,7 +735,7 @@ <h3 id="argoproj.io/v1alpha1.EventDependencyFilter">EventDependencyFilter
<td>
<code>context</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.EventContext
Argo Events common.EventContext
</em>
</td>
<td>
Expand Down Expand Up @@ -1609,7 +1609,7 @@ <h3 id="argoproj.io/v1alpha1.NodeStatus">NodeStatus
<td>
<code>event</code></br>
<em>
github.com/argoproj/argo-events/pkg/apis/common.Event
Argo Events common.Event
</em>
</td>
<td>
Expand Down Expand Up @@ -3008,5 +3008,5 @@ <h3 id="argoproj.io/v1alpha1.URLArtifact">URLArtifact
<hr/>
<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
on git commit <code>ce4ab23</code>.
on git commit <code>7f3198f</code>.
</em></p>
11 changes: 4 additions & 7 deletions api/sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ Description

<td>

<code>s3</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.S3Artifact </em>
<code>s3</code></br> <em> Argo Events common.S3Artifact </em>

</td>

Expand Down Expand Up @@ -1496,8 +1495,7 @@ Time filter on the event with escalation

<td>

<code>context</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.EventContext </em>
<code>context</code></br> <em> Argo Events common.EventContext </em>

</td>

Expand Down Expand Up @@ -3245,8 +3243,7 @@ events

<td>

<code>event</code></br> <em>
github.com/argoproj/argo-events/pkg/apis/common.Event </em>
<code>event</code></br> <em> Argo Events common.Event </em>

</td>

Expand Down Expand Up @@ -6001,6 +5998,6 @@ VerifyCert decides whether the connection is secure or not
<p>

<em> Generated with <code>gen-crd-api-reference-docs</code> on git
commit <code>ce4ab23</code>. </em>
commit <code>7f3198f</code>. </em>

</p>
21 changes: 21 additions & 0 deletions gateways/server/gitlab/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ func (router *Router) PostActivate() error {

formattedUrl := common.FormattedURL(gitlabEventSource.Webhook.URL, gitlabEventSource.Webhook.Endpoint)

// Get existing webhooks and check if the integration for same url and event type is already available
if !gitlabEventSource.AllowDuplicate {
hooks, _, err := router.gitlabClient.Projects.ListProjectHooks(router.gitlabEventSource.ProjectId, &gitlab.ListProjectHooksOptions{})
if err != nil {
return errors.Wrapf(err, "failed to list existing hooks to check for duplicates for project id %s", router.gitlabEventSource.ProjectId)
}

for _, hook := range hooks {
elem := reflect.ValueOf(hook).Elem().FieldByName(router.gitlabEventSource.Event)
if ok := elem.IsValid(); !ok {
return errors.Errorf("unknown event %s", router.gitlabEventSource.Event)
}
value := elem.Bool()

if value && hook.URL == formattedUrl {
logger.Infoln("webhook already exists, won't register it...")
return nil
}
}
}

opt := &gitlab.AddProjectHookOptions{
URL: &formattedUrl,
Token: &c.token,
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/eventsources/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pkg/apis/eventsources/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ type SNSEventSource struct {
// RoleARN is the Amazon Resource Name (ARN) of the role to assume.
// +optional
RoleARN string `json:"roleARN,omitempty" protobuf:"bytes,6,opt,name=roleARN"`

}

// SQSEventSource refers to event-source for AWS SQS related events
Expand Down Expand Up @@ -331,6 +330,10 @@ type GitlabEventSource struct {
// DeleteHookOnFinish determines whether to delete the GitLab hook for the project once the event source is stopped.
// +optional
DeleteHookOnFinish bool `json:"deleteHookOnFinish,omitempty" protobuf:"bytes,8,opt,name=deleteHookOnFinish"`
// AllowDuplicate allows the gateway to register the same webhook integrations for multiple event source configurations.
// Defaults to false.
// +optional.
AllowDuplicate bool `json:"allowDuplicate,omitempty" protobuf:"bytes,9,opt,name=allowDuplicate"`
}

// HDFSEventSource refers to event-source for HDFS related events
Expand Down

0 comments on commit 4916c8b

Please sign in to comment.