Search in sources :

Example 1 with FeaturestoreS3ConnectorAccessAndSecretKey

use of io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorAccessAndSecretKey in project hopsworks by logicalclocks.

the class FeaturestoreS3ConnectorController method updateFeaturestoreS3Connector.

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Transactional(rollbackOn = { FeaturestoreException.class, UserException.class, ProjectException.class })
public FeaturestoreS3Connector updateFeaturestoreS3Connector(Users user, Featurestore featurestore, FeaturestoreS3ConnectorDTO featurestoreS3ConnectorDTO, FeaturestoreS3Connector featurestoreS3Connector) throws FeaturestoreException, UserException, ProjectException {
    if (storageConnectorUtil.shouldUpdate(featurestoreS3Connector.getBucket(), featurestoreS3ConnectorDTO.getBucket())) {
        verifyS3ConnectorBucket(featurestoreS3ConnectorDTO.getBucket());
        featurestoreS3Connector.setBucket(featurestoreS3ConnectorDTO.getBucket());
    }
    if (storageConnectorUtil.shouldUpdate(featurestoreS3Connector.getIamRole(), featurestoreS3ConnectorDTO.getIamRole())) {
        featurestoreS3Connector.setIamRole(featurestoreS3ConnectorDTO.getIamRole());
    }
    Secret secret = null;
    FeaturestoreS3ConnectorAccessAndSecretKey keys = storageConnectorUtil.getSecret(featurestoreS3Connector.getSecret(), FeaturestoreS3ConnectorAccessAndSecretKey.class);
    if (storageConnectorUtil.shouldUpdate(keys.getAccessKey(), featurestoreS3ConnectorDTO.getAccessKey()) || storageConnectorUtil.shouldUpdate(keys.getSecretKey(), featurestoreS3ConnectorDTO.getSecretKey())) {
        secret = updateSecret(user, featurestoreS3ConnectorDTO, featurestore, featurestoreS3Connector);
    }
    String currentEncryptionAlgorithm = featurestoreS3Connector.getServerEncryptionAlgorithm() != null ? featurestoreS3Connector.getServerEncryptionAlgorithm().getAlgorithm() : null;
    if (storageConnectorUtil.shouldUpdate(currentEncryptionAlgorithm, featurestoreS3ConnectorDTO.getServerEncryptionAlgorithm())) {
        if (featurestoreS3ConnectorDTO.getServerEncryptionAlgorithm() != null) {
            FeaturestoreS3ConnectorEncryptionAlgorithm serverEncryptionAlgorithm = getEncryptionAlgorithm(featurestoreS3ConnectorDTO.getServerEncryptionAlgorithm());
            featurestoreS3Connector.setServerEncryptionAlgorithm(serverEncryptionAlgorithm);
            if (serverEncryptionAlgorithm != null && serverEncryptionAlgorithm.isRequiresKey()) {
                verifyS3ConnectorServerEncryptionKey(featurestoreS3ConnectorDTO.getServerEncryptionKey());
                featurestoreS3Connector.setServerEncryptionKey(featurestoreS3ConnectorDTO.getServerEncryptionKey());
            } else {
                featurestoreS3Connector.setServerEncryptionKey(null);
            }
        } else if (!Strings.isNullOrEmpty(featurestoreS3ConnectorDTO.getServerEncryptionKey())) {
            throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.ILLEGAL_S3_CONNECTOR_SERVER_ENCRYPTION_ALGORITHM, Level.FINE, "Illegal server encryption algorithm, encryption algorithm not provided");
        } else {
            featurestoreS3Connector.setServerEncryptionAlgorithm(null);
            featurestoreS3Connector.setServerEncryptionKey(null);
        }
    }
    // verify if key or iam role is set
    verifyKeyAndIAMRole(featurestoreS3Connector.getIamRole(), featurestoreS3Connector.getSecret());
    if (featurestoreS3Connector.getSecret() == null && secret != null) {
        secretsFacade.deleteSecret(secret.getId());
    }
    return featurestoreS3Connector;
}
Also used : Secret(io.hops.hopsworks.persistence.entity.user.security.secrets.Secret) FeaturestoreS3ConnectorAccessAndSecretKey(io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorAccessAndSecretKey) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException) FeaturestoreS3ConnectorEncryptionAlgorithm(io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorEncryptionAlgorithm) TransactionAttribute(javax.ejb.TransactionAttribute) Transactional(javax.transaction.Transactional)

Example 2 with FeaturestoreS3ConnectorAccessAndSecretKey

use of io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorAccessAndSecretKey in project hopsworks by logicalclocks.

the class FeaturestoreS3ConnectorController method getS3ConnectorDTO.

public FeaturestoreS3ConnectorDTO getS3ConnectorDTO(FeaturestoreConnector featurestoreConnector) throws FeaturestoreException {
    FeaturestoreS3ConnectorDTO featurestoreS3ConnectorDTO = new FeaturestoreS3ConnectorDTO(featurestoreConnector);
    if (featurestoreConnector.getS3Connector().getSecret() != null) {
        FeaturestoreS3ConnectorAccessAndSecretKey accessAndSecretKey = storageConnectorUtil.getSecret(featurestoreConnector.getS3Connector().getSecret(), FeaturestoreS3ConnectorAccessAndSecretKey.class);
        setAccessAndSecretKeysInDTO(featurestoreS3ConnectorDTO, accessAndSecretKey);
    }
    return featurestoreS3ConnectorDTO;
}
Also used : FeaturestoreS3ConnectorAccessAndSecretKey(io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorAccessAndSecretKey)

Aggregations

FeaturestoreS3ConnectorAccessAndSecretKey (io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorAccessAndSecretKey)2 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)1 FeaturestoreS3ConnectorEncryptionAlgorithm (io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorEncryptionAlgorithm)1 Secret (io.hops.hopsworks.persistence.entity.user.security.secrets.Secret)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 Transactional (javax.transaction.Transactional)1