Exemple #1
0
        /// <summary>
        /// If the sts regional flag environment variable is set, then first validate that
        /// it is an acceptable value, if not, then throw an error. Then
        /// set the sts regional flag to that value.
        /// </summary>
        /// <returns> _isRegionalFlagSet: a boolean for whether or not
        /// the environment variable set the regional flag </returns>
        private static StsRegionalEndpointsValue?CheckSTSEnvironmentVariable()
        {
            string stsRegionalFlag = Environment.GetEnvironmentVariable(AwsStsRegionalEndpointsEnvironmentVariable);

            if (!string.IsNullOrEmpty(stsRegionalFlag))
            {
#if BCL35
                StsRegionalEndpointsValue?stsRegionalFlagValue = null;
                try
                {
                    stsRegionalFlagValue = (StsRegionalEndpointsValue)Enum.Parse(typeof(StsRegionalEndpointsValue), stsRegionalFlag, true);
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Invalid value for AWS_STS_REGIONAL_ENDPOINTS environment variable. A string regional/legacy is expected.");
                }
#else
                if (!Enum.TryParse <StsRegionalEndpointsValue>(stsRegionalFlag, true, out var stsRegionalFlagValue))
                {
                    throw new InvalidOperationException("Invalid value for AWS_STS_REGIONAL_ENDPOINTS environment variable. A string regional/legacy is expected.");
                }
#endif
                return(stsRegionalFlagValue);
            }
            return(null);
        }
Exemple #2
0
        private bool TryGetProfile(string profileName, bool doRefresh, out CredentialProfile profile)
        {
            if (doRefresh)
            {
                Refresh();
            }

            Dictionary <string, string> profileDictionary = null;

            if (TryGetSection(profileName, out profileDictionary))
            {
                CredentialProfileOptions    profileOptions;
                Dictionary <string, string> reservedProperties;
                Dictionary <string, string> userProperties;
                PropertyMapping.ExtractProfileParts(profileDictionary, ReservedPropertyNames,
                                                    out profileOptions, out reservedProperties, out userProperties);

                string toolkitArtifactGuidStr;
                Guid?  toolkitArtifactGuid = null;
                if (reservedProperties.TryGetValue(ToolkitArtifactGuidField, out toolkitArtifactGuidStr))
                {
                    if (!GuidUtils.TryParseNullableGuid(toolkitArtifactGuidStr, out toolkitArtifactGuid))
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. GUID expected.", toolkitArtifactGuidStr, ToolkitArtifactGuidField, profileName);
                        profile = null;
                        return(false);
                    }
                }

                string         regionString;
                RegionEndpoint region = null;
                if (reservedProperties.TryGetValue(RegionField, out regionString))
                {
                    region = RegionEndpoint.GetBySystemName(regionString);
                }

                string endpointDiscoveryEnabledString;
                bool?  endpointDiscoveryEnabled = null;
                if (reservedProperties.TryGetValue(EndpointDiscoveryEnabledField, out endpointDiscoveryEnabledString))
                {
                    bool endpointDiscoveryEnabledOut;
                    if (!bool.TryParse(endpointDiscoveryEnabledString, out endpointDiscoveryEnabledOut))
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A boolean true/false is expected.", endpointDiscoveryEnabledString, EndpointDiscoveryEnabledField, profileName);
                        profile = null;
                        return(false);
                    }

                    endpointDiscoveryEnabled = endpointDiscoveryEnabledOut;
                }

                StsRegionalEndpointsValue?stsRegionalEndpoints = null;
                if (reservedProperties.TryGetValue(StsRegionalEndpointsField, out var stsRegionalEndpointsString))
                {
#if BCL35
                    try
                    {
                        stsRegionalEndpoints = (StsRegionalEndpointsValue)Enum.Parse(typeof(StsRegionalEndpointsValue), stsRegionalEndpointsString, true);
                    }
                    catch (Exception)
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", stsRegionalEndpointsString, StsRegionalEndpointsField, profileName);
                        profile = null;
                        return(false);
                    }
#else
                    if (!Enum.TryParse <StsRegionalEndpointsValue>(stsRegionalEndpointsString, true, out var stsRegionalEndpointsTemp))
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", stsRegionalEndpointsString, StsRegionalEndpointsField, profileName);
                        profile = null;
                        return(false);
                    }
                    stsRegionalEndpoints = stsRegionalEndpointsTemp;
