| 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 | */ |
| 19 | package org.jclouds.scriptbuilder.functions; |
| 20 | |
| 21 | import javax.inject.Inject; |
| 22 | |
| 23 | import org.jclouds.scriptbuilder.domain.Statement; |
| 24 | import org.jclouds.scriptbuilder.domain.StatementList; |
| 25 | import org.jclouds.scriptbuilder.statements.login.AdminAccess; |
| 26 | import org.jclouds.scriptbuilder.statements.login.AdminAccess.Configuration; |
| 27 | |
| 28 | import com.google.common.base.Function; |
| 29 | import com.google.common.collect.ImmutableList; |
| 30 | import com.google.common.collect.ImmutableList.Builder; |
| 31 | |
| 32 | /** |
| 33 | * Statement used in a shell script |
| 34 | * |
| 35 | * @author Adrian Cole |
| 36 | */ |
| 37 | public class InitAdminAccess implements Function<Statement, Statement> { |
| 38 | private final AdminAccess.Configuration adminAccessConfiguration; |
| 39 | |
| 40 | @Inject |
| 41 | public InitAdminAccess(Configuration adminAccessConfiguration) { |
| 42 | this.adminAccessConfiguration = adminAccessConfiguration; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public Statement apply(Statement input) { |
| 47 | if (input instanceof StatementList) { |
| 48 | Builder<Statement> statements = ImmutableList.<Statement> builder(); |
| 49 | for (Statement statement : StatementList.class.cast(input).getStatements()) |
| 50 | statements.add(apply(statement)); |
| 51 | return new StatementList(statements.build()); |
| 52 | } else if (input instanceof AdminAccess) { |
| 53 | return AdminAccess.class.cast(input).apply(adminAccessConfiguration); |
| 54 | } else { |
| 55 | return input; |
| 56 | } |
| 57 | } |
| 58 | } |