Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BaseIO.php

function BaseIO::loadConfiguration

@inheritDoc

Overrides IOInterface::loadConfiguration

File

vendor/composer/composer/src/Composer/IO/BaseIO.php, line 116

Class

BaseIO

Namespace

Composer\IO

Code

public function loadConfiguration(Config $config) {
    $bitbucketOauth = $config->get('bitbucket-oauth');
    $githubOauth = $config->get('github-oauth');
    $gitlabOauth = $config->get('gitlab-oauth');
    $gitlabToken = $config->get('gitlab-token');
    $httpBasic = $config->get('http-basic');
    $bearerToken = $config->get('bearer');
    // reload oauth tokens from config if available
    foreach ($bitbucketOauth as $domain => $cred) {
        $this->checkAndSetAuthentication($domain, $cred['consumer-key'], $cred['consumer-secret']);
    }
    foreach ($githubOauth as $domain => $token) {
        if ($domain !== 'github.com' && !in_array($domain, $config->get('github-domains'), true)) {
            $this->debug($domain . ' is not in the configured github-domains, adding it implicitly as authentication is configured for this domain');
            $config->merge([
                'config' => [
                    'github-domains' => array_merge($config->get('github-domains'), [
                        $domain,
                    ]),
                ],
            ], 'implicit-due-to-auth');
        }
        // allowed chars for GH tokens are from https://github.blog/changelog/2021-03-04-authentication-token-format-updates/
        // plus dots which were at some point used for GH app integration tokens
        if (!Preg::isMatch('{^[.A-Za-z0-9_]+$}', $token)) {
            throw new \UnexpectedValueException('Your github oauth token for ' . $domain . ' contains invalid characters: "' . $token . '"');
        }
        $this->checkAndSetAuthentication($domain, $token, 'x-oauth-basic');
    }
    foreach ($gitlabOauth as $domain => $token) {
        if ($domain !== 'gitlab.com' && !in_array($domain, $config->get('gitlab-domains'), true)) {
            $this->debug($domain . ' is not in the configured gitlab-domains, adding it implicitly as authentication is configured for this domain');
            $config->merge([
                'config' => [
                    'gitlab-domains' => array_merge($config->get('gitlab-domains'), [
                        $domain,
                    ]),
                ],
            ], 'implicit-due-to-auth');
        }
        $token = is_array($token) ? $token["token"] : $token;
        $this->checkAndSetAuthentication($domain, $token, 'oauth2');
    }
    foreach ($gitlabToken as $domain => $token) {
        if ($domain !== 'gitlab.com' && !in_array($domain, $config->get('gitlab-domains'), true)) {
            $this->debug($domain . ' is not in the configured gitlab-domains, adding it implicitly as authentication is configured for this domain');
            $config->merge([
                'config' => [
                    'gitlab-domains' => array_merge($config->get('gitlab-domains'), [
                        $domain,
                    ]),
                ],
            ], 'implicit-due-to-auth');
        }
        $username = is_array($token) ? $token["username"] : $token;
        $password = is_array($token) ? $token["token"] : 'private-token';
        $this->checkAndSetAuthentication($domain, $username, $password);
    }
    // reload http basic credentials from config if available
    foreach ($httpBasic as $domain => $cred) {
        $this->checkAndSetAuthentication($domain, $cred['username'], $cred['password']);
    }
    foreach ($bearerToken as $domain => $token) {
        $this->checkAndSetAuthentication($domain, $token, 'bearer');
    }
    // setup process timeout
    ProcessExecutor::setTimeout($config->get('process-timeout'));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal