Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.cli.security; |
| 18 | |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.console.CommandLine; |
| 21 | import org.apache.karaf.shell.api.console.Session; |
| 22 | import org.apache.karaf.shell.support.completers.StringsCompleter; |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 23 | import org.onosproject.app.ApplicationService; |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 24 | import org.onosproject.app.ApplicationState; |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 25 | import org.onosproject.cli.AbstractCompleter; |
| 26 | import org.onosproject.core.Application; |
| 27 | |
| 28 | import java.util.Iterator; |
| 29 | import java.util.List; |
| 30 | import java.util.SortedSet; |
| 31 | |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 32 | import static org.onosproject.app.ApplicationState.INSTALLED; |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 33 | import static org.onosproject.cli.AbstractShellCommand.get; |
| 34 | |
| 35 | /** |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 36 | * Application name completer for security review command. |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 37 | */ |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 38 | @Service |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 39 | public class ReviewApplicationNameCompleter extends AbstractCompleter { |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 40 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 41 | public int complete(Session session, CommandLine commandLine, List<String> candidates) { |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 42 | // Delegate string completer |
| 43 | StringsCompleter delegate = new StringsCompleter(); |
| 44 | |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 45 | ApplicationService service = get(ApplicationService.class); |
| 46 | Iterator<Application> it = service.getApplications().iterator(); |
| 47 | SortedSet<String> strings = delegate.getStrings(); |
| 48 | while (it.hasNext()) { |
| 49 | Application app = it.next(); |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 50 | ApplicationState state = service.getState(app.id()); |
| 51 | // if (previousApps.contains(app.id().name())) { |
| 52 | // continue; |
| 53 | // } |
| 54 | if (state == INSTALLED) { |
| 55 | strings.add(app.id().name()); |
| 56 | } |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | // Now let the completer do the work for figuring out what to offer. |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 60 | return delegate.complete(session, commandLine, candidates); |
Changhoon Yoon | 23dee8f | 2015-05-18 22:19:49 +0900 | [diff] [blame] | 61 | } |
Changhoon Yoon | b856b81 | 2015-08-10 03:47:19 +0900 | [diff] [blame] | 62 | } |