示例#1
0
        /// <summary>
        /// Add the profile to this store, if it's valid.
        /// </summary>
        /// <param name="profile">The profile to add.</param>
        public void RegisterProfile(CredentialProfile profile)
        {
            if (profile.CanCreateAWSCredentials || profile.Options.IsEmpty)
            {
                var reservedProperties = new Dictionary <string, string>();
                if (profile.CanCreateAWSCredentials)
                {
                    // set profile type field for backward compatibility
                    SetProfileTypeField(reservedProperties, profile.ProfileType.Value);
                }

                if (profile.Region != null)
                {
                    reservedProperties[RegionField] = profile.Region.SystemName;
                }

                var profileDictionary = PropertyMapping.CombineProfileParts(
                    profile.Options, ReservedPropertyNames, reservedProperties, profile.Properties);

                // Set the UniqueKey.  It might change if the unique key is set by the objectManger,
                // or if this is an update to an existing profile.
                string newUniqueKeyStr = settingsManager.RegisterObject(profile.Name, profileDictionary);
                Guid?  newUniqueKey;
                if (GuidUtils.TryParseNullableGuid(newUniqueKeyStr, out newUniqueKey))
                {
                    profile.UniqueKey = newUniqueKey;
                }
                profile.CredentialProfileStore = this;
            }
            else
            {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture,
                                                          "Unable to register profile {0}.  The CredentialProfileOptions provided is not valid.", profile.Name));
            }
        }
示例#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);
                }

                profile = new CredentialProfile(profileName, profileOptions)
                {
                    UniqueKey              = toolkitArtifactGuid,
                    Properties             = userProperties,
                    Region                 = region,
                    CredentialProfileStore = this
                };

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

                return(true);
            }
            else
            {
                profile = null;
                return(false);
            }
        }
示例#3
0
        /// <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);
                    }

                    profile = new CredentialProfile(profileName, profileOptions)
                    {
                        UniqueKey              = uniqueKey,
                        Properties             = userProperties,
                        Region                 = region,
                        CredentialProfileStore = this
                    };
                    return(true);
                }
                catch (ArgumentException)
                {
                    profile = null;
                    return(false);
                }
            }
            else
            {
                profile = null;
                return(false);
            }
        }
示例#4
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);
            }
        }
示例#7
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);
        }