No Description
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.

hash.js 1.3KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getEndpointHash = exports.getSecretsHash = exports.getSourceHash = exports.getEnvironmentVariablesHash = void 0;
  4. const promises_1 = require("node:fs/promises");
  5. const crypto = require("crypto");
  6. const secrets_1 = require("../../../functions/secrets");
  7. function getEnvironmentVariablesHash(backend) {
  8. return createHash(JSON.stringify(backend.environmentVariables || {}));
  9. }
  10. exports.getEnvironmentVariablesHash = getEnvironmentVariablesHash;
  11. async function getSourceHash(pathToFile) {
  12. const data = await (0, promises_1.readFile)(pathToFile);
  13. return createHash(data);
  14. }
  15. exports.getSourceHash = getSourceHash;
  16. function getSecretsHash(endpoint) {
  17. const secretVersions = (0, secrets_1.getSecretVersions)(endpoint);
  18. return createHash(JSON.stringify(secretVersions || {}));
  19. }
  20. exports.getSecretsHash = getSecretsHash;
  21. function getEndpointHash(sourceHash, envHash, secretsHash) {
  22. const combined = [sourceHash, envHash, secretsHash].filter((hash) => !!hash).join("");
  23. return createHash(combined);
  24. }
  25. exports.getEndpointHash = getEndpointHash;
  26. function createHash(data, algorithm = "sha1") {
  27. const hash = crypto.createHash(algorithm);
  28. hash.update(data);
  29. return hash.digest("hex");
  30. }