protected override void ProcessRecord() { AWSPSCredentials currentCredentials = null; if (this.TryGetCredentials(Host, out currentCredentials, SessionState)) { // used to be equivalent of write-host but got customer feedback that the inability to // suppress it interfered with console output (https://forums.aws.amazon.com/thread.jspa?threadID=211600&tstart=0). WriteVerbose(InitializeDefaultConfigurationCmdlet.CredentialsSourceMessage(currentCredentials)); } else { this.ThrowTerminatingError(new ErrorRecord(new ArgumentException("Cannot determine credentials from supplied parameters"), "ArgumentException", ErrorCategory.InvalidArgument, this)); } if (currentCredentials != null) { WriteObject(currentCredentials.Credentials); } }
protected override void ProcessRecord() { AWSPSCredentials currentCredentials = null; if (this.TryGetCredentials(Host, out currentCredentials, SessionState)) { WriteVerbose(InitializeDefaultConfigurationCmdlet.CredentialsSourceMessage(currentCredentials)); if (string.IsNullOrEmpty(StoreAs)) { SetUpIfFederatedCredentials(currentCredentials); string scope = MyInvocation.BoundParameters.ContainsKey("Scope") ? Scope.ToString() + ":" : ""; this.SessionState.PSVariable.Set(scope + SessionKeys.AWSCredentialsVariableName, currentCredentials); } else { if (MyInvocation.BoundParameters.ContainsKey("Scope")) { this.ThrowTerminatingError(new ErrorRecord( new ArgumentException("Parameters Scope and StoreAs cannot be used together."), "ArgumentException", ErrorCategory.InvalidArgument, this)); } if (string.Equals(AWSCredentialsArgumentsFullCmdlet.AWSCredentialsObjectSet, ParameterSetName, StringComparison.Ordinal)) { // We're storing from the -Credential parameter to a credentials file. // Only some types of AWSCredentials are supported. var options = CredentialProfileOptionsExtractor.ExtractProfileOptions(currentCredentials.Credentials); if (options != null) { SettingsStore.RegisterProfile(options, StoreAs, ProfileLocation, null); } } else { if (string.Equals(AWSCredentialsArgumentsFullCmdlet.StoredProfileSet, ParameterSetName, StringComparison.Ordinal)) { // We're copying from one profile to another. var chain = new CredentialProfileStoreChain(ProfileLocation); CredentialProfile profile; if (chain.TryGetProfile(ProfileName, out profile)) { profile.CredentialProfileStore.CopyProfile(ProfileName, StoreAs, true); } else { // Parameters.TryGetCredentials has already tested for this but... this.ThrowTerminatingError(new ErrorRecord( new ArgumentException("Cannot determine credentials from supplied parameters"), "ArgumentException", ErrorCategory.InvalidArgument, this)); } } else { // We're storing from individual command line values to a credentials file. SettingsStore.RegisterProfile(GetCredentialProfileOptions(), StoreAs, ProfileLocation, null); } } if (string.IsNullOrEmpty(ProfileLocation)) { WriteVerbose("Updated .NET credentials file."); } else { WriteVerbose("Updated shared credentials file at " + ProfileLocation); } } } else { this.ThrowTerminatingError(new ErrorRecord(new ArgumentException("Cannot determine credentials from supplied parameters"), "ArgumentException", ErrorCategory.InvalidArgument, this)); } }