예제 #1
0
        /// <summary>
        /// Creates the AWSCredentials using either the profile indicated from the AWSOptions object
        /// of the SDK fallback credentials search.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static AWSCredentials CreateCredentials(AWSOptions options)
        {
            if (options != null &&
                !string.IsNullOrEmpty(options.Profile) &&
                StoredProfileAWSCredentials.IsProfileKnown(options.Profile, options.ProfilesLocation))
            {
                return(new StoredProfileAWSCredentials(options.Profile, options.ProfilesLocation));
            }

            return(FallbackCredentialsFactory.GetCredentials());
        }
예제 #2
0
        private static AWSCredentials DetermineCredentials(AWSLoggerConfig config)
        {
            if (config.Credentials != null)
            {
                return(config.Credentials);
            }
            if (!string.IsNullOrEmpty(config.Profile) && StoredProfileAWSCredentials.IsProfileKnown(config.Profile, config.ProfilesLocation))
            {
                return(new StoredProfileAWSCredentials(config.Profile, config.ProfilesLocation));
            }

            return(FallbackCredentialsFactory.GetCredentials());
        }
예제 #3
0
        private AWSCredentials DetermineAWSCredentials()
        {
            AWSCredentials credentials;

            if (this.Credentials != null)
            {
                credentials = this.Credentials;
            }
            else
            {
                var profile = this.Profile;
                if (string.IsNullOrEmpty(profile))
                {
                    profile = DefaultConfig[DefinedCommandOptions.ARGUMENT_AWS_PROFILE.Switch] as string;
                }

                if (!string.IsNullOrEmpty(profile))
                {
                    if (!StoredProfileAWSCredentials.IsProfileKnown(profile, this.ProfileLocation))
                    {
                        throw new LambdaToolsException($"Profile {profile} cannot be found", LambdaToolsException.ErrorCode.ProfileNotFound);
                    }
                    if (!StoredProfileAWSCredentials.CanCreateFrom(profile, this.ProfileLocation))
                    {
                        throw new LambdaToolsException($"Cannot create AWS credentials for profile {profile}", LambdaToolsException.ErrorCode.ProfileNotCreateable);
                    }
                    credentials = new StoredProfileAWSCredentials(profile, this.ProfileLocation);
                }
                else
                {
                    credentials = FallbackCredentialsFactory.GetCredentials();
                }
            }

            return(credentials);
        }