Skip to content

Commit

Permalink
Merge pull request apache#7877 from jhorvath/open-in-console
Browse files Browse the repository at this point in the history
Open in OCI Console command
  • Loading branch information
jhorvath authored Oct 18, 2024
2 parents cba9fc0 + c09e577 commit e8df219
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 25 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,14 +18,20 @@
*/
package org.netbeans.modules.cloud.oracle.bucket;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public final class BucketItem extends OCIItem {
public final class BucketItem extends OCIItem implements URLProvider {

private String namespace;

Expand All @@ -47,4 +53,18 @@ public int maxInProject() {
return Integer.MAX_VALUE;
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/object-storage/buckets/%s/%s/objects?region=%s",
getNamespace(), getName(), getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@
import com.oracle.bmc.containerengine.requests.CreateKubeconfigRequest;
import com.oracle.bmc.containerengine.responses.CreateKubeconfigResponse;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import org.netbeans.modules.cloud.oracle.OCIManager;
import org.netbeans.modules.cloud.oracle.OCIProfile;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;
Expand All @@ -33,7 +38,7 @@
*
* @author Jan Horvath
*/
public final class ClusterItem extends OCIItem {
public final class ClusterItem extends OCIItem implements URLProvider{
private String config = null;
private String namespace = "default"; //NOI8N

Expand Down Expand Up @@ -80,4 +85,18 @@ public void update() {
Exceptions.printStackTrace(ex);
}
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/containers/clusters/%s?region=%s", getKey().getValue(), getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
*/
package org.netbeans.modules.cloud.oracle.compute;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public final class ComputeInstanceItem extends OCIItem {
public final class ComputeInstanceItem extends OCIItem implements URLProvider {
private String publicIp = null;
private String processorDescription;
private String username;
Expand Down Expand Up @@ -70,4 +76,16 @@ void setPublicId(String publicIp) {
this.publicIp = publicIp;
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/compute/instances/%s?region=%s", getKey().getValue(), getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@
*/
package org.netbeans.modules.cloud.oracle.database;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.netbeans.api.db.explorer.ConnectionManager;
import org.netbeans.api.db.explorer.DatabaseConnection;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.assets.CloudAssets;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.netbeans.modules.cloud.oracle.vault.SensitiveData;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public class DatabaseItem extends OCIItem implements SensitiveData {
public class DatabaseItem extends OCIItem implements SensitiveData, URLProvider {
private static final String DEFAULT_REF_NAME = "DEFAULT";
private final String serviceUrl;
private final String connectionName;
Expand Down Expand Up @@ -106,4 +112,17 @@ public DatabaseConnection getCorrespondingConnection() {
}
return null;
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/db/adbs/%s?region=%s", getKey().getValue(), getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@
*/
package org.netbeans.modules.cloud.oracle.items;

import com.oracle.bmc.Region;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Represents Oracle Cloud Resource identified by Oracle Cloud Identifier (OCID)
*
* @author Jan Horvath
*/
public abstract class OCIItem {

private static final Logger LOG = Logger.getLogger(OCIItem.class.getName());

final OCID id;
final String name;
final String compartmentId;
Expand Down Expand Up @@ -188,4 +194,16 @@ public void fireRefNameChanged(String oldRefName, String referenceName) {
changeSupport.firePropertyChange("referenceName", oldRefName, referenceName);
}

public String getRegion() {
if (getRegionCode() != null) {
try {
Region region = Region.fromRegionCodeOrId(getRegionCode());
return region.getRegionId();
} catch (IllegalArgumentException e) {
LOG.log(Level.INFO, "Unknown Region Code", e);
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,52 @@
*/
package org.netbeans.modules.cloud.oracle.vault;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public class KeyItem extends OCIItem {
public class KeyItem extends OCIItem implements URLProvider {

public KeyItem(OCID id, String compartmentId, String name, String tenancyId, String regionCode) {
private String vaultId;

public KeyItem(OCID id, String compartmentId, String name, String vaultId, String tenancyId, String regionCode) {
super(id, compartmentId, name, tenancyId, regionCode);
this.vaultId = vaultId;
}

public KeyItem() {
super();
}

public String getVaultId() {
return vaultId;
}

@Override
public int maxInProject() {
return Integer.MAX_VALUE;
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/security/kms/vaults/%s/keys/%s?region=%s", getVaultId(), getKey().getValue(), getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static ChildrenProvider.SessionAware<VaultItem, KeyItem> getKeys() {
OCID.of(d.getId(), "Vault/Key"), //NOI18N
d.getCompartmentId(),
d.getDisplayName(),
vault.getKey().getValue(),
tenancyId,
regionCode)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,31 @@
*/
package org.netbeans.modules.cloud.oracle.vault;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Date;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public class SecretItem extends OCIItem {
public class SecretItem extends OCIItem implements URLProvider {

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 +59,10 @@ public int maxInProject() {
public Date getDeletionTime() {
return this.deletionTime;
}

public String getVaultId() {
return vaultId;
}

void setDeletionTime(Date deletionTime) {
this.deletionTime = deletionTime;
Expand All @@ -63,4 +75,19 @@ public String getLifecycleState() {
void setLifecycleState(String lifecycleState) {
this.lifecycleState = lifecycleState;
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/security/kms/vaults/%s/secrets/%s?region=%s",
getVaultId(), getKey().getValue(), getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}

}
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 @@ -18,14 +18,20 @@
*/
package org.netbeans.modules.cloud.oracle.vault;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.openide.util.Exceptions;

/**
*
* @author Jan Horvath
*/
public class VaultItem extends OCIItem {
public class VaultItem extends OCIItem implements URLProvider {
private String managementEndpoint;

public VaultItem(OCID id, String compartment, String name, String managementEndpoint, String tenancyId, String regionCode) {
Expand All @@ -46,4 +52,17 @@ public int maxInProject() {
return 1;
}

@Override
public URL getURL() {
if (getKey().getValue() != null && getRegion() != null) {
try {
URI uri = new URI(String.format("https://cloud.oracle.com/security/kms/vaults/%s?region=%s", getKey().getValue(), getRegion()));
return uri.toURL();
} catch (MalformedURLException | URISyntaxException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}

}
Loading

0 comments on commit e8df219

Please sign in to comment.