private Optional getAuthFromTreeNode()

in src/main/java/org/apache/openwhisk/intellij/explorer/toolwindow/ui/WhiskExplorerWindowForm.java [409:430]


    private Optional<WhiskAuth> getAuthFromTreeNode(DefaultMutableTreeNode node) {
        try {
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
            if (node.getUserObject() instanceof WhiskNamespace
                    && parent.getUserObject() instanceof WhiskEndpoint) {
                WhiskNamespace namespace = (WhiskNamespace) node.getUserObject();
                WhiskEndpoint endpoint = (WhiskEndpoint) parent.getUserObject();
                return Optional.of(new WhiskAuth(namespace.getAuth(), endpoint.getApihost()));
            } else if (node.getUserObject() instanceof WhiskActionMetaData
                    || node.getUserObject() instanceof CompactWhiskAction
                    || node.getUserObject() instanceof WhiskTriggerMetaData
                    || node.getUserObject() instanceof WhiskTriggerRoot
                    || node.getUserObject() instanceof WhiskPackage
            ) {
                return getAuthFromTreeNode(parent);
            }
        } catch (Exception e) {
            LOG.error(e);
            return Optional.empty();
        }
        return Optional.empty();
    }