This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GalasaSecret resource type in resources route and add secrets enc…
…ryption/decryption (#660) * Add credentials encryption and decryption, mount encryption keys in test pods (#658) * Add initial decryption logic for reading credentials Signed-off-by: Eamonn Mansour <[email protected]> * Mount encryption keys secret in test pods, refactor k8s controller settings + unit tests Signed-off-by: Eamonn Mansour <[email protected]> * fix: Fix OSGI wiring error, change oldDecryptionKeys to fallbackDecryptionKeys Signed-off-by: Eamonn Mansour <[email protected]> * review: Rename RunPoll to TestPodScheduler, parameterise randomiser, separate YAML parsing Signed-off-by: Eamonn Mansour <[email protected]> --------- Signed-off-by: Eamonn Mansour <[email protected]> * Add GalasaSecret resource processing to /resources route (#659) * Add initial decryption logic for reading credentials Signed-off-by: Eamonn Mansour <[email protected]> * Mount encryption keys secret in test pods, refactor k8s controller settings + unit tests Signed-off-by: Eamonn Mansour <[email protected]> * Refactor: separate resource processing logic out from resources route Signed-off-by: Eamonn Mansour <[email protected]> * Start adding GalasaSecret resource processing Signed-off-by: Eamonn Mansour <[email protected]> * feat: Add GalasaSecret resource processing Signed-off-by: Eamonn Mansour <[email protected]> * review: Remove unvalidated values from error messages Signed-off-by: Eamonn Mansour <[email protected]> --------- Signed-off-by: Eamonn Mansour <[email protected]> --------- Signed-off-by: Eamonn Mansour <[email protected]>
- Loading branch information
Showing
50 changed files
with
2,899 additions
and
900 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
41 changes: 41 additions & 0 deletions
41
....api.common/src/main/java/dev/galasa/framework/api/common/resources/GalasaSecretType.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright contributors to the Galasa project | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package dev.galasa.framework.api.common.resources; | ||
|
||
public enum GalasaSecretType { | ||
USERNAME_PASSWORD("UsernamePassword", "username", "password"), | ||
USERNAME_TOKEN("UsernameToken", "username", "token"), | ||
USERNAME("Username", "username"), | ||
TOKEN("Token", "token"); | ||
|
||
private String name; | ||
private String[] requiredDataFields; | ||
|
||
private GalasaSecretType(String type, String... requiredDataFields) { | ||
this.name = type; | ||
this.requiredDataFields = requiredDataFields; | ||
} | ||
|
||
public static GalasaSecretType getFromString(String typeAsString) { | ||
GalasaSecretType match = null; | ||
for (GalasaSecretType resource : values()) { | ||
if (resource.toString().equalsIgnoreCase(typeAsString.trim())) { | ||
match = resource; | ||
break; | ||
} | ||
} | ||
return match; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
|
||
public String[] getRequiredDataFields() { | ||
return requiredDataFields; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...rk.api.common/src/main/java/dev/galasa/framework/api/common/resources/ResourceAction.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright contributors to the Galasa project | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package dev.galasa.framework.api.common.resources; | ||
|
||
public enum ResourceAction { | ||
APPLY("apply"), | ||
CREATE("create"), | ||
UPDATE("update"), | ||
DELETE("delete"); | ||
|
||
private String actionLabel; | ||
|
||
private ResourceAction(String action) { | ||
this.actionLabel = action; | ||
} | ||
|
||
public static ResourceAction getFromString(String actionAsString) { | ||
ResourceAction match = null; | ||
for (ResourceAction action : values()) { | ||
if (action.toString().equalsIgnoreCase(actionAsString.trim())) { | ||
match = action; | ||
break; | ||
} | ||
} | ||
return match; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return actionLabel; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
....framework.api.common/src/main/java/dev/galasa/framework/api/common/resources/Secret.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright contributors to the Galasa project | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package dev.galasa.framework.api.common.resources; | ||
|
||
import dev.galasa.ICredentials; | ||
import dev.galasa.framework.api.common.InternalServletException; | ||
import dev.galasa.framework.api.common.ServletError; | ||
import dev.galasa.framework.spi.creds.CredentialsException; | ||
import dev.galasa.framework.spi.creds.ICredentialsService; | ||
|
||
import static dev.galasa.framework.api.common.ServletErrorMessage.*; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class Secret { | ||
|
||
private String secretId; | ||
private ICredentialsService credentialsService; | ||
private ICredentials value; | ||
|
||
public Secret(ICredentialsService credentialsService, String secretName) { | ||
this.secretId = secretName; | ||
this.credentialsService = credentialsService; | ||
} | ||
|
||
public boolean existsInCredentialsStore() { | ||
return value != null; | ||
} | ||
|
||
public void loadValueFromCredentialsStore() throws InternalServletException { | ||
try { | ||
value = credentialsService.getCredentials(secretId); | ||
} catch (CredentialsException e) { | ||
ServletError error = new ServletError(GAL5079_FAILED_TO_GET_SECRET); | ||
throw new InternalServletException(error, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
public void setSecretToCredentialsStore(ICredentials newValue) throws InternalServletException { | ||
try { | ||
credentialsService.setCredentials(secretId, newValue); | ||
} catch (CredentialsException e) { | ||
ServletError error = new ServletError(GAL5077_FAILED_TO_SET_SECRET); | ||
throw new InternalServletException(error, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
public void deleteSecretFromCredentialsStore() throws InternalServletException { | ||
try { | ||
credentialsService.deleteCredentials(secretId); | ||
} catch (CredentialsException e) { | ||
ServletError error = new ServletError(GAL5078_FAILED_TO_DELETE_SECRET); | ||
throw new InternalServletException(error, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
} |
This file contains 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
57 changes: 57 additions & 0 deletions
57
...n/src/testFixtures/java/dev/galasa/framework/api/common/mocks/MockCredentialsService.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dev.galasa.framework.api.common.mocks; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import dev.galasa.ICredentials; | ||
import dev.galasa.framework.spi.creds.CredentialsException; | ||
import dev.galasa.framework.spi.creds.ICredentialsService; | ||
|
||
public class MockCredentialsService implements ICredentialsService { | ||
|
||
private Map<String, ICredentials> creds = new HashMap<>(); | ||
|
||
private boolean throwError = false; | ||
|
||
public MockCredentialsService(Map<String, ICredentials> creds) { | ||
this.creds = creds; | ||
} | ||
|
||
@Override | ||
public ICredentials getCredentials(@NotNull String credentialsId) throws CredentialsException { | ||
if (throwError) { | ||
throwMockError(); | ||
} | ||
return this.creds.get(credentialsId); | ||
} | ||
|
||
@Override | ||
public void setCredentials(String credentialsId, ICredentials credentials) throws CredentialsException { | ||
if (throwError) { | ||
throwMockError(); | ||
} | ||
this.creds.put(credentialsId, credentials); | ||
} | ||
|
||
@Override | ||
public void deleteCredentials(String credentialsId) throws CredentialsException { | ||
if (throwError) { | ||
throwMockError(); | ||
} | ||
this.creds.remove(credentialsId); | ||
} | ||
|
||
public Map<String, ICredentials> getAllCredentials() { | ||
return creds; | ||
} | ||
|
||
public void setThrowError(boolean throwError) { | ||
this.throwError = throwError; | ||
} | ||
|
||
private void throwMockError() throws CredentialsException { | ||
throw new CredentialsException("simulating a credentials service error"); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.