From 07b730c7ad59d6c2dab4a8d244b92186dbdb89aa Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 22 Apr 2015 17:07:16 -0400 Subject: [PATCH] generic trigger credentials --- endpoints/trigger.py | 27 ++++++++++++++----- static/directives/credentials.html | 24 +++++++++++++++++ .../repo-view/repo-panel-builds.html | 2 +- static/directives/setup-trigger-dialog.html | 23 +++------------- .../trigger-credentials-dialog.html | 19 +------------ static/js/directives/ui/credentials.js | 16 +++++++++++ 6 files changed, 66 insertions(+), 45 deletions(-) create mode 100644 static/directives/credentials.html create mode 100644 static/js/directives/ui/credentials.js diff --git a/endpoints/trigger.py b/endpoints/trigger.py index 2f79a4a72..c81fdd96b 100644 --- a/endpoints/trigger.py +++ b/endpoints/trigger.py @@ -188,10 +188,16 @@ class GithubBuildTrigger(BuildTrigger): raise TriggerActivationException(msg) # Add a deploy key to the GitHub repository. + public_key, private_key = generate_ssh_keypair() + config['credentials'] = [ + { + 'name': 'SSH Public Key', + 'value': public_key, + }, + ] try: - config['public_key'], private_key = generate_ssh_keypair() deploy_key = gh_repo.create_key('%s Builder' % app.config['REGISTRY_TITLE'], - config['public_key']) + public_key) config['deploy_key_id'] = deploy_key.id except GithubException: msg = 'Unable to add deploy key to repository: %s' % new_build_source @@ -642,7 +648,7 @@ class CustomBuildTrigger(BuildTrigger): return 'custom-git' def is_active(self, config): - return 'public_key' in config + return config.has_key('credentials') def _metadata_from_payload(self, payload): try: @@ -673,12 +679,21 @@ class CustomBuildTrigger(BuildTrigger): return dockerfile_id, tags, build_name, trigger.config['subdir'], metadata def activate(self, trigger_uuid, standard_webhook_url, auth_token, config): - config['webhook_url'] = standard_webhook_url - config['public_key'], private_key = generate_ssh_keypair() + public_key, private_key = generate_ssh_keypair() + config['credentials'] = [ + { + 'name': 'SSH Public Key', + 'value': public_key, + }, + { + 'name': 'Webhook Endpoint URL', + 'value': standard_webhook_url, + }, + ] return config, private_key def deactivate(self, auth_token, config): - config.pop('public_key', None) + config.pop('credentials', None) return config def manual_start(self, trigger, run_parameters=None): diff --git a/static/directives/credentials.html b/static/directives/credentials.html new file mode 100644 index 000000000..e17e481af --- /dev/null +++ b/static/directives/credentials.html @@ -0,0 +1,24 @@ +
+ +
+

+ In order to use this trigger, the following first requires action: +

    +
  • You must give the following public key read access to the git repository.
  • +
  • You must set your repository to POST to the following URL to trigger a build.
  • +
+ For more information, refer to the Custom Git Triggers documentation. +

+
+
+

The following key has been automatically added to your GitHub repository.

+
+ + +
+

+ {{ credential.name }}: +

+

+
+
diff --git a/static/directives/repo-view/repo-panel-builds.html b/static/directives/repo-view/repo-panel-builds.html index c8eef1b6d..86a525b0b 100644 --- a/static/directives/repo-view/repo-panel-builds.html +++ b/static/directives/repo-view/repo-panel-builds.html @@ -140,7 +140,7 @@ - + View Credentials -
-
-
- The trigger has been successfully created, but the following first requires action: -
    -
  • You must give the following public key read access to the git repository.
  • -
  • You must set your repository to POST to the following URL to trigger a build.
  • -
- For more information, refer to the Custom Git Triggers documentation. -
-

- SSH Public Key: -

-

-

- Webhook Endpoint URL: -

-

-
-
+
+
+
The trigger has been successfully created.
diff --git a/static/directives/trigger-credentials-dialog.html b/static/directives/trigger-credentials-dialog.html index 8a00de291..9d0fb98e9 100644 --- a/static/directives/trigger-credentials-dialog.html +++ b/static/directives/trigger-credentials-dialog.html @@ -9,24 +9,7 @@