Skip to content

Commit

Permalink
Fix configuration failure with missing configuration file from AWS CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jul 27, 2018
1 parent c5d80f9 commit bed7ec3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Expand Up @@ -34,6 +34,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import java.io.File;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
Expand All @@ -42,6 +43,7 @@
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.profile.ProfilesConfigFile;
import com.amazonaws.auth.profile.internal.BasicProfile;
import com.amazonaws.profile.path.AwsProfileFileLocationProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder;
Expand Down Expand Up @@ -70,8 +72,13 @@ public Credentials configure(final Host host) throws LoginFailureException, Logi
if(log.isDebugEnabled()) {
log.debug(String.format("Look for profile name %s in ~/.aws/credentials", profile));
}
final File file = AwsProfileFileLocationProvider.DEFAULT_CREDENTIALS_LOCATION_PROVIDER.getLocation();
if(null == file) {
log.warn("Missing configuration file ~/.aws/ccredentials. Skip auto configuration");
return host.getCredentials();
}
// Iterating all profiles on our own because AWSProfileCredentialsConfigurator does not support MFA tokens
final ProfilesConfigFile config = new ProfilesConfigFile();
final ProfilesConfigFile config = new ProfilesConfigFile(file);
final Map<String, BasicProfile> profiles = config.getAllBasicProfiles();
final Optional<Map.Entry<String, BasicProfile>> optional = profiles.entrySet().stream().filter(new Predicate<Map.Entry<String, BasicProfile>>() {
@Override
Expand Down
@@ -0,0 +1,30 @@
package ch.cyberduck.core.sts;

/*
* Copyright (c) 2002-2018 iterate GmbH. All rights reserved.
* https://cyberduck.io/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

import ch.cyberduck.core.DisabledPasswordCallback;
import ch.cyberduck.core.Host;
import ch.cyberduck.core.TestProtocol;

import org.junit.Test;

public class STSCredentialsConfiguratorTest {

@Test
public void testConfigure() throws Exception {
new STSCredentialsConfigurator(new DisabledPasswordCallback()).configure(new Host(new TestProtocol()));
}
}

0 comments on commit bed7ec3

Please sign in to comment.