1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 07:19:41 +02:00
portainer/app/docker/components/imageRegistry/por-image-registry-rate-limits.controller.js
Chaim Lev-Ari 7fe0712b61
feat(home): move edge device to view [EE-4559] (#8189)
Co-authored-by: matias.spinarolli <matias.spinarolli@portainer.io>
2022-12-21 10:07:34 +13:00

42 lines
1.1 KiB
JavaScript

import { isAgentEnvironment, isLocalEnvironment } from '@/react/portainer/environments/utils';
export default class porImageRegistryContainerController {
/* @ngInject */
constructor(DockerHubService, Notifications) {
this.DockerHubService = DockerHubService;
this.Notifications = Notifications;
this.pullRateLimits = null;
}
$onChanges({ registryId }) {
if (registryId) {
this.fetchRateLimits();
}
}
$onInit() {
this.setValidity =
this.setValidity ||
(() => {
/* noop */
});
}
async fetchRateLimits() {
this.pullRateLimits = null;
if (!isAgentEnvironment(this.endpoint.Type) && !isLocalEnvironment(this.endpoint)) {
this.setValidity(true);
return;
}
try {
this.pullRateLimits = await this.DockerHubService.checkRateLimits(this.endpoint, this.registryId || 0);
this.setValidity(!this.pullRateLimits.limit || (this.pullRateLimits.limit && this.pullRateLimits.remaining >= 0));
} catch (e) {
// eslint-disable-next-line no-console
console.error('Failed loading DockerHub pull rate limits', e);
this.setValidity(true);
}
}
}