From 2656e3f3fa1315669ed3d3f22fdbfc3d3e19c535 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Tue, 14 Feb 2017 15:20:29 -0500 Subject: [PATCH 001/125] Insights project api side integration * Extend scm credential type to support username and password for redhat portal accounts * Update project update playbook to work with remote insights server --- awx/main/migrations/0036_v311_insights.py | 24 +++++++++++++++++++++ awx/main/models/projects.py | 7 +++++- awx/main/tasks.py | 4 ++++ awx/main/utils/common.py | 5 +++-- awx/playbooks/project_update.yml | 26 +++++++++++++++++++++++ awx/settings/defaults.py | 2 ++ 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 awx/main/migrations/0036_v311_insights.py diff --git a/awx/main/migrations/0036_v311_insights.py b/awx/main/migrations/0036_v311_insights.py new file mode 100644 index 0000000000..57baff9b5d --- /dev/null +++ b/awx/main/migrations/0036_v311_insights.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0035_v310_remove_tower_settings'), + ] + + operations = [ + migrations.AlterField( + model_name='project', + name='scm_type', + field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), + ), + migrations.AlterField( + model_name='projectupdate', + name='scm_type', + field=models.CharField(default=b'', choices=[(b'', 'Manual'), (b'git', 'Git'), (b'hg', 'Mercurial'), (b'svn', 'Subversion'), (b'insights', 'Red Hat Insights')], max_length=8, blank=True, help_text='Specifies the source control system used to store the project.', verbose_name='SCM Type'), + ), + ] diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index 9897067843..6f80fafd6a 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -43,6 +43,7 @@ class ProjectOptions(models.Model): ('git', _('Git')), ('hg', _('Mercurial')), ('svn', _('Subversion')), + ('insights', _('Red Hat Insights')), ] class Meta: @@ -120,6 +121,8 @@ class ProjectOptions(models.Model): return self.scm_type or '' def clean_scm_url(self): + if self.scm_type == 'insights': + self.scm_url = settings.INSIGHTS_URL_BASE scm_url = unicode(self.scm_url or '') if not self.scm_type: return '' @@ -139,8 +142,10 @@ class ProjectOptions(models.Model): cred = self.credential if cred: if cred.kind != 'scm': - raise ValidationError(_("Credential kind must be 'scm'.")) + raise ValidationError(_("Credential kind must be either 'scm'.")) try: + if self.scm_type == 'insights': + self.scm_url = settings.INSIGHTS_URL_BASE scm_url = update_scm_url(self.scm_type, self.scm_url, check_special_cases=False) scm_url_parts = urlparse.urlsplit(scm_url) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 91ef460f16..c96441c1c4 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -1189,6 +1189,9 @@ class RunProjectUpdate(BaseTask): scm_username = False elif scm_url_parts.scheme.endswith('ssh'): scm_password = False + elif scm_type == 'insights': + extra_vars['scm_username'] = scm_username + extra_vars['scm_password'] = scm_password scm_url = update_scm_url(scm_type, scm_url, scm_username, scm_password, scp_format=True) else: @@ -1218,6 +1221,7 @@ class RunProjectUpdate(BaseTask): scm_branch = project_update.scm_branch or {'hg': 'tip'}.get(project_update.scm_type, 'HEAD') extra_vars.update({ 'project_path': project_update.get_project_path(check_if_exists=False), + 'insights_url': settings.INSIGHTS_URL_BASE, 'scm_type': project_update.scm_type, 'scm_url': scm_url, 'scm_branch': scm_branch, diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 49d92b5f9c..50ccb3bf89 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -261,7 +261,7 @@ def update_scm_url(scm_type, url, username=True, password=True, # git: https://www.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS # hg: http://www.selenic.com/mercurial/hg.1.html#url-paths # svn: http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.advanced.reposurls - if scm_type not in ('git', 'hg', 'svn'): + if scm_type not in ('git', 'hg', 'svn', 'insights'): raise ValueError(_('Unsupported SCM type "%s"') % str(scm_type)) if not url.strip(): return '' @@ -307,6 +307,7 @@ def update_scm_url(scm_type, url, username=True, password=True, 'git': ('ssh', 'git', 'git+ssh', 'http', 'https', 'ftp', 'ftps', 'file'), 'hg': ('http', 'https', 'ssh', 'file'), 'svn': ('http', 'https', 'svn', 'svn+ssh', 'file'), + 'insights': ('http', 'https') } if parts.scheme not in scm_type_schemes.get(scm_type, ()): raise ValueError(_('Unsupported %s URL') % scm_type) @@ -342,7 +343,7 @@ def update_scm_url(scm_type, url, username=True, password=True, #raise ValueError('Password not supported for SSH with Mercurial.') netloc_password = '' - if netloc_username and parts.scheme != 'file': + if netloc_username and parts.scheme != 'file' and scm_type != "insights": netloc = u':'.join([urllib.quote(x) for x in (netloc_username, netloc_password) if x]) else: netloc = u'' diff --git a/awx/playbooks/project_update.yml b/awx/playbooks/project_update.yml index 0f4d354ff7..c42017b748 100644 --- a/awx/playbooks/project_update.yml +++ b/awx/playbooks/project_update.yml @@ -105,6 +105,32 @@ scm_version: "{{ scm_result['after'] }}" when: "'after' in scm_result" + - name: update project using insights + uri: + url: "{{insights_url}}/r/insights/v1/maintenance" + user: "{{scm_username|quote}}" + password: "{{scm_password|quote}}" + force_basic_auth: yes + when: scm_type == 'insights' + register: insights_output + + - name: Ensure the project directory is present + file: + dest: "{{project_path|quote}}" + state: directory + when: scm_type == 'insights' + + - name: Fetch Insights Playbook + get_url: + url: "{{insights_url}}/r/insights/v3/maintenance/{{item.maintenance_id}}/playbook" + dest: "{{project_path|quote}}/{{item.maintenance_id}}.yml" + url_username: "{{scm_username|quote}}" + url_password: "{{scm_password|quote}}" + force_basic_auth: yes + when: scm_type == 'insights' + with_items: "{{insights_output.json}}" + failed_when: false + - name: detect requirements.yml stat: path={{project_path|quote}}/roles/requirements.yml register: doesRequirementsExist diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 0901961fa5..e673e347a7 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -862,6 +862,8 @@ TOWER_ADMIN_ALERTS = True # Note: This setting may be overridden by database settings. TOWER_URL_BASE = "https://towerhost" +INSIGHTS_URL_BASE = "https://access.redhat.com" + TOWER_SETTINGS_MANIFEST = {} LOG_AGGREGATOR_ENABLED = False From 0ff837449b011aa714a723455df46d4f46847f2d Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Wed, 15 Feb 2017 16:58:04 -0500 Subject: [PATCH 002/125] adding insights support for project add --- awx/ui/client/src/controllers/Projects.js | 9 +++++++++ awx/ui/client/src/forms/Projects.js | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/controllers/Projects.js b/awx/ui/client/src/controllers/Projects.js index e97194c1b1..58cb8f165b 100644 --- a/awx/ui/client/src/controllers/Projects.js +++ b/awx/ui/client/src/controllers/Projects.js @@ -415,6 +415,7 @@ export function ProjectsAdd($scope, $rootScope, $compile, $location, $log, if ($scope.scm_type.value) { switch ($scope.scm_type.value) { case 'git': + $scope.credentialLabel = "SCM Credential"; $scope.urlPopover = '

' + i18n._('Example URLs for GIT SCM include:') + '