use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.
the class SecretsController method add.
/**
* Adds a new Secret. The secret is encrypted before persisted in the database.
* It throws an exception if a Secret with the same name already exists for the
* same user.
*
* @param user User to add the Secret
* @param secretName Identifier of the secret
* @param secret The secret itself
* @param visibilityType Visibility of a Secret. It can be private or shared among members of a project
* @throws UserException
*/
public Secret add(Users user, String secretName, String secret, VisibilityType visibilityType, Integer projectIdScope) throws UserException {
SecretId secretId = new SecretId(user.getUid(), secretName);
if (secretsFacade.findById(secretId) != null) {
throw new UserException(RESTCodes.UserErrorCode.SECRET_EXISTS, Level.FINE, "Secret already exists", "Secret with name " + secretName + " already exists for user " + user.getUsername());
}
Secret storedSecret = validateAndCreateSecret(secretId, user, secret, visibilityType, projectIdScope);
secretsFacade.persist(storedSecret);
return storedSecret;
}
use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.
the class SecretsController method addOrUpdate.
/**
* Adds a new Secret. The secret is encrypted before persisted in the database.
* If a secret with the same name already exists for the user, it updates it.
*
* @param user
* @param secretName
* @param secretStr
* @param visibilityType
* @param projectIdScope
* @return
*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Secret addOrUpdate(Users user, String secretName, String secretStr, VisibilityType visibilityType, Integer projectIdScope) throws UserException {
SecretId secretId = new SecretId(user.getUid(), secretName);
Secret secret = secretsFacade.findById(secretId);
if (secret != null) {
Secret generatedSecret = validateAndCreateSecret(secretId, user, secretStr, visibilityType, projectIdScope);
secret.setSecret(generatedSecret.getSecret());
secret.setAddedOn(generatedSecret.getAddedOn());
secret.setVisibilityType(generatedSecret.getVisibilityType());
secret.setProjectIdScope(generatedSecret.getProjectIdScope());
} else {
secret = validateAndCreateSecret(secretId, user, secretStr, visibilityType, projectIdScope);
}
secretsFacade.persist(secret);
return secret;
}
use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.
the class FeaturestoreS3ConnectorController method updateSecret.
private Secret updateSecret(Users user, FeaturestoreS3ConnectorDTO featurestoreS3ConnectorDTO, Featurestore featurestore, FeaturestoreS3Connector featurestoreS3Connector) throws UserException, FeaturestoreException, ProjectException {
Secret secret = featurestoreS3Connector.getSecret();
if (secret != null) {
secretsController.checkCanAccessSecret(secret, user);
}
if (secret == null && keysNotNullOrEmpty(featurestoreS3ConnectorDTO)) {
verifyS3ConnectorAccessKey(featurestoreS3ConnectorDTO.getAccessKey());
verifyS3ConnectorSecretKey(featurestoreS3ConnectorDTO.getSecretKey());
setSecret(user, featurestoreS3ConnectorDTO, featurestoreS3Connector, featurestore);
} else if (keysNotNullOrEmpty(featurestoreS3ConnectorDTO)) {
try {
verifyS3ConnectorAccessKey(featurestoreS3ConnectorDTO.getAccessKey());
verifyS3ConnectorSecretKey(featurestoreS3ConnectorDTO.getSecretKey());
String jsonSecretString = createS3AccessAndSecretKeysSecret(featurestoreS3ConnectorDTO.getAccessKey(), featurestoreS3ConnectorDTO.getSecretKey());
secret.setSecret(secretsController.encryptSecret(jsonSecretString));
} catch (IOException | GeneralSecurityException e) {
throw new UserException(RESTCodes.UserErrorCode.SECRET_ENCRYPTION_ERROR, Level.SEVERE, "Error encrypting secret", "Could not encrypt Secret " + secret.getId().getName(), e);
}
} else {
featurestoreS3Connector.setSecret(null);
// Secret can't be removed here b/c of ON DELETE RESTRICT
}
return secret;
}
use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.
the class FeaturestoreSnowflakeConnectorController method updateSecret.
private Secret updateSecret(Users user, FeaturestoreSnowflakeConnectorDTO featurestoreSnowflakeConnectorDTO, FeaturestoreSnowflakeConnector snowflakeConnector) throws UserException, ProjectException {
String secret;
Secret existingSecret = getSecret(snowflakeConnector);
secretsController.checkCanAccessSecret(existingSecret, user);
if (!Strings.isNullOrEmpty(featurestoreSnowflakeConnectorDTO.getPassword())) {
secret = featurestoreSnowflakeConnectorDTO.getPassword();
} else {
secret = featurestoreSnowflakeConnectorDTO.getToken();
}
try {
existingSecret.setSecret(secretsController.encryptSecret(secret));
} catch (IOException | GeneralSecurityException e) {
throw new UserException(RESTCodes.UserErrorCode.SECRET_ENCRYPTION_ERROR, Level.SEVERE, "Error encrypting secret", "Could not encrypt Secret " + existingSecret.getId().getName(), e);
}
return existingSecret;
}
use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.
the class FeaturestoreSnowflakeConnectorController method createSecret.
private Secret createSecret(Users user, Featurestore featurestore, FeaturestoreSnowflakeConnectorDTO featurestoreSnowflakeConnectorDTO) throws ProjectException, UserException {
String secretName = storageConnectorUtil.createSecretName(featurestore.getId(), featurestoreSnowflakeConnectorDTO.getName(), featurestoreSnowflakeConnectorDTO.getStorageConnectorType());
Secret secret;
if (!Strings.isNullOrEmpty(featurestoreSnowflakeConnectorDTO.getPassword())) {
secret = secretsController.createSecretForProject(user, secretName, featurestoreSnowflakeConnectorDTO.getPassword(), featurestore.getProject().getId());
} else {
secret = secretsController.createSecretForProject(user, secretName, featurestoreSnowflakeConnectorDTO.getToken(), featurestore.getProject().getId());
}
return secret;
}
Aggregations