Use censor attribute for CLI commands
[netconf.git] / netconf / netconf-console / src / main / java / org / opendaylight / netconf / console / commands / NetconfUpdateDeviceCommand.java
index 08a8a1e202e366a5db796fe390e3d11e6ffdf06e..9d0581b8a47e4862f143b690e34e2a4378246f32 100644 (file)
@@ -11,20 +11,23 @@ package org.opendaylight.netconf.console.commands;
 import com.google.common.annotations.VisibleForTesting;
 import java.util.HashMap;
 import java.util.Map;
-
-import org.apache.karaf.shell.commands.Command;
-import org.apache.karaf.shell.commands.Option;
-import org.apache.karaf.shell.console.AbstractAction;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.netconf.console.api.NetconfCommands;
 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
 
-@Command(name = "netconf:update-device", scope = "netconf", description = "Update netconf device attributes.")
-public class NetconfUpdateDeviceCommand extends AbstractAction {
+@Service
+@Command(name = "update-device", scope = "netconf", description = "Update netconf device attributes.")
+public class NetconfUpdateDeviceCommand implements Action {
 
-    protected final NetconfCommands service;
+    @Reference
+    private NetconfCommands service;
+
+    public NetconfUpdateDeviceCommand() {
 
-    public NetconfUpdateDeviceCommand(final NetconfCommands service) {
-        this.service = service;
     }
 
     @VisibleForTesting
@@ -44,6 +47,7 @@ public class NetconfUpdateDeviceCommand extends AbstractAction {
             aliases = { "--username" },
             description = "Username for NETCONF connection",
             required = true,
+            censor = true,
             multiValued = false)
     private String username;
 
@@ -51,6 +55,7 @@ public class NetconfUpdateDeviceCommand extends AbstractAction {
             aliases = { "--password" },
             description = "Password for NETCONF connection",
             required = true,
+            censor = true,
             multiValued = false)
     private String password;
 
@@ -97,8 +102,7 @@ public class NetconfUpdateDeviceCommand extends AbstractAction {
     private String newSchemaless = "false";
 
     @Override
-    protected Object doExecute() throws Exception {
-
+    public Object execute() {
         Map<String, String> updated = new HashMap<>();
         updated.put(NetconfConsoleConstants.NETCONF_IP, newIp);
         updated.put(NetconfConsoleConstants.NETCONF_PORT, newPort);
@@ -110,10 +114,8 @@ public class NetconfUpdateDeviceCommand extends AbstractAction {
 
         if (updated.isEmpty()) {
             return "Nothing to update.";
-        } else {
-            String statusMessage = service.updateDevice(deviceId, username, password, updated);
-            return statusMessage;
         }
-    }
 
+        return service.updateDevice(deviceId, username, password, updated);
+    }
 }