Skip to content
Snippets Groups Projects
Select Git revision
  • eda75c7c39d0cc8e01840dc1fccb632d8315d5b1
  • main default protected
  • release-0.15
  • automated-updates-main
  • release-0.13
  • automated-updates-release-0.13
  • release-0.14
  • release-0.10
  • release-0.11
  • release-0.12
  • fix-versions-action
  • versions-fix
  • release-0.9
  • release-0.8
  • release-0.7
  • release-0.6
  • release-0.5
  • release-0.4
  • release-0.3
  • release-0.1
  • release-0.2
  • v0.15.0
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
  • v0.6.0
  • v0.5.0
  • v0.4.0
  • v0.3.0
  • v0.2.0
  • v0.1.0
36 results

bootkube.jsonnet

Blame
  • host-rules.ts 2.45 KiB
    import {
      GITHUB_API_USING_HOST_TYPES,
      GITLAB_API_USING_HOST_TYPES,
      PLATFORM_TYPE_GITHUB,
      PLATFORM_TYPE_GITLAB,
    } from '../../constants/platforms';
    import { logger } from '../../logger';
    import { hasProxy } from '../../proxy';
    import type { HostRule } from '../../types';
    import * as hostRules from '../host-rules';
    import type { GotOptions } from './types';
    
    function findMatchingRules(options: GotOptions, url: string): HostRule {
      const { hostType } = options;
      let res = hostRules.find({ hostType, url });
    
      // Fallback to `github` hostType
      if (
        GITHUB_API_USING_HOST_TYPES.includes(hostType) &&
        hostType !== PLATFORM_TYPE_GITHUB
      ) {
        res = {
          ...hostRules.find({
            hostType: PLATFORM_TYPE_GITHUB,
            url,
          }),
          ...res,
        };
      }
    
      // Fallback to `gitlab` hostType
      if (
        GITLAB_API_USING_HOST_TYPES.includes(hostType) &&
        hostType !== PLATFORM_TYPE_GITLAB
      ) {
        res = {
          ...hostRules.find({
            hostType: PLATFORM_TYPE_GITLAB,
            url,
          }),
          ...res,
        };
      }
    
      return res;
    }
    
    // Apply host rules to requests
    export function applyHostRules(url: string, inOptions: GotOptions): GotOptions {
      const options: GotOptions = { ...inOptions };
      const foundRules = findMatchingRules(options, url);
      const { username, password, token, enabled, authType } = foundRules;
      if (options.noAuth) {
        logger.trace({ url }, `Authorization disabled`);
      } else if (
        options.headers?.authorization ||
        options.password ||
        options.token
      ) {
        logger.trace({ url }, `Authorization already set`);
      } else if (password !== undefined) {
        logger.trace({ url }, `Applying Basic authentication`);
        options.username = username;
        options.password = password;
      } else if (token) {
        logger.trace({ url }, `Applying Bearer authentication`);
        options.token = token;
        options.context = { ...options.context, authType };
      } else if (enabled === false) {
        options.enabled = false;