Skip to content

Commit

Permalink
working on agent work
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Dec 22, 2023
1 parent 7aaf046 commit 12d4fa7
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/Agent/AgentServiceConnectProxyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
class AgentServiceConnectProxyConfig extends AbstractModel
{
protected const FIELDS = [
self::FIELD_ENVOY_EXTENSIONS => [
Transcoding::FIELD_CLASS => EnvoyExtension::class,
Transcoding::FIELD_TYPE => Transcoding::ARRAY,
Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
Transcoding::FIELD_OMITEMPTY => true,
],
self::FIELD_DESTINATION_SERVICE_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
self::FIELD_DESTINATION_SERVICE_ID => Transcoding::OMITEMPTY_STRING_FIELD,
self::FIELD_LOCAL_SERVICE_ADDRESS => Transcoding::OMITEMPTY_STRING_FIELD,
Expand All @@ -57,6 +63,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel
],
];

private const FIELD_ENVOY_EXTENSIONS = 'EnvoyExtension';
private const FIELD_DESTINATION_SERVICE_NAME = 'DestinationServiceName';
private const FIELD_DESTINATION_SERVICE_ID = 'DestinationServiceID';
private const FIELD_LOCAL_SERVICE_ADDRESS = 'LocalServiceAddress';
Expand All @@ -66,6 +73,8 @@ class AgentServiceConnectProxyConfig extends AbstractModel
private const FIELD_MESH_GATEWAY = 'MeshGateway';
private const FIELD_EXPOSE = 'Expose';

/** @var \DCarbone\PHPConsulAPI\Agent\EnvoyExtension[] */
public array $EnvoyExtensions = [];
/** @var string */
public string $DestinationServiceName = '';
/** @var string */
Expand All @@ -74,6 +83,12 @@ class AgentServiceConnectProxyConfig extends AbstractModel
public string $LocalServiceAddress = '';
/** @var int */
public int $LocalServicePort = 0;
/** @var string */
public string $LocalServiceSocketPath = '';
/** @var string */
public string $Mode = '';
/** @var \DCarbone\PHPConsulAPI\Agent\TransparentProxyConfig|null */
public ?TransparentProxyConfig $TransparentProxy = null;
/** @var \DCarbone\PHPConsulAPI\Agent\Upstream[] */
public array $Upstreams = [];
/** @var \DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig */
Expand All @@ -96,6 +111,34 @@ public function __construct(?array $data = [])
}
}

/**
* @return array
*/
public function getEnvoyExtensions(): array
{
return $this->EnvoyExtensions;
}

/**
* @param EnvoyExtension $envoyExtension
* @return \DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig
*/
public function addEnvoyExtension(EnvoyExtension $envoyExtension): self
{
$this->EnvoyExtensions[] = $envoyExtension;
return $this;
}

/**
* @param array $EnvoyExtensions
* @return \DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig
*/
public function setEnvoyExtensions(array $EnvoyExtensions): self
{
$this->EnvoyExtensions = $EnvoyExtensions;
return $this;
}

/**
* @return string
*/
Expand Down Expand Up @@ -168,6 +211,60 @@ public function setLocalServicePort(int $LocalServicePort): self
return $this;
}

/**
* @return string
*/
public function getLocalServiceSocketPath(): string
{
return $this->LocalServiceSocketPath;
}

/**
* @param string $LocalServiceSocketPath
* @return AgentServiceConnectProxyConfig
*/
public function setLocalServiceSocketPath(string $LocalServiceSocketPath): self
{
$this->LocalServiceSocketPath = $LocalServiceSocketPath;
return $this;
}

/**
* @return string
*/
public function getMode(): string
{
return $this->Mode;
}

/**
* @param string $Mode
* @return AgentServiceConnectProxyConfig
*/
public function setMode(string $Mode): self
{
$this->Mode = $Mode;
return $this;
}

/**
* @return \DCarbone\PHPConsulAPI\Agent\TransparentProxyConfig|null
*/
public function getTransparentProxy(): ?TransparentProxyConfig
{
return $this->TransparentProxy;
}

