generic trigger credentials

This commit is contained in:
Jimmy Zelinskie 2015-04-22 17:07:16 -04:00
parent cfcd636cc0
commit 07b730c7ad
6 changed files with 66 additions and 45 deletions

View file

@ -188,10 +188,16 @@ class GithubBuildTrigger(BuildTrigger):
raise TriggerActivationException(msg) raise TriggerActivationException(msg)
# Add a deploy key to the GitHub repository. # 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: try:
config['public_key'], private_key = generate_ssh_keypair()
deploy_key = gh_repo.create_key('%s Builder' % app.config['REGISTRY_TITLE'], deploy_key = gh_repo.create_key('%s Builder' % app.config['REGISTRY_TITLE'],
config['public_key']) public_key)
config['deploy_key_id'] = deploy_key.id config['deploy_key_id'] = deploy_key.id
except GithubException: except GithubException:
msg = 'Unable to add deploy key to repository: %s' % new_build_source msg = 'Unable to add deploy key to repository: %s' % new_build_source
@ -642,7 +648,7 @@ class CustomBuildTrigger(BuildTrigger):
return 'custom-git' return 'custom-git'
def is_active(self, config): def is_active(self, config):
return 'public_key' in config return config.has_key('credentials')
def _metadata_from_payload(self, payload): def _metadata_from_payload(self, payload):
try: try:
@ -673,12 +679,21 @@ class CustomBuildTrigger(BuildTrigger):
return dockerfile_id, tags, build_name, trigger.config['subdir'], metadata return dockerfile_id, tags, build_name, trigger.config['subdir'], metadata
def activate(self, trigger_uuid, standard_webhook_url, auth_token, config): def activate(self, trigger_uuid, standard_webhook_url, auth_token, config):
config['webhook_url'] = standard_webhook_url public_key, private_key = generate_ssh_keypair()
config['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 return config, private_key
def deactivate(self, auth_token, config): def deactivate(self, auth_token, config):
config.pop('public_key', None) config.pop('credentials', None)
return config return config
def manual_start(self, trigger, run_parameters=None): def manual_start(self, trigger, run_parameters=None):

View file

@ -0,0 +1,24 @@
<div ng-switch on="trigger.service">
<!-- Message -->
<div ng-switch-when="custom-git" class="alert alert-info">
<p>
In order to use this trigger, the following first requires action:
<ul>
<li>You must give the following public key read access to the git repository.</li>
<li>You must set your repository to POST to the following URL to trigger a build.</li>
</ul>
For more information, refer to the <a href="http://docs.quay.io/guides/custom-trigger.html" target="_blank">Custom Git Triggers documentation</a>.
</p>
</div>
<div ng-switch-when="github" class="alert alert-info">
<p>The following key has been automatically added to your GitHub repository.</p>
</div>
<!-- Credentials -->
<div ng-repeat="credential in trigger.config.credentials">
<p>
{{ credential.name }}:
<div class="copy-box" value="credential.value"></div>
</p>
</div>
</div>

View file

@ -140,7 +140,7 @@
</td> </td>
<td> <td>
<span class="cor-options-menu"> <span class="cor-options-menu">
<span class="cor-option" option-click="showTriggerCredentialsModal(trigger)" ng-show="trigger.service == 'custom-git'"> <span ng-if="trigger.config.credentials" class="cor-option" option-click="showTriggerCredentialsModal(trigger)">
<i class="fa fa-unlock-alt"></i> View Credentials <i class="fa fa-unlock-alt"></i> View Credentials
</span> </span>
<span class="cor-option" option-click="askRunTrigger(trigger)" <span class="cor-option" option-click="askRunTrigger(trigger)"

View file

@ -113,26 +113,9 @@
</div> </div>
<div class="trigger-option-section" ng-show="currentView == 'postActivation'" ng-switch on="trigger.service"> <div class="trigger-option-section" ng-show="currentView == 'postActivation'">
<div ng-switch-when="custom-git"> <div ng-if="trigger.config.credentials" class="credentials" trigger="trigger"></div>
<div class="alert alert-warning"> <div ng-if="!trigger.config.credentials">
The trigger has been successfully created, but the following first requires action:
<ul>
<li>You must give the following public key read access to the git repository.</li>
<li>You must set your repository to POST to the following URL to trigger a build.</li>
</ul>
For more information, refer to the <a href="http://docs.quay.io/guides/custom-trigger.html" target="_blank">Custom Git Triggers documentation</a>.
</div>
<p>
SSH Public Key:
<div class="copy-box" value="trigger.config.public_key"></div>
</p>
<p>
Webhook Endpoint URL:
<div class="copy-box" value="trigger.config.webhook_url"></div>
</p>
</div>
<div ng-switch-default>
<div class="alert alert-success">The trigger has been successfully created.</div> <div class="alert alert-success">The trigger has been successfully created.</div>
</div> </div>
</div> </div>

View file

@ -9,24 +9,7 @@
</h4> </h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="alert alert-info"> <div class="credentials" trigger="trigger"></div>
<p>
In order to use this trigger, the following first requires action:
<ul>
<li>You must give the following public key read access to the git repository.</li>
<li>You must set your repository to POST to the following URL to trigger a build.</li>
</ul>
For more information, refer to the <a href="http://docs.quay.io/guides/custom-trigger.html" target="_blank">Custom Git Triggers documentation</a>.
</p>
</div>
<p>
SSH Public Key:
<div class="copy-box" value="trigger.config.public_key"></div>
</p>
<p>
Webhook Endpoint URL:
<div class="copy-box" value="trigger.config.webhook_url"></div>
</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Done</button> <button type="button" class="btn btn-default" data-dismiss="modal">Done</button>

View file

@ -0,0 +1,16 @@
/**
* An element which displays a credentials for a build trigger.
*/
angular.module('quay').directive('credentials', function() {
var directiveDefinitionObject = {
templateUrl: '/static/directives/credentials.html',
replace: false,
transclude: false,
restrict: 'C',
scope: {
'trigger': '=trigger'
},
controller: function($scope) {}
};
return directiveDefinitionObject;
});