EMMA Coverage Report (generated Mon Oct 17 05:41:20 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 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
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