Skip to content
Snippets Groups Projects
Select Git revision
  • 1ff8c2806ceaff6970cdb98f01b3971035d05e90
  • main default protected
  • dependabot/github_actions/ci-641206964f
  • upgrade-deps
  • release/v2.6.x
  • conform-k8s-1.33
  • rfc-external-artifact
  • release/v2.5.x
  • release/v2.4.x
  • remove-notation-validation
  • release/v2.3.x
  • release/v2.2.x
  • RFC
  • fix-commit-log
  • flux-audit
  • release/v2.1.x
  • context-ns
  • ksm-dashboard
  • rfc-passwordless-git-auth
  • release/v2.0.x
  • rfc-gating
  • v2.6.4 protected
  • v2.6.3 protected
  • v2.6.2 protected
  • v2.6.1 protected
  • v2.6.0 protected
  • v2.5.1 protected
  • v2.5.0 protected
  • v2.4.0 protected
  • v2.3.0 protected
  • v2.2.3 protected
  • v2.2.2 protected
  • v2.2.1 protected
  • v2.2.0 protected
  • v2.1.2 protected
  • v2.1.1 protected
  • v2.1.0 protected
  • v2.0.1 protected
  • v2.0.0 protected
  • v2.0.0-rc.5 protected
  • v2.0.0-rc.4 protected
41 results

get_receiver.go

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;