'use strict';

var config = require('@backstage/config');

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
const _PublisherConfig = class _PublisherConfig {
  /**
   * Returns Backstage config suitable for use when instantiating a Publisher. If
   * there are any missing or invalid options provided, an error is thrown.
   *
   * Note: This assumes that proper credentials are set in Environment
   * variables for the respective GCS/AWS clients to work.
   */
  static getValidConfig(opts) {
    const publisherType = opts.publisherType;
    if (!_PublisherConfig.isKnownPublisher(publisherType)) {
      throw new Error(`Unknown publisher type ${opts.publisherType}`);
    }
    return new config.ConfigReader({
      // This backend config is not used at all. Just something needed a create a mock discovery instance.
      backend: {
        baseUrl: "http://localhost:7007",
        listen: {
          port: 7007
        }
      },
      techdocs: {
        publisher: _PublisherConfig.configFactories[publisherType](opts),
        legacyUseCaseSensitiveTripletPaths: opts.legacyUseCaseSensitiveTripletPaths
      }
    });
  }
  /**
   * Typeguard to ensure the publisher has a known config getter.
   */
  static isKnownPublisher(type) {
    return _PublisherConfig.configFactories.hasOwnProperty(type);
  }
  /**
   * Retrieve valid AWS S3 configuration based on the command.
   */
  static getValidAwsS3Config(opts) {
    return {
      type: "awsS3",
      awsS3: {
        bucketName: opts.storageName,
        ...opts.awsBucketRootPath && {
          bucketRootPath: opts.awsBucketRootPath
        },
        ...opts.awsRoleArn && { credentials: { roleArn: opts.awsRoleArn } },
        ...opts.awsEndpoint && { endpoint: opts.awsEndpoint },
        ...opts.awsS3ForcePathStyle && { s3ForcePathStyle: true },
        ...opts.awsS3sse && { sse: opts.awsS3sse },
        ...opts.awsProxy && { httpsProxy: opts.awsProxy }
      }
    };
  }
  /**
   * Retrieve valid Azure Blob Storage configuration based on the command.
   */
  static getValidAzureConfig(opts) {
    if (!opts.azureAccountName) {
      throw new Error(
        `azureBlobStorage requires --azureAccountName to be specified`
      );
    }
    return {
      type: "azureBlobStorage",
      azureBlobStorage: {
        containerName: opts.storageName,
        credentials: {
          accountName: opts.azureAccountName,
          accountKey: opts.azureAccountKey
        }
      }
    };
  }
  /**
   * Retrieve valid GCS configuration based on the command.
   */
  static getValidGoogleGcsConfig(opts) {
    return {
      type: "googleGcs",
      googleGcs: {
        bucketName: opts.storageName,
        ...opts.gcsBucketRootPath && {
          bucketRootPath: opts.gcsBucketRootPath
        }
      }
    };
  }
  /**
   * Retrieves valid OpenStack Swift configuration based on the command.
   */
  static getValidOpenStackSwiftConfig(opts) {
    const missingParams = [
      "osCredentialId",
      "osSecret",
      "osAuthUrl",
      "osSwiftUrl"
    ].filter((param) => !opts[param]);
    if (missingParams.length) {
      throw new Error(
        `openStackSwift requires the following params to be specified: ${missingParams.join(
          ", "
        )}`
      );
    }
    return {
      type: "openStackSwift",
      openStackSwift: {
        containerName: opts.storageName,
        credentials: {
          id: opts.osCredentialId,
          secret: opts.osSecret
        },
        authUrl: opts.osAuthUrl,
        swiftUrl: opts.osSwiftUrl
      }
    };
  }
};
/**
 * Maps publisher-specific config keys to config getters.
 */
__publicField(_PublisherConfig, "configFactories", {
  awsS3: _PublisherConfig.getValidAwsS3Config,
  azureBlobStorage: _PublisherConfig.getValidAzureConfig,
  googleGcs: _PublisherConfig.getValidGoogleGcsConfig,
  openStackSwift: _PublisherConfig.getValidOpenStackSwiftConfig
});
let PublisherConfig = _PublisherConfig;

exports.PublisherConfig = PublisherConfig;
//# sourceMappingURL=PublisherConfig-B9GYw8mh.cjs.js.map
