EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.ec2.compute.strategy]

COVERAGE SUMMARY FOR SOURCE FILE [EC2PopulateDefaultLoginCredentialsForImageStrategy.java]

nameclass, %method, %block, %line, %
EC2PopulateDefaultLoginCredentialsForImageStrategy.java100% (1/1)100% (2/2)69%  (45/65)78%  (10.9/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2PopulateDefaultLoginCredentialsForImageStrategy100% (1/1)100% (2/2)69%  (45/65)78%  (10.9/14)
execute (Object): Credentials 100% (1/1)68%  (42/62)76%  (9.9/13)
EC2PopulateDefaultLoginCredentialsForImageStrategy (): void 100% (1/1)100% (3/3)100% (1/1)

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.ec2.compute.strategy;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22 
23import javax.inject.Singleton;
24 
25import org.jclouds.ec2.domain.Image;
26import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
27import org.jclouds.domain.Credentials;
28 
29/**
30 * @author Oleksiy Yarmula
31 */
32@Singleton
33public class EC2PopulateDefaultLoginCredentialsForImageStrategy implements
34      PopulateDefaultLoginCredentialsForImageStrategy {
35 
36   @Override
37   public Credentials execute(Object resourceToAuthenticate) {
38      Credentials credentials = new Credentials("root", null);
39      if (resourceToAuthenticate != null) {
40         String owner = null;
41         if (resourceToAuthenticate instanceof Image) {
42            owner = Image.class.cast(resourceToAuthenticate).getImageOwnerId();
43         } else if (resourceToAuthenticate instanceof org.jclouds.compute.domain.Image) {
44            owner = org.jclouds.compute.domain.Image.class.cast(resourceToAuthenticate).getUserMetadata().get("owner");
45         }
46         checkArgument(owner != null, "Resource must be an image (for EC2)");
47         // canonical/alestic images use the ubuntu user to login
48         if (owner.matches("063491364108|099720109477")) {
49            credentials = new Credentials("ubuntu", null);
50            // http://typepad.com/2010/09/introducing-amazon-linux-ami.html
51         } else if (owner.equals("137112412989")) {
52            credentials = new Credentials("ec2-user", null);
53         }
54      }
55      return credentials;
56   }
57}

[all classes][org.jclouds.ec2.compute.strategy]
EMMA 2.0.5312 (C) Vladimir Roubtsov