EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.scriptbuilder.statements.ssh]

COVERAGE SUMMARY FOR SOURCE FILE [InstallRSAPrivateKey.java]

nameclass, %method, %block, %line, %
InstallRSAPrivateKey.java100% (1/1)75%  (3/4)98%  (99/101)94%  (16/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InstallRSAPrivateKey100% (1/1)75%  (3/4)98%  (99/101)94%  (16/17)
functionDependencies (OsFamily): Iterable 0%   (0/1)0%   (0/2)0%   (0/1)
InstallRSAPrivateKey (String): void 100% (1/1)100% (5/5)100% (2/2)
InstallRSAPrivateKey (String, String): void 100% (1/1)100% (15/15)100% (4/4)
render (OsFamily): String 100% (1/1)100% (79/79)100% (10/10)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.scriptbuilder.statements.ssh;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
23import static org.jclouds.scriptbuilder.domain.Statements.exec;
24 
25import java.util.Collections;
26 
27import org.jclouds.scriptbuilder.domain.OsFamily;
28import org.jclouds.scriptbuilder.domain.Statement;
29import org.jclouds.scriptbuilder.domain.StatementList;
30 
31import com.google.common.base.Splitter;
32import com.google.common.collect.ImmutableList;
33import com.google.common.collect.ImmutableList.Builder;
34 
35/**
36 * 
37 * @author Adrian Cole
38 */
39public class InstallRSAPrivateKey implements Statement {
40   private final String sshDir;
41   private final String privateKey;
42 
43   public InstallRSAPrivateKey(String privateKey) {
44      this("~/.ssh", privateKey);
45   }
46 
47   public InstallRSAPrivateKey(String sshDir, String privateKey) {
48      this.sshDir = checkNotNull(sshDir, "sshDir");
49      this.privateKey = checkNotNull(privateKey, "privateKey");
50   }
51 
52   @Override
53   public Iterable<String> functionDependencies(OsFamily family) {
54      return Collections.emptyList();
55   }
56 
57   @Override
58   public String render(OsFamily family) {
59      checkNotNull(family, "family");
60      if (family == OsFamily.WINDOWS)
61         throw new UnsupportedOperationException("windows not yet implemented");
62      Builder<Statement> statements = ImmutableList.<Statement> builder();
63      statements.add(exec("{md} " + sshDir));
64      String idRsa = sshDir + "{fs}id_rsa";
65      statements.add(exec("{rm} " + idRsa));
66      statements.add(appendFile(idRsa, Splitter.on('\n').split(privateKey)));
67      statements.add(exec("chmod 600 " + idRsa));
68      return new StatementList(statements.build()).render(family);
69   }
70}

[all classes][org.jclouds.scriptbuilder.statements.ssh]
EMMA 2.0.5312 (C) Vladimir Roubtsov