GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Client = exports.GCR_SUBDOMAIN_MAPPING = void 0;
  4. const error_1 = require("../error");
  5. const api = require("../apiv2");
  6. exports.GCR_SUBDOMAIN_MAPPING = {
  7. "us-west1": "us",
  8. "us-west2": "us",
  9. "us-west3": "us",
  10. "us-west4": "us",
  11. "us-central1": "us",
  12. "us-central2": "us",
  13. "us-east1": "us",
  14. "us-east4": "us",
  15. "northamerica-northeast1": "us",
  16. "southamerica-east1": "us",
  17. "europe-west1": "eu",
  18. "europe-west2": "eu",
  19. "europe-west3": "eu",
  20. "europe-west4": "eu",
  21. "europe-west5": "eu",
  22. "europe-west6": "eu",
  23. "europe-central2": "eu",
  24. "europe-north1": "eu",
  25. "asia-east1": "asia",
  26. "asia-east2": "asia",
  27. "asia-northeast1": "asia",
  28. "asia-northeast2": "asia",
  29. "asia-northeast3": "asia",
  30. "asia-south1": "asia",
  31. "asia-southeast2": "asia",
  32. "australia-southeast1": "asia",
  33. };
  34. function isErrors(response) {
  35. return !!response && Object.prototype.hasOwnProperty.call(response, "errors");
  36. }
  37. const API_VERSION = "v2";
  38. class Client {
  39. constructor(origin) {
  40. this.client = new api.Client({
  41. apiVersion: API_VERSION,
  42. auth: true,
  43. urlPrefix: origin,
  44. });
  45. }
  46. async listTags(path) {
  47. const response = await this.client.get(`${path}/tags/list`);
  48. if (isErrors(response.body)) {
  49. throw new error_1.FirebaseError(`Failed to list GCR tags at ${path}`, {
  50. children: response.body.errors,
  51. });
  52. }
  53. return response.body;
  54. }
  55. async deleteTag(path, tag) {
  56. var _a;
  57. const response = await this.client.delete(`${path}/manifests/${tag}`);
  58. if (!response.body) {
  59. return;
  60. }
  61. if (((_a = response.body.errors) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
  62. throw new error_1.FirebaseError(`Failed to delete tag ${tag} at path ${path}`, {
  63. children: response.body.errors,
  64. });
  65. }
  66. }
  67. async deleteImage(path, digest) {
  68. var _a;
  69. const response = await this.client.delete(`${path}/manifests/${digest}`);
  70. if (!response.body) {
  71. return;
  72. }
  73. if (((_a = response.body.errors) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
  74. throw new error_1.FirebaseError(`Failed to delete image ${digest} at path ${path}`, {
  75. children: response.body.errors,
  76. });
  77. }
  78. }
  79. }
  80. exports.Client = Client;