Azure Blob setcontainer ACL using PHP - php

I'm trying to update container ACL using latest Azure-PHP sdk.
setContainerAcl($container, $acl, $options = null)
In $container i gave my container name, but in $acl i don't know what to provide?
But I can able to GET the container acl data using getContainerAcl method.

Looking at the source code here for setContainerAcl: https://github.com/Azure/azure-sdk-for-php/blob/master/WindowsAzure/Blob/BlobRestProxy.php#L946, $acl should be an object of type ContainerAcl which you will need to request first using the container name. The source code for ContainerACL can be found here: https://github.com/Azure/azure-sdk-for-php/blob/master/WindowsAzure/Blob/Models/ContainerACL.php.

Related

GCE - Switch ON and OFF a VM from API request

I'm figuring out if there is a way to switch ON and OFF an instance on Google Compute Engine directly by API (hosted on app engine with PHP).
I've found this documentation:
https://cloud.google.com/compute/docs/reference/rest/v1/instances/start
But can't understand if this documentation is what really i need or not :/
EDIT:
$client = new Google_Client();
$client->setApplicationName('Google-ComputeSample/0.1');
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$service = new Google_Service_Compute($client);
// Project ID for this request.
$project = 'my-project';
// The name of the zone for this request.
$zone = 'europe-west3-c';
// Name of the instance resource to start.
$instance = 'name-instance';
$response = $service->instances->start($project, $zone, $instance);
print_r($response)
Get this error:
Uncaught exception 'DomainException' with message 'Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information'
I'm trying to run this code from localhost, i think this is the problem.
If i run this code from an app engine inside my project, i suppose it will work.
But the google-php-client folder for the APIs has > 10000 files inside, so I can't push it on an app engine versione and try it :/
The document that you cite is correct for what you want to achieve, so using that API call you will start a VM instance and with the method instances.stop you will stop them. The examples for PHP are in the same document, to start [1] and to stop [2]. I hope this information helps.

Programmatically set metadata for simplesamlphp

I'm using SimpleSAMLphp for single sign on purposes. The default set up has an authsources.php file that holds the $config data and then a bunch of files in the metadata directory that set the $metadata for each of the IdP's. I don't want this information to be kept in static files. I'd prefer to set the $config and $metadata programmatically.
I've figured out how to do the $config. That's fairly simple. Just create the $config array that you want to use and then pass it to SimpleSAML_Configuration in the constructor. Bada-bing. Bada-boom. Done.
I can't find anything that allows you to manually set the $metadata though. Does SimpleSAMLphp have such a utility that I'm missing? Basically, I want something that would work like this...
$metadata = array(/* some data here */);
$util = new SomeMetaDataObject();
$util->setMetaData($metadata);
// Then do the whole Auth thing after this.
When I was looking at it, it wasn't possible, since all config was statically loaded from files, and impossible to override programmatically. Not sure if that changed by some newer version. But that was the reason why I started writing light saml php library and saml sp symfony bundle - a more configurable and reusable SAML library in PHP. Please try it, would appreciate some feedback and means to improve it.

Setting ACL Google Cloud Storage via the PHP library

I am using the PHP library for Google API Storage. How do I set the acl parameter (to 'public-read' for example) when inserting a storage object, in order to make an object public via its URI?
I have tried this:
$gso = new \Google_Service_Storage_StorageObject();
$gso->setName($folderAndFileName);
$gso->setAcl('public-read');
but the use of setAcl doesn't seem to have any effect.
I'm not sure if there's an easier way, but this should work:
$acl = new Google_Service_Storage_ObjectAccessControl();
$acl->setEntity('allUsers');
$acl->setRole('READER');
$acl->setBucket('<BUCKET-NAME>');
$acl->setObject('<OBJECT-NAME>');
// $storage being a valid Google_Service_Storage instance
$response = $storage->objectAccessControls->insert('<BUCKET-NAME>', '<OBJECT-NAME>', $acl);
You can see all the possible values here.
Also, this requires the https://www.googleapis.com/auth/devstorage.full_control scope when authenticating.
In order to set the access control for an individual request, you must do the following:
In order to make the file public, the role must be set as "OWNER" and entity as "allUsers"
Documentation can be found here:
https://cloud.google.com/storage/docs/access-control#predefined-project-private
$acl = new Google_Service_Storage_ObjectAccessControl();
$acl->setEntity('allUsers');
$acl->setRole('OWNER');
and then you must apply the ACL to storage object as follows:
$storObj = new Google_Service_Storage_StorageObject();
$storObj ->setAcl(array($acl));
The setAcl function requires an array as it parameter, therefore you add your access control object as the only element in an anonymous array

OAuth 2.0 and php slim

I am following this guide (http://www.lornajane.net/posts/2013/oauth-middleware-for-slim) to setup oAuth2 with php SLIM.
I dont't understand this part:
$auth = new \Service\Mysql\AuthService($this->mysql, $this->config);
$validated_user_id = $auth->verifyOAuth($authHeader);
$this->app->user_id = $validated_user_id;
Where can I take the class \Service\Mysql\AuthService and what is the variable config ?
Otherwise is there another guide with more details also without direct SLIM implementation ?
Thanks
That's the service class that will actually do the loading and storing of user details.
Then you should put your own class.
This could be useful: https://github.com/alexbilbie/oauth2-example-resource-server

Working example Zend_Rest_Controller with Zend_Rest_Client?

I am trying to write a short Rest Service with Zend Framework. But the documentation is not the best at this Part.
I have an ApiController extended Zend_Rest_Controller with all needed abstract methods. My goal is to get Post data and return something.
My client looks like this:
public function indexAction()
{
$url = 'http://localhost/url/public/api';
$client = new Zend_Rest_Client();
$client->setUri($url);
$client->url = 'http://www.google.de';
$result = $client->post();
}
but the provided "$client->url" is not inside the post array on Server side. Does I have to use Zend Rest Server inside the postAction on my ApiController?
If someone has an example how to send and to get the data with Zend Rest, that would be great.
Maybe this tutorial Create RESTful Applications Using The Zend Framework can help.
Have you tried setting it to access 127.0.0.1 rather than localhost? I know this can cause issues sometimes.

Categories