Skip to content

setDefaultOption : verify ? #62

Closed
Closed

Description

@BorderCloud

Hi

How can I set the option verify of client in your lib ?
I need to precise a custom SSL certificate on disk.

Doc Guzzle : http://docs.guzzlephp.org/en/latest/request-options.html#verify

NB : I have to use the api V3.

Thanks
Karima

Activity

  1. jamiehannaford commented on Jun 20, 2016

    @jamiehannaford
    Contributor

    Right now, this is not possible to do. We should definitely add this ability though, since it's a fairly standard use case. I imagine you'd pass in options as a new constructor key to the OpenStack builder. What do you think @haphan?

  2. haphan commented on Jun 20, 2016

    @haphan
    Collaborator

    @jamiehannaford 👍 for having a new constructor key in OpenCloud\Common\Service\Builder.

    Propose PR: php-opencloud/common#3

  3. BorderCloud commented on Jun 20, 2016

    @BorderCloud
    Author

    Hello

    How to insert the option verify in this example ?

    require 'vendor/autoload.php';
    
    $openstack = new OpenStack\OpenStack([
        'authUrl' => '{authUrl}',
        'region'  => '{region}',
        'user'    => [
            'id'       => '{userId}',
            'password' => '{password}'
        ],
        'scope'   => ['project' => ['id' => '{projectId}']]
    ]);
    
    $images = $openstack->imagesV2()
                        ->listImages();
    
    foreach ($images as $image) {
    }
    

    Thanks

  4. haphan commented on Jun 21, 2016

    @haphan
    Collaborator

    @BorderCloud Updated

    $requestOptions = [
        'verify'  => '/path/to/custom/ca.cert',
        'headers' => ['User-Agent' => 'PHP-OPENCLOUD/SDKv1.0'],
    ];
    
    $params = [
        'authUrl'          => 'http://172.16.113.139:5000/v3',
        'region'           => 'RegionOne',
        'user'             => [
            'name'     => 'admin',
            'password' => '034cdbdb0fd84c5f',
            'domain'   => ['id' => 'default'],
        ],
        'requestOptions'   => $requestOptions,
    ];
    
    
    $openstack = new OpenStack\OpenStack($params);
    
    foreach ($openstack->computeV2()->listImages() as $image) {
    }

    Until @jamiehannaford is going tag php-opencloud/common, you will have to manually specify php-opencloud/common: dev-master in your composer.json

    Update: correct sample code

  5. jamiehannaford commented on Jun 21, 2016

    @jamiehannaford
    Contributor

    php-opencloud/common:v1.0.4 is now released

  6. haphan commented on Jun 21, 2016

    @haphan
    Collaborator

    @jamiehannaford btw can you also tag php-opencloud/openstack?

  7. BorderCloud commented on Jun 21, 2016

    @BorderCloud
    Author

    Thanks, I suppose Builder waits a list of parameters in the array because I have now messages like:

    • "authUrl" is a required option
    • and after, "identityService" must be specified and implement OpenCloud\Common\Auth\IdentityService

    Can you give a example with builder ? I am a newbie on openstack...

    use OpenCloud\Common\Service\Builder;
    
    // see list of built-in Guzzle request options at GuzzleHttp\RequestOptions
    $requestOptions = [
        'verify' => '/path/to/custom/ca.cert',
        'timeout' => '60'
    ];
    
    $builder = new Builder([], 'OpenCloud', $requestOptions);
    $openstack = new OpenStack\OpenStack([
        'authUrl' => '{authUrl}',
        'region'  => '{region}',
        'user'    => [
            'id'       => '{userId}',
            'password' => '{password}'
        ],
        'scope'   => ['project' => ['id' => '{projectId}']]
    ], $builder);
    
    $images = $openstack->imagesV2()
                        ->listImages();
    
    foreach ($images as $image) {
    }
    

    Thanks
    Karima

  8. jamiehannaford commented on Jun 21, 2016

    @jamiehannaford
    Contributor

    @haphan @BorderCloud I think we should add requestOptions to the OpenStack class. That could be fed into the service builder.

  9. haphan commented on Jun 22, 2016

    @haphan
    Collaborator

    @jamiehannaford
    I agree that requestOptions need to pass to OpenStack since a HTTP client is also created here.

    Regarding requestOption, I think it'd better to directly use array $options['requestOptions'] to OpenStack class. This options will also be fed into Builder.

  10. haphan commented on Jun 22, 2016

    @haphan
    Collaborator
  11. haphan commented on Jun 22, 2016

    @haphan
    Collaborator

    @BorderCloud See my updated sample code above. You may need to run composer update php-opencloud/openstack to fetch latest version.

  12. BorderCloud commented on Jun 23, 2016

    @BorderCloud
    Author

    Ok I have the version Installing php-opencloud/common (v1.0.5)
    But I always the message cURL error 7: Permission denied

    If I test with a bad file, the message is always the same... Strange...

    $requestOptions = [
         'verify' => '/var/www/html/demo/NotExistFile.pem', // or 'NotExistFile.pem'
        'headers' => ['User-Agent' => 'PHP-OPENCLOUD/SDKv1.0']
    ];
    

    An idea ?

  13. haphan commented on Jun 23, 2016

    @haphan
    Collaborator

    @BorderCloud Looks like environment issue for me. Are you running Centos with SELINUX enabled? Reference: guzzle/guzzle#1001

    When an invalid pem file is supplied, this is what I got:
    Fatal error: Uncaught InvalidArgumentException: SSL CA bundle not found: /not/valid/ca.pem in /app/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:331

  14. BorderCloud commented on Jun 23, 2016

    @BorderCloud
    Author

    Ok without SELinux I have now the message

     Client error: `POST https://keystone.....:5000/v3/auth/tokens` resulted in a `401 Unauthorized` response:
    {"error": {"message": "The request you have made requires authentication.", "code": 401, "title": "Unauthorized"}}
    

    A problem in the lib or in the config ?

  15. haphan commented on Jun 23, 2016

    @haphan
    Collaborator

    Check your openstack crendential.

    On Thursday, 23 June 2016, Karima Rafes notifications@github.com wrote:

    Ok without SELinux I have now the message

    Client error: POST https://keystone.....:5000/v3/auth/tokens resulted in a 401 Unauthorized response:
    {"error": {"message": "The request you have made requires authentication.", "code": 401, "title": "Unauthorized"}}

    A problem in the lib or in the config ?

    —
    You are receiving this because you were mentioned.
    Reply to this email directly, view it on GitHub
    #62 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe/AAwIsnoxSS0oW6CPVC4PKDXNdopSVDYBks5qOmTvgaJpZM4I5Iuv
    .

  16. haphan commented on Jun 24, 2016

    @haphan
    Collaborator

    Issued resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy