Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
feat: test server connection
Browse files Browse the repository at this point in the history
  • Loading branch information
le-yams committed Nov 22, 2023
1 parent c9bbf61 commit 1d4a981
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 94 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ repositories {

dependencies {
implementation("dev.openfga:openfga-sdk:0.2.2")
implementation("org.dmfs:oauth2-essentials:0.22.0")
implementation("org.dmfs:httpurlconnection-executor:1.21.3")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

public class DslToJsonAction extends AnAction {

private static final Logger logger = Logger.getInstance(DslToJsonAction.class);

@Override
public void update(@NotNull AnActionEvent event) {
super.update(event);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.le_yams.openfga4intellij.servers.model;

public record Oidc(
String authority,
String clientId,
String clientSecret,
String issuer,
String audience
String scope
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ public Server(String name) {
}

public String loadUrl() {
var credentials = getCredentials("url");
var credentials = getCredentials(CredentialKey.URL);
if (credentials == null) {
return "";
}
return credentials.getPasswordAsString();
}

public void storeUrl(String url) {
var attributes = getCredentialAttributes("url");
var attributes = getCredentialAttributes(CredentialKey.URL);
PasswordSafe.getInstance().set(attributes, new Credentials(id, url));
}

public String loadApiToken() {
var credentials = getCredentials("apiToken");
var credentials = getCredentials(CredentialKey.API_TOKEN);
if (credentials == null) {
return "";
}
return credentials.getPasswordAsString();
}

public void storeApiToken(String token) {
var attributes = getCredentialAttributes("apiToken");
var attributes = getCredentialAttributes(CredentialKey.API_TOKEN);
PasswordSafe.getInstance().set(attributes, new Credentials(id, token));
}

Expand Down Expand Up @@ -84,31 +84,39 @@ public void setAuthenticationMethod(AuthenticationMethod authenticationMethod) {
}

public Oidc loadOidc() {
var credentials = getCredentials("oidc_client");
var credentials = getCredentials(CredentialKey.OIDC_CLIENT);
var clientId = credentials != null ? credentials.getUserName() : "";
var clientSecret = credentials != null ? credentials.getPasswordAsString() : "";

credentials = getCredentials("oidc_issuer");
var issuer = credentials != null ? credentials.getPasswordAsString() : "";
credentials = getCredentials(CredentialKey.OIDC_AUTHORITY);
var authority = credentials != null ? credentials.getPasswordAsString() : "";

credentials = getCredentials("oidc_audience");
credentials = getCredentials(CredentialKey.OIDC_SCOPE);
var audience = credentials != null ? credentials.getPasswordAsString() : "";

return new Oidc(clientId, clientSecret, issuer, audience);
return new Oidc(authority, clientId, clientSecret, audience);
}

public void storeOidc(Oidc oidc) {
var attributes = getCredentialAttributes("oidc_client");
var attributes = getCredentialAttributes(CredentialKey.OIDC_CLIENT);
PasswordSafe.getInstance().set(attributes, new Credentials(oidc.clientId(), oidc.clientSecret()));
attributes = getCredentialAttributes("oidc_issuer");
PasswordSafe.getInstance().set(attributes, new Credentials(id, oidc.issuer()));
attributes = getCredentialAttributes("oidc_audience");
PasswordSafe.getInstance().set(attributes, new Credentials(id, oidc.audience()));
attributes = getCredentialAttributes(CredentialKey.OIDC_AUTHORITY);
PasswordSafe.getInstance().set(attributes, new Credentials(id, oidc.authority()));
attributes = getCredentialAttributes(CredentialKey.OIDC_SCOPE);
PasswordSafe.getInstance().set(attributes, new Credentials(id, oidc.scope()));
}

@Override
public String toString() {
return name;
}

private interface CredentialKey {

String URL = "url";
String API_TOKEN = "apiToken";
String OIDC_CLIENT = "oidc_client";
String OIDC_AUTHORITY = "oidc_authority";
String OIDC_SCOPE = "oidc_scope";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.le_yams.openfga4intellij.servers.service.OpenFGAServers;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.treeStructure.Tree;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,8 +15,13 @@
import java.util.Optional;

class OpenFGAToolWindowContent {
private final ToolWindow toolWindow;
private Tree tree;

OpenFGAToolWindowContent(ToolWindow toolWindow) {
this.toolWindow = toolWindow;
}

public JComponent getContentPanel() {
var mainPanel = new JPanel(new BorderLayout());

Expand All @@ -27,7 +33,7 @@ public JComponent getContentPanel() {


toolbarDecorator.setAddAction(anActionButton -> {
var server = ServerDialog.showAddServerDialog();
var server = ServerDialog.showAddServerDialog(toolWindow);
if (server == null) {
return;
}
Expand All @@ -44,7 +50,7 @@ public JComponent getContentPanel() {
toolbarDecorator.setEditActionUpdater(updater -> getSelectedNode().isPresent());
toolbarDecorator.setEditAction(anActionButton -> getSelectedNode()
.ifPresent(node -> {
ServerDialog.showEditServerDialog(node.getServer());
ServerDialog.showEditServerDialog(toolWindow, node.getServer());
tree.updateUI();
}));
toolbarDecorator.setRemoveActionUpdater(updater -> getSelectedNode().isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class OpenFGAToolWindowFactory implements ToolWindowFactory {
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {

var toolWindowContent = new OpenFGAToolWindowContent();
var toolWindowContent = new OpenFGAToolWindowContent(toolWindow);
Content content = ContentFactory.getInstance().createContent(toolWindowContent.getContentPanel(), "", false);
toolWindow.getContentManager().addContent(content);
}
Expand Down
Loading

0 comments on commit 1d4a981

Please sign in to comment.