All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rundeck.api.domain.BaseKeyResource Maven / Gradle / Ivy

The newest version!
package org.rundeck.api.domain;

import java.util.ArrayList;
import java.util.List;

/**
 * BaseKeyResource is ...
 *
 * @author Greg Schueler 
 * @since 2014-04-04
 */
public class BaseKeyResource extends BaseStorageResource implements KeyResource {
    private boolean privateKey;

    public BaseKeyResource() {
    }


    public boolean isPrivateKey() {
        return privateKey;
    }

    public void setPrivateKey(boolean privateKey) {
        this.privateKey = privateKey;
    }

    ArrayList keyResources = new ArrayList();

    @Override
    public void setDirectoryContents(List directoryContents) {
        for (StorageResource directoryContent : directoryContents) {
            keyResources.add(from(directoryContent));
        }
    }

    @Override
    public List getDirectoryContents() {
        return keyResources;
    }

    public static BaseKeyResource from(final StorageResource source) {
        final BaseKeyResource baseSshKeyResource = new BaseKeyResource();
        baseSshKeyResource.setDirectory(source.isDirectory());
        baseSshKeyResource.setPath(source.getPath());
        baseSshKeyResource.setName(source.getName());
        baseSshKeyResource.setMetadata(source.getMetadata());
        baseSshKeyResource.setUrl(source.getUrl());
        if (!baseSshKeyResource.isDirectory()) {
            baseSshKeyResource.setPrivateKey(
                    null != baseSshKeyResource.getMetadata() && "private".equals(baseSshKeyResource.getMetadata().get
                            ("Rundeck-key-type"))
            );
        } else if (null != source.getDirectoryContents()) {
            baseSshKeyResource.setDirectoryContents(source.getDirectoryContents());
        }
        return baseSshKeyResource;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy