Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete action for Container Repository Images and Vault Secrets #7649

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions enterprise/cloud.oracle/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
<specification-version>2.29</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.actions</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>6.65</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.awt</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.cloud.oracle;

import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;

/**
*
* @author Dusan Petrovic
*/
public class NotificationUtils {

public static boolean confirmAction(String message) {
NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation(message, NotifyDescriptor.YES_NO_OPTION);
Object choice = DialogDisplayer.getDefault().notify(msg);
return choice == NotifyDescriptor.YES_OPTION || choice == NotifyDescriptor.OK_OPTION;
}

public static void showErrorMessage(String message) {
DialogDisplayer.getDefault()
.notifyLater(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE));
}

public static void showMessage(String message) {
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openide.nodes.Node;
import org.openide.util.ContextAwareAction;
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor;
import org.openide.util.Utilities;
import org.openide.util.lookup.Lookups;

Expand Down Expand Up @@ -111,15 +112,21 @@ public static final List<? extends Action> actionsForPath(String path, Lookup lk
}

public void refresh() {
if (factory != null) {
factory.refreshKeys();
}
update(item);
RequestProcessor.getDefault().post(() -> {
sdedic marked this conversation as resolved.
Show resolved Hide resolved
if (factory != null) {
factory.refreshKeys();
}
update(item);
});
}

public void update(OCIItem item) {

}

public OCIItem getItem() {
return this.item;
}

@Override
public Node.Handle getHandle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,42 @@
package org.netbeans.modules.cloud.oracle.developer;

import com.oracle.bmc.artifacts.ArtifactsClient;
import com.oracle.bmc.artifacts.requests.DeleteContainerImageRequest;
import com.oracle.bmc.artifacts.requests.ListContainerImagesRequest;
import com.oracle.bmc.artifacts.responses.DeleteContainerImageResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.swing.Action;
import org.netbeans.modules.cloud.oracle.ChildrenProvider;
import org.netbeans.modules.cloud.oracle.NodeProvider;
import static org.netbeans.modules.cloud.oracle.NotificationUtils.confirmAction;
import static org.netbeans.modules.cloud.oracle.NotificationUtils.showErrorMessage;
import static org.netbeans.modules.cloud.oracle.NotificationUtils.showMessage;
import org.netbeans.modules.cloud.oracle.OCIManager;
import org.netbeans.modules.cloud.oracle.OCINode;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.openide.actions.DeleteAction;
import org.openide.nodes.Children;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
import org.openide.util.actions.SystemAction;

/**
*
* @author Jan Horvath
*/
@NbBundle.Messages({
"ContainerTagDesc=Pull URL: {0}\nVersion: {1}\nDigest: {2}"
"ContainerTagDesc=Pull URL: {0}\nVersion: {1}\nDigest: {2}",
"# {0} - [OCIItem name]",
"MSG_ConfirmDeleteAction=Are you sure that you want to delete {0}.",
"# {0} - [OCIItem name]",
"MSG_DeleteActionFailed=Failed to delete {0}.",
"# {0} - [OCIItem name]",
"MSG_DeleteActionSuccess=Successfully deleted {0}."
})
public class ContainerTagNode extends OCINode {
private static final String CONTAINER_TAG_ICON = "org/netbeans/modules/cloud/oracle/resources/containertag.svg"; // NOI18N
Expand All @@ -49,6 +70,51 @@ public ContainerTagNode(ContainerTagItem tag) {
public static NodeProvider<ContainerTagItem> createNode() {
return ContainerTagNode::new;
}

@Override
public Action[] getActions(boolean context) {
Action[] actions = super.getActions(context);
List<Action> actionList = new ArrayList<>(Arrays.asList(actions));
actionList.add(SystemAction.get(DeleteAction.class));
return actionList.toArray(Action[]::new);
}

@Override
public boolean canDestroy() {
return true;
}

@Override
public void destroy() throws IOException {
RequestProcessor.getDefault().post(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use default RP. Create a dedicated one for this class with throughput 1 like this:
RequestProcessor RP = new RequestProcessor(ContainerTagNode.class);

if (!confirmAction(Bundle.MSG_ConfirmDeleteAction(this.getName()))) {
return;
}
ArtifactsClient client = OCIManager.getDefault().getActiveSession().newClient(ArtifactsClient.class);
DeleteContainerImageRequest request = DeleteContainerImageRequest.builder()
.imageId(this.getItem().getKey().getValue())
.build();
DeleteContainerImageResponse response;

try {
response = client.deleteContainerImage(request);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
showErrorMessage(Bundle.MSG_DeleteActionFailed(this.getName()));
return;
}
if (response.get__httpStatusCode__() != 204) {
showErrorMessage(Bundle.MSG_DeleteActionFailed(this.getName()));
return;
}

if (this.getParentNode() instanceof OCINode) {
((OCINode)this.getParentNode()).refresh();
}
showMessage(Bundle.MSG_DeleteActionSuccess(this.getName()));
});

}

/**
* Retrieves list of Vaults belonging to a given Compartment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.modules.cloud.oracle.vault;

import java.util.Date;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.items.OCIItem;

Expand All @@ -26,18 +27,40 @@
* @author Jan Horvath
*/
public class SecretItem extends OCIItem {

private String lifecycleState;
private Date deletionTime;

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

public SecretItem() {
public SecretItem() {
super();
this.lifecycleState = null;
this.deletionTime = null;
}

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

public Date getDeletionTime() {
return this.deletionTime;
}

void setDeletionTime(Date deletionTime) {
this.deletionTime = deletionTime;
}

public String getLifecycleState() {
return this.lifecycleState;
}

void setLifecycleState(String lifecycleState) {
this.lifecycleState = lifecycleState;
}
}
Loading
Loading