UNPKG

@harbor/ui

Version:

Harbor shared UI components based on Clarity and Angular6

1,690 lines (1,679 loc) 1.58 MB
import { InjectionToken, Inject, Injectable, Component, Input, Output, EventEmitter, ViewChild, ChangeDetectorRef, ChangeDetectionStrategy, Directive, ContentChild, ViewChildren, TemplateRef, HostListener, ViewEncapsulation, NgModule, Optional, SkipSelf, Renderer, APP_INITIALIZER } from '@angular/core'; import { __values, __extends, __spread } from 'tslib'; import { Observable, of, throwError, Subject, forkJoin, timer, from, fromEvent } from 'rxjs'; import { RequestOptions, Headers, Http, URLSearchParams, ResponseContentType, HttpModule } from '@angular/http'; import { map, catchError, debounceTime, distinctUntilChanged, finalize } from 'rxjs/operators'; import { throwError as throwError$1, Subject as Subject$1 } from 'rxjs/index'; import { TranslateService, TranslateLoader, TranslateModule, MissingTranslationHandler } from '@ngx-translate/core'; import { FormBuilder, Validators, NG_VALIDATORS, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { Router } from '@angular/router'; import { trigger, state, animate, transition, style } from '@angular/animations'; import { DOCUMENT } from '@angular/platform-browser'; import { CommonModule } from '@angular/common'; import { HttpClientModule, HttpClient } from '@angular/common/http'; import { ClarityModule } from '@clr/angular'; import { CookieService, CookieModule } from 'ngx-cookie'; import { MarkdownModule } from 'ngx-markdown'; import { TranslateHttpLoader } from '@ngx-translate/http-loader'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var Filter = /** @class */ (function () { function Filter(kind, pattern) { this.kind = kind; this.pattern = pattern; } return Filter; }()); var Trigger = /** @class */ (function () { function Trigger(kind, param) { this.kind = kind; this.schedule_param = param; } return Trigger; }()); /** @enum {number} */ var VulnerabilitySeverity = { _SEVERITY: 0, NONE: 1, UNKNOWN: 2, LOW: 3, MEDIUM: 4, HIGH: 5, }; VulnerabilitySeverity[VulnerabilitySeverity._SEVERITY] = '_SEVERITY'; VulnerabilitySeverity[VulnerabilitySeverity.NONE] = 'NONE'; VulnerabilitySeverity[VulnerabilitySeverity.UNKNOWN] = 'UNKNOWN'; VulnerabilitySeverity[VulnerabilitySeverity.LOW] = 'LOW'; VulnerabilitySeverity[VulnerabilitySeverity.MEDIUM] = 'MEDIUM'; VulnerabilitySeverity[VulnerabilitySeverity.HIGH] = 'HIGH'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** @type {?} */ var SERVICE_CONFIG = new InjectionToken("service.config"); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Convert the different async channels to the Promise<T> type. * * * * template T * ** deprecated param {(Observable<T> | Promise<T> | T)} async * returns {Promise<T>} * @template T * @param {?} async * @return {?} */ function toPromise(async) { if (!async) { return Promise.reject("Bad argument"); } if (async instanceof Observable) { /** @type {?} */ var obs = async; return obs.toPromise(); } else { return Promise.resolve(async); } } /** * * The default cookie key used to store current used language preference. @type {?} */ var DEFAULT_LANG_COOKIE_KEY = 'harbor-lang'; /** * * Declare what languages are supported now. @type {?} */ var DEFAULT_SUPPORTING_LANGS = ['en-us', 'zh-cn', 'es-es', 'fr-fr', 'pt-br']; /** * * The default language. @type {?} */ var DEFAULT_LANG = 'en-us'; /** @type {?} */ var HTTP_JSON_OPTIONS = new RequestOptions({ headers: new Headers({ "Content-Type": 'application/json', "Accept": 'application/json' }) }); /** @type {?} */ var HTTP_GET_OPTIONS = new RequestOptions({ headers: new Headers({ "Content-Type": 'application/json', "Accept": 'application/json', "Cache-Control": 'no-cache', "Pragma": 'no-cache' }) }); /** @type {?} */ var FILE_UPLOAD_OPTION = new RequestOptions({ headers: new Headers({ "Content-Type": 'multipart/form-data', }) }); /** * Build http request options * * * * ** deprecated param {RequestQueryParams} params * returns {RequestOptions} * @param {?} params * @return {?} */ function buildHttpRequestOptions(params) { /** @type {?} */ var reqOptions = new RequestOptions({ headers: new 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 @type {?} */ var ButtonClickEvents = { left: { button: 0 }, right: { button: 2 } }; /** * Simulate element click. Defaults to mouse left-button click event. * @param {?} el * @param {?=} eventObj * @return {?} */ function click(el, eventObj) { if (eventObj === void 0) { eventObj = ButtonClickEvents.left; } if (el instanceof HTMLElement) { el.click(); } else { el.triggerEventHandler('click', eventObj); } } /** * Comparator for fields with specific type. * * @template T */ var /** * Comparator for fields with specific type. * * @template T */ CustomComparator = /** @class */ (function () { function CustomComparator(fieldName, type) { this.fieldName = fieldName; this.type = type; } /** * @param {?} a * @param {?} b * @return {?} */ CustomComparator.prototype.compare = /** * @param {?} a * @param {?} b * @return {?} */ function (a, b) { /** @type {?} */ var comp = 0; if (a && b) { /** @type {?} */ var fieldA = a[this.fieldName]; /** @type {?} */ 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 @type {?} */ var DEFAULT_PAGE_SIZE = 15; /** * * The state of vulnerability scanning @type {?} */ var VULNERABILITY_SCAN_STATUS = { unknown: "n/a", pending: "pending", running: "running", error: "error", stopped: "stopped", finished: "finished" }; /** * Calculate page number by state * @param {?} state * @return {?} */ function calculatePage(state$$1) { if (!state$$1 || !state$$1.page) { return 1; } return Math.ceil((state$$1.page.to + 1) / state$$1.page.size); } /** * Filter columns via RegExp * * * * ** deprecated param {State} state * returns {void} * @template T * @param {?} items * @param {?} state * @return {?} */ function doFiltering(items, state$$1) { if (!items || items.length === 0) { return items; } if (!state$$1 || !state$$1.filters || state$$1.filters.length === 0) { return items; } state$$1.filters.forEach(function (filter) { items = items.filter(function (item) { if (filter['property'].indexOf('.') !== -1) { /** @type {?} */ var arr_1 = filter['property'].split('.'); if (Array.isArray(item[arr_1[0]]) && item[arr_1[0]].length) { return item[arr_1[0]].some(function (data) { return filter['value'] === data[arr_1[1]]; }); } } else { return regexpFilter(filter['value'], item[filter['property']]); } }); }); return items; } /** * Match items via RegExp * * * * ** deprecated param {string} terms * ** deprecated param {*} testedValue * returns {boolean} * @param {?} terms * @param {?} testedValue * @return {?} */ function regexpFilter(terms, testedValue) { /** @type {?} */ var reg = new RegExp('.*' + terms + '.*', 'i'); return reg.test(testedValue); } /** * Sorting the data by column * * * * template T * ** deprecated param {T[]} items * ** deprecated param {State} state * returns {T[]} * @template T * @param {?} items * @param {?} state * @return {?} */ function doSorting(items, state$$1) { if (!items || items.length === 0) { return items; } if (!state$$1 || !state$$1.sort) { return items; } return items.sort(function (a, b) { /** @type {?} */ var comp = 0; if (typeof state$$1.sort.by !== "string") { comp = state$$1.sort.by.compare(a, b); } else { /** @type {?} */ var propA = a[state$$1.sort.by.toString()]; /** @type {?} */ var propB = b[state$$1.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$$1.sort.reverse) { comp = -comp; } return comp; }); } /** * Compare the two objects to adjust if they're equal * * * * ** deprecated param {*} a * ** deprecated param {*} b * returns {boolean} * @param {?} a * @param {?} b * @return {?} */ 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 '{}' * * * * ** deprecated param {*} obj * returns {boolean} * @param {?} obj * @return {?} */ function isEmptyObject(obj) { return !obj || JSON.stringify(obj) === "{}"; } /** * Deeper clone all * * * * ** deprecated param {*} srcObj * returns {*} * @param {?} srcObj * @return {?} */ function clone(srcObj) { if (!srcObj) { return null; } return JSON.parse(JSON.stringify(srcObj)); } /** * @param {?} obj * @return {?} */ function isEmpty(obj) { return !obj || JSON.stringify(obj) === '{}'; } /** * @param {?} fileData * @return {?} */ function downloadFile(fileData) { /** @type {?} */ var url = window.URL.createObjectURL(fileData.data); /** @type {?} */ var a = document.createElement("a"); document.body.appendChild(a); a.setAttribute("style", "display: none"); a.href = url; a.download = fileData.filename; a.click(); window.URL.revokeObjectURL(url); a.remove(); } /** * @param {?} original * @param {?} afterChange * @return {?} */ function getChanges(original, afterChange) { var e_1, _a; /** @type {?} */ var changes = {}; if (!afterChange || !original) { return changes; } try { for (var _b = __values(Object.keys(afterChange)), _c = _b.next(); !_c.done; _c = _b.next()) { var prop = _c.value; /** @type {?} */ var field = original[prop]; if (field && field.editable) { if (!compareValue(field.value, afterChange[prop].value)) { changes[prop] = afterChange[prop].value; // Number if (typeof field.value === 'number') { changes[prop] = +changes[prop]; } // Trim string value if (typeof field.value === 'string') { changes[prop] = ('' + changes[prop]).trim(); } } } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return changes; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Get System information about current backend server. * @abstract * class * @abstract */ var /** * Get System information about current backend server. * @abstract * class * @abstract */ SystemInfoService = /** @class */ (function () { function SystemInfoService() { } return SystemInfoService; }()); var SystemInfoDefaultService = /** @class */ (function (_super) { __extends(SystemInfoDefaultService, _super); function SystemInfoDefaultService(config, http) { var _this = _super.call(this) || this; _this.config = config; _this.http = http; return _this; } /** * @return {?} */ SystemInfoDefaultService.prototype.getSystemInfo = /** * @return {?} */ function () { /** @type {?} */ 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); }); }; SystemInfoDefaultService.decorators = [ { type: Injectable } ]; /** @nocollapse */ SystemInfoDefaultService.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: Inject, args: [SERVICE_CONFIG,] }] }, { type: Http } ]; }; return SystemInfoDefaultService; }(SystemInfoService)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Define service methods to handle the access log related things. * * * * @abstract * class AccessLogService * @abstract */ var /** * Define service methods to handle the access log related things. * * * * @abstract * class AccessLogService * @abstract */ AccessLogService = /** @class */ (function () { function AccessLogService() { } return AccessLogService; }()); /** * Implement a default service for access log. * * * * class AccessLogDefaultService * extends {AccessLogService} */ var AccessLogDefaultService = /** @class */ (function (_super) { __extends(AccessLogDefaultService, _super); function AccessLogDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; return _this; } /** * @param {?} projectId * @param {?=} queryParams * @return {?} */ AccessLogDefaultService.prototype.getAuditLogs = /** * @param {?} projectId * @param {?=} queryParams * @return {?} */ function (projectId, queryParams) { return of(/** @type {?} */ ({})); }; /** * @param {?=} queryParams * @return {?} */ AccessLogDefaultService.prototype.getRecentLogs = /** * @param {?=} queryParams * @return {?} */ function (queryParams) { /** @type {?} */ 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) { /** @type {?} */ var result = { metadata: { xTotalCount: 0 }, data: [] }; /** @type {?} */ 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 = /** @type {?} */ (response.json()); } } return result; }) .catch(function (error) { return Promise.reject(error); }); }; AccessLogDefaultService.decorators = [ { type: Injectable } ]; /** @nocollapse */ AccessLogDefaultService.ctorParameters = function () { return [ { type: Http }, { type: undefined, decorators: [{ type: Inject, args: [SERVICE_CONFIG,] }] } ]; }; return AccessLogDefaultService; }(AccessLogService)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Wrap the class 'URLSearchParams' for future extending requirements. * Currently no extra methods provided. * * * * class RequestQueryParams * extends {URLSearchParams} */ var /** * Wrap the class 'URLSearchParams' for future extending requirements. * Currently no extra methods provided. * * * * class RequestQueryParams * extends {URLSearchParams} */ RequestQueryParams = /** @class */ (function (_super) { __extends(RequestQueryParams, _super); function RequestQueryParams() { return _super.call(this) || this; } return RequestQueryParams; }(URLSearchParams)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Define the service methods to handle the endpoint related things. * * * * @abstract * class EndpointService * @abstract */ var /** * Define the service methods to handle the endpoint related things. * * * * @abstract * class EndpointService * @abstract */ EndpointService = /** @class */ (function () { function EndpointService() { } return EndpointService; }()); /** * Implement default service for endpoint. * * * * class EndpointDefaultService * extends {EndpointService} */ var EndpointDefaultService = /** @class */ (function (_super) { __extends(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; } /** * @param {?=} endpointName * @param {?=} queryParams * @return {?} */ EndpointDefaultService.prototype.getEndpoints = /** * @param {?=} endpointName * @param {?=} queryParams * @return {?} */ function (endpointName, queryParams) { if (!queryParams) { queryParams = new RequestQueryParams(); } if (endpointName) { queryParams.set("name", endpointName); } /** @type {?} */ 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); }); }; /** * @param {?} endpointId * @return {?} */ EndpointDefaultService.prototype.getEndpoint = /** * @param {?} endpointId * @return {?} */ function (endpointId) { if (!endpointId || endpointId <= 0) { return Promise.reject("Bad request argument."); } /** @type {?} */ 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); }); }; /** * @param {?} endpoint * @return {?} */ EndpointDefaultService.prototype.createEndpoint = /** * @param {?} endpoint * @return {?} */ function (endpoint) { if (!endpoint) { return Promise.reject("Invalid endpoint."); } /** @type {?} */ 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); }); }; /** * @param {?} endpointId * @param {?} endpoint * @return {?} */ EndpointDefaultService.prototype.updateEndpoint = /** * @param {?} endpointId * @param {?} endpoint * @return {?} */ function (endpointId, endpoint) { if (!endpointId || endpointId <= 0) { return Promise.reject("Bad request argument."); } if (!endpoint) { return Promise.reject("Invalid endpoint."); } /** @type {?} */ 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); }); }; /** * @param {?} endpointId * @return {?} */ EndpointDefaultService.prototype.deleteEndpoint = /** * @param {?} endpointId * @return {?} */ function (endpointId) { if (!endpointId || endpointId <= 0) { return Promise.reject("Bad request argument."); } /** @type {?} */ var requestUrl = this._endpointUrl + "/" + endpointId; return this.http .delete(requestUrl) .toPromise() .then(function (response) { return response.status; }) .catch(function (error) { return Promise.reject(error); }); }; /** * @param {?} endpoint * @return {?} */ EndpointDefaultService.prototype.pingEndpoint = /** * @param {?} endpoint * @return {?} */ function (endpoint) { if (!endpoint) { return Promise.reject("Invalid endpoint."); } /** @type {?} */ 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); }); }; /** * @param {?} endpointId * @return {?} */ EndpointDefaultService.prototype.getEndpointWithReplicationRules = /** * @param {?} endpointId * @return {?} */ function (endpointId) { if (!endpointId || endpointId <= 0) { return Promise.reject("Bad request argument."); } /** @type {?} */ 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); }); }; EndpointDefaultService.decorators = [ { type: Injectable } ]; /** @nocollapse */ EndpointDefaultService.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: Inject, args: [SERVICE_CONFIG,] }] }, { type: Http } ]; }; return EndpointDefaultService; }(EndpointService)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Define the service methods to handle the replication (rule and job) related things. * * * * @abstract * class ReplicationService * @abstract */ var /** * Define the service methods to handle the replication (rule and job) related things. * * * * @abstract * class ReplicationService * @abstract */ ReplicationService = /** @class */ (function () { function ReplicationService() { } return ReplicationService; }()); /** * Implement default service for replication rule and job. * * * * class ReplicationDefaultService * extends {ReplicationService} */ var ReplicationDefaultService = /** @class */ (function (_super) { __extends(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"; _this._replicateUrl = config.replicationBaseEndpoint ? config.replicationBaseEndpoint : "/api/replications"; return _this; } // Private methods // Check if the rule object is valid /** * @param {?} rule * @return {?} */ ReplicationDefaultService.prototype._isValidRule = /** * @param {?} rule * @return {?} */ function (rule) { return (rule !== undefined && rule != null && rule.name !== undefined && rule.name.trim() !== "" && rule.targets.length !== 0); }; /** * @return {?} */ ReplicationDefaultService.prototype.getJobBaseUrl = /** * @return {?} */ function () { return this._jobBaseUrl; }; /** * @param {?=} projectId * @param {?=} ruleName * @param {?=} queryParams * @return {?} */ ReplicationDefaultService.prototype.getReplicationRules = /** * @param {?=} projectId * @param {?=} ruleName * @param {?=} queryParams * @return {?} */ 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); }); }; /** * @param {?} ruleId * @return {?} */ ReplicationDefaultService.prototype.getReplicationRule = /** * @param {?} ruleId * @return {?} */ function (ruleId) { if (!ruleId) { return Promise.reject("Bad argument"); } /** @type {?} */ 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); }); }; /** * @param {?} replicationRule * @return {?} */ ReplicationDefaultService.prototype.createReplicationRule = /** * @param {?} replicationRule * @return {?} */ 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); }); }; /** * @param {?} id * @param {?} rep * @return {?} */ ReplicationDefaultService.prototype.updateReplicationRule = /** * @param {?} id * @param {?} rep * @return {?} */ function (id, rep) { if (!this._isValidRule(rep)) { return Promise.reject("Bad argument"); } /** @type {?} */ var url = this._ruleBaseUrl + "/" + id; return this.http .put(url, JSON.stringify(rep), HTTP_JSON_OPTIONS) .toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; /** * @param {?} ruleId * @return {?} */ ReplicationDefaultService.prototype.deleteReplicationRule = /** * @param {?} ruleId * @return {?} */ function (ruleId) { if (!ruleId || ruleId <= 0) { return Promise.reject("Bad argument"); } /** @type {?} */ 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); }); }; /** * @param {?} ruleId * @return {?} */ ReplicationDefaultService.prototype.replicateRule = /** * @param {?} ruleId * @return {?} */ function (ruleId) { if (!ruleId) { return Promise.reject("Bad argument"); } /** @type {?} */ var url = "" + this._replicateUrl; return this.http .post(url, { policy_id: ruleId }, HTTP_JSON_OPTIONS) .toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; /** * @param {?} ruleId * @param {?} enablement * @return {?} */ ReplicationDefaultService.prototype.enableReplicationRule = /** * @param {?} ruleId * @param {?} enablement * @return {?} */ function (ruleId, enablement) { if (!ruleId || ruleId <= 0) { return Promise.reject("Bad argument"); } /** @type {?} */ 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); }); }; /** * @param {?} ruleId * @return {?} */ ReplicationDefaultService.prototype.disableReplicationRule = /** * @param {?} ruleId * @return {?} */ function (ruleId) { if (!ruleId || ruleId <= 0) { return Promise.reject("Bad argument"); } /** @type {?} */ 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); }); }; /** * @param {?} ruleId * @param {?=} queryParams * @return {?} */ ReplicationDefaultService.prototype.getJobs = /** * @param {?} ruleId * @param {?=} queryParams * @return {?} */ 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) { /** @type {?} */ var result = { metadata: { xTotalCount: 0 }, data: [] }; if (response && response.headers) { /** @type {?} */ var xHeader = response.headers.get("X-Total-Count"); if (xHeader) { result.metadata.xTotalCount = parseInt(xHeader, 0); } } result.data = /** @type {?} */ (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); }); }; /** * @param {?} jobId * @return {?} */ ReplicationDefaultService.prototype.getJobLog = /** * @param {?} jobId * @return {?} */ function (jobId) { if (!jobId || jobId <= 0) { return Promise.reject("Bad argument"); } /** @type {?} */ 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); }); }; /** * @param {?} jobId * @return {?} */ ReplicationDefaultService.prototype.stopJobs = /** * @param {?} jobId * @return {?} */ function (jobId) { return this.http .put(this._jobBaseUrl, JSON.stringify({ policy_id: jobId, status: "stop" }), HTTP_JSON_OPTIONS) .toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; ReplicationDefaultService.decorators = [ { type: Injectable } ]; /** @nocollapse */ ReplicationDefaultService.ctorParameters = function () { return [ { type: Http }, { type: undefined, decorators: [{ type: Inject, args: [SERVICE_CONFIG,] }] } ]; }; return ReplicationDefaultService; }(ReplicationService)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Define service methods for handling the repository related things. * Loose couple with project module. * * * * @abstract * class RepositoryService * @abstract */ var /** * Define service methods for handling the repository related things. * Loose couple with project module. * * * * @abstract * class RepositoryService * @abstract */ RepositoryService = /** @class */ (function () { function RepositoryService() { } return RepositoryService; }()); /** * Implement default service for repository. * * * * class RepositoryDefaultService * extends {RepositoryService} */ var RepositoryDefaultService = /** @class */ (function (_super) { __extends(RepositoryDefaultService, _super); function RepositoryDefaultService(http, config) { var _this = _super.call(this) || this; _this.http = http; _this.config = config; return _this; } /** * @param {?} projectId * @param {?=} repositoryName * @param {?=} queryParams * @return {?} */ RepositoryDefaultService.prototype.getRepositories = /** * @param {?} projectId * @param {?=} repositoryName * @param {?=} queryParams * @return {?} */ 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); } /** @type {?} */ var url = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories'; return this.http.get(url, buildHttpRequestOptions(queryParams)).toPromise() .then(function (response) { /** @type {?} */ var result = { metadata: { xTotalCount: 0 }, data: [] }; if (response && response.headers) { /** @type {?} */ var xHeader = response.headers.get('X-Total-Count'); if (xHeader) { result.metadata.xTotalCount = parseInt(xHeader, 0); } } result.data = /** @type {?} */ (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); }); }; /** * @param {?} repositoryName * @param {?} description * @param {?=} queryParams * @return {?} */ RepositoryDefaultService.prototype.updateRepositoryDescription = /** * @param {?} repositoryName * @param {?} description * @param {?=} queryParams * @return {?} */ function (repositoryName, description, queryParams) { if (!queryParams) { queryParams = new RequestQueryParams(); } /** @type {?} */ var baseUrl = this.config.repositoryBaseEndpoint ? this.config.repositoryBaseEndpoint : '/api/repositories'; /** @type {?} */ var url = baseUrl + "/" + repositoryName; return this.http.put(url, { 'description': description }, HTTP_JSON_OPTIONS).toPromise() .then(function (response) { return response; }) .catch(function (error) { return Promise.reject(error); }); }; /** * @param {?} repositoryName * @return {?} */ RepositoryDefaultService.prototype.deleteRepository = /** * @param {?} repositoryName * @return {?} */ function (repositoryName) { if (!repositoryName) { return Promise.reject('Bad argument'); } /** @type {?} */ 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) { return Promise.reject(error); }); }; RepositoryDefaultService.decorators = [ { type: Injectable } ]; /** @nocollapse */ RepositoryDefaultService.ctorParameters = function () { return [ { type: Http }, { type: undefined, decorators: [{ type: Inject, args: [SERVICE_CONFIG,] }] } ]; }; return RepositoryDefaultService; }(RepositoryService)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * For getting tag signatures. * This is temporary, will be removed in future. * * * * class VerifiedSignature */ var /** * For getting tag signatures. * This is temporary, will be removed in future. * * * * class VerifiedSignature */ VerifiedSignature = /** @class */ (function () { function VerifiedSignature() { } return VerifiedSignature; }()); /** * Define the service methods to handle the repository tag related things. * * * * @abstract * class TagService * @abstract */ var /** * Define the service methods to handle the repository tag related things. * * * * @abstract * class TagService * @abstract */ TagService = /** @class */ (function () { function TagService() { } return TagService; }()); /** * Implement default service for tag. * * * * class TagDefaultService * extends {TagService} */ var TagDefaultService = /** @class */ (function (_super) { __extends(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"; _this._labelUrl = _this.config.labelEndpoint ? _this.config.labelEndpoint : "/api/labels"; return _this; } // Private methods // These two methods are temporary, will be deleted in future after API refactored /** * @param {?} repositoryName * @param {?=} queryParams * @return {?} */ TagDefaultService.prototype._getTags = /** * @param {?} repositoryName * @param {?=} queryParams * @return {?} */ function (repositoryName, queryParams) { if (!queryParams) { queryParams = new RequestQueryParams(); } queryParams.set("detail", "1"); /** @type {?} */ 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); }); }; /** * @param {?} repositoryName * @return {?} */ TagDefaultService.prototype._getSignatures = /** * @param {?} repositoryName * @return {?} */ function (repositoryName) { /** @type {?} */ 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); }); }; /** * @param {?} repositoryName * @param {?=} queryParams * @return {?} */ TagDefaultService.prototype.getTags = /** * @param {?} repositoryName * @param {?=} queryParams * @return {?} */ function (repositoryName, queryParams) { if (!repositoryName) { return Promise.reject("Bad argument"); } return this._getTags(repositoryName, queryParams); }; /** * @param {?} repositoryName * @param {?} tag * @return {?} */ TagDefaultService.prototype.deleteTag = /** * @param {?} repositoryName * @param {?} tag * @return {?} */ function (repositoryName, tag) { if (!repositoryName || !tag) { return Promise.reject("Bad argument"); } /** @type {?} */ 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); }); }; /** * @param {?} repositoryName * @param {?} tag * @param {?=} queryParams * @return {?} */ TagDefaultService.prototype.getTag = /** * @param {?} repositoryName * @param {?} tag * @param {?=} queryParams * @return {?} */ function (repositoryName, tag, queryParams) { if (!repositoryName || !tag) { return Promise.reject("Bad argument"); } /** @type {?} */ 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); }); }; /** * @param {?} repoName * @param {?} tagName * @param {?} labelId * @return {?} */ TagDefaultService.prototype.addLabelToImages = /** * @param {?} repoName * @param {?} tagName * @param {?} labelId * @return {?} */ function (repoName, tagName, labelId) { if (!labelId || !tagName || !repoName) { return Promise.reject("Invalid parameters."); } /** @type {?} */ var _addLabelToImageUrl = this._baseUrl + "/" + repoName + "/tags/" + tagName + "/labels"; return this.http .post(_addLabelToImageUrl, { id: labelId }, HTTP_JSON_OPTIONS) .toPromise() .then(function (response) { return response.status; }) .catch(function (error) { return Promise.reject(error); }); }; /** * @param {?} repoName * @param {?} tagName * @param {?} labelId * @return {?} */ TagDefaultService.prototype.deleteLabelToImages = /** * @param {?} repoName * @param {?} tagName * @param {?} labelId * @return {?} */ function (repoName, tagName, labelId) { if (!labelId || !tagName || !repoName) { return Promise.reject("Invalid parameters."); } /** @type {?} */ var _addLabelToImageUrl = this._baseUrl + "/" + repoName + "/tags/" + tagName + "/labels/" + labelId; return this.http .delete(_addLabelToImageUrl) .toPromise() .then(function (response) { return response.status; }) .catch(function (error) { return Promise.reject(error); }); }; /** * @param {?} repositoryName * @param {?} tag * @return {?} */ TagDefaultService.prototype.getManifest = /** * @param {?} repositoryName * @param {?} tag * @return {?} */ function (repositoryName, tag) { if (!repositoryName || !tag) { return Promise.reject("Bad argument"); } /** @type {?} */ var url = this._baseUrl + "/" + repositoryName + "/tags/" + tag + "/manifest"; return this.http .get(url, HTTP_GET_OPTIONS) .toPromise() .then(function (response) { return (response.json()); }) .catch(function (error) { return Promise.reject(error); }); }; TagDefaultService.decorators = [ { type: Injectable } ]; /** @nocollapse */ TagDefaultService.ctorParameters = function () { return [ { type: Http }, { type: undefined, decorators: [{ type: Inject, args: [SERVICE_CONFIG,] }] } ]; }; return TagDefaultService; }(TagService)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * Get the vulnerabilities scanning results for the specified tag. * * * * @abstract * class ScanningResultService * @abstract */ var /** * Get the vulnerabilities scanning results for the specified tag. * * * * @abstract * class ScanningResultService * @abstract */ ScanningResultService = /** @class */ (function () { function ScanningResultService() { } return ScanningResultService; }()); var ScanningResultDefaultService = /** @class */ (function (_super) { __extends(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; } /** * @param {?} repoName * @param {?} tagId * @param {?=} queryParams * @return {?} */ ScanningResultDefaultService.prototype.getVulnerabilityScanningSummary = /** * @param {?} repoName * @param {?} tagId * @param {?=} queryParams * @return {?} */ function (repoName, tagId, queryParams) { if (!repoName || repoName.trim() === "" || !tagId || tagId.trim() === "") { return Promise.reject("Bad argument"); } return of(/** @type {?} */ ({})); }; /** * @param {?} repoName * @param {?} tagId * @param {?=} queryParams * @return {?} */ ScanningResultDefaultService.prototype.getVulnerabilityScanningResults = /** * @param {?} repoName * @param {?} tagId * @param {?=} queryParams * @return {?} */ 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); }); }; /** * @param {?} repoName * @param {?} tagId * @return {?} */ ScanningResultDefaultService.prototype.startVulnerabilityScanning = /** * @param {?} repoName * @param {?} tagId * @return {?} */ 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); }); }; /** * @return {?} */ ScanningResultDefaultService.prototype.startScanningAll = /** * @return {?} */ function () { return this.http .post(this._baseUrl + "/scanAll", HTTP_JSON_OPTIONS) .toPromise() .then(function () { return true; }) .catch(function (error) { return Promise.reject(error); }); }; ScanningResultDefaul