Skip to content

Commit

Permalink
Drop Bitbucket support
Browse files Browse the repository at this point in the history
since only the Bitbucket Server product supports signed payloads,
bitbucket.org does not.  And we are requiring signed payloads.
  • Loading branch information
jbradberry committed Sep 30, 2019
1 parent f7396cf commit 885841c
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 74 deletions.
2 changes: 0 additions & 2 deletions awx/api/urls/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
WebhookKeyView,
GithubWebhookReceiver,
GitlabWebhookReceiver,
BitbucketWebhookReceiver,
)


urlpatterns = [
url(r'^webhook_key/$', WebhookKeyView.as_view(), name='webhook_key'),
url(r'^github/$', GithubWebhookReceiver.as_view(), name='webhook_receiver_github'),
url(r'^gitlab/$', GitlabWebhookReceiver.as_view(), name='webhook_receiver_gitlab'),
url(r'^bitbucket/$', BitbucketWebhookReceiver.as_view(), name='webhook_receiver_bitbucket'),
]
1 change: 0 additions & 1 deletion awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
WebhookKeyView,
GithubWebhookReceiver,
GitlabWebhookReceiver,
BitbucketWebhookReceiver,
)


Expand Down
49 changes: 0 additions & 49 deletions awx/api/views/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,52 +240,3 @@ def check_signature(self, obj):
# analysis by attackers.
if not hmac.compare_digest(force_bytes(obj.webhook_key), self.get_signature()):
raise PermissionDenied


class BitbucketWebhookReceiver(WebhookReceiverBase):
service = 'bitbucket'

ref_keys = {
# Bitbucket Server
'repo:refs_changed': 'changes.0.toHash',
'repo:comment:added': 'commit',
'repo:comment:edited': 'commit',
'repo:comment:deleted': 'commit',
'pr:opened': 'pullRequest.fromRef.latestCommit',
'pr:modified': 'pullRequest.fromRef.latestCommit',
'pr:reviewer:updated': 'pullRequest.fromRef.latestCommit',
'pr:reviewer:approved': 'pullRequest.fromRef.latestCommit',
'pr:reviewer:unapproved': 'pullRequest.fromRef.latestCommit',
'pr:reviewer:needs_work': 'pullRequest.fromRef.latestCommit',
'pr:merged': 'pullRequest.fromRef.latestCommit',
'pr:declined': 'pullRequest.fromRef.latestCommit',
'pr:deleted': 'pullRequest.fromRef.latestCommit',
'pr:comment:added': 'pullRequest.fromRef.latestCommit',
'pr:comment:edited': 'pullRequest.fromRef.latestCommit',
'pr:comment:deleted': 'pullRequest.fromRef.latestCommit',

# Bitbucket Cloud, aka bitbucket.org
'repo:push': 'push.changes.0.new.target.hash',
'repo:commit_comment_created': 'commit.hash',
'pullrequest:created': 'pullrequest.source.commit',
'pullrequest:updated': 'pullrequest.source.commit',
'pullrequest:approved': 'pullrequest.source.commit',
'pullrequest:unapproved': 'pullrequest.source.commit',
'pullrequest:fulfilled': 'pullrequest.source.commit',
'pullrequest:rejected': 'pullrequest.source.commit',
'pullrequest:comment_created': 'pullrequest.source.commit',
'pullrequest:comment_updated': 'pullrequest.source.commit',
'pullrequest:comment_deleted': 'pullrequest.source.commit',
}

def get_event_type(self):
return self.request.META.get('HTTP_X_EVENT_KEY')

def get_event_guid(self):
return self.request.META.get('HTTP_X_REQUEST_UUID')

def get_signature(self):
header_sig = self.request.META.get('HTTP_X_HUB_SIGNATURE')
if not header_sig:
raise PermissionDenied
return force_bytes(header_sig)
4 changes: 2 additions & 2 deletions awx/main/migrations/0092_v360_webhook_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='jobtemplate',
name='webhook_service',
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab'), ('bitbucket', 'Bitbucket')], max_length=16),
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab')], max_length=16),
),
migrations.AddField(
model_name='workflowjobtemplate',
Expand All @@ -39,6 +39,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='workflowjobtemplate',
name='webhook_service',
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab'), ('bitbucket', 'Bitbucket')], max_length=16),
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab')], max_length=16),
),
]
4 changes: 2 additions & 2 deletions awx/main/migrations/0094_v360_webhook_mixin2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='job',
name='webhook_service',
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab'), ('bitbucket', 'Bitbucket')], max_length=16),
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab')], max_length=16),
),
migrations.AddField(
model_name='workflowjob',
Expand All @@ -39,6 +39,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='workflowjob',
name='webhook_service',
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab'), ('bitbucket', 'Bitbucket')], max_length=16),
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab')], max_length=16),
),
]
16 changes: 0 additions & 16 deletions awx/main/models/credential/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,22 +1001,6 @@ def create(self):
},
)

ManagedCredentialType(
namespace='bitbucket_token',
kind='token',
name=ugettext_noop('Bitbucket Personal Access Token'),
managed_by_tower=True,
inputs={
'fields': [{
'id': 'token',
'label': ugettext_noop('Token'),
'type': 'string',
'secret': True,
}],
'required': ['token'],
},
)

ManagedCredentialType(
namespace='insights',
kind='insights',
Expand Down
1 change: 0 additions & 1 deletion awx/main/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ class Meta:
SERVICES = [
('github', "Github"),
('gitlab', "Gitlab"),
('bitbucket', "Bitbucket"),
]

webhook_service = models.CharField(
Expand Down
1 change: 0 additions & 1 deletion awx/main/tests/functional/test_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def test_default_cred_types():
'aws',
'azure_kv',
'azure_rm',
'bitbucket_token',
'cloudforms',
'conjur',
'gce',
Expand Down

0 comments on commit 885841c

Please sign in to comment.