EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.scriptbuilder.statements.ssh]

COVERAGE SUMMARY FOR SOURCE FILE [AuthorizeRSAPublicKeys.java]

nameclass, %method, %block, %line, %
AuthorizeRSAPublicKeys.java100% (1/1)75%  (3/4)98%  (91/93)94%  (15/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AuthorizeRSAPublicKeys100% (1/1)75%  (3/4)98%  (91/93)94%  (15/16)
functionDependencies (OsFamily): Iterable 0%   (0/1)0%   (0/2)0%   (0/1)
AuthorizeRSAPublicKeys (Iterable): void 100% (1/1)100% (5/5)100% (2/2)
AuthorizeRSAPublicKeys (String, Iterable): void 100% (1/1)100% (16/16)100% (4/4)
render (OsFamily): String 100% (1/1)100% (70/70)100% (9/9)

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;
26import java.util.List;
27 
28import org.jclouds.scriptbuilder.domain.OsFamily;
29import org.jclouds.scriptbuilder.domain.Statement;
30import org.jclouds.scriptbuilder.domain.StatementList;
31 
32import com.google.common.base.Joiner;
33import com.google.common.base.Splitter;
34import com.google.common.collect.ImmutableList;
35import com.google.common.collect.ImmutableList.Builder;
36 
37/**
38 * 
39 * @author Adrian Cole
40 */
41public class AuthorizeRSAPublicKeys implements Statement {
42   private final String sshDir;
43   private final List<String> publicKeys;
44 
45   public AuthorizeRSAPublicKeys(Iterable<String> publicKeys) {
46      this("~/.ssh", publicKeys);
47   }
48 
49   public AuthorizeRSAPublicKeys(String sshDir, Iterable<String> publicKeys) {
50      this.sshDir = checkNotNull(sshDir, "sshDir");
51      this.publicKeys = ImmutableList.copyOf(checkNotNull(publicKeys, "publicKeys"));
52   }
53 
54   @Override
55   public Iterable<String> functionDependencies(OsFamily family) {
56      return Collections.emptyList();
57   }
58 
59   @Override
60   public String render(OsFamily family) {
61      checkNotNull(family, "family");
62      if (family == OsFamily.WINDOWS)
63         throw new UnsupportedOperationException("windows not yet implemented");
64      Builder<Statement> statements = ImmutableList.<Statement> builder();
65      statements.add(exec("mkdir -p " + sshDir));
66      String authorizedKeys = sshDir + "{fs}authorized_keys";
67      statements.add(appendFile(authorizedKeys, Splitter.on('\n').split(Joiner.on("\n\n").join(publicKeys))));
68      statements.add(exec("chmod 600 " + authorizedKeys));
69      return new StatementList(statements.build()).render(family);
70   }
71}

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