#endif
                }

                string s3UseArnRegionString;
                bool?  s3UseArnRegion = null;
                if (reservedProperties.TryGetValue(S3UseArnRegionField, out s3UseArnRegionString))
                {
                    bool s3UseArnRegionOut;
                    if (!bool.TryParse(s3UseArnRegionString, out s3UseArnRegionOut))
                    {
                        profile = null;
                        return(false);
                    }
                    s3UseArnRegion = s3UseArnRegionOut;
                }

                S3UsEast1RegionalEndpointValue?s3RegionalEndpoint = null;
                if (reservedProperties.TryGetValue(S3RegionalEndpointField, out var s3RegionalEndpointString))
                {
#if BCL35
                    try
                    {
                        s3RegionalEndpoint = (S3UsEast1RegionalEndpointValue)Enum.Parse(typeof(S3UsEast1RegionalEndpointValue), s3RegionalEndpointString, true);
                    }
                    catch (Exception)
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", s3RegionalEndpointString, S3RegionalEndpointField, profileName);
                        profile = null;
                        return(false);
                    }
#else
                    if (!Enum.TryParse <S3UsEast1RegionalEndpointValue>(s3RegionalEndpointString, true, out var s3RegionalEndpointTemp))
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", s3RegionalEndpointString, S3RegionalEndpointField, profileName);
                        profile = null;
                        return(false);
                    }
                    s3RegionalEndpoint = s3RegionalEndpointTemp;
#endif
                }

                RequestRetryMode?requestRetryMode = null;
                if (reservedProperties.TryGetValue(RetryModeField, out var retryModeString))
                {
#if BCL35
                    try
                    {
                        requestRetryMode = (RequestRetryMode)Enum.Parse(typeof(RequestRetryMode), retryModeString, true);
                    }
                    catch (Exception)
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string legacy/standard/adaptive is expected.", retryModeString, RetryModeField, profileName);
                        profile = null;
                        return(false);
                    }
#else
                    if (!Enum.TryParse <RequestRetryMode>(retryModeString, true, out var retryModeTemp))
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string legacy/standard/adaptive is expected.", retryModeString, RetryModeField, profileName);
                        profile = null;
                        return(false);
                    }
                    requestRetryMode = retryModeTemp;
