use of com.influxdb.client.domain.PermissionResource in project nifi-influxdb-bundle by influxdata.
the class AbstractITInfluxDB_2 method init.
protected void init() throws Exception {
influxDBClient = InfluxDBClientFactory.create(INFLUX_DB_2, "my-token".toCharArray());
organization = influxDBClient.getOrganizationsApi().findOrganizations().stream().filter(it -> it.getName().equals("my-org")).findFirst().orElseThrow(IllegalStateException::new);
bucketName = "nifi-bucket-" + System.currentTimeMillis();
Bucket bucket = influxDBClient.getBucketsApi().createBucket(bucketName, null, organization);
PermissionResource resource = new PermissionResource();
resource.setId(bucket.getId());
resource.setOrgID(organization.getId());
resource.setType(PermissionResource.TypeEnum.BUCKETS);
//
// Add Permissions to read and write to the Bucket
//
Permission readBucket = new Permission();
readBucket.setResource(resource);
readBucket.setAction(Permission.ActionEnum.READ);
Permission writeBucket = new Permission();
writeBucket.setResource(resource);
writeBucket.setAction(Permission.ActionEnum.WRITE);
Authorization authorization = influxDBClient.getAuthorizationsApi().createAuthorization(organization, Arrays.asList(readBucket, writeBucket));
String token = authorization.getToken();
influxDBClient.close();
InfluxDBClientOptions options = InfluxDBClientOptions.builder().url(INFLUX_DB_2).authenticateToken(token.toCharArray()).org(organization.getId()).bucket(bucket.getId()).build();
influxDBClient = InfluxDBClientFactory.create(options);
queryApi = influxDBClient.getQueryApi();
}
Aggregations