@Test public void getValueFromStaticMapping() throws Exception { String mapping = "k=v; a=a; alice=bob; id1=userA; foo=bar"; assertEquals("v", CommonUtils.getValueFromStaticMapping(mapping, "k")); assertEquals("a", CommonUtils.getValueFromStaticMapping(mapping, "a")); assertEquals("bob", CommonUtils.getValueFromStaticMapping(mapping, "alice")); assertEquals("userA", CommonUtils.getValueFromStaticMapping(mapping, "id1")); assertEquals("bar", CommonUtils.getValueFromStaticMapping(mapping, "foo")); assertEquals(null, CommonUtils.getValueFromStaticMapping(mapping, "")); assertEquals(null, CommonUtils.getValueFromStaticMapping(mapping, "/")); assertEquals(null, CommonUtils.getValueFromStaticMapping(mapping, "v")); assertEquals(null, CommonUtils.getValueFromStaticMapping(mapping, "nonexist")); }
/** * Since there is no group in S3 acl, the owner is reused as the group. This method calls the * S3 API and requires additional permissions aside from just read only. This method is best * effort and will continue with default permissions (no owner, no group, 0700). * * @return the permissions associated with this under storage system */ private ObjectPermissions getPermissionsInternal() { short bucketMode = DEFAULT_MODE; String accountOwner = DEFAULT_OWNER; // if ACL enabled try to inherit bucket acl for all the objects. if (Boolean.parseBoolean(mConf.get(PropertyKey.UNDERFS_S3A_INHERIT_ACL))) { try { Owner owner = mClient.getS3AccountOwner(); AccessControlList acl = mClient.getBucketAcl(mBucketName); bucketMode = S3AUtils.translateBucketAcl(acl, owner.getId()); if (mConf.isSet(PropertyKey.UNDERFS_GCS_OWNER_ID_TO_USERNAME_MAPPING)) { accountOwner = CommonUtils.getValueFromStaticMapping( mConf.get(PropertyKey.UNDERFS_S3_OWNER_ID_TO_USERNAME_MAPPING), owner.getId()); } else { // If there is no user-defined mapping, use display name or id. accountOwner = owner.getDisplayName() != null ? owner.getDisplayName() : owner.getId(); } } catch (AmazonClientException e) { LOG.warn("Failed to inherit bucket ACLs, proceeding with defaults. {}", e.getMessage()); } } return new ObjectPermissions(accountOwner, accountOwner, bucketMode); }
accountOwnerId = storageOwner.getId(); String owner = CommonUtils.getValueFromStaticMapping( conf.get(PropertyKey.UNDERFS_GCS_OWNER_ID_TO_USERNAME_MAPPING), accountOwnerId);
accountOwnerId = storageOwner.getId(); String owner = CommonUtils.getValueFromStaticMapping( conf.getValue(PropertyKey.UNDERFS_GCS_OWNER_ID_TO_USERNAME_MAPPING), accountOwnerId);
String owner = CommonUtils.getValueFromStaticMapping( conf.getValue(PropertyKey.UNDERFS_S3_OWNER_ID_TO_USERNAME_MAPPING), accountOwnerId);