#endif
                }

                int?maxAttempts = null;
                if (reservedProperties.TryGetValue(MaxAttemptsField, out var maxAttemptsString))
                {
                    if (!int.TryParse(maxAttemptsString, out var maxAttemptsTemp) || maxAttemptsTemp <= 0)
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A positive integer is expected.", maxAttemptsString, MaxAttemptsField, profileName);
                        profile = null;
                        return(false);
                    }

                    maxAttempts = maxAttemptsTemp;
                }

                profile = new CredentialProfile(profileName, profileOptions)
                {
                    UniqueKey                = toolkitArtifactGuid,
                    Properties               = userProperties,
                    Region                   = region,
                    CredentialProfileStore   = this,
                    EndpointDiscoveryEnabled = endpointDiscoveryEnabled,
                    StsRegionalEndpoints     = stsRegionalEndpoints,
                    S3UseArnRegion           = s3UseArnRegion,
                    S3RegionalEndpoint       = s3RegionalEndpoint,
                    RetryMode                = requestRetryMode,
                    MaxAttempts              = maxAttempts
                };

                if (!IsSupportedProfileType(profile.ProfileType))
                {
                    _logger.InfoFormat("The profile type {0} is not supported by SharedCredentialsFile.", profile.ProfileType);
                    profile = null;
                    return(false);
                }

                return(true);
            }

            profile = null;
            return(false);
        }
        /// <summary>
        /// Get the profile with the name given, if it exists in this store.
        /// </summary>
        /// <param name="profileName">The name of the profile to find.</param>
        /// <param name="profile">The profile, if it was found, null otherwise</param>
        /// <returns>True if the profile was found, false otherwise.</returns>
        public bool TryGetProfile(string profileName, out CredentialProfile profile)
        {
            Dictionary <string, string> properties;
            string uniqueKeyStr;

            if (_settingsManager.TryGetObject(profileName, out uniqueKeyStr, out properties))
            {
                try
                {
                    CredentialProfileOptions    profileOptions;
                    Dictionary <string, string> userProperties;
                    Dictionary <string, string> reservedProperties;
                    PropertyMapping.ExtractProfileParts(properties, ReservedPropertyNames, out profileOptions, out reservedProperties, out userProperties);

                    string         regionString;
                    RegionEndpoint region = null;
                    if (reservedProperties.TryGetValue(RegionField, out regionString))
                    {
                        region = RegionEndpoint.GetBySystemName(regionString);
                    }

                    Guid?uniqueKey = null;
                    if (!GuidUtils.TryParseNullableGuid(uniqueKeyStr, out uniqueKey))
                    {
                        profile = null;
                        return(false);
                    }

                    string endpointDiscoveryEnabledString;
                    bool?  endpointDiscoveryEnabled = null;
                    if (reservedProperties.TryGetValue(EndpointDiscoveryEnabledField, out endpointDiscoveryEnabledString))
                    {
                        bool endpointDiscoveryEnabledOut;
                        if (!bool.TryParse(endpointDiscoveryEnabledString, out endpointDiscoveryEnabledOut))
                        {
                            profile = null;
                            return(false);
                        }

                        endpointDiscoveryEnabled = endpointDiscoveryEnabledOut;
                    }

                    StsRegionalEndpointsValue?stsRegionalEndpoints = null;
                    if (reservedProperties.TryGetValue(StsRegionalEndpointsField, out var stsRegionalEndpointsString))
                    {
#if BCL35
                        try
                        {
                            stsRegionalEndpoints = (StsRegionalEndpointsValue)Enum.Parse(typeof(StsRegionalEndpointsValue), stsRegionalEndpointsString, true);
                        }
                        catch (Exception)
                        {
                            profile = null;
                            return(false);
                        }
#else
                        if (!Enum.TryParse <StsRegionalEndpointsValue>(stsRegionalEndpointsString, true, out var tempStsRegionalEndpoints))
                        {
                            profile = null;
                            return(false);
                        }
                        stsRegionalEndpoints = tempStsRegionalEndpoints;
#endif
                    }

                    string s3UseArnRegionString;
                    bool?  s3UseArnRegion = null;
                    if (reservedProperties.TryGetValue(S3UseArnRegionField, out s3UseArnRegionString))
                    {
                        bool s3UseArnRegionOut;
                        if (!bool.TryParse(s3UseArnRegionString, out s3UseArnRegionOut))
                        {
                            profile = null;
                            return(false);
                        }

                        s3UseArnRegion = s3UseArnRegionOut;
                    }

                    S3UsEast1RegionalEndpointValue?s3RegionalEndpoint = null;
                    if (reservedProperties.TryGetValue(S3RegionalEndpointField, out var s3RegionalEndpointString))
                    {
#if BCL35
                        try
                        {
                            s3RegionalEndpoint = (S3UsEast1RegionalEndpointValue)Enum.Parse(typeof(S3UsEast1RegionalEndpointValue), s3RegionalEndpointString, true);
                        }
                        catch (Exception)
                        {
                            profile = null;
                            return(false);
                        }
#else
                        if (!Enum.TryParse <S3UsEast1RegionalEndpointValue>(s3RegionalEndpointString, true, out var tempS3RegionalEndpoint))
                        {
                            profile = null;
                            return(false);
                        }
                        s3RegionalEndpoint = tempS3RegionalEndpoint;
#endif
                    }

                    RequestRetryMode?requestRetryMode = null;
                    if (reservedProperties.TryGetValue(RetryModeField, out var retryModeString))
                    {
#if BCL35
                        try
                        {
                            requestRetryMode = (RequestRetryMode)Enum.Parse(typeof(RequestRetryMode), retryModeString, true);
                        }
                        catch (Exception)
                        {
                            profile = null;
                            return(false);
                        }
#else
                        if (!Enum.TryParse <RequestRetryMode>(retryModeString, true, out var tempRetryMode))
                        {
                            profile = null;
                            return(false);
                        }
                        requestRetryMode = tempRetryMode;
#endif
                    }

                    int?maxAttempts = null;
                    if (reservedProperties.TryGetValue(MaxAttemptsField, out var maxAttemptsString))
                    {
                        if (!int.TryParse(maxAttemptsString, out var maxAttemptsTemp) || maxAttemptsTemp <= 0)
                        {
                            Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A positive integer is expected.", maxAttemptsString, MaxAttemptsField, profileName);
                            profile = null;
                            return(false);
                        }

                        maxAttempts = maxAttemptsTemp;
                    }

                    profile = new CredentialProfile(profileName, profileOptions)
                    {
                        UniqueKey                = uniqueKey,
                        Properties               = userProperties,
                        Region                   = region,
                        CredentialProfileStore   = this,
                        EndpointDiscoveryEnabled = endpointDiscoveryEnabled,
                        StsRegionalEndpoints     = stsRegionalEndpoints,
                        S3UseArnRegion           = s3UseArnRegion,
                        S3RegionalEndpoint       = s3RegionalEndpoint,
                        RetryMode                = requestRetryMode,
                        MaxAttempts              = maxAttempts
                    };
                    return(true);
                }
                catch (ArgumentException)
                {
                    profile = null;
                    return(false);
                }
            }
            else
            {
                profile = null;
                return(false);
            }
        }
        /// <summary>
        /// Get the profile with the name given, if it exists in this store.
        /// </summary>
        /// <param name="profileName">The name of the profile to find.</param>
        /// <param name="profile">The profile, if it was found, null otherwise</param>
        /// <returns>True if the profile was found, false otherwise.</returns>
        public bool TryGetProfile(string profileName, out CredentialProfile profile)
        {
            Dictionary <string, string> properties;
            string uniqueKeyStr;

            if (_settingsManager.TryGetObject(profileName, out uniqueKeyStr, out properties))
            {
                try
                {
                    CredentialProfileOptions    profileOptions;
                    Dictionary <string, string> userProperties;
                    Dictionary <string, string> reservedProperties;
                    PropertyMapping.ExtractProfileParts(properties, ReservedPropertyNames, out profileOptions, out reservedProperties, out userProperties);

                    string         regionString;
                    RegionEndpoint region = null;
                    if (reservedProperties.TryGetValue(RegionField, out regionString))
                    {
                        region = RegionEndpoint.GetBySystemName(regionString);
                    }

                    Guid?uniqueKey = null;
                    if (!GuidUtils.TryParseNullableGuid(uniqueKeyStr, out uniqueKey))
                    {
                        profile = null;
                        return(false);
                    }

                    string endpointDiscoveryEnabledString;
                    bool?  endpointDiscoveryEnabled = null;
                    if (reservedProperties.TryGetValue(EndpointDiscoveryEnabledField, out endpointDiscoveryEnabledString))
                    {
                        bool endpointDiscoveryEnabledOut;
                        if (!bool.TryParse(endpointDiscoveryEnabledString, out endpointDiscoveryEnabledOut))
                        {
                            profile = null;
                            return(false);
                        }

                        endpointDiscoveryEnabled = endpointDiscoveryEnabledOut;
                    }

                    StsRegionalEndpointsValue?stsRegionalEndpoints = null;
                    if (reservedProperties.TryGetValue(StsRegionalEndpointsField, out var stsRegionalEndpointsString))
                    {
#if BCL35
                        try
                        {
                            stsRegionalEndpoints = (StsRegionalEndpointsValue)Enum.Parse(typeof(StsRegionalEndpointsValue), stsRegionalEndpointsString, true);
                        }
                        catch (Exception)
                        {
                            profile = null;
                            return(false);
                        }
#else
                        if (!Enum.TryParse <StsRegionalEndpointsValue>(stsRegionalEndpointsString, true, out var tempStsRegionalEndpoints))
                        {
                            profile = null;
                            return(false);
                        }
                        stsRegionalEndpoints = tempStsRegionalEndpoints;
#endif
                    }

                    string s3UseArnRegionString;
                    bool?  s3UseArnRegion = null;
                    if (reservedProperties.TryGetValue(S3UseArnRegionField, out s3UseArnRegionString))
                    {
                        bool s3UseArnRegionOut;
                        if (!bool.TryParse(s3UseArnRegionString, out s3UseArnRegionOut))
                        {
                            profile = null;
                            return(false);
                        }

                        s3UseArnRegion = s3UseArnRegionOut;
                    }

                    S3UsEast1RegionalEndpointValue?s3RegionalEndpoint = null;
                    if (reservedProperties.TryGetValue(S3RegionalEndpointField, out var s3RegionalEndpointString))
                    {
#if BCL35
                        try
                        {
                            s3RegionalEndpoint = (S3UsEast1RegionalEndpointValue)Enum.Parse(typeof(S3UsEast1RegionalEndpointValue), s3RegionalEndpointString, true);
                        }
                        catch (Exception)
                        {
                            profile = null;
                            return(false);
                        }
#else
                        if (!Enum.TryParse <S3UsEast1RegionalEndpointValue>(s3RegionalEndpointString, true, out var tempS3RegionalEndpoint))
                        {
                            profile = null;
                            return(false);
                        }
                        s3RegionalEndpoint = tempS3RegionalEndpoint;
#endif
                    }

                    profile = new CredentialProfile(profileName, profileOptions)
                    {
                        UniqueKey                = uniqueKey,
                        Properties               = userProperties,
                        Region                   = region,
                        CredentialProfileStore   = this,
                        EndpointDiscoveryEnabled = endpointDiscoveryEnabled,
                        StsRegionalEndpoints     = stsRegionalEndpoints,
                        S3UseArnRegion           = s3UseArnRegion,
                        S3RegionalEndpoint       = s3RegionalEndpoint
                    };
                    return(true);
                }
                catch (ArgumentException)
                {
                    profile = null;
                    return(false);
                }
            }
            else
            {
                profile = null;
                return(false);
            }
        }
