You are here

public function video_amazon_s3::setZencoderAccessPolicy in Video 6.5

Same name and namespace in other branches
  1. 6.4 plugins/video_s3/video_s3.lib.inc \video_amazon_s3::setZencoderAccessPolicy()

Set access control policy to zencoder if module is enabled

@todo Add this to video_zencoder module

Parameters

string $bucket:

string $filepath:

string $perm WRITE, READ or auto. If auto, $perm is set to READ for files and WRITE for buckets:

Return value

bool|null True if the settings have been applied, false on error, NULL when settings already set or zencoder not enabled.

1 call to video_amazon_s3::setZencoderAccessPolicy()
video_amazon_s3::pushFile in plugins/video_s3/video_s3.lib.inc

File

plugins/video_s3/video_s3.lib.inc, line 238
Class file to handle amazon s3 transfers.

Class

video_amazon_s3

Code

public function setZencoderAccessPolicy($bucket, $filepath = '', $perm = 'auto') {
  if (!module_exists('video_zencoder')) {
    return NULL;
  }
  if ($perm == 'auto') {
    $perm = empty($filepath) ? AmazonS3::GRANT_WRITE : AmazonS3::GRANT_READ;
  }
  if (empty($filepath)) {
    $acp = $this->s3
      ->get_bucket_acl($bucket);
  }
  else {
    $acp = $this->s3
      ->get_object_acl($bucket, $filepath);
  }

  // Store existing ACLs to preserve them when adding zencoder
  $acl = array();

  // check if the acl is already present
  foreach ($acp->body->AccessControlList->Grant as $grant) {
    if ($grant->Grantee->DisplayName == 'zencodertv' && $grant->Permission == $perm) {
      return NULL;
    }
    $acl[] = array(
      'id' => isset($grant->Grantee->URI) ? (string) $grant->Grantee->URI : (string) $grant->Grantee->ID,
      'permission' => (string) $grant->Permission,
    );
  }

  // Add the Zencoder credentials
  $acl[] = array(
    'id' => 'aws@zencoder.com',
    'permission' => $perm,
  );
  if (empty($filepath)) {
    return $this->s3
      ->set_bucket_acl($bucket, $acl)
      ->isOK();
  }
  else {
    return $this->s3
      ->set_object_acl($bucket, $filepath, $acl)
      ->isOK();
  }
}