/**
* @param \DCarbone\PHPConsulAPI\Agent\TransparentProxyConfig|null $TransparentProxy
* @return AgentServiceConnectProxyConfig
*/
public function setTransparentProxy(?TransparentProxyConfig $TransparentProxy): self
{
$this->TransparentProxy = $TransparentProxy;
return $this;
}

/**
* @return \DCarbone\PHPConsulAPI\Agent\Upstream[]
*/
Expand Down
135 changes: 135 additions & 0 deletions src/Agent/EnvoyExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

declare(strict_types=1);

namespace DCarbone\PHPConsulAPI\Agent;

/*
Copyright 2023 Daniel Carbone ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\FakeMap;
use DCarbone\PHPConsulAPI\Transcoding;

class EnvoyExtension extends AbstractModel
{
protected const FIELDS = [
self::FIELD_ARGUMENTS => Transcoding::MAP_FIELD,
];

private const FIELD_ARGUMENTS = 'Arguments';

/** @var string */
public string $Name = '';
/** @var bool */
public bool $Required = false;
/** @var \DCarbone\PHPConsulAPI\FakeMap|null */
public ?FakeMap $Arguments = null;
/** @var string */
public string $ConsulVersion = '';
/** @var string */
public string $EnvoyVersion = '';

/**
* @return string
*/
public function getName(): string
{
return $this->Name;
}

/**
* @param string $Name
* @return EnvoyExtension
*/
public function setName(string $Name): EnvoyExtension
{
$this->Name = $Name;
return $this;
}

/**
* @return bool
*/
public function isRequired(): bool
{
return $this->Required;
}

/**
* @param bool $Required
* @return EnvoyExtension
*/
public function setRequired(bool $Required): EnvoyExtension
{
$this->Required = $Required;
return $this;
}

/**
* @return \DCarbone\PHPConsulAPI\FakeMap|null
*/
public function getArguments(): ?FakeMap
{
return $this->Arguments;
}

/**
* @param \DCarbone\PHPConsulAPI\FakeMap|null $Arguments
* @return EnvoyExtension
*/
public function setArguments(?FakeMap $Arguments): EnvoyExtension
{
$this->Arguments = $Arguments;
return $this;
}

/**
* @return string
*/
public function getConsulVersion(): string
{
return $this->ConsulVersion;
}

/**
* @param string $ConsulVersion
* @return EnvoyExtension
*/
public function setConsulVersion(string $ConsulVersion): EnvoyExtension
{
$this->ConsulVersion = $ConsulVersion;
return $this;
}

/**
* @return string
*/
public function getEnvoyVersion(): string
{
return $this->EnvoyVersion;
}

/**
* @param string $EnvoyVersion
* @return EnvoyExtension
*/
public function setEnvoyVersion(string $EnvoyVersion): EnvoyExtension
{
$this->EnvoyVersion = $EnvoyVersion;
return $this;
}
}
49 changes: 49 additions & 0 deletions src/Agent/TransparentProxyConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace DCarbone\PHPConsulAPI\Agent;

/*
Copyright 2023 Daniel Carbone ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use DCarbone\PHPConsulAPI\AbstractModel;

class TransparentProxyConfig extends AbstractModel
{
/** @var int */
public int $OutboundListenerPort = 0;
/** @var bool */
public bool $DialedDirectly = false;

/**
* @return int
*/
public function getOutboundListenerPort(): int
{
return $this->OutboundListenerPort;
}

/**
* @param int $OutboundListenerPort
* @return TransparentProxyConfig
*/
public function setOutboundListenerPort(int $OutboundListenerPort): TransparentProxyConfig
{
$this->OutboundListenerPort = $OutboundListenerPort;
return $this;
}
}
4 changes: 4 additions & 0 deletions src/Consul.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class Consul
public const ACLModeLegacy = '2';
public const ACLModeUnknown = '3';

public const ProxyModeDefault = '';
public const ProxyModeTransparent = 'transparent';
public const ProxyModeDirect = 'direct';

// "private" constants

public const _headerConsulPrefix = 'X-Consul-';
Expand Down

0 comments on commit 12d4fa7

Please sign in to comment.