Exemple #5
0
        private bool TryGetProfile(string profileName, bool doRefresh, out CredentialProfile profile)
        {
            if (doRefresh)
            {
                Refresh();
            }

            Dictionary <string, string> profileDictionary = null;

            if (TryGetSection(profileName, out profileDictionary))
            {
                CredentialProfileOptions    profileOptions;
                Dictionary <string, string> reservedProperties;
                Dictionary <string, string> userProperties;
                PropertyMapping.ExtractProfileParts(
                    profileDictionary,
                    ReservedPropertyNames,
                    out profileOptions,
                    out reservedProperties,
                    out userProperties);

                string toolkitArtifactGuidStr;
                Guid?  toolkitArtifactGuid = null;
                if (reservedProperties.TryGetValue(ToolkitArtifactGuidField, out toolkitArtifactGuidStr))
                {
                    if (!GuidUtils.TryParseNullableGuid(toolkitArtifactGuidStr, out toolkitArtifactGuid))
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. GUID expected.", toolkitArtifactGuidStr, ToolkitArtifactGuidField, profileName);
                        profile = null;
                        return(false);
                    }
                }

                string         regionString;
                RegionEndpoint region = null;
                if (reservedProperties.TryGetValue(RegionField, out regionString))
                {
                    region = RegionEndpoint.GetBySystemName(regionString);
                }

                string endpointDiscoveryEnabledString;
                bool?  endpointDiscoveryEnabled = null;
                if (reservedProperties.TryGetValue(EndpointDiscoveryEnabledField, out endpointDiscoveryEnabledString))
                {
                    bool endpointDiscoveryEnabledOut;
                    if (!bool.TryParse(endpointDiscoveryEnabledString, out endpointDiscoveryEnabledOut))
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A boolean true/false is expected.", endpointDiscoveryEnabledString, EndpointDiscoveryEnabledField, profileName);
                        profile = null;
                        return(false);
                    }

                    endpointDiscoveryEnabled = endpointDiscoveryEnabledOut;
                }

                StsRegionalEndpointsValue?stsRegionalEndpoints = null;
                if (reservedProperties.TryGetValue(StsRegionalEndpointsField, out var stsRegionalEndpointsString))
                {
#if BCL35
                    try
                    {
                        stsRegionalEndpoints = (StsRegionalEndpointsValue)Enum.Parse(typeof(StsRegionalEndpointsValue), stsRegionalEndpointsString, true);
                    }
                    catch (Exception)
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", stsRegionalEndpointsString, StsRegionalEndpointsField, profileName);
                        profile = null;
                        return(false);
                    }
