Skip to content

[Notifier] [OvhCloud] Add "sender" #40377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
5.3
---

* Add `sender` option to the DSN that allows configuring the sender
* The bridge is not marked as `@experimental` anymore

5.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class OvhCloudTransport extends AbstractTransport
private $applicationSecret;
private $consumerKey;
private $serviceName;
private $sender;

public function __construct(string $applicationKey, string $applicationSecret, string $consumerKey, string $serviceName, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
Expand All @@ -44,9 +45,20 @@ public function __construct(string $applicationKey, string $applicationSecret, s

public function __toString(): string
{
if (null !== $this->sender) {
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s&sender=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName, $this->sender);
}

return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName);
}

public function setSender(?string $sender): self
{
$this->sender = $sender;

return $this;
}

public function supports(MessageInterface $message): bool
{
return $message instanceof SmsMessage;
Expand All @@ -68,9 +80,14 @@ protected function doSend(MessageInterface $message): SentMessage
'receivers' => [$message->getPhone()],
'noStopClause' => false,
'priority' => 'medium',
'senderForResponse' => true,
];

if ($this->sender) {
$content['sender'] = $this->sender;
} else {
$content['senderForResponse'] = true;
}

$now = time() + $this->calculateTimeDelta();
$headers['X-Ovh-Application'] = $this->applicationKey;
$headers['X-Ovh-Timestamp'] = $now;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public function create(Dsn $dsn): TransportInterface
$applicationSecret = $this->getPassword($dsn);
$consumerKey = $dsn->getRequiredOption('consumer_key');
$serviceName = $dsn->getRequiredOption('service_name');
$sender = $dsn->getOption('sender');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

return (new OvhCloudTransport($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
return (new OvhCloudTransport($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))->setHost($host)->setPort($port)->setSender($sender);
}

protected function getSupportedSchemes(): array
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/OvhCloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ DSN example
-----------

```
OVHCLOUD_DSN=ovhcloud://APPLICATION_KEY:APPLICATION_SECRET@default?consumer_key=CONSUMER_KEY&service_name=SERVICE_NAME
OVHCLOUD_DSN=ovhcloud://APPLICATION_KEY:APPLICATION_SECRET@default?consumer_key=CONSUMER_KEY&service_name=SERVICE_NAME&sender=SENDER
```

where:
- `APPLICATION_KEY` is your OvhCloud application key
- `APPLICATION_SECRET` is your OvhCloud application secret
- `CONSUMER_KEY` is your OvhCloud consumer key
- `SERVICE_NAME` is your OvhCloud service name
- `SENDER` is your sender (optional)

Resources
---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ public function createProvider(): iterable
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName',
];

yield [
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
];
}

public function supportsProvider(): iterable
{
yield [true, 'ovhcloud://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
yield [false, 'somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
yield [true, 'ovhcloud://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
yield [false, 'somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
}

public function missingRequiredOptionProvider(): iterable
Expand All @@ -47,8 +52,9 @@ public function missingRequiredOptionProvider(): iterable

public function unsupportedSchemeProvider(): iterable
{
yield ['somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
yield ['somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
yield ['somethingElse://key:secret@default?service_name=serviceName'];
yield ['somethingElse://key:secret@default?consumer_key=consumerKey'];
yield ['somethingElse://key:secret@default?sender=sender'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ final class OvhCloudTransportTest extends TransportTestCase
/**
* @return OvhCloudTransport
*/
public function createTransport(?HttpClientInterface $client = null): TransportInterface
public function createTransport(?HttpClientInterface $client = null, ?string $sender = null): TransportInterface
{
return new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?: $this->createMock(HttpClientInterface::class));
return (new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?: $this->createMock(HttpClientInterface::class)))->setSender($sender);
}

public function toStringProvider(): iterable
{
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName', $this->createTransport()];
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName&sender=sender', $this->createTransport(null, 'sender')];
}

public function supportedMessagesProvider(): iterable
Expand Down