UNPKG

harbor-ui-master

Version:

Harbor shared UI components based on Clarity and Angular4

1,232 lines (1,213 loc) 317 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/http'), require('rxjs/Observable'), require('rxjs/add/operator/toPromise'), require('rxjs/add/observable/of'), require('rxjs/Subject'), require('rxjs/add/operator/debounceTime'), require('rxjs/add/operator/distinctUntilChanged'), require('@ngx-translate/core'), require('@angular/router'), require('@angular/forms'), require('rxjs/Rx'), require('@angular/common'), require('clarity-angular'), require('@ngx-translate/http-loader'), require('ngx-cookie'), require('@angular/platform-browser')) : typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/http', 'rxjs/Observable', 'rxjs/add/operator/toPromise', 'rxjs/add/observable/of', 'rxjs/Subject', 'rxjs/add/operator/debounceTime', 'rxjs/add/operator/distinctUntilChanged', '@ngx-translate/core', '@angular/router', '@angular/forms', 'rxjs/Rx', '@angular/common', 'clarity-angular', '@ngx-translate/http-loader', 'ngx-cookie', '@angular/platform-browser'], factory) : (factory((global.harborui = global.harborui || {}),global.ng.core,global.ng.http,global.Rx,global.Rx.Observable.prototype,global.Rx.Observable,global.rxjs.Subject,null,null,global.ngx.translate,global.ng.router,global.ng.forms,global.Rx,global.ng.common,global.ng.clarity,global.ngx.translate,global.ngx.cookie,global.ng.platformBrowser)); }(this, (function (exports,_angular_core,_angular_http,rxjs_Observable,rxjs_add_operator_toPromise,rxjs_add_observable_of,rxjs_Subject,rxjs_add_operator_debounceTime,rxjs_add_operator_distinctUntilChanged,_ngxTranslate_core,_angular_router,_angular_forms,rxjs_Rx,_angular_common,clarityAngular,_ngxTranslate_httpLoader,ngxCookie,_angular_platformBrowser) { 'use strict'; (function (VulnerabilitySeverity) { VulnerabilitySeverity[VulnerabilitySeverity["_SEVERITY"] = 0] = "_SEVERITY"; VulnerabilitySeverity[VulnerabilitySeverity["NONE"] = 1] = "NONE"; VulnerabilitySeverity[VulnerabilitySeverity["UNKNOWN"] = 2] = "UNKNOWN"; VulnerabilitySeverity[VulnerabilitySeverity["LOW"] = 3] = "LOW"; VulnerabilitySeverity[VulnerabilitySeverity["MEDIUM"] = 4] = "MEDIUM"; VulnerabilitySeverity[VulnerabilitySeverity["HIGH"] = 5] = "HIGH"; })(exports.VulnerabilitySeverity || (exports.VulnerabilitySeverity = {})); var SERVICE_CONFIG = new _angular_core.OpaqueToken("service.config"); /** * Convert the different async channels to the Promise<T> type. * * @export * @template T * @param {(Observable<T> | Promise<T> | T)} async * @returns {Promise<T>} */ function toPromise(async) { if (!async) { return Promise.reject("Bad argument"); } if (async instanceof rxjs_Observable.Observable) { var obs = async; return obs.toPromise(); } else { return Promise.resolve(async); } } /** * The default cookie key used to store current used language preference. */ var DEFAULT_LANG_COOKIE_KEY = 'harbor-lang'; /** * Declare what languages are supported now. */ var DEFAULT_SUPPORTING_LANGS = ['en-us', 'zh-cn', 'es-es']; /** * The default language. */ var DEFAULT_LANG = 'en-us'; var HTTP_JSON_OPTIONS = new _angular_http.RequestOptions({ headers: new _angular_http.Headers({ "Content-Type": 'application/json', "Accept": 'application/json' }) }); var HTTP_GET_OPTIONS = new _angular_http.RequestOptions({ headers: new _angular_http.Headers({ "Content-Type": 'application/json', "Accept": 'application/json', "Cache-Control": 'no-cache', "Pragma": 'no-cache' }) }); /** * Build http request options * * @export * @param {RequestQueryParams} params * @returns {RequestOptions} */ function buildHttpRequestOptions(params) { var reqOptions = new _angular_http.RequestOptions({ headers: new _angular_http.Headers({ "Content-Type": 'application/json', "Accept": 'application/json', "Cache-Control": 'no-cache', "Pragma": 'no-cache' }) }); if (params) { reqOptions.search = params; } return reqOptions; } /** Button events to pass to `DebugElement.triggerEventHandler` for RouterLink event handler */ /** Simulate element click. Defaults to mouse left-button click event. */ /** * Comparator for fields with specific type. * */ var CustomComparator = (function () { function CustomComparator(fieldName, type) { this.fieldName = fieldName; this.type = type; } CustomComparator.prototype.compare = function (a, b) { var comp = 0; if (a && b) { var fieldA = a[this.fieldName]; var fieldB = b[this.fieldName]; switch (this.type) { case "number": comp = fieldB - fieldA; break; case "date": comp = new Date(fieldB).getTime() - new Date(fieldA).getTime(); break; } } return comp; }; return CustomComparator; }()); /** * The default page size */ var DEFAULT_PAGE_SIZE = 15; /** * The state of vulnerability scanning */ var VULNERABILITY_SCAN_STATUS = { unknown: "n/a", pending: "pending", running: "running", error: "error", stopped: "stopped", finished: "finished" }; /** * Calculate page number by state */ function calculatePage(state) { if (!state || !state.page) { return 1; } return Math.ceil((state.page.to + 1) / state.page.size); } /** * Filter columns via RegExp * * @export * @param {State} state * @returns {void} */ function doFiltering(items, state) { if (!items || items.length === 0) { return items; } if (!state || !state.filters || state.filters.length === 0) { return items; } state.filters.forEach(function (filter) { items = items.filter(function (item) { return regexpFilter(filter["value"], item[filter["property"]]); }); }); return items; } /** * Match items via RegExp * * @export * @param {string} terms * @param {*} testedValue * @returns {boolean} */ function regexpFilter(terms, testedValue) { var reg = new RegExp('.*' + terms + '.*', 'i'); return reg.test(testedValue); } /** * Sorting the data by column * * @export * @template T * @param {T[]} items * @param {State} state * @returns {T[]} */ function doSorting(items, state) { if (!items || items.length === 0) { return items; } if (!state || !state.sort) { return items; } return items.sort(function (a, b) { var comp = 0; if (typeof state.sort.by !== "string") { comp = state.sort.by.compare(a, b); } else { var propA = a[state.sort.by.toString()], propB = b[state.sort.by.toString()]; if (typeof propA === "string") { comp = propA.localeCompare(propB); } else { if (propA > propB) { comp = 1; } else if (propA < propB) { comp = -1; } } } if (state.sort.reverse) { comp = -comp; } return comp; }); } /** * Compare the two objects to adjust if they're equal * * @export * @param {*} a * @param {*} b * @returns {boolean} */ function compareValue(a, b) { if ((a && !b) || (!a && b)) return false; if (!a && !b) return true; return JSON.stringify(a) === JSON.stringify(b); } /** * Check if the object is null or empty '{}' * * @export * @param {*} obj * @returns {boolean} */ function isEmptyObject(obj) { return !obj || JSON.stringify(obj) === "{}"; } /** * Deeper clone all * * @export * @param {*} srcObj * @returns {*} */ function clone(srcObj) { if (!srcObj) return null; return JSON.parse(JSON.stringify(srcObj)); } var __extends = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Get System information about current backend server. * @abstract * @class */ var SystemInfoService = (function () { function SystemInfoService() { } return SystemInfoService; }()); var SystemInfoDefaultService = (function (_super) { __extends(SystemInfoDefaultService, _super); function SystemInfoDefaultService(config, http) { var _this = _super.call(this) || this; _this.config = config; _this.http = http; return _this; } SystemInfoDefaultService.prototype.getSystemInfo = function () { var url = this.config.systemInfoEndpoint ? this.config.systemInfoEndpoint : '/api/systeminfo'; return this.http.get(url, HTTP_GET_OPTIONS) .toPromise() .then(function (systemInfo) { return systemInfo.json(); }) .catch(function (error) { return Promise.reject(error); }); }; return SystemInfoDefaultService; }(SystemInfoService)); SystemInfoDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ SystemInfoDefaultService.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, { type: _angular_http.Http, }, ]; }; var __extends$1 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Define service methods to handle the access log related things. * * @export * @abstract * @class AccessLogService */ var AccessLogService = (function () { function AccessLogService() { } return AccessLogService; }()); /** * Implement a default service for access log. * * @export * @class AccessLogDefaultService * @extends {AccessLogService} */ var AccessLogDefaultService = (function (_super) { __extends$1(AccessLogDefaultService, _super); function AccessLogDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; return _this; } AccessLogDefaultService.prototype.getAuditLogs = function (projectId, queryParams) { return rxjs_Observable.Observable.of({}); }; AccessLogDefaultService.prototype.getRecentLogs = function (queryParams) { var url = this.config.logBaseEndpoint ? this.config.logBaseEndpoint : ""; if (url === '') { url = '/api/logs'; } return this.http.get(url, queryParams ? buildHttpRequestOptions(queryParams) : HTTP_GET_OPTIONS).toPromise() .then(function (response) { var result = { metadata: { xTotalCount: 0 }, data: [] }; var xHeader = "0"; if (response && response.headers) { xHeader = response.headers.get("X-Total-Count"); } if (result && result.metadata) { result.metadata.xTotalCount = parseInt(xHeader ? xHeader : "0", 0); if (result.metadata.xTotalCount > 0) { result.data = response.json(); } } return result; }) .catch(function (error) { return Promise.reject(error); }); }; return AccessLogDefaultService; }(AccessLogService)); AccessLogDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ AccessLogDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$3 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Wrap the class 'URLSearchParams' for future extending requirements. * Currently no extra methods provided. * * @export * @class RequestQueryParams * @extends {URLSearchParams} */ var RequestQueryParams = (function (_super) { __extends$3(RequestQueryParams, _super); function RequestQueryParams() { return _super.call(this) || this; } return RequestQueryParams; }(_angular_http.URLSearchParams)); var __extends$2 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Define the service methods to handle the endpoint related things. * * @export * @abstract * @class EndpointService */ var EndpointService = (function () { function EndpointService() { } return EndpointService; }()); /** * Implement default service for endpoint. * * @export * @class EndpointDefaultService * @extends {EndpointService} */ var EndpointDefaultService = (function (_super) { __extends$2(EndpointDefaultService, _super); function EndpointDefaultService(config, http) { var _this = _super.call(this) || this; _this.http = http; _this._endpointUrl = config.targetBaseEndpoint ? config.targetBaseEndpoint : '/api/targets'; return _this; } EndpointDefaultService.prototype.getEndpoints = function (endpointName, queryParams) { if (!queryParams) { queryParams = new RequestQueryParams(); } if (endpointName) { queryParams.set('name', endpointName); } var requestUrl = "" + this._endpointUrl; return this.http .get(requestUrl, buildHttpRequestOptions(queryParams)) .toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; EndpointDefaultService.prototype.getEndpoint = function (endpointId) { if (!endpointId || endpointId <= 0) { return Promise.reject('Bad request argument.'); } var requestUrl = this._endpointUrl + "/" + endpointId; return this.http .get(requestUrl, HTTP_GET_OPTIONS) .toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; EndpointDefaultService.prototype.createEndpoint = function (endpoint) { if (!endpoint) { return Promise.reject('Invalid endpoint.'); } var requestUrl = "" + this._endpointUrl; return this.http .post(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS) .toPromise() .then(function (response) { return response.status; }) .catch(function (error) { return Promise.reject(error); }); }; EndpointDefaultService.prototype.updateEndpoint = function (endpointId, endpoint) { if (!endpointId || endpointId <= 0) { return Promise.reject('Bad request argument.'); } if (!endpoint) { return Promise.reject('Invalid endpoint.'); } var requestUrl = this._endpointUrl + "/" + endpointId; return this.http .put(requestUrl, JSON.stringify(endpoint), HTTP_JSON_OPTIONS) .toPromise() .then(function (response) { return response.status; }) .catch(function (error) { return Promise.reject(error); }); }; EndpointDefaultService.prototype.deleteEndpoint = function (endpointId) { if (!endpointId || endpointId <= 0) { return Promise.reject('Bad request argument.'); } var requestUrl = this._endpointUrl + "/" + endpointId; return this.http .delete(requestUrl) .toPromise() .then(function (response) { return response.status; }) .catch(function (error) { return Promise.reject(error); }); }; EndpointDefaultService.prototype.pingEndpoint = function (endpoint) { if (!endpoint) { return Promise.reject('Invalid endpoint.'); } var requestUrl = this._endpointUrl + "/ping"; return this.http .post(requestUrl, endpoint, HTTP_JSON_OPTIONS) .toPromise() .then(function (response) { return response.status; }) .catch(function (error) { return Promise.reject(error); }); }; EndpointDefaultService.prototype.getEndpointWithReplicationRules = function (endpointId) { if (!endpointId || endpointId <= 0) { return Promise.reject('Bad request argument.'); } var requestUrl = this._endpointUrl + "/" + endpointId + "/policies"; return this.http .get(requestUrl, HTTP_GET_OPTIONS) .toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; return EndpointDefaultService; }(EndpointService)); EndpointDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ EndpointDefaultService.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, { type: _angular_http.Http, }, ]; }; var __extends$4 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Define the service methods to handle the replication (rule and job) related things. * * @export * @abstract * @class ReplicationService */ var ReplicationService = (function () { function ReplicationService() { } return ReplicationService; }()); /** * Implement default service for replication rule and job. * * @export * @class ReplicationDefaultService * @extends {ReplicationService} */ var ReplicationDefaultService = (function (_super) { __extends$4(ReplicationDefaultService, _super); function ReplicationDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this._ruleBaseUrl = config.replicationRuleEndpoint ? config.replicationRuleEndpoint : '/api/policies/replication'; _this._jobBaseUrl = config.replicationJobEndpoint ? config.replicationJobEndpoint : '/api/jobs/replication'; return _this; } //Private methods //Check if the rule object is valid ReplicationDefaultService.prototype._isValidRule = function (rule) { return rule !== undefined && rule != null && rule.name !== undefined && rule.name.trim() !== '' && rule.target_id !== 0; }; ReplicationDefaultService.prototype.getReplicationRules = function (projectId, ruleName, queryParams) { if (!queryParams) { queryParams = new RequestQueryParams(); } if (projectId) { queryParams.set('project_id', '' + projectId); } if (ruleName) { queryParams.set('name', ruleName); } return this.http.get(this._ruleBaseUrl, buildHttpRequestOptions(queryParams)).toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.getReplicationRule = function (ruleId) { if (!ruleId) { return Promise.reject("Bad argument"); } var url = this._ruleBaseUrl + "/" + ruleId; return this.http.get(url, HTTP_GET_OPTIONS).toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.createReplicationRule = function (replicationRule) { if (!this._isValidRule(replicationRule)) { return Promise.reject('Bad argument'); } return this.http.post(this._ruleBaseUrl, JSON.stringify(replicationRule), HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.updateReplicationRule = function (replicationRule) { if (!this._isValidRule(replicationRule) || !replicationRule.id) { return Promise.reject('Bad argument'); } var url = this._ruleBaseUrl + "/" + replicationRule.id; return this.http.put(url, JSON.stringify(replicationRule), HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.deleteReplicationRule = function (ruleId) { if (!ruleId || ruleId <= 0) { return Promise.reject('Bad argument'); } var url = this._ruleBaseUrl + "/" + ruleId; return this.http.delete(url, HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.enableReplicationRule = function (ruleId, enablement) { if (!ruleId || ruleId <= 0) { return Promise.reject('Bad argument'); } var url = this._ruleBaseUrl + "/" + ruleId + "/enablement"; return this.http.put(url, { enabled: enablement }, HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.disableReplicationRule = function (ruleId) { if (!ruleId || ruleId <= 0) { return Promise.reject('Bad argument'); } var url = this._ruleBaseUrl + "/" + ruleId + "/enablement"; return this.http.put(url, { enabled: 0 }, HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.getJobs = function (ruleId, queryParams) { if (!ruleId || ruleId <= 0) { return Promise.reject('Bad argument'); } if (!queryParams) { queryParams = new RequestQueryParams(); } queryParams.set('policy_id', '' + ruleId); return this.http.get(this._jobBaseUrl, buildHttpRequestOptions(queryParams)).toPromise() .then(function (response) { var result = { metadata: { xTotalCount: 0 }, data: [] }; if (response && response.headers) { var xHeader = response.headers.get("X-Total-Count"); if (xHeader) { result.metadata.xTotalCount = parseInt(xHeader, 0); } } result.data = response.json(); if (result.metadata.xTotalCount === 0) { if (result.data && result.data.length > 0) { result.metadata.xTotalCount = result.data.length; } } return result; }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.prototype.getJobLog = function (jobId) { if (!jobId || jobId <= 0) { return Promise.reject('Bad argument'); } var logUrl = this._jobBaseUrl + "/" + jobId + "/log"; return this.http.get(logUrl, HTTP_GET_OPTIONS).toPromise() .then(function (response) { return response.text(); }) .catch(function (error) { return Promise.reject(error); }); }; return ReplicationDefaultService; }(ReplicationService)); ReplicationDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ ReplicationDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$5 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Define service methods for handling the repository related things. * Loose couple with project module. * * @export * @abstract * @class RepositoryService */ var RepositoryService = (function () { function RepositoryService() { } return RepositoryService; }()); /** * Implement default service for repository. * * @export * @class RepositoryDefaultService * @extends {RepositoryService} */ var RepositoryDefaultService = (function (_super) { __extends$5(RepositoryDefaultService, _super); function RepositoryDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; return _this; } RepositoryDefaultService.prototype.getRepositories = function (projectId, repositoryName, queryParams) { if (!projectId) { return Promise.reject("Bad argument"); } if (!queryParams) { queryParams = new RequestQueryParams(); } queryParams.set('project_id', "" + projectId); if (repositoryName && repositoryName.trim() !== '') { queryParams.set('q', repositoryName); } var url = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : "/api/repositories"; return this.http.get(url, buildHttpRequestOptions(queryParams)).toPromise() .then(function (response) { var result = { metadata: { xTotalCount: 0 }, data: [] }; if (response && response.headers) { var xHeader = response.headers.get("X-Total-Count"); if (xHeader) { result.metadata.xTotalCount = parseInt(xHeader, 0); } } result.data = response.json(); if (result.metadata.xTotalCount === 0) { if (result.data && result.data.length > 0) { result.metadata.xTotalCount = result.data.length; } } return result; }) .catch(function (error) { return Promise.reject(error); }); }; RepositoryDefaultService.prototype.deleteRepository = function (repositoryName) { if (!repositoryName) { return Promise.reject('Bad argument'); } var url = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories'; url = url + "/" + repositoryName; return this.http.delete(url, HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { Promise.reject(error); }); }; return RepositoryDefaultService; }(RepositoryService)); RepositoryDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ RepositoryDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$6 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * For getting tag signatures. * This is temporary, will be removed in future. * * @export * @class VerifiedSignature */ var VerifiedSignature = (function () { function VerifiedSignature() { } return VerifiedSignature; }()); /** * Define the service methods to handle the repository tag related things. * * @export * @abstract * @class TagService */ var TagService = (function () { function TagService() { } return TagService; }()); /** * Implement default service for tag. * * @export * @class TagDefaultService * @extends {TagService} */ var TagDefaultService = (function (_super) { __extends$6(TagDefaultService, _super); function TagDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; _this._baseUrl = _this.config.repositoryBaseEndpoint ? _this.config.repositoryBaseEndpoint : '/api/repositories'; return _this; } //Private methods //These two methods are temporary, will be deleted in future after API refactored TagDefaultService.prototype._getTags = function (repositoryName, queryParams) { if (!queryParams) { queryParams = new RequestQueryParams(); } queryParams.set('detail', '1'); var url = this._baseUrl + "/" + repositoryName + "/tags"; return this.http.get(url, buildHttpRequestOptions(queryParams)).toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; TagDefaultService.prototype._getSignatures = function (repositoryName) { var url = this._baseUrl + "/" + repositoryName + "/signatures"; return this.http.get(url, HTTP_GET_OPTIONS).toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; TagDefaultService.prototype.getTags = function (repositoryName, queryParams) { if (!repositoryName) { return Promise.reject("Bad argument"); } return this._getTags(repositoryName, queryParams); }; TagDefaultService.prototype.deleteTag = function (repositoryName, tag) { if (!repositoryName || !tag) { return Promise.reject("Bad argument"); } var url = this._baseUrl + "/" + repositoryName + "/tags/" + tag; return this.http.delete(url, HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; TagDefaultService.prototype.getTag = function (repositoryName, tag, queryParams) { if (!repositoryName || !tag) { return Promise.reject("Bad argument"); } var url = this._baseUrl + "/" + repositoryName + "/tags/" + tag; return this.http.get(url, HTTP_GET_OPTIONS).toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; return TagDefaultService; }(TagService)); TagDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ TagDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$7 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Get the vulnerabilities scanning results for the specified tag. * * @export * @abstract * @class ScanningResultService */ var ScanningResultService = (function () { function ScanningResultService() { } return ScanningResultService; }()); var ScanningResultDefaultService = (function (_super) { __extends$7(ScanningResultDefaultService, _super); function ScanningResultDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; _this._baseUrl = '/api/repositories'; if (_this.config && _this.config.vulnerabilityScanningBaseEndpoint) { _this._baseUrl = _this.config.vulnerabilityScanningBaseEndpoint; } return _this; } ScanningResultDefaultService.prototype.getVulnerabilityScanningSummary = function (repoName, tagId, queryParams) { if (!repoName || repoName.trim() === '' || !tagId || tagId.trim() === '') { return Promise.reject('Bad argument'); } return rxjs_Observable.Observable.of({}); }; ScanningResultDefaultService.prototype.getVulnerabilityScanningResults = function (repoName, tagId, queryParams) { if (!repoName || repoName.trim() === '' || !tagId || tagId.trim() === '') { return Promise.reject('Bad argument'); } return this.http.get(this._baseUrl + "/" + repoName + "/tags/" + tagId + "/vulnerability/details", buildHttpRequestOptions(queryParams)).toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; ScanningResultDefaultService.prototype.startVulnerabilityScanning = function (repoName, tagId) { if (!repoName || repoName.trim() === '' || !tagId || tagId.trim() === '') { return Promise.reject('Bad argument'); } return this.http.post(this._baseUrl + "/" + repoName + "/tags/" + tagId + "/scan", HTTP_JSON_OPTIONS).toPromise() .then(function () { return true; }) .catch(function (error) { return Promise.reject(error); }); }; ScanningResultDefaultService.prototype.startScanningAll = function () { return this.http.post(this._baseUrl + "/scanAll", HTTP_JSON_OPTIONS).toPromise() .then(function () { return true; }) .catch(function (error) { return Promise.reject(error); }); }; return ScanningResultDefaultService; }(ScanningResultService)); ScanningResultDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ ScanningResultDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$8 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Service used to get and save registry-related configurations. * * @export * @abstract * @class ConfigurationService */ var ConfigurationService = (function () { function ConfigurationService() { } return ConfigurationService; }()); var ConfigurationDefaultService = (function (_super) { __extends$8(ConfigurationDefaultService, _super); function ConfigurationDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; _this._baseUrl = _this.config && _this.config.configurationEndpoint ? _this.config.configurationEndpoint : "/api/configurations"; return _this; } ConfigurationDefaultService.prototype.getConfigurations = function () { return this.http.get(this._baseUrl, HTTP_GET_OPTIONS).toPromise() .then(function (response) { return response.json(); }) .catch(function (error) { return Promise.reject(error); }); }; ConfigurationDefaultService.prototype.saveConfigurations = function (changedConfigs) { if (!changedConfigs) { return Promise.reject("Bad argument!"); } return this.http.put(this._baseUrl, JSON.stringify(changedConfigs), HTTP_JSON_OPTIONS) .toPromise() .then(function () { }) .catch(function (error) { return Promise.reject(error); }); }; return ConfigurationDefaultService; }(ConfigurationService)); ConfigurationDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ ConfigurationDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$9 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Define the service methods to handle the job log related things. * * @export * @abstract * @class JobLogService */ var JobLogService = (function () { function JobLogService() { } return JobLogService; }()); /** * Implement default service for job log service. * * @export * @class JobLogDefaultService * @extends {ReplicationService} */ var JobLogDefaultService = (function (_super) { __extends$9(JobLogDefaultService, _super); function JobLogDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this._replicationJobBaseUrl = config.replicationJobEndpoint ? config.replicationJobEndpoint : '/api/jobs/replication'; _this._scanningJobBaseUrl = config.scanJobEndpoint ? config.scanJobEndpoint : "/api/jobs/scan"; _this._supportedJobTypes = ["replication", "scan"]; return _this; } JobLogDefaultService.prototype._getJobLog = function (logUrl) { return this.http.get(logUrl, HTTP_GET_OPTIONS).toPromise() .then(function (response) { return response.text(); }) .catch(function (error) { return Promise.reject(error); }); }; JobLogDefaultService.prototype._isSupportedJobType = function (jobType) { if (this._supportedJobTypes.find(function (t) { return t === jobType; })) { return true; } return false; }; JobLogDefaultService.prototype.getJobLog = function (jobType, jobId) { if (!this._isSupportedJobType(jobType)) { return Promise.reject("Unsupport job type: " + jobType); } if (!jobId || jobId <= 0) { return Promise.reject('Bad argument'); } var logUrl = this._replicationJobBaseUrl + "/" + jobId + "/log"; if (jobType === "scan") { logUrl = this._scanningJobBaseUrl + "/" + jobId + "/log"; } return this._getJobLog(logUrl); }; return JobLogDefaultService; }(JobLogService)); JobLogDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ JobLogDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$10 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Define the service methods to handle the Prject related things. * * @export * @abstract * @class ProjectService */ var ProjectService = (function () { function ProjectService() { } return ProjectService; }()); /** * Implement default service for project. * * @export * @class ProjectDefaultService * @extends {ProjectService} */ var ProjectDefaultService = (function (_super) { __extends$10(ProjectDefaultService, _super); function ProjectDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; return _this; } ProjectDefaultService.prototype.getProject = function (projectId) { if (!projectId) { return Promise.reject('Bad argument'); } return this.http .get("/api/projects/" + projectId, HTTP_GET_OPTIONS) .map(function (response) { return response.json(); }) .catch(function (error) { return rxjs_Observable.Observable.throw(error); }); }; ProjectDefaultService.prototype.updateProjectPolicy = function (projectId, projectPolicy) { return this.http .put("/api/projects/" + projectId, { 'metadata': { 'public': projectPolicy.Public ? 'true' : 'false', 'enable_content_trust': projectPolicy.ContentTrust ? 'true' : 'false', 'prevent_vul': projectPolicy.PreventVulImg ? 'true' : 'false', 'severity': projectPolicy.PreventVulImgSeverity, 'auto_scan': projectPolicy.ScanImgOnPush ? 'true' : 'false' } }, HTTP_JSON_OPTIONS) .map(function (response) { return response.status; }) .catch(function (error) { return rxjs_Observable.Observable.throw(error); }); }; return ProjectDefaultService; }(ProjectService)); ProjectDefaultService.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ ProjectDefaultService.ctorParameters = function () { return [ { type: _angular_http.Http, }, { type: undefined, decorators: [{ type: _angular_core.Inject, args: [SERVICE_CONFIG,] },] }, ]; }; var __extends$11 = (undefined && undefined.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Declare interface for error handling * * @export * @abstract * @class ErrorHandler */ var ErrorHandler = (function () { function ErrorHandler() { } return ErrorHandler; }()); var DefaultErrorHandler = (function (_super) { __extends$11(DefaultErrorHandler, _super); function DefaultErrorHandler() { return _super !== null && _super.apply(this, arguments) || this; } DefaultErrorHandler.prototype.error = function (error) { console.error("[Default error handler]: ", error); }; DefaultErrorHandler.prototype.warning = function (warning) { console.warn("[Default warning handler]: ", warning); }; DefaultErrorHandler.prototype.info = function (info) { console.info("[Default info handler]: ", info); }; DefaultErrorHandler.prototype.log = function (log) { console.log("[Default log handler]: ", log); }; return DefaultErrorHandler; }(ErrorHandler)); DefaultErrorHandler.decorators = [ { type: _angular_core.Injectable }, ]; /** @nocollapse */ DefaultErrorHandler.ctorParameters = function () { return []; }; /** * Define the inline template and styles with ts variables */ /** * Define the inline template and styles with ts variables */ var LOG_TEMPLATE = "\n<div>\n <h2 class=\"h2-log-override\" *ngIf=\"withTitle\">{{'SIDE_NAV.LOGS' | translate}}</h2>\n <div class=\"row flex-items-xs-between flex-items-xs-bottom\">\n <div></div>\n <div class=\"action-head-pos\">\n <hbr-filter [withDivider]=\"true\" filterPlaceholder='{{\"AUDIT_LOG.FILTER_PLACEHOLDER\" | translate}}' (filter)=\"doFilter($event)\" [currentValue]=\"currentTerm\"></hbr-filter>\n <span (click)=\"refresh()\" class=\"refresh-btn\">\n <clr-icon shape=\"refresh\" [hidden]=\"inProgress\" ng-disabled=\"inProgress\"></clr-icon>\n <span class=\"spinner spinner-inline\" [hidden]=\"!inProgress\"></span>\n </span>\n </div>\n </div>\n <div>\n <clr-datagrid (clrDgRefresh)=\"load($event)\" [clrDgLoading]=\"loading\">\n <clr-dg-column [clrDgField]=\"'username'\">{{'AUDIT_LOG.USERNAME' | translate}}</clr-dg-column>\n <clr-dg-column [clrDgField]=\"'repo_name'\">{{'AUDIT_LOG.REPOSITORY_NAME' | translate}}</clr-dg-column>\n <clr-dg-column [clrDgField]=\"'repo_tag'\">{{'AUDIT_LOG.TAGS' | translate}}</clr-dg-column>\n <clr-dg-column [clrDgField]=\"'operation'\">{{'AUDIT_LOG.OPERATION' | translate}}</clr-dg-column>\n <clr-dg-column [clrDgSortBy]=\"opTimeComparator\">{{'AUDIT_LOG.TIMESTAMP' | translate}}</clr-dg-column>\n <clr-dg-placeholder>We couldn't find any logs!</clr-dg-placeholder>\n <clr-dg-row *ngFor=\"let l of recentLogs\">\n <clr-dg-cell>{{l.username}}</clr-dg-cell>\n <clr-dg-cell>{{l.repo_name}}</clr-dg-cell>\n <clr-dg-cell>{{l.repo_tag}}</clr-dg-cell>\n <clr-dg-cell>{{l.operation}}</clr-dg-cell>\n <clr-dg-cell>{{l.op_time | date: 'short'}}</clr-dg-cell>\n </clr-dg-row>\n <clr-dg-footer>\n {{pagination.firstItem + 1}} - {{pagination.lastItem + 1}}\n {{'AUDIT_LOG.OF' | translate}} {{pagination.totalItems}} {{'AUDIT_LOG.ITEMS' | translate}}\n <clr-dg-pagination #pagination [(clrDgPage)]=\"currentPage\" [clrDgPageSize]=\"pageSize\" [clrDgTotalItems]=\"totalCount\"></clr-dg-pagination>\n </clr-dg-footer>\n </clr-datagrid>\n </div>\n</div>\n"; var LOG_STYLES = "\n.h2-log-override {\n margin-top: 0px !important;\n}\n\n.action-head-pos {\n padding-right: 18px;\n height: 24px;\n}\n\n.refresh-btn {\n cursor: pointer;\n}\n\n.refresh-btn:hover {\n color: #007CBB;\n}\n\n.custom-lines-button {\n padding: 0px !important;\n min-width: 25px !important;\n}\n\n.lines-button-toggole {\n font-size: 16px;\n text-decoration: underline;\n}\n\n.log-select {\n width: 130px;\n display: inline-block;\n top: 1px;\n}\n\n.item-divider {\n height: 24px;\n display: inline-block;\n width: 1px;\n background-color: #ccc;\n opacity: 0.55;\n margin-left: 12px;\n top: 8px;\n position: relative;\n}\n"; // Copyright (c) 2017 VMware, Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. var RecentLogComponent = (fun