#else
                    if (!Enum.TryParse <StsRegionalEndpointsValue>(stsRegionalEndpointsString, true, out var stsRegionalEndpointsTemp))
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", stsRegionalEndpointsString, StsRegionalEndpointsField, profileName);
                        profile = null;
                        return(false);
                    }
                    stsRegionalEndpoints = stsRegionalEndpointsTemp;
#endif
                }

                string s3UseArnRegionString;
                bool?  s3UseArnRegion = null;
                if (reservedProperties.TryGetValue(S3UseArnRegionField, out s3UseArnRegionString))
                {
                    bool s3UseArnRegionOut;
                    if (!bool.TryParse(s3UseArnRegionString, out s3UseArnRegionOut))
                    {
                        profile = null;
                        return(false);
                    }
                    s3UseArnRegion = s3UseArnRegionOut;
                }

                S3UsEast1RegionalEndpointValue?s3RegionalEndpoint = null;
                if (reservedProperties.TryGetValue(S3RegionalEndpointField, out var s3RegionalEndpointString))
                {
#if BCL35
                    try
                    {
                        s3RegionalEndpoint = (S3UsEast1RegionalEndpointValue)Enum.Parse(typeof(S3UsEast1RegionalEndpointValue), s3RegionalEndpointString, true);
                    }
                    catch (Exception)
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", s3RegionalEndpointString, S3RegionalEndpointField, profileName);
                        profile = null;
                        return(false);
                    }
