Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/scripts/node_modules
/target
.idea
.DS_Store
.DS_Store
/java-test
192 changes: 192 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ The `Auth` component provides methods for authentication:
### Universal Auth

#### Authenticating

```java
public void UniversalAuthLogin(
String clientId,
String clientSecret
)
throws InfisicalException
```

```java
sdk.Auth().UniversalAuthLogin(
"CLIENT_ID",
Expand All @@ -91,9 +100,43 @@ sdk.Auth().UniversalAuthLogin(
- `clientId` (string): The client ID of your Machine Identity.
- `clientSecret` (string): The client secret of your Machine Identity.

### LDAP Auth

```java
public void LdapAuthLogin(
LdapAuthLoginInput input
)
throws InfisicalException
```

```java
var input = LdapAuthLoginInput
.builder()
.identityId("<machine-identity-id>")
.username("<ldap-username>")
.password("<ldap-password>")
.build();

sdk.Auth().LdapAuthLogin(input);
```

**Parameters:**
- `input` (LdapAuthLoginInput): The input for authenticating with LDAP.
- `identityId` (String): The ID of the machine identity to authenticate with.
- `username` (String): The LDAP username.
- `password` (String): The LDAP password.

### Access Token Auth

#### Authenticating

```java
public void SetAccessToken(
String accessToken
)
throws InfisicalException
```

```java
sdk.Auth().SetAccessToken("ACCESS_TOKEN");
```
Expand Down Expand Up @@ -288,3 +331,152 @@ Secret deletedSecret = sdk.Secrets().DeleteSecret(
**Returns:**
- `Secret`: The deleted secret.


### `Folders`

#### Get Folder By Name

```java
public Folder Get(
String folderId
);
throws InfisicalException
```

```java
Folder folder = sdk.Folders().Get("<folder-id>");
```

**Parameters:**
- `folderId` (String): The ID of the folder to retrieve.

**Returns:**
- `Folder`: The retrieved folder.

#### List Folders

```java
public List<Folder> List(
ListFoldersInput input
)
throws InfisicalException
```

```java
ListFoldersInput input = ListFoldersInput
.builder()
.projectId("<your-project-id>")
.environmentSlug("<env-slug>")
.folderPath("/")
.recursive(false)
.build();

List<Folder> folders = sdk.Folders().List(input);
```


**Parameters:**
- `input` (ListFoldersInput): The input for listing folders.
- `projectId` (String): The ID of the project to list folders from.
- `environmentSlug` (String): The slug of the environment to list folders from.
- `folderPath` (String): The path to list folders from. Defaults to `/`.
- `recursive` (Boolean): Whether or not to list sub-folders recursively from the specified folder path and downwards. Defaults to `false`.

**Returns:**
- `List<Folder>`: The retrieved folders.

#### Create Folder

```java
public Folder Create(
CreateFolderInput input
)
throws InfisicalException
```

```java
var input = CreateFolderInput
.builder()
.projectId("<your-project-id>")
.environmentSlug("<env-slug>")
.folderName("<folder-name>")
.folderPath("/")
.description("Optional folder description")
.build();

Folder createdFolder = sdk.Folders().Create(input);
```

**Parameters:**
- `input` (CreateFolderInput): The input for creating a folder.
- `projectId` (String): The ID of the project to create the folder in.
- `environmentSlug` (String): The slug of the environment to create the folder in.
- `folderPath` (String): The path to create the folder in. Defaults to `/`.
- `folderName` (String): The name of the folder to create.
- `description` (String): The description of the folder to create. This is optional.

**Returns:**
- `Folder`: The created folder.

#### Update Folder

```java
public Folder Update(
UpdateFolderInput input
)
throws InfisicalException
```

```java
var input = UpdateFolderInput
.builder()
.projectId("<your-project-id>")
.environmentSlug("<env-slug>")
.folderId("<id-of-folder-to-update>")
.newFolderName("<the-new-folder-name>")
.folderPath("/")
.build();

