-
Notifications
You must be signed in to change notification settings - Fork 6
feat(secrets): add secrets to system properties #5
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
Merged
+114
−88
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4057df0
feat(secrets): add secrets to system properties
DanielHougaard 4081b2f
fix: upgrade deprecated workflow package
DanielHougaard 37029c0
Delete .DS_Store
DanielHougaard d331f00
Update .gitignore
DanielHougaard 938b953
fix: tests failing
DanielHougaard fa16211
fix: overload ListSecrets to avoid breaking changes
DanielHougaard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/scripts/node_modules | ||
/target | ||
.idea | ||
.idea | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 100 additions & 76 deletions
176
src/main/java/com/infisical/sdk/resources/SecretsClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,128 @@ | ||
package com.infisical.sdk.resources; | ||
|
||
import com.infisical.sdk.api.QueryBuilder; | ||
import com.infisical.sdk.models.*; | ||
|
||
import com.infisical.sdk.util.Helper; | ||
import java.util.List; | ||
|
||
import com.infisical.sdk.api.ApiClient; | ||
import com.infisical.sdk.api.QueryBuilder; | ||
import com.infisical.sdk.models.CreateSecretInput; | ||
import com.infisical.sdk.models.DeleteSecretInput; | ||
import com.infisical.sdk.models.ListSecretsResponse; | ||
import com.infisical.sdk.models.Secret; | ||
import com.infisical.sdk.models.SingleSecretResponse; | ||
import com.infisical.sdk.models.UpdateSecretInput; | ||
import com.infisical.sdk.util.Helper; | ||
import com.infisical.sdk.util.InfisicalException; | ||
import java.util.List; | ||
|
||
public class SecretsClient { | ||
private final ApiClient httpClient; | ||
|
||
public SecretsClient(ApiClient apiClient) { | ||
this.httpClient = apiClient; | ||
} | ||
|
||
public List<Secret> ListSecrets(String projectId, String environmentSlug, String secretPath, Boolean expandSecretReferences, Boolean recursive, Boolean includeImports) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), "/api/v3/secrets/raw"); | ||
|
||
var queryParameters = new QueryBuilder() | ||
.add("workspaceId", projectId) | ||
.add("environment", environmentSlug) | ||
.add("secretPath", secretPath) | ||
.add("expandSecretReferences", Helper.booleanToString(expandSecretReferences)) | ||
.add("recursive", Helper.booleanToString(recursive)) | ||
.add("includeImports", Helper.booleanToString(includeImports)) | ||
.build(); | ||
|
||
var listSecrets = this.httpClient.get(url, queryParameters, ListSecretsResponse.class); | ||
|
||
return listSecrets.getSecrets(); | ||
private final ApiClient httpClient; | ||
|
||
public SecretsClient(ApiClient apiClient) { | ||
this.httpClient = apiClient; | ||
} | ||
|
||
// Overload to avoid breaking changes for new setSecretsOnSystemProperties | ||
// parameter | ||
public List<Secret> ListSecrets(String projectId, String environmentSlug, String secretPath, | ||
Boolean expandSecretReferences, Boolean recursive, Boolean includeImports) throws InfisicalException { | ||
return ListSecrets(projectId, environmentSlug, secretPath, expandSecretReferences, recursive, includeImports, | ||
false); | ||
} | ||
|
||
public List<Secret> ListSecrets(String projectId, String environmentSlug, String secretPath, | ||
Boolean expandSecretReferences, Boolean recursive, Boolean includeImports, Boolean setSecretsOnSystemProperties) | ||
throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), "/api/v3/secrets/raw"); | ||
|
||
var queryParameters = new QueryBuilder() | ||
.add("workspaceId", projectId) | ||
.add("environment", environmentSlug) | ||
.add("secretPath", secretPath) | ||
.add("expandSecretReferences", Helper.booleanToString(expandSecretReferences)) | ||
.add("recursive", Helper.booleanToString(recursive)) | ||
.add("includeImports", Helper.booleanToString(includeImports)) | ||
.build(); | ||
|
||
var listSecrets = this.httpClient.get(url, queryParameters, ListSecretsResponse.class); | ||
|
||
if (setSecretsOnSystemProperties) { | ||
for (Secret secret : listSecrets.getSecrets()) { | ||
System.setProperty(secret.getSecretKey(), secret.getSecretValue()); | ||
} | ||
} | ||
|
||
public Secret GetSecret(String secretName, String projectId, String environmentSlug, String secretPath, Boolean expandSecretReferences, Boolean includeImports, String secretType) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
return listSecrets.getSecrets(); | ||
} | ||
|
||
var queryParameters = new QueryBuilder() | ||
.add("workspaceId", projectId) | ||
.add("environment", environmentSlug) | ||
.add("secretPath", secretPath) | ||
.add("expandSecretReferences", Helper.booleanToString(expandSecretReferences)) | ||
.add("includeImports", Helper.booleanToString(includeImports)) | ||
.add("type", secretType) | ||
.build(); | ||
public Secret GetSecret(String secretName, String projectId, String environmentSlug, String secretPath, | ||
Boolean expandSecretReferences, Boolean includeImports, String secretType) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
|
||
var result = this.httpClient.get(url, queryParameters, SingleSecretResponse.class); | ||
var queryParameters = new QueryBuilder() | ||
.add("workspaceId", projectId) | ||
.add("environment", environmentSlug) | ||
.add("secretPath", secretPath) | ||
.add("expandSecretReferences", Helper.booleanToString(expandSecretReferences)) | ||
.add("includeImports", Helper.booleanToString(includeImports)) | ||
.add("type", secretType) | ||
.build(); | ||
|
||
return result.getSecret(); | ||
} | ||
var result = this.httpClient.get(url, queryParameters, SingleSecretResponse.class); | ||
|
||
public Secret UpdateSecret(String secretName, String projectId, String environmentSlug, String secretPath, String newSecretValue, String newSecretName) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
return result.getSecret(); | ||
} | ||
|
||
var inputBuilder = UpdateSecretInput.builder() | ||
.secretPath(secretPath) | ||
.projectId(projectId) | ||
.environmentSlug(environmentSlug) | ||
.newSecretName(newSecretName) | ||
.secretValue(newSecretValue); | ||
public Secret UpdateSecret(String secretName, String projectId, String environmentSlug, String secretPath, | ||
String newSecretValue, String newSecretName) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
|
||
if (newSecretName != null) inputBuilder.newSecretName(newSecretName); | ||
if (newSecretName != null) inputBuilder.secretValue(newSecretValue); | ||
var inputBuilder = UpdateSecretInput.builder() | ||
.secretPath(secretPath) | ||
.projectId(projectId) | ||
.environmentSlug(environmentSlug) | ||
.newSecretName(newSecretName) | ||
.secretValue(newSecretValue); | ||
|
||
var requestInput = inputBuilder.build(); | ||
if (newSecretName != null) | ||
inputBuilder.newSecretName(newSecretName); | ||
if (newSecretName != null) | ||
inputBuilder.secretValue(newSecretValue); | ||
|
||
var requestInput = inputBuilder.build(); | ||
|
||
var result = this.httpClient.patch(url, requestInput, SingleSecretResponse.class); | ||
|
||
return result.getSecret(); | ||
} | ||
var result = this.httpClient.patch(url, requestInput, SingleSecretResponse.class); | ||
|
||
return result.getSecret(); | ||
} | ||
|
||
public Secret CreateSecret(String secretName, String secretValue, String projectId, String environmentSlug, String secretPath) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
public Secret CreateSecret(String secretName, String secretValue, String projectId, String environmentSlug, | ||
String secretPath) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
|
||
var createSecretInput = CreateSecretInput.builder() | ||
.secretPath(secretPath) | ||
.projectId(projectId) | ||
.environmentSlug(environmentSlug) | ||
.secretValue(secretValue) | ||
.build(); | ||
var createSecretInput = CreateSecretInput.builder() | ||
.secretPath(secretPath) | ||
.projectId(projectId) | ||
.environmentSlug(environmentSlug) | ||
.secretValue(secretValue) | ||
.build(); | ||
|
||
createSecretInput.setSecretValue(!secretValue.isEmpty() ? secretValue : ""); | ||
createSecretInput.setSecretValue(!secretValue.isEmpty() ? secretValue : ""); | ||
|
||
var result = this.httpClient.post(url, createSecretInput, SingleSecretResponse.class); | ||
var result = this.httpClient.post(url, createSecretInput, SingleSecretResponse.class); | ||
|
||
return result.getSecret(); | ||
} | ||
return result.getSecret(); | ||
} | ||
|
||
public Secret DeleteSecret(String secretName, String projectId, String environmentSlug, String secretPath) throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
public Secret DeleteSecret(String secretName, String projectId, String environmentSlug, String secretPath) | ||
throws InfisicalException { | ||
var url = String.format("%s%s", this.httpClient.GetBaseUrl(), String.format("/api/v3/secrets/raw/%s", secretName)); | ||
|
||
var deleteSecretInput = DeleteSecretInput.builder() | ||
.secretPath(secretPath) | ||
.projectId(projectId) | ||
.environmentSlug(environmentSlug) | ||
.build(); | ||
var deleteSecretInput = DeleteSecretInput.builder() | ||
.secretPath(secretPath) | ||
.projectId(projectId) | ||
.environmentSlug(environmentSlug) | ||
.build(); | ||
|
||
var result = this.httpClient.delete(url, deleteSecretInput, SingleSecretResponse.class); | ||
return result.getSecret(); | ||
} | ||
var result = this.httpClient.delete(url, deleteSecretInput, SingleSecretResponse.class); | ||
return result.getSecret(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.