"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
const access_key_credential_1 = __importDefault(require("./access_key_credential"));
const sts_token_credential_1 = __importDefault(require("./sts_token_credential"));
const ecs_ram_role_credential_1 = __importDefault(require("./ecs_ram_role_credential"));
const ram_role_arn_credential_1 = __importDefault(require("./ram_role_arn_credential"));
const oidc_role_arn_credential_1 = __importDefault(require("./oidc_role_arn_credential"));
const rsa_key_pair_credential_1 = __importDefault(require("./rsa_key_pair_credential"));
const bearer_token_credential_1 = __importDefault(require("./bearer_token_credential"));
const DefaultProvider = __importStar(require("./provider/provider_chain"));
const config_1 = __importDefault(require("./config"));
exports.Config = config_1.default;
const uri_credential_1 = __importDefault(require("./uri_credential"));
class Credential {
    constructor(config = null, runtime = {}) {
        this.load(config, runtime);
    }
    getAccessKeyId() {
        return this.credential.getAccessKeyId();
    }
    getAccessKeySecret() {
        return this.credential.getAccessKeySecret();
    }
    getSecurityToken() {
        return this.credential.getSecurityToken();
    }
    getBearerToken() {
        return this.credential.getBearerToken();
    }
    getType() {
        return this.credential.getType();
    }
    getCredential() {
        return this.credential.getCredential();
    }
    load(config, runtime) {
        if (!config) {
            this.credential = DefaultProvider.getCredentials();
            return;
        }
        if (!config.type) {
            throw new Error('Missing required type option');
        }
        switch (config.type) {
            case 'access_key':
                this.credential = new access_key_credential_1.default(config.accessKeyId, config.accessKeySecret);
                break;
            case 'sts':
                this.credential = new sts_token_credential_1.default(config.accessKeyId, config.accessKeySecret, config.securityToken);
                break;
            case 'ecs_ram_role':
                this.credential = new ecs_ram_role_credential_1.default(config.roleName);
                break;
            case 'ram_role_arn':
                this.credential = new ram_role_arn_credential_1.default(config, runtime);
                break;
            case 'oidc_role_arn':
                this.credential = new oidc_role_arn_credential_1.default(config, runtime);
                break;
            case 'rsa_key_pair':
                this.credential = new rsa_key_pair_credential_1.default(config.publicKeyId, config.privateKeyFile);
                break;
            case 'bearer':
                this.credential = new bearer_token_credential_1.default(config.bearerToken);
                break;
            case 'credentials_uri':
                this.credential = new uri_credential_1.default(config.credentialsURI);
                break;
            default:
                throw new Error('Invalid type option, support: access_key, sts, ecs_ram_role, ram_role_arn, rsa_key_pair, credentials_uri');
        }
    }
}
exports.default = Credential;
//# sourceMappingURL=client.js.map