Skip to content

Commit

Permalink
Open in OCI Console command
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorvath committed Oct 16, 2024
1 parent 5fe09ad commit ba5fa43
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private OCINode(CloudChildFactory factory, OCIItem item, OCISessionInitiator ses
}

public OCINode(OCIItem item, Children children) {
super(children, Lookups.fixed(item, OCIManager.getDefault().getActiveProfile(item)));
super(children, Lookups.fixed(item));
setName(item.getName());
this.item = item;
this.factory = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.modules.cloud.oracle.items;

import com.oracle.bmc.Region;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Objects;
Expand Down Expand Up @@ -188,4 +189,12 @@ public void fireRefNameChanged(String oldRefName, String referenceName) {
changeSupport.firePropertyChange("referenceName", oldRefName, referenceName);
}

public String getRegion() {
if (getRegionCode() != null) {
Region region = Region.fromRegionCodeOrId(getRegionCode());
return region.getRegionId();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public class SecretItem extends OCIItem {

private String lifecycleState;
private Date deletionTime;
private String vaultId;

public SecretItem(OCID id, String compartmentId, String name, String lifecycleState, Date deletionTime, String tenancyId, String regionCode) {
public SecretItem(OCID id, String compartmentId, String name, String lifecycleState, Date deletionTime, String vaultId, String tenancyId, String regionCode) {
super(id, compartmentId, name, tenancyId, regionCode);
this.lifecycleState = lifecycleState;
this.deletionTime = deletionTime;
this.vaultId = vaultId;
}

public SecretItem() {
Expand All @@ -51,6 +53,10 @@ public int maxInProject() {
public Date getDeletionTime() {
return this.deletionTime;
}

public String getVaultId() {
return vaultId;
}

void setDeletionTime(Date deletionTime) {
this.deletionTime = deletionTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public static ChildrenProvider.SessionAware<VaultItem, SecretItem> getSecrets()
d.getSecretName(),
d.getLifecycleState().getValue(),
d.getTimeOfDeletion(),
vault.getKey().getValue(),
tenancyId,
regionCode)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@
import org.openide.nodes.Node;
import org.openide.util.lookup.ServiceProvider;


/**
*
* @author Jan Horvath
*/
@ServiceProvider(service = TreeDataProvider.Factory.class, path = "Explorers/cloud.assets")
public class LspAssetsDecorationProvider implements TreeDataProvider.Factory {
private static final Logger LOG = Logger.getLogger(LspAssetsDecorationProvider.class.getName());

public static final String CTXVALUE_CAP_REFERENCE_NAME = "cap:refName"; // NOI18N
public static final String CTXVALUE_PREFIX_REFERENCE_NAME = "cloudAssetsReferenceName:"; // NOI18N
public static final String CTXVALUE_PREFIX_PUBLIC_IP = "publicIp:"; // NOI18N
Expand All @@ -54,12 +53,13 @@ public class LspAssetsDecorationProvider implements TreeDataProvider.Factory {
public static final String CTXVALUE_PREFIX_REPOSITORY_PUBLIC = "repositoryPublic:"; // NOI18N
public static final String CTXVALUE_PREFIX_SECRET_LIFECYCLE_STATE = "lifecycleState:"; // NOI18N
public static final String CTXVALUE_PREFIX_CLUSTER_NAMESPACE = "clusterNamespace:"; // NOI18N
public static final String CTXVALUE_PREFIX_CONSOLE_URL = "consoleUrl:"; // NOI18N

@Override
public synchronized TreeDataProvider createProvider(String treeId) {
return new ProviderImpl(null);
}

static class ProviderImpl implements TreeDataProvider {
public ProviderImpl(NodeLookupContextValues lookupValues) {
}
Expand All @@ -69,11 +69,46 @@ public TreeItemData createDecorations(Node n, boolean expanded) {
TreeItemData d = new TreeItemData();
String refName;
boolean set = false;

OCIItem item = n.getLookup().lookup(OCIItem.class);
if (item == null) {
return null;
}
String consolePath = null;
String region = item.getRegion();
String keyValue = item.getKey().getValue();
if (region != null && keyValue != null) {
switch (item.getKey().getPath()) {
case "Databases":
consolePath = String.format("https://cloud.oracle.com/db/adbs/%s?region=%s", keyValue, region);
break;
case "Vault":
consolePath = String.format("https://cloud.oracle.com/security/kms/vaults/%s?region=%s", keyValue, region);
break;
case "Cluster":
consolePath = String.format("https://cloud.oracle.com/containers/clusters/%s?region=%s", keyValue, region);
break;
case "ComputeInstance":
consolePath = String.format("https://cloud.oracle.com/compute/instances/%s?region=%s", keyValue, region);
break;
case "Vault/Secret":
if (item instanceof SecretItem) {
consolePath = String.format("https://cloud.oracle.com/security/kms/vaults/%s/secrets/%s?region=%s",
((SecretItem) item).getVaultId(), keyValue, region);
}
break;
case "Bucket":
if (item instanceof BucketItem) {
consolePath = String.format("https://cloud.oracle.com/object-storage/buckets/%s/%s/objects?region=%s",
((BucketItem) item).getNamespace(), ((BucketItem) item).getName(), region);
}
break;
}
if (consolePath != null) {
d.addContextValues(CTXVALUE_PREFIX_CONSOLE_URL + consolePath);
set = true;
}
}
refName = CloudAssets.getDefault().getReferenceName(item);
if (refName != null) {
d.addContextValues(CTXVALUE_PREFIX_REFERENCE_NAME + refName);
Expand Down Expand Up @@ -107,36 +142,39 @@ public TreeItemData createDecorations(Node n, boolean expanded) {
} else {
ClusterItem cluster = CloudAssets.getDefault().getItem(ClusterItem.class);
if (cluster != null) {
d.addContextValues(CTXVALUE_PREFIX_CLUSTER_NAME + cluster.getName());
d.addContextValues(CTXVALUE_PREFIX_CLUSTER_NAME + cluster.getName());
}
}
d.addContextValues(CTXVALUE_PREFIX_IMAGE_URL + imageUrl);
set = true;
}
if (item instanceof BucketItem
if (item instanceof BucketItem
|| item instanceof DatabaseItem) {
d.addContextValues(CTXVALUE_CAP_REFERENCE_NAME);
set = true;
}

if (item instanceof SecretItem) {
d.addContextValues(CTXVALUE_PREFIX_SECRET_LIFECYCLE_STATE + ((SecretItem)item).getLifecycleState());
d.addContextValues(CTXVALUE_PREFIX_SECRET_LIFECYCLE_STATE + ((SecretItem) item).getLifecycleState());
set = true;
}
return set ? d : null;
}

@Override
public void addTreeItemDataListener(TreeDataListener l) {
public void addTreeItemDataListener(TreeDataListener l
) {
}

@Override
public void removeTreeItemDataListener(TreeDataListener l) {
public void removeTreeItemDataListener(TreeDataListener l
) {
}

@Override
public void nodeReleased(Node n) {
public void nodeReleased(Node n
) {
}

}
}
29 changes: 21 additions & 8 deletions java/java.lsp.server/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@
"command": "nbls.cloud.publicIp.copy",
"title": "Copy the public IP address"
},
{
"command": "nbls.cloud.openConsole",
"title": "Open in OCI Console"
},
{
"command": "nbls.cloud.imageUrl.copy",
"title": "Copy pull command"
Expand Down Expand Up @@ -868,6 +872,10 @@
"command": "nbls.cloud.publicIp.copy",
"when": "false"
},
{
"command": "nbls.cloud.openConsole",
"when": "false"
},
{
"command": "nbls.cloud.imageUrl.copy",
"when": "false"
Expand Down Expand Up @@ -1118,12 +1126,17 @@
{
"command": "nbls.cloud.publicIp.copy",
"when": "viewItem =~ /publicIp:.*/ && viewItem =~ /^(?!.*imageUrl:).*/",
"group": "oci@1000"
"group": "instance@1500"
},
{
"command": "nbls.cloud.openConsole",
"when": "viewItem =~ /consoleUrl:.*/",
"group": "oci@2000"
},
{
"command": "nbls.cloud.imageUrl.copy",
"when": "viewItem =~ /imageUrl:.*/",
"group": "oci@1000"
"group": "container@100"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.adm.ShowInBrowserAction",
Expand All @@ -1133,27 +1146,27 @@
{
"command": "nbls.cloud.computeInstance.ssh",
"when": "viewItem =~ /publicIp:.*/ && viewItem =~ /^(?!.*imageUrl:).*/",
"group": "inline@10"
"group": "instance@10"
},
{
"command": "nbls.cloud.container.docker",
"when": "viewItem =~ /publicIp:.*/ && viewItem =~ /imageUrl:.*/",
"group": "inline@10"
"group": "container@10"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.RunInClusterAction",
"when": "viewItem =~ /clusterName:.*/ && viewItem =~ /imageUrl:.*/",
"group": "inline@10"
"group": "container@10"
},
{
"command": "nbls.project.buildPushImage",
"when": "viewItem =~ /class:oracle.developer.ContainerRepositoryItem/",
"group": "inline@9"
"group": "container@9"
},
{
"command": "nbls.cloud.assets.buildPushNativeImage",
"when": "viewItem =~ /class:oracle.developer.ContainerRepositoryItem/",
"group": "oci@1000"
"group": "container@1000"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.AddRepository",
Expand All @@ -1163,7 +1176,7 @@
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.CreateBuildRun",
"when": "viewItem =~ /class:oracle.devops.BuildPipelineItem/",
"group": "inline@12"
"group": "container@12"
},
{
"command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.AddToProject",
Expand Down
8 changes: 8 additions & 0 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,14 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
}
));

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.cloud.openConsole',
async (node) => {
const consoleUrl = getValueAfterPrefix(node.contextValue, 'consoleUrl:');
const url = vscode.Uri.parse(consoleUrl);
vscode.env.openExternal(url);
}
));

context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.cloud.imageUrl.copy',
async (node) => {
const imageUrl = getValueAfterPrefix(node.contextValue, 'imageUrl:');
Expand Down

0 comments on commit ba5fa43

Please sign in to comment.