blob: 452664b81338a23899e5f55d0b7ecfef9f21607f [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 Milkeyd84f89b2018-08-17 14:54:17 -070019import org.apache.karaf.shell.api.console.CommandLine;
20import org.apache.karaf.shell.api.console.Session;
21import org.apache.karaf.shell.support.completers.StringsCompleter;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090022import org.onosproject.app.ApplicationService;
Changhoon Yoonb856b812015-08-10 03:47:19 +090023import org.onosproject.app.ApplicationState;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090024import org.onosproject.cli.AbstractCompleter;
25import org.onosproject.core.Application;
26
27import java.util.Iterator;
28import java.util.List;
29import java.util.SortedSet;
30
Changhoon Yoonb856b812015-08-10 03:47:19 +090031import static org.onosproject.app.ApplicationState.INSTALLED;
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090032import static org.onosproject.cli.AbstractShellCommand.get;
33
34/**
Changhoon Yoonb856b812015-08-10 03:47:19 +090035 * Application name completer for security review command.
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090036 */
Changhoon Yoonb856b812015-08-10 03:47:19 +090037public class ReviewApplicationNameCompleter extends AbstractCompleter {
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090038 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070039 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090040 // Delegate string completer
41 StringsCompleter delegate = new StringsCompleter();
42
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090043 ApplicationService service = get(ApplicationService.class);
44 Iterator<Application> it = service.getApplications().iterator();
45 SortedSet<String> strings = delegate.getStrings();
46 while (it.hasNext()) {
47 Application app = it.next();
Changhoon Yoonb856b812015-08-10 03:47:19 +090048 ApplicationState state = service.getState(app.id());
49// if (previousApps.contains(app.id().name())) {
50// continue;
51// }
52 if (state == INSTALLED) {
53 strings.add(app.id().name());
54 }
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090055 }
56
57 // Now let the completer do the work for figuring out what to offer.
Ray Milkeyd84f89b2018-08-17 14:54:17 -070058 return delegate.complete(session, commandLine, candidates);
Changhoon Yoon23dee8f2015-05-18 22:19:49 +090059 }
Changhoon Yoonb856b812015-08-10 03:47:19 +090060}