Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3780820
D2962.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D2962.diff
View Options
diff --git a/src/Build/TriggerBuild.php b/src/Build/TriggerBuild.php
--- a/src/Build/TriggerBuild.php
+++ b/src/Build/TriggerBuild.php
@@ -32,11 +32,18 @@
protected $image;
/**
- * Trigger token used to authentify requests
+ * The source UUID matching the repository to build
*
* @var string
*/
- protected $token;
+ protected $source;
+
+ /**
+ * The trigger UUID to authenticate the request
+ *
+ * @var string
+ */
+ protected $trigger;
/**
* The name of the class implementing PSR-7 message, or such an instance
@@ -53,12 +60,14 @@
* Initializes a new instance of the TriggerBuild class.
*
* @param Keruald\DockerHub\DockerHubImage $image The image to build
- * @param string $token The token to authentify the build request
+ * @param string $source The identifier for the repository to build
+ * @param string $trigger The identifier to authenticate the build request
* @param \GuzzleHttp\ClientInterface|null $client A PSR-7 HTTP client
*/
- public function __construct (Image $image, $token, ClientInterface $client = null) {
+ public function __construct (Image $image, string $source, string $trigger, ClientInterface $client = null) {
$this->image = $image;
- $this->token = $token;
+ $this->source = $source;
+ $this->trigger = $trigger;
$this->client = $client;
}
@@ -72,8 +81,8 @@
* @return string
*/
public function getTriggerUrl () {
- return $this->image->getRegistryUrl()
- . '/trigger/' . $this->token . '/';
+ return $this->image->getRegistryUrl() . "/api/build/v1/source/" . $this->source
+ . '/trigger/' . $this->trigger . '/call/';
}
///
diff --git a/src/Build/TriggerBuildFactory.php b/src/Build/TriggerBuildFactory.php
--- a/src/Build/TriggerBuildFactory.php
+++ b/src/Build/TriggerBuildFactory.php
@@ -10,7 +10,7 @@
/**
* Allows to build several TriggerBuild instances
- * with the same HTTP client and a collection of tokens.
+ * with the same HTTP client and a collection of sources and triggers.
*/
class TriggerBuildFactory {
@@ -21,7 +21,7 @@
/**
* @var $array
*/
- private $tokens;
+ private $triggers;
/**
* @var \GuzzleHttp\ClientInterface
@@ -36,11 +36,11 @@
* Initializes a new instance of the TriggerBuildFactory object.
*
* @param \GuzzleHttp\ClientInterface $client HTTP client
- * @param array $tokens The tokens for the image
+ * @param array $triggers The triggers for the image
*/
- public function __construct (ClientInterface $client, array $tokens) {
+ public function __construct (ClientInterface $client, array $triggers) {
$this->client = $client;
- $this->tokens = $tokens;
+ $this->triggers = $triggers;
}
///
@@ -56,7 +56,8 @@
public function getForImage ($image) {
return new TriggerBuild(
DockerHubImage::loadFromSlashNotation($image),
- $this->getToken($image),
+ $this->getProperty($image, "source"),
+ $this->getProperty($image, "trigger"),
$this->client
);
}
@@ -71,12 +72,12 @@
}
/**
- * Determines if we've a token for the specified image.
+ * Determines if we've a trigger for the specified image.
*
- * @return bool true if we've a token for this image; otherwise, false.
+ * @return bool true if we've a trigger for this image; otherwise, false.
*/
- public function hasToken ($image) {
- return array_key_exists($image, $this->tokens);
+ public function contains ($image): bool {
+ return array_key_exists($image, $this->triggers);
}
///
@@ -84,16 +85,18 @@
///
/**
- * Gets the token associated to an image.
- *
- * @return string
+ * Gets the property associated to an image.
*/
- protected function getToken ($image) {
- if ($this->hasToken($image)) {
- return $this->tokens[$image];
+ private function getProperty (string $image, string $property) : string {
+ if (!$this->contains($image)) {
+ throw new InvalidArgumentException("No trigger found for image $image.");
+ }
+
+ if (!array_key_exists($property, $this->triggers[$image])) {
+ throw new InvalidArgumentException("No property $property found for image $image.");
}
- throw new InvalidArgumentException("No token found for image $image.");
+ return $this->triggers[$image][$property];
}
}
diff --git a/src/DockerHubImage.php b/src/DockerHubImage.php
--- a/src/DockerHubImage.php
+++ b/src/DockerHubImage.php
@@ -17,7 +17,7 @@
* @return string
*/
public function getRegistryUrl () {
- return "https://registry.hub.docker.com/u/$this->user/$this->image";
+ return "https://hub.docker.com";
}
///
@@ -29,21 +29,23 @@
* to be able to prepare a build trigger payload.
*
* @param \Guzzle\ClientInterface A HTTP client [optional]
- * @param string $token The token to authentify the build request [optional]
+ * @param string $source The UUID to represent the image
+ * @param string $trigger The UUID to authenticate the request
* @return Keruald\DockerHub\Build\TriggerBuild
*/
- public function getTriggerBuild (ClientInterface $client = null, $token = "") {
- return new TriggerBuild($this, $token, $client);
+ public function getTriggerBuild (ClientInterface $client = null, string $source, string $trigger) {
+ return new TriggerBuild($this, $source, $trigger, $client);
}
/**
* Triggers a full build for this image.
*
* @param \Guzzle\ClientInterface A HTTP client
- * @param string $token The token to authentify the build request
+ * @param string $source The UUID to represent the image
+ * @param string $trigger The UUID to authenticate the request
*/
- public function triggerBuild (ClientInterface $client, $token) {
- $this->getTriggerBuild($client, $token)->sendPayloadForAll();
+ public function triggerBuild (ClientInterface $client, $source, $trigger) {
+ $this->getTriggerBuild($client, $source, $trigger)->sendPayloadForAll();
}
}
diff --git a/tests/Build/TriggerBuildFactoryTest.php b/tests/Build/TriggerBuildFactoryTest.php
--- a/tests/Build/TriggerBuildFactoryTest.php
+++ b/tests/Build/TriggerBuildFactoryTest.php
@@ -30,7 +30,10 @@
*/
private static function mockTokens () {
return [
- "acme/foo" => "0000",
+ "acme/foo" => [
+ "source" => "0000",
+ "trigger" => "0000",
+ ],
];
}
@@ -54,12 +57,12 @@
$this->expectNotToPerformAssertions();
}
- public function testHasToken () {
- $this->assertTrue($this->factory->hasToken("acme/foo"));
+ public function testContains () {
+ $this->assertTrue($this->factory->contains("acme/foo"));
}
- public function testHasTokenWhenWeDoNot () {
- $this->assertFalse($this->factory->hasToken("acme/bar"));
+ public function testContainsWhenWeDoNot () {
+ $this->assertFalse($this->factory->contains("acme/bar"));
}
}
diff --git a/tests/Build/TriggerBuildTest.php b/tests/Build/TriggerBuildTest.php
--- a/tests/Build/TriggerBuildTest.php
+++ b/tests/Build/TriggerBuildTest.php
@@ -28,12 +28,12 @@
public function setUp () : void {
$this->image = new DockerHubImage("acme", "foo");
- $this->trigger = new TriggerBuild($this->image, "0000");
+ $this->trigger = new TriggerBuild($this->image, "0000", "1234");
}
public function testGetTriggerUrl () {
$this->assertSame(
- "https://registry.hub.docker.com/u/acme/foo/trigger/0000/",
+ "https://hub.docker.com/api/build/v1/source/0000/trigger/1234/call/",
$this->trigger->getTriggerUrl()
);
}
@@ -94,7 +94,7 @@
public function testPostThrowsRuntimeExceptionWhenResponseIsNot200 () {
$this->expectException(\RuntimeException::class);
$mockClient = $this->mockHttpClient(500);
- $trigger = new TriggerBuild($this->image, "0000", $mockClient);
+ $trigger = new TriggerBuild($this->image, "0000", "1234", $mockClient);
$trigger->sendPayloadForAll();
}
diff --git a/tests/DockerHubImageTest.php b/tests/DockerHubImageTest.php
--- a/tests/DockerHubImageTest.php
+++ b/tests/DockerHubImageTest.php
@@ -32,7 +32,7 @@
public function testGetRegistryUrl () {
$this->assertSame(
- "https://registry.hub.docker.com/u/acme/foo",
+ "https://hub.docker.com",
$this->image->getRegistryUrl()
);
}
@@ -41,7 +41,7 @@
$client = self::mockHttpClient(200);
$this->assertInstanceOf(
TriggerBuild::class,
- $this->image->getTriggerBuild($client, '0000')
+ $this->image->getTriggerBuild($client, '0000', '1234')
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 16:55 (17 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264847
Default Alt Text
D2962.diff (8 KB)
Attached To
Mode
D2962: Switch to trigger build /source/.../trigger/... URL
Attached
Detach File
Event Timeline
Log In to Comment