Folder updatedFolder = sdk.Folders().Update(input);
```

**Parameters:**
- `input` (UpdateFolderInput): The input for updating a folder.
- `projectId` (String): The ID of the project where the folder exists.
- `environmentSlug` (String): The slug of the environment where the folder exists.
- `folderPath` (String): The path of the folder to update.
- `folderId` (String): The ID of the folder to update.
- `newFolderName` (String): The new folder name.

**Returns:**
- `Folder`: The updated folder.

#### Delete Folder

```java
public Folder Delete(
DeleteFolderInput input
)
throws InfisicalException
```

```java
var input = DeleteFolderInput
.builder()
.folderId("<the-folder-id>")
.environmentSlug("<env-slug>")
.projectId("<your-project-id>")
.build();

Folder deletedFolder = sdk.Folders().Delete(input);
```


**Parameters:**
- `input` (DeleteFolderInput): The input for deleting a folder.
- `projectId` (String): The ID of the project where the folder exists.
- `environmentSlug` (String): The slug of the environment where the folder exists.
- `folderId` (String): The ID of the folder to delete.

**Returns:**
- `Folder`: The deleted folder.
36 changes: 32 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,23 @@
<gson-fire-version>1.8.3</gson-fire-version>
</properties>
<dependencies>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.17.1</version>
</dependency>
<!-- Annotation dependencies-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

<!-- Logging dependencies-->
Expand Down Expand Up @@ -128,6 +139,23 @@
</activation>
<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>21</release>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/infisical/sdk/InfisicalSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.infisical.sdk.api.ApiClient;
import com.infisical.sdk.config.SdkConfig;
import com.infisical.sdk.resources.AuthClient;
import com.infisical.sdk.resources.FoldersClient;
import com.infisical.sdk.resources.SecretsClient;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;


public class InfisicalSdk {
private SecretsClient secretsClient;
private FoldersClient foldersClient;
private AuthClient authClient;

private ApiClient apiClient;
Expand All @@ -26,14 +28,17 @@ private void onAuthenticate(String accessToken) {
this.apiClient = new ApiClient(apiClient.GetBaseUrl(), accessToken);

this.secretsClient = new SecretsClient(apiClient);
this.foldersClient = new FoldersClient(apiClient);
this.authClient = new AuthClient(apiClient, this::onAuthenticate);
}

public AuthClient Auth() {
return this.authClient;
}

public SecretsClient Secrets() {
return this.secretsClient;
}
public FoldersClient Folders() {
return this.foldersClient;
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/infisical/sdk/api/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public <R> R get(String baseUrl, Map<String, String> queryParams, Class<R> respo
try {
HttpUrl.Builder urlBuilder = HttpUrl.parse(baseUrl).newBuilder();

queryParams.forEach(urlBuilder::addQueryParameter);
if (queryParams != null) {
queryParams.forEach(urlBuilder::addQueryParameter);
}

var requestBuilder = new Request.Builder()
.url(urlBuilder.build())
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/infisical/sdk/models/CreateFolderInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.infisical.sdk.models;

import com.google.gson.annotations.SerializedName;

import com.infisical.sdk.util.Helper;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class CreateFolderInput {
@SerializedName("workspaceId")
private String projectId;

@SerializedName("environment")
private String environmentSlug;

@SerializedName("name")
private String folderName;

@SerializedName("path")
private String folderPath;

@SerializedName("description")
private String description;

public String validate() {
if (Helper.isNullOrEmpty(projectId)) {
return "Project ID is required";
}

if (Helper.isNullOrEmpty(environmentSlug)) {
return "Environment Slug is required";
}

if (Helper.isNullOrEmpty(folderName)) {
return "Folder Name is required";
}

if (Helper.isNullOrEmpty(folderPath)) {
return "Folder Path is required";
}

return null;
}

}
Loading