GithubHelp home page GithubHelp logo

hpez / php-consul-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dcarbone/php-consul-api

0.0 0.0 0.0 1.26 MB

PHP client implementation for the Consul API

License: Apache License 2.0

Shell 0.06% PHP 99.78% Makefile 0.05% Dockerfile 0.11%

php-consul-api's Introduction

php-consul-api

Tests

PHP client for the Consul HTTP API

This library is loosely based upon the official GO client.

Version Compatibility

PHPConsulAPI Version Consul Version
0.3.x 0.6.4
0.6.x 0.7-0.8
v1.x 0.9-current
dev-master current

Newer versions of the api lib will probably work in a limited capacity with older versions of Consul, but no guarantee is made and backwards compatibility issues will not be addressed.

Composer

This lib is designed to be used with Composer

Require Entry:

{
    "require": {
        "dcarbone/php-consul-api": "^v1.0"
    }
}

Configuration

First, construct a Config. This class is modeled quite closely after the Config Struct present in the Consul API Subpackage.

Default Configuration

If you have defined some of the Consul Environment Variables on your hosts then it would probably be easiest to simply execute the following:

$config = \DCarbone\PHPConsulAPI\Config::newDefaultConfig();

Advanced Configuration

You may alternatively define values yourself:

$config = new \DCarbone\PHPConsulAPI\Config([
    'HttpClient' => $client,            // [required] Client conforming to GuzzleHttp\ClientInterface
    'Address' => 'address of server',   // [required]

    'Scheme' => 'http or https',            // [optional] defaults to "http"
    'Datacenter' => 'name of datacenter',   // [optional]
    'HttpAuth' => 'user:pass',              // [optional]
    'WaitTime' => '0s',                     // [optional] amount of time to wait on certain blockable endpoints.  go time duration string format. 
    'Token' => 'auth token',                // [optional] default auth token to use
    'TokenFile' => 'file with auth token',  // [optional] file containing auth token string
    'InsecureSkipVerify' => false,          // [optional] if set to true, ignores all SSL validation
    'CAFile' => '',                         // [optional] path to ca cert file, see http://docs.guzzlephp.org/en/latest/request-options.html#verify
    'CertFile' => '',                       // [optional] path to client public key.  if set, requires KeyFile also be set
    'KeyFile' => '',                        // [optional] path to client private key.  if set, requires CertFile also be set
    'JSONEncodeOpts'=> 0,                   // [optional] php json encode opt value to use when serializing requests
]);

Configuration Note:

By default, this client will attempt to locate a series of environment variables to describe much of the above configuration properties. See here for that list, and see here for a list of the env var names.

For more advanced client configuration, such as proxy configuration, you must construct your own GuzzleHttp client prior to constructing a PHPConsulAPI Config object.

As an example:

$proxyClient = new \GuzzleHttp\Client(['proxy' => 'whatever proxy you want']]);
$config = new \DCarbone\PHPConsulAPI\Config([
    'HttpClient' => $proxyClient,
    'Address' => 'address of server',
]);

When constructing your client, if you are using the GuzzleHttp\Client object directly or derivative thereof, you may pass any option listed in the Guzzle Request Options.

Consul

Next, construct a Consul object:

$consul = new \DCarbone\PHPConsulAPI\Consul($config);

NOTE: If you do not create your own config object, Consul will create it's own using Config::newDefaultConfig() and attempt to locate a suitable HTTP Client.

Once constructed, you interact with each Consul API via it's corresponding Client class:

$kvResp = $consul->KV->Keys();
if (null !== $kvResp->Err)
    die($kvResp->Err);

var_dump($kvResp->Value);

...as an example.

Current Clients

More will be added as time goes on!

Tests

The testing suite is still in it's infancy, however it is being tested directly against an actual Consul agent. They will be back-filled as time allows. Future plans are to set up a simple cluster to provide a more real-world testing scenario.

php-consul-api's People

Contributors

dcarbone avatar dmitriygarden avatar sactor avatar slt avatar urosgruber avatar wiggels avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.