Sha256: 94e931cb753bc7971792468b7bb0688232e8b410186d34ca4bcf383f42532b70

Contents?: true

Size: 1.79 KB

Versions: 21

Compression:

Stored size: 1.79 KB

Contents

// @ts-check

const { join } = require('path');
const { homedir } = require('os');
const { statSync, readFileSync } = require('fs');
const yaml = require('js-yaml');

/**
 * @param {string} msg
 * @returns {{baseURL: string, apiKey: string, exists: boolean}}
 */
const failUsage = (msg) => {
  console.warn(msg);
  return { baseURL: null, apiKey: null, exists: false };
};

const { baseURL, apiKey, exists } =
  /**
   * @returns {{baseURL, apiKey}}
   */
  (() => {
    const applandConfigFilePath = join(homedir(), '.appland');
    const applandConfigStat = statSync(applandConfigFilePath);
    if (!applandConfigStat.isFile()) {
      return failUsage(
        `AppMap Cloud config file ${applandConfigFilePath} does not exist`
      );
    }
    const applandConfig = /** @type {object} */ (
      yaml.load(readFileSync(applandConfigFilePath).toString())
    );
    const currentContext =
      /** @type {string} */ applandConfig.current_context || 'default';
    const contextConfig =
      /** @type {import('./types').Context} */ applandConfig.contexts[
        currentContext
      ];
    if (!contextConfig) {
      return failUsage(
        `No context configuration '${currentContext}' in AppMap Cloud config file ${applandConfigFilePath}`
      );
    }
    const { url: configURL, api_key: configApiKey } = contextConfig;
    if (!configURL) {
      return failUsage(
        `No 'url' in context configuration '${currentContext}' in AppMap Cloud config file ${applandConfigFilePath}`
      );
    }
    if (!configApiKey) {
      return failUsage(
        `No 'api_key' in context configuration '${currentContext}' in AppMap Cloud config file ${applandConfigFilePath}`
      );
    }

    return { baseURL: configURL, apiKey: configApiKey, exists: true };
  })();

module.exports = {
  baseURL,
  apiKey,
  exists,
};

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.72.1 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.72.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.71.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.70.2 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.70.1 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.70.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.69.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.68.2 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.68.1 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.68.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.67.1 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.67.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.66.2 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.66.1 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.66.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.65.1 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.65.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.64.0 ./node_modules/@appland/appmap/src/appland/settings.js
appmap-0.63.0 ./node_modules/@appland/appmap/src/appland/settings.js