Search in sources :

Example 1 with UgiExceptionHandler

use of org.talend.components.simplefileio.runtime.ugi.UgiExceptionHandler in project components by Talend.

the class SimpleFileIODatasetRuntime method getReadWriteUgiDoAs.

/**
 * Helper method for any runtime to get the appropriate {@link UgiDoAs} for executing.
 *
 * @param datasetProperties dataset properties, containing credentials for the cluster.
 * @param accessType the type of access to the dataset that the user will be performing.
 * @return An object that can be used to execute actions with the correct credentials.
 */
public static UgiDoAs getReadWriteUgiDoAs(SimpleFileIODatasetProperties datasetProperties, UgiExceptionHandler.AccessType accessType) {
    String path = datasetProperties.path.getValue();
    SimpleFileIODatastoreProperties datastoreProperties = datasetProperties.getDatastoreProperties();
    if (datastoreProperties.useKerberos.getValue()) {
        UgiDoAs doAs = UgiDoAs.ofKerberos(datastoreProperties.kerberosPrincipal.getValue(), datastoreProperties.kerberosKeytab.getValue());
        return new UgiExceptionHandler(doAs, accessType, datastoreProperties.kerberosPrincipal.getValue(), path);
    } else if (datastoreProperties.userName.getValue() != null && !datastoreProperties.userName.getValue().isEmpty()) {
        UgiDoAs doAs = UgiDoAs.ofSimple(datastoreProperties.userName.getValue());
        return new UgiExceptionHandler(doAs, accessType, datastoreProperties.userName.getValue(), path);
    } else {
        return new UgiExceptionHandler(UgiDoAs.ofNone(), accessType, null, path);
    }
}
Also used : SimpleFileIODatastoreProperties(org.talend.components.simplefileio.SimpleFileIODatastoreProperties) UgiDoAs(org.talend.components.simplefileio.runtime.ugi.UgiDoAs) UgiExceptionHandler(org.talend.components.simplefileio.runtime.ugi.UgiExceptionHandler)

Aggregations

SimpleFileIODatastoreProperties (org.talend.components.simplefileio.SimpleFileIODatastoreProperties)1 UgiDoAs (org.talend.components.simplefileio.runtime.ugi.UgiDoAs)1 UgiExceptionHandler (org.talend.components.simplefileio.runtime.ugi.UgiExceptionHandler)1