jippi / vault-php-sdk

Vault PHP SDK, inspired by sensio consul sdk
MIT License
54 stars 35 forks source link

missing client token #7

Closed zerowebcorp closed 7 years ago

zerowebcorp commented 7 years ago

Trying to write something and I am getting this, I am pretty sure that I am passing the token correctly and dump shows the same.

public function factory()
    {
        if (!$this->factory) {
            $options = [];
            $token ='my_token_here';
            $options['defaults']['headers']['X-Vault-Token'] = $token;
            $this->factory = new VaultFactory($options);
            dump($this->factory);
        }

        return $this->factory;
    }

 public function getVaultDataService()
    {
        return $this->factory()->get('data');
    }

$this->getVaultDataService()->write('/secret/test', 'value');

Fatal error: Uncaught Jippi\Vault\Exception\ClientException: Something went wrong when calling vault (400 - Bad Request). {"errors":["missing client token"]} in /var/www/html/vendor/jippi/vault-php-sdk/src/Client.php:98 Stack trace: #0 /var/www/html/vendor/jippi/vault-php-sdk/src/Client.php(52): Jippi\Vault\Client->send(Object(GuzzleHttp\Psr7\Request), Array) #1 /var/www/html/vendor/jippi/vault-php-sdk/src/Services/Data.php(36): Jippi\Vault\Client->put('/v1//secret/us-...', Array) #2 /var/www/html/KeyStoreClass.php(236): Jippi\Vault\Services\Data->write('/secret/us-prod...', 'ddd') #3 /var/www/html/ajax.php(19): KeyStoreClass->addToVault('sd', 'ddd', 'us-prod', 'soss') #4 {main} thrown in /var/www/html/vendor/jippi/vault-php-sdk/src/Client.php on line 98

dump() shows


ServiceFactory {#2
  -client: Client {#4
    -client: Client {#5
      -config: array:9 [
        "base_uri" => Uri {#18
          -scheme: "http"
          -userInfo: ""
          -host: "127.0.0.1"
          -port: 8200
          -path: ""
          -query: ""
          -fragment: ""
        }
        "http_errors" => false
        "headers" => array:2 [
          "User-Agent" => "Vault-PHP-SDK/1.0"
          "Content-Type" => "application/json"
        ]
        "defaults" => array:1 [
          "headers" => array:1 [
            "X-Vault-Token" => "my_token_here"
          ]
        ]
        "handler" => HandlerStack {#6
          -handler: Closure {#13
            class: "GuzzleHttp\Handler\Proxy"
            parameters: {
              $request: {
                typeHint: "Psr\Http\Message\RequestInterface"
              }
              $options: {
                typeHint: "array"
              }
            }
            use: {
              $default: Closure {#11
                class: "GuzzleHttp\Handler\Proxy"
                parameters: {
                  $request: {
                    typeHint: "Psr\Http\Message\RequestInterface"
                  }
                  $options: {
                    typeHint: "array"
                  }
                }
                use: {
                  $default: CurlMultiHandler {#7
                    -factory: CurlFactory {#8
                      -handles: null
                      -maxHandles: 50
                    }
                    -selectTimeout: 1
                    -active: null
                    -handles: []
                    -delays: []
                  }
                  $sync: CurlHandler {#9
                    -factory: CurlFactory {#10
                      -handles: null
                      -maxHandles: 3
                    }
                  }
                }
                file: "/var/www/html/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php"
                line: "25 to 29"
              }
              $streaming: StreamHandler {#12
                -lastHeaders: []
              }
            }
            file: "/var/www/html/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php"
            line: "49 to 53"
          }
          -stack: array:4 [
            0 => array:2 [
              0 => Closure {#14
                class: "GuzzleHttp\Middleware"
                parameters: {
                  $handler: {
                    typeHint: "callable"
                  }
                }
                file: "/var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php"
                line: "54 to 69"
              }
              1 => "http_errors"
            ]
            1 => array:2 [
              0 => Closure {#15
                class: "GuzzleHttp\Middleware"
                parameters: {
                  $handler: {
                    typeHint: "callable"
                  }
                }
                file: "/var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php"
                line: "148 to 150"
              }
              1 => "allow_redirects"
            ]
            2 => array:2 [
              0 => Closure {#16
                class: "GuzzleHttp\Middleware"
                parameters: {
                  $handler: {
                    typeHint: "callable"
                  }
                }
                file: "/var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php"
                line: "27 to 43"
              }
              1 => "cookies"
            ]
            3 => array:2 [
              0 => Closure {#17
                class: "GuzzleHttp\Middleware"
                parameters: {
                  $handler: {
                    typeHint: "callable"
                  }
                }
                file: "/var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php"
                line: "216 to 218"
              }
              1 => "prepare_body"
            ]
          ]
          -cached: null
        }
        "allow_redirects" => array:5 [
          "max" => 5
          "protocols" => array:2 [
            0 => "http"
            1 => "https"
          ]
          "strict" => false
          "referer" => false
          "track_redirects" => false
        ]
        "decode_content" => true
        "verify" => true
        "cookies" => false
      ]
    }
    -logger: NullLogger {#19}
  }
}
zerowebcorp commented 7 years ago

Issue resolved by changing

$options['defaults']['headers']['X-Vault-Token']

to

$options['headers']['X-Vault-Token']