#else
                    if (!Enum.TryParse <S3UsEast1RegionalEndpointValue>(s3RegionalEndpointString, true, out var s3RegionalEndpointTemp))
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string regional/legacy is expected.", s3RegionalEndpointString, S3RegionalEndpointField, profileName);
                        profile = null;
                        return(false);
                    }
                    s3RegionalEndpoint = s3RegionalEndpointTemp;
#endif
                }

                string s3DisableMultiRegionAccessPointsString;
                bool?  s3DisableMultiRegionAccessPoints = null;
                if (reservedProperties.TryGetValue(S3DisableMultiRegionAccessPointsField, out s3DisableMultiRegionAccessPointsString))
                {
                    bool s3DisableMultiRegionAccessPointsOut;
                    if (!bool.TryParse(s3DisableMultiRegionAccessPointsString, out s3DisableMultiRegionAccessPointsOut))
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A boolean true/false is expected.", s3DisableMultiRegionAccessPointsString, S3DisableMultiRegionAccessPointsField, profileName);
                        profile = null;
                        return(false);
                    }
                    s3DisableMultiRegionAccessPoints = s3DisableMultiRegionAccessPointsOut;
                }


                RequestRetryMode?requestRetryMode = null;
                if (reservedProperties.TryGetValue(RetryModeField, out var retryModeString))
                {
#if BCL35
                    try
                    {
                        requestRetryMode = (RequestRetryMode)Enum.Parse(typeof(RequestRetryMode), retryModeString, true);
                    }
                    catch (Exception)
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string legacy/standard/adaptive is expected.", retryModeString, RetryModeField, profileName);
                        profile = null;
                        return(false);
                    }
#else
                    if (!Enum.TryParse <RequestRetryMode>(retryModeString, true, out var retryModeTemp))
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string legacy/standard/adaptive is expected.", retryModeString, RetryModeField, profileName);
                        profile = null;
                        return(false);
                    }
                    requestRetryMode = retryModeTemp;
