blob: fa8dbce8977638402224128fcfa0a4560c014217 [file] [log] [blame]
Changhoon Yoon23dee8f2015-05-18 22:19:49 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Changhoon Yoon23dee8f2015-05-18 22:19:49 +09003 *
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
17package org.onosproject.cli.security;
18
Ray Milkey0068fd02018-10-11 15:45:39 -070019import org.apache.karaf.shell.api.action.lifecycle.Service;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070020import org.apache.karaf.shell.api.console.CommandLine;
21import org.apache.karaf.shell.api.console.Session;
22import org.apache.karaf.shell.support.completers.StringsCompleter;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090023import org.onosproject.app.ApplicationService;
Changhoon Yoonb856b812015-08-10 03:47:19 +090024import org.onosproject.app.ApplicationState;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090025import org.onosproject.cli.AbstractCompleter;
26import org.onosproject.core.Application;
27
28import java.util.Iterator;
29import java.util.List;
30import java.util.SortedSet;
31
Changhoon Yoonb856b812015-08-10 03:47:19 +090032import static org.onosproject.app.ApplicationState.INSTALLED;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090033import static org.onosproject.cli.AbstractShellCommand.get;
34
35/**
Changhoon Yoonb856b812015-08-10 03:47:19 +090036 * Application name completer for security review command.
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090037 */
Ray Milkey0068fd02018-10-11 15:45:39 -070038@Service
Changhoon Yoonb856b812015-08-10 03:47:19 +090039public class ReviewApplicationNameCompleter extends AbstractCompleter {
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090040 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070041 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090042 // Delegate string completer
43 StringsCompleter delegate = new StringsCompleter();
44
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090045 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 Yoonb856b812015-08-10 03:47:19 +090050 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 Yoon23dee8f2015-05-18 22:19:49 +090057 }
58
59 // Now let the completer do the work for figuring out what to offer.
Ray Milkeyd84f89b2018-08-17 14:54:17 -070060 return delegate.complete(session, commandLine, candidates);
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090061 }
Changhoon Yoonb856b812015-08-10 03:47:19 +090062}