use of org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretPatchRequest in project identity-api-server by wso2.
the class SecretManagementService method patchSecret.
/**
* To make a partial update or update the specific property of the secret.
*
* @param secretType Secret type name.
* @param name Secret name.
* @param secretPatchRequest Secret's patch details.
* @return Updated secret.
*/
public SecretResponse patchSecret(String secretType, String name, SecretPatchRequest secretPatchRequest) {
Secret secret, responseDTO;
try {
secret = SecretManagementServiceHolder.getSecretConfigManager().getSecret(secretType, name);
if (secret == null) {
throw handleException(Response.Status.NOT_FOUND, SecretManagementConstants.ErrorMessage.ERROR_CODE_SECRET_NOT_FOUND, name);
}
String path = secretPatchRequest.getPath();
SecretPatchRequest.OperationEnum operation = secretPatchRequest.getOperation();
// Only the Replace operation supported with PATCH request.
if (SecretPatchRequest.OperationEnum.REPLACE.equals(operation)) {
if (SecretManagementConstants.VALUE_PATH.equals(path)) {
responseDTO = SecretManagementServiceHolder.getSecretConfigManager().updateSecretValue(secretType, name, secretPatchRequest.getValue());
} else if (SecretManagementConstants.DESCRIPTION_PATH.equals(path)) {
responseDTO = SecretManagementServiceHolder.getSecretConfigManager().updateSecretDescription(secretType, name, secretPatchRequest.getValue());
} else {
throw handleException(Response.Status.BAD_REQUEST, SecretManagementConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT, "Path");
}
} else {
// Throw an error if any other patch operations are sent in the request.
throw handleException(Response.Status.BAD_REQUEST, SecretManagementConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT, "Operation");
}
} catch (SecretManagementException e) {
throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_SECRET, name);
}
return buildSecretResponseFromResponseDTO(responseDTO);
}
Aggregations