Esempio n. 1
0
    /// <summary>
    ///     With provider for credentials and session token if being used
    /// </summary>
    /// <returns></returns>
    public MinioClient WithCredentialsProvider(ClientProvider provider)
    {
        Provider = provider;
        AccessCredentials credentials = null;

        if (Provider is IAMAWSProvider iAMAWSProvider)
        {
            // Empty object, we need the Minio client completely
            credentials = new AccessCredentials();
        }
        else
        {
            credentials = Provider.GetCredentials();
        }

        if (credentials == null)
        {
            // Unable to fetch credentials.
            return(this);
        }

        AccessKey = credentials.AccessKey;
        SecretKey = credentials.SecretKey;
        var isSessionTokenAvailable = !string.IsNullOrEmpty(credentials.SessionToken);

        if ((Provider is AWSEnvironmentProvider ||
             Provider is IAMAWSProvider ||
             Provider is CertificateIdentityProvider ||
             (Provider is ChainedProvider chainedProvider && chainedProvider.CurrentProvider is AWSEnvironmentProvider)) &&
            isSessionTokenAvailable)
        {
            SessionToken = credentials.SessionToken;
        }
        return(this);
    }