Cyberduck Mountain Duck CLI

Changeset 43184


Ignore:
Timestamp:
Nov 3, 2017 1:01:53 PM (4 years ago)
Author:
Tomas Celaya
Message:

Fixes for config and private key usage, friendly error message, providing MantaSearchFeature

Location:
shelves/Tomas_Celaya
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • shelves/Tomas_Celaya

    • Property subgit:lock changed from commit:af29875159f37ef9f5d4bff94b2f5abc07a27940 timestamp:2017-11-06T08:59:53.279 to commit:e2b12d5acefb33307d9a3aaf2c06a5c98f8e5c03 timestamp:2017-11-06T09:00:11.600
  • shelves/Tomas_Celaya/profiles/Joyent Triton Object Storage.cyberduckprofile

    r43173 r43184  
    2929        <string>us-east.manta.joyent.com</string>
    3030        <key>Hostname Configurable</key>
    31         <false/>
     31        <true/>
    3232        <key>Password Configurable</key>
    3333        <false/>
  • shelves/Tomas_Celaya/triton/src/main/java/ch/cyberduck/core/manta/MantaHttpExceptionMappingService.java

    r43166 r43184  
    3232            case 403:
    3333                final StringBuilder buffer = new StringBuilder();
    34                 this.append(buffer, failure.getMessage());
     34                this.append(buffer, failure.getStatusMessage());
    3535                return new LoginFailureException(buffer.toString(), failure);
    3636        }
  • shelves/Tomas_Celaya/triton/src/main/java/ch/cyberduck/core/manta/MantaListService.java

    r43166 r43184  
    2727
    2828import java.io.IOException;
    29 import java.io.UncheckedIOException;
    3029import java.util.EnumSet;
    3130import java.util.Iterator;
     
    3332import com.joyent.manta.client.MantaObject;
    3433import com.joyent.manta.exception.MantaClientHttpResponseException;
     34import com.joyent.manta.exception.MantaObjectException;
    3535
    3636public class MantaListService implements ListService {
     
    5151            objectsIter = session.getClient().listObjects(directory.getAbsolute()).iterator();
    5252        }
    53         catch(UncheckedIOException uioe) {
     53        catch(MantaObjectException e) {
    5454            if(directory.isRoot()) {
    5555                // Most users should not be able to list all buckets, treat this as a regular exception
    5656                throw new AccessDeniedException("Cannot list buckets.");
    5757            }
    58             throw uioe;
     58            throw new MantaExceptionMappingService().map("Listing directory {0} failed", e, directory);
    5959        }
    6060        catch(MantaClientHttpResponseException e) {
  • shelves/Tomas_Celaya/triton/src/main/java/ch/cyberduck/core/manta/MantaObjectAttributeAdapter.java

    r43166 r43184  
    1616 */
    1717
     18import ch.cyberduck.core.AbstractPath;
    1819import ch.cyberduck.core.DescriptiveUrl;
     20import ch.cyberduck.core.Path;
    1921import ch.cyberduck.core.PathAttributes;
    2022import ch.cyberduck.core.Permission;
     
    2224import ch.cyberduck.core.io.HashAlgorithm;
    2325
     26import org.apache.commons.codec.binary.Hex;
    2427import org.apache.log4j.Logger;
    2528
    2629import java.net.URI;
    2730import java.net.URISyntaxException;
     31import java.util.EnumSet;
    2832
    2933import com.joyent.manta.client.MantaObject;
     
    5660
    5761        final byte[] md5Bytes = object.getMd5Bytes();
    58 
    59         if(md5Bytes != null) {
    60             attributes.setChecksum(new Checksum(HashAlgorithm.md5, new String(md5Bytes)));
     62        if (md5Bytes != null) {
     63            attributes.setChecksum(new Checksum(HashAlgorithm.md5, Hex.encodeHexString(md5Bytes)));
    6164        }
    6265
    63         attributes.setStorageClass(object.getHeaderAsString(HEADER_KEY_STORAGE_CLASS));
     66        final String storageClass = object.getHeaderAsString(HEADER_KEY_STORAGE_CLASS);
     67        if (storageClass != null) {
     68            attributes.setStorageClass(storageClass);
     69        }
    6470
    6571        return attributes;
     72    }
     73
     74    public Path toPath(final MantaObject object) {
     75        final EnumSet<AbstractPath.Type> type;
     76
     77        if (object.isDirectory()) {
     78            type = EnumSet.of(AbstractPath.Type.directory);
     79        } else {
     80            type = EnumSet.of(AbstractPath.Type.file);
     81        }
     82
     83        return new Path(object.getPath(), type);
    6684    }
    6785
     
    82100    }
    83101
    84 
    85102    private void populateLinkAttribute(final PathAttributes attributes, final MantaObject object) {
    86103        // mantaObject.getPath() starts with /
    87         final String joinedPath = session.getHost().getDefaultWebURL() + object.getPath();
     104        final String joinedPath = session.getHost().getWebURL() + object.getPath();
    88105
    89106        try {
  • shelves/Tomas_Celaya/triton/src/main/java/ch/cyberduck/core/manta/MantaPublicKeyAuthentication.java

    r43166 r43184  
    3030import ch.cyberduck.core.threading.CancelCallback;
    3131
    32 import org.apache.commons.io.IOUtils;
    3332import org.apache.commons.lang3.StringUtils;
    3433import org.apache.log4j.Logger;
    3534
    36 import java.io.ByteArrayOutputStream;
    3735import java.io.IOException;
    3836import java.io.InputStream;
     
    5351import net.schmizz.sshj.userauth.password.Resource;
    5452
    55 public class MantaPublicKeyAuthentication implements MantaAuthentication {
     53public class MantaPublicKeyAuthentication {
    5654    private static final Logger log = Logger.getLogger(MantaPublicKeyAuthentication.class);
    5755
     
    6765        final KeyFormat format = this.detectKeyFormat(identity);
    6866        final FileKeyProvider provider = this.buildProvider(identity, format);
    69         this.readKeyContentsIntoConfig(identity);
     67
     68        final SettableConfigContext config = (SettableConfigContext) session.getClient().getContext();
     69        config.setMantaKeyPath(identity.getAbsolute());
     70
    7071        if(log.isInfoEnabled()) {
    7172            log.info(String.format("Reading private key %s with key format %s", identity, format));
     
    7475            new InputStreamReader(identity.getInputStream(), StandardCharsets.UTF_8),
    7576            new PasswordFinder() {
     77                private volatile boolean shouldRetry = true;
     78
    7679                @Override
    7780                public char[] reqPassword(Resource<?> resource) {
    7881                    final String password = keychain.find(bookmark);
    7982                    if(StringUtils.isEmpty(password)) {
     83                        final Credentials provided;
    8084                        try {
    81                             prompt.prompt(
     85                             provided = prompt.prompt(
    8286                                bookmark,
    8387                                credentials.getUsername(),
     
    8791                                    identity.getAbbreviatedPath()),
    8892                                new LoginOptions(bookmark.getProtocol()));
     93
     94                            if (provided.getPassword() == null) {
     95                                return null;
     96                            }
    8997                        }
    9098                        catch(LoginCanceledException e) {
     
    92100                        }
    93101
    94                         if(StringUtils.isEmpty(credentials.getPassword())) {
    95                             return null; // user left field blank
     102                        config.setPassword(provided.getPassword());
     103                        shouldRetry = false;
     104                        return provided.getPassword().toCharArray();
     105                    } else {
     106                        if (log.isDebugEnabled()) {
     107                            log.debug("Password found in keychain");
    96108                        }
    97                         final SettableConfigContext config = (SettableConfigContext) session.getClient().getContext();
    98                         config.setPassword(credentials.getPassword());
    99                         return credentials.getPassword().toCharArray();
     109
    100110                    }
    101111                    return password.toCharArray();
     
    104114                @Override
    105115                public boolean shouldRetry(Resource<?> resource) {
    106                     return false;
     116                    return shouldRetry;
    107117                }
    108118            });
     119
    109120        return this.computeFingerprint(provider);
    110121    }
     
    149160        return format;
    150161    }
    151 
    152     /**
    153      * This method is required as a result of https://github.com/joyent/java-manta/issues/294
    154      *
    155      * @param identity credentials identity to read
    156      * @throws BackgroundException when reading the key contents fails
    157      */
    158     private void readKeyContentsIntoConfig(final Local identity) throws BackgroundException {
    159         try (InputStream is = identity.getInputStream();
    160              ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
    161             IOUtils.copy(is, baos);
    162             final SettableConfigContext config = (SettableConfigContext) session.getClient().getContext();
    163             config.setMantaKeyPath(null);
    164             config.setPrivateKeyContent(new String(baos.toByteArray(), StandardCharsets.UTF_8));
    165         }
    166         catch(IOException e) {
    167             throw new DefaultIOExceptionMappingService().map(e);
    168         }
    169     }
    170162}
  • shelves/Tomas_Celaya/triton/src/main/java/ch/cyberduck/core/manta/MantaSession.java

    r43170 r43184  
    3232import ch.cyberduck.core.features.Move;
    3333import ch.cyberduck.core.features.Read;
     34import ch.cyberduck.core.features.Search;
    3435import ch.cyberduck.core.features.Touch;
    3536import ch.cyberduck.core.features.Write;
     
    7677        super(host, new ThreadLocalHostnameDelegatingTrustManager(new DisabledX509TrustManager(), host.getHostname()), key);
    7778        config = new AuthAwareConfigContext(new ChainedConfigContext(
     79            new DefaultsConfigContext(),
    7880            new StandardConfigContext()
    7981                .setNoAuth(true)
     
    8284                .setDisableNativeSignatures(true)
    8385                .setMantaUser(host.getCredentials().getUsername())
    84                 .setMantaURL(String.format("%s://%s", host.getProtocol().getScheme().name(), host.getHostname())),
    85             new DefaultsConfigContext()
     86                .setMantaURL(String.format("%s://%s", host.getProtocol().getScheme().name(), host.getHostname()))
    8687        ));
    8788    }
     
    194195            return (T) new MantaHomeFinderFeature(this);
    195196        }
     197        else if(type == Search.class) {
     198            return (T) new MantaSearchFeature(this);
     199        }
    196200        return super._getFeature(type);
    197201    }
Note: See TracChangeset for help on using the changeset viewer.