#endif
                }

                int?maxAttempts = null;
                if (reservedProperties.TryGetValue(MaxAttemptsField, out var maxAttemptsString))
                {
                    if (!int.TryParse(maxAttemptsString, out var maxAttemptsTemp) || maxAttemptsTemp <= 0)
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A positive integer is expected.", maxAttemptsString, MaxAttemptsField, profileName);
                        profile = null;
                        return(false);
                    }

                    maxAttempts = maxAttemptsTemp;
                }

                string defaultConfigurationModeName;
                reservedProperties.TryGetValue(DefaultConfigurationModeField, out defaultConfigurationModeName);

                string ec2MetadataServiceEndpoint;
                if (reservedProperties.TryGetValue(EC2MetadataServiceEndpointField, out ec2MetadataServiceEndpoint))
                {
                    if (!Uri.IsWellFormedUriString(ec2MetadataServiceEndpoint, UriKind.Absolute))
                    {
                        throw new AmazonClientException($"Invalid value {ec2MetadataServiceEndpoint} for {EC2MetadataServiceEndpointField} in profile {profileName}. A well-formed Uri is expected.");
                    }
                }

                EC2MetadataServiceEndpointMode?ec2MetadataServiceEndpointMode = null;
                if (reservedProperties.TryGetValue(EC2MetadataServiceEndpointModeField, out var ec2MetadataServiceEndpointModeString))
                {
#if BCL35
                    try
                    {
                        ec2MetadataServiceEndpointMode = (EC2MetadataServiceEndpointMode)Enum.Parse(typeof(EC2MetadataServiceEndpointMode), ec2MetadataServiceEndpointModeString, true);
                    }
                    catch (Exception)
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string IPv4 or IPV6 is expected.", ec2MetadataServiceEndpointModeString, EC2MetadataServiceEndpointModeField, profileName);
                        profile = null;
                        return(false);
                    }
#else
                    if (!Enum.TryParse <EC2MetadataServiceEndpointMode>(ec2MetadataServiceEndpointModeString, true, out var ec2MetadataServiceEndpointModeTemp))
                    {
                        _logger.InfoFormat("Invalid value {0} for {1} in profile {2}. A string IPv4 or IPV6 is expected.", ec2MetadataServiceEndpointModeString, EC2MetadataServiceEndpointModeField, profileName);
                        profile = null;
                        return(false);
                    }
                    ec2MetadataServiceEndpointMode = ec2MetadataServiceEndpointModeTemp;
#endif
                }

                string useDualstackEndpointString;
                bool?  useDualstackEndpoint = null;
                if (reservedProperties.TryGetValue(UseDualstackEndpointField, out useDualstackEndpointString))
                {
                    bool useDualstackEndpointOut;
                    if (!bool.TryParse(useDualstackEndpointString, out useDualstackEndpointOut))
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A boolean true/false is expected.", useDualstackEndpointString, UseDualstackEndpointField, profileName);
                        profile = null;
                        return(false);
                    }
                    useDualstackEndpoint = useDualstackEndpointOut;
                }

                string useFIPSEndpointString;
                bool?  useFIPSEndpoint = null;
                if (reservedProperties.TryGetValue(UseFIPSEndpointField, out useFIPSEndpointString))
                {
                    bool useFIPSEndpointOut;
                    if (!bool.TryParse(useFIPSEndpointString, out useFIPSEndpointOut))
                    {
                        Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A boolean true/false is expected.", useFIPSEndpointString, UseFIPSEndpointField, profileName);
                        profile = null;
                        return(false);
                    }
                    useFIPSEndpoint = useFIPSEndpointOut;
                }

                profile = new CredentialProfile(profileName, profileOptions)
                {
                    UniqueKey                        = toolkitArtifactGuid,
                    Properties                       = userProperties,
                    Region                           = region,
                    CredentialProfileStore           = this,
                    DefaultConfigurationModeName     = defaultConfigurationModeName,
                    EndpointDiscoveryEnabled         = endpointDiscoveryEnabled,
                    StsRegionalEndpoints             = stsRegionalEndpoints,
                    S3UseArnRegion                   = s3UseArnRegion,
                    S3RegionalEndpoint               = s3RegionalEndpoint,
                    S3DisableMultiRegionAccessPoints = s3DisableMultiRegionAccessPoints,
                    RetryMode                        = requestRetryMode,
                    MaxAttempts                      = maxAttempts,
                    EC2MetadataServiceEndpoint       = ec2MetadataServiceEndpoint,
                    EC2MetadataServiceEndpointMode   = ec2MetadataServiceEndpointMode,
                    UseDualstackEndpoint             = useDualstackEndpoint,
                    UseFIPSEndpoint                  = useFIPSEndpoint
                };

                if (!IsSupportedProfileType(profile.ProfileType))
                {
                    _logger.InfoFormat("The profile type {0} is not supported by SharedCredentialsFile.", profile.ProfileType);
                    profile = null;
                    return(false);
                }

                return(true);
            }

            profile = null;
            return(false);
        }