View Javadoc

1   package org.rundeck.api.domain;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * BaseKeyResource is ...
8    *
9    * @author Greg Schueler <greg@simplifyops.com>
10   * @since 2014-04-04
11   */
12  public class BaseKeyResource extends BaseStorageResource implements KeyResource {
13      private boolean privateKey;
14  
15      public BaseKeyResource() {
16      }
17  
18  
19      public boolean isPrivateKey() {
20          return privateKey;
21      }
22  
23      public void setPrivateKey(boolean privateKey) {
24          this.privateKey = privateKey;
25      }
26  
27      ArrayList<KeyResource> keyResources = new ArrayList<KeyResource>();
28  
29      @Override
30      public void setDirectoryContents(List<? extends StorageResource> directoryContents) {
31          for (StorageResource directoryContent : directoryContents) {
32              keyResources.add(from(directoryContent));
33          }
34      }
35  
36      @Override
37      public List<KeyResource> getDirectoryContents() {
38          return keyResources;
39      }
40  
41      public static BaseKeyResource from(final StorageResource source) {
42          final BaseKeyResource baseSshKeyResource = new BaseKeyResource();
43          baseSshKeyResource.setDirectory(source.isDirectory());
44          baseSshKeyResource.setPath(source.getPath());
45          baseSshKeyResource.setName(source.getName());
46          baseSshKeyResource.setMetadata(source.getMetadata());
47          baseSshKeyResource.setUrl(source.getUrl());
48          if (!baseSshKeyResource.isDirectory()) {
49              baseSshKeyResource.setPrivateKey(
50                      null != baseSshKeyResource.getMetadata() && "private".equals(baseSshKeyResource.getMetadata().get
51                              ("Rundeck-key-type"))
52              );
53          } else if (null != source.getDirectoryContents()) {
54              baseSshKeyResource.setDirectoryContents(source.getDirectoryContents());
55          }
56          return baseSshKeyResource;
57      }
58  }