From 3542a520f58417de000846dd540df1ca041b5c62 Mon Sep 17 00:00:00 2001 From: jakedt Date: Mon, 17 Mar 2014 13:10:12 -0400 Subject: [PATCH] Fix bugs, mostly related to date formatting. --- endpoints/api/__init__.py | 2 +- endpoints/api/build.py | 26 +++++++++++++++++++++----- endpoints/api/image.py | 5 +++-- endpoints/api/logs.py | 9 +++++---- endpoints/api/permission.py | 2 +- endpoints/api/prototype.py | 6 ++---- endpoints/api/team.py | 1 - endpoints/api/trigger.py | 17 +---------------- endpoints/api/webhook.py | 4 +++- static/js/graphing.js | 2 +- templates/base.html | 8 ++++---- 11 files changed, 42 insertions(+), 40 deletions(-) diff --git a/endpoints/api/__init__.py b/endpoints/api/__init__.py index 1a70c566d..3b1ce6568 100644 --- a/endpoints/api/__init__.py +++ b/endpoints/api/__init__.py @@ -1,7 +1,7 @@ import logging import json -from flask import Blueprint, request, make_response +from flask import Blueprint, request from flask.ext.restful import Resource, abort, Api, reqparse from flask.ext.restful.utils.cors import crossdomain from calendar import timegm diff --git a/endpoints/api/build.py b/endpoints/api/build.py index f8daafa5a..6588a5b5b 100644 --- a/endpoints/api/build.py +++ b/endpoints/api/build.py @@ -7,8 +7,9 @@ from flask.ext.restful import abort from app import app from endpoints.api import (RepositoryParamResource, parse_args, query_param, nickname, resource, require_repo_read, require_repo_write, validate_json_request, - ApiResource, internal_only) + ApiResource, internal_only, format_date) from endpoints.common import start_build +from endpoints.trigger import BuildTrigger from data import model from auth.permissions import ModifyRepositoryPermission @@ -18,14 +19,28 @@ user_files = app.config['USERFILES'] build_logs = app.config['BUILDLOGS'] +def trigger_view(trigger): + if trigger and trigger.uuid: + config_dict = json.loads(trigger.config) + build_trigger = BuildTrigger.get_trigger_for_service(trigger.service.name) + return { + 'service': trigger.service.name, + 'config': config_dict, + 'id': trigger.uuid, + 'connected_user': trigger.connected_user.username, + 'is_active': build_trigger.is_active(config_dict) + } + + return None + + def build_status_view(build_obj, can_write=False): status = build_logs.get_status(build_obj.uuid) logger.debug('Can write: %s job_config: %s', can_write, build_obj.job_config) - build_obj.job_config = None resp = { 'id': build_obj.uuid, 'phase': build_obj.phase, - 'started': build_obj.started, + 'started': format_date(build_obj.started), 'display_name': build_obj.display_name, 'status': status, 'job_config': json.loads(build_obj.job_config) if can_write else None, @@ -33,8 +48,9 @@ def build_status_view(build_obj, can_write=False): 'trigger': trigger_view(build_obj.trigger), 'resource_key': build_obj.resource_key, } + if can_write: - resp['archive_url'] = user_files.get_file_url(build.resource_key) + resp['archive_url'] = user_files.get_file_url(build_obj.resource_key) return resp @@ -63,9 +79,9 @@ class RepositoryBuildList(RepositoryParamResource): }, } + @require_repo_read @parse_args @query_param('limit', 'The maximum number of builds to return', type=int, default=5) - @require_repo_read @nickname('getRepoBuilds') def get(self, args, namespace, repository): """ Get the list of repository builds. """ diff --git a/endpoints/api/image.py b/endpoints/api/image.py index f52e4544f..db0ebcc47 100644 --- a/endpoints/api/image.py +++ b/endpoints/api/image.py @@ -4,7 +4,8 @@ from collections import defaultdict from flask.ext.restful import abort from app import app -from endpoints.api import resource, nickname, require_repo_read, RepositoryParamResource +from endpoints.api import (resource, nickname, require_repo_read, RepositoryParamResource, + format_date) from data import model from util.cache import cache_control_flask_restful @@ -20,7 +21,7 @@ def image_view(image): command = extended_props.command return { 'id': image.docker_image_id, - 'created': extended_props.created, + 'created': format_date(extended_props.created), 'comment': extended_props.comment, 'command': json.loads(command) if command else None, 'ancestors': image.ancestors, diff --git a/endpoints/api/logs.py b/endpoints/api/logs.py index eaee69aae..eadfbab0d 100644 --- a/endpoints/api/logs.py +++ b/endpoints/api/logs.py @@ -4,7 +4,8 @@ from datetime import datetime, timedelta from flask.ext.restful import abort from endpoints.api import (resource, nickname, ApiResource, query_param, parse_args, - RepositoryParamResource, require_repo_admin, related_user_resource) + RepositoryParamResource, require_repo_admin, related_user_resource, + format_date) from auth.permissions import AdministerOrganizationPermission, AdministerOrganizationPermission from auth.auth_context import get_authenticated_user from data import model @@ -15,7 +16,7 @@ def log_view(log): 'kind': log.kind.name, 'metadata': json.loads(log.metadata_json), 'ip': log.ip, - 'datetime': log.datetime, + 'datetime': format_date(log.datetime), } if log.performer: @@ -56,8 +57,8 @@ def get_logs(namespace, start_time, end_time, performer_name=None, logs = model.list_logs(namespace, start_time, end_time, performer=performer, repository=repository) return { - 'start_time': start_time, - 'end_time': end_time, + 'start_time': format_date(start_time), + 'end_time': format_date(end_time), 'logs': [log_view(log) for log in logs] } diff --git a/endpoints/api/permission.py b/endpoints/api/permission.py index c7307575a..dd64b81eb 100644 --- a/endpoints/api/permission.py +++ b/endpoints/api/permission.py @@ -156,7 +156,7 @@ class RepositoryUserPermission(RepositoryParamResource): @require_repo_admin @nickname('deleteUserPermissions') - def delete(namespace, repository, username): + def delete(self, namespace, repository, username): """ Delete the permission for the user. """ try: model.delete_user_permission(username, namespace, repository) diff --git a/endpoints/api/prototype.py b/endpoints/api/prototype.py index c9098fe2f..2a3dc829a 100644 --- a/endpoints/api/prototype.py +++ b/endpoints/api/prototype.py @@ -156,10 +156,8 @@ class PermissionPrototypeList(ApiResource): delegate_username = delegate_name if delegate_kind == 'user' else None delegate_teamname = delegate_name if delegate_kind == 'team' else None - activating_user = (model.get_user(activating_username) - if activating_username else None) - delegate_user = (model.get_user(delegate_username) - if delegate_username else None) + activating_user = (model.get_user(activating_username) if activating_username else None) + delegate_user = (model.get_user(delegate_username) if delegate_username else None) delegate_team = (model.get_organization_team(orgname, delegate_teamname) if delegate_teamname else None) diff --git a/endpoints/api/team.py b/endpoints/api/team.py index 065e64a88..3049e4254 100644 --- a/endpoints/api/team.py +++ b/endpoints/api/team.py @@ -37,7 +37,6 @@ class OrganizationTeam(ApiResource): 'description': 'Description of a team', 'required': [ 'role', - 'description', ], 'properties': { 'role': { diff --git a/endpoints/api/trigger.py b/endpoints/api/trigger.py index e76876e1e..9410379ce 100644 --- a/endpoints/api/trigger.py +++ b/endpoints/api/trigger.py @@ -10,7 +10,7 @@ from app import app from endpoints.api import (RepositoryParamResource, nickname, resource, require_repo_admin, log_action, request_error, query_param, parse_args, validate_json_request) -from endpoints.api.build import build_status_view +from endpoints.api.build import build_status_view, trigger_view from endpoints.common import start_build from endpoints.trigger import (BuildTrigger, TriggerDeactivationException, TriggerActivationException, EmptyRepositoryException) @@ -21,21 +21,6 @@ from auth.permissions import UserPermission logger = logging.getLogger(__name__) -def trigger_view(trigger): - if trigger and trigger.uuid: - config_dict = json.loads(trigger.config) - build_trigger = BuildTrigger.get_trigger_for_service(trigger.service.name) - return { - 'service': trigger.service.name, - 'config': config_dict, - 'id': trigger.uuid, - 'connected_user': trigger.connected_user.username, - 'is_active': build_trigger.is_active(config_dict) - } - - return None - - def _prepare_webhook_url(scheme, username, password, hostname, path): auth_hostname = '%s:%s@%s' % (quote(username), quote(password), hostname) return urlunparse((scheme, auth_hostname, path, '', '', '')) diff --git a/endpoints/api/webhook.py b/endpoints/api/webhook.py index 9e9dbf5ca..ab260a4cd 100644 --- a/endpoints/api/webhook.py +++ b/endpoints/api/webhook.py @@ -1,3 +1,5 @@ +import json + from flask import request, url_for from flask.ext.restful import abort @@ -74,4 +76,4 @@ class Webhook(RepositoryParamResource): log_action('delete_repo_webhook', namespace, {'repo': repository, 'webhook_id': public_id}, repo=model.get_repository(namespace, repository)) - return make_response('No Content', 204) + return 'No Content', 204 diff --git a/static/js/graphing.js b/static/js/graphing.js index b4db1a78f..d8bb2e5ff 100644 --- a/static/js/graphing.js +++ b/static/js/graphing.js @@ -1450,7 +1450,7 @@ function LogUsageChart(titleMap) { * Builds the D3-representation of the data. */ LogUsageChart.prototype.buildData_ = function(logs) { - var parseDate = d3.time.format("%a, %d %b %Y %H:%M:%S GMT").parse + var parseDate = d3.time.format("%a, %d %b %Y %H:%M:%S %Z").parse // Build entries for each kind of event that occurred, on each day. We have one // entry per {kind, day} pair. diff --git a/templates/base.html b/templates/base.html index 3a9b23c89..0256d8632 100644 --- a/templates/base.html +++ b/templates/base.html @@ -117,12 +117,12 @@ var isProd = document.location.hostname === 'quay.io';