Skip to content

Commit 6bc4b24

Browse files
authored
Merge pull request #652 from favicode/fix/upload-vcl-cli-error
Fixing problems with VCL upload using CLI
2 parents 61270a7 + 5d6df28 commit 6bc4b24

File tree

4 files changed

+138
-42
lines changed

4 files changed

+138
-42
lines changed

Diff for: Console/Command/EnableCommand.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use Fastly\Cdn\Model\Config;
2424
use Fastly\Cdn\Model\Api;
2525
use Fastly\Cdn\Helper\Vcl;
26+
use Fastly\Cdn\Model\Upload\Acl;
27+
use Fastly\Cdn\Model\Upload\Dictionary;
2628
use Symfony\Component\Console\Command\Command;
2729
use Symfony\Component\Console\Input\ArrayInput;
2830
use Symfony\Component\Console\Input\InputInterface;
@@ -76,6 +78,16 @@ class EnableCommand extends Command
7678
*/
7779
private $filesystem;
7880

81+
/**
82+
* @var Acl
83+
*/
84+
private $acl;
85+
86+
/**
87+
* @var Dictionary
88+
*/
89+
private $dictionary;
90+
7991
/**
8092
* @inheritdoc
8193
*/
@@ -257,14 +269,18 @@ protected function configure() // @codingStandardsIgnoreLine - required by paren
257269
* @param WriterInterface $configWriter
258270
* @param Manager $cacheManager
259271
* @param Filesystem $filesystem
272+
* @param Acl $acl
273+
* @param Dictionary $dictionary
260274
*/
261275
public function __construct(
262276
Config $config,
263277
Api $api,
264278
Vcl $vcl,
265279
WriterInterface $configWriter,
266280
Manager $cacheManager,
267-
Filesystem $filesystem
281+
Filesystem $filesystem,
282+
Acl $acl,
283+
Dictionary $dictionary
268284
) {
269285
parent::__construct();
270286
$this->config = $config;
@@ -273,6 +289,8 @@ public function __construct(
273289
$this->configWriter = $configWriter;
274290
$this->cacheManager = $cacheManager;
275291
$this->filesystem = $filesystem;
292+
$this->acl = $acl;
293+
$this->dictionary = $dictionary;
276294
}
277295

278296
/**
@@ -733,6 +751,10 @@ private function uploadVcl($activate)
733751
];
734752

735753
$this->api->createRequest($clone->number, $request);
754+
755+
$this->dictionary->setupDictionary($clone->number, $currActiveVersion);
756+
$this->acl->setupAcl($clone->number, $currActiveVersion);
757+
736758
$this->api->validateServiceVersion($clone->number);
737759
$msg = 'Successfully uploaded VCL. ';
738760

@@ -893,7 +915,7 @@ private function validateCustomSnippet($customSnippet)
893915
$snippetNameData = explode('_', $snippetName, 3);
894916
$containsEmpty = in_array("", $snippetNameData, true);
895917
$types = ['init', 'recv', 'hit', 'miss', 'pass', 'fetch', 'error', 'log', 'deliver', 'hash', 'none'];
896-
$exception = 'Failed to upload VCL snippets. Please make sure the custom VCL snippets
918+
$exception = 'Failed to upload VCL snippets. Please make sure the custom VCL snippets
897919
follow this naming convention: [vcl_snippet_type]_[priority]_[short_name_description].vcl';
898920

899921
if (count($snippetNameData) < 3) {

Diff for: Controller/Adminhtml/FastlyCdn/Vcl/Upload.php

+21-40
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Fastly\Cdn\Model\Api;
2525
use Fastly\Cdn\Model\Config;
2626
use Fastly\Cdn\Model\Config\Backend\CustomSnippetUpload;
27+
use Fastly\Cdn\Model\Upload\Acl;
28+
use Fastly\Cdn\Model\Upload\Dictionary;
2729
use Magento\Backend\App\Action;
2830
use Magento\Backend\App\Action\Context;
2931
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -90,6 +92,16 @@ class Upload extends Action
9092
*/
9193
private $typeList;
9294

95+
/**
96+
* @var Dictionary
97+
*/
98+
private $dictionary;
99+
100+
/**
101+
* @var Acl
102+
*/
103+
private $acl;
104+
93105
/**
94106
* Upload constructor.
95107
*
@@ -105,6 +117,8 @@ class Upload extends Action
105117
* @param Filesystem $filesystem
106118
* @param CoreConfig $coreConfig
107119
* @param TypeListInterface $typeList
120+
* @param Dictionary $dictionary
121+
* @param Acl $acl
108122
*/
109123
public function __construct(
110124
Context $context,
@@ -118,7 +132,9 @@ public function __construct(
118132
TimezoneInterface $timezone,
119133
Filesystem $filesystem,
120134
CoreConfig $coreConfig,
121-
TypeListInterface $typeList
135+
TypeListInterface $typeList,
136+
Dictionary $dictionary,
137+
Acl $acl
122138
) {
123139
$this->request = $request;
124140
$this->resultJson = $resultJsonFactory;
@@ -132,7 +148,8 @@ public function __construct(
132148
parent::__construct($context);
133149
$this->coreConfig = $coreConfig;
134150
$this->typeList = $typeList;
135-
151+
$this->dictionary = $dictionary;
152+
$this->acl = $acl;
136153
}
137154

138155
/**
@@ -205,8 +222,8 @@ public function execute()
205222
];
206223

207224
$this->api->createRequest($clone->number, $request);
208-
$dictionary = $this->setupDictionary($clone->number, $currActiveVersion);
209-
$acl = $this->setupAcl($clone->number, $currActiveVersion);
225+
$dictionary = $this->dictionary->setupDictionary($clone->number, $currActiveVersion);
226+
$acl = $this->acl->setupAcl($clone->number, $currActiveVersion);
210227

211228
if (!$dictionary || !$acl) {
212229
throw new LocalizedException(__('Failed to create Containers'));
@@ -272,42 +289,6 @@ private function validateCustomSnippet($customSnippet)
272289
return $snippetNameData;
273290
}
274291

275-
/**
276-
* @param $cloneNumber
277-
* @param $currActiveVersion
278-
* @return bool|mixed
279-
* @throws LocalizedException
280-
*/
281-
private function setupDictionary($cloneNumber, $currActiveVersion)
282-
{
283-
$dictionaryName = Config::CONFIG_DICTIONARY_NAME;
284-
$dictionary = $this->api->getSingleDictionary($currActiveVersion, $dictionaryName);
285-
286-
if (!$dictionary) {
287-
$params = ['name' => $dictionaryName];
288-
$dictionary = $this->api->createDictionary($cloneNumber, $params);
289-
}
290-
return $dictionary;
291-
}
292-
293-
/**
294-
* @param $cloneNumber
295-
* @param $currActiveVersion
296-
* @return bool|mixed
297-
* @throws LocalizedException
298-
*/
299-
private function setupAcl($cloneNumber, $currActiveVersion)
300-
{
301-
$aclName = Config::MAINT_ACL_NAME;
302-
$acl = $this->api->getSingleAcl($currActiveVersion, $aclName);
303-
304-
if (!$acl) {
305-
$params = ['name' => $aclName];
306-
$acl = $this->api->createAcl($cloneNumber, $params);
307-
}
308-
return $acl;
309-
}
310-
311292
/**
312293
* @param $clone
313294
* @throws LocalizedException

Diff for: Model/Upload/Acl.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Fastly\Cdn\Model\Upload;
4+
5+
use Fastly\Cdn\Model\Api;
6+
use Fastly\Cdn\Model\Config;
7+
8+
class Acl
9+
{
10+
11+
/**
12+
* @var Api
13+
*/
14+
private $api;
15+
16+
/**
17+
* @param Api $api
18+
*/
19+
public function __construct(
20+
Api $api
21+
) {
22+
$this->api = $api;
23+
}
24+
25+
/**
26+
* @param $cloneNumber
27+
* @param $currActiveVersion
28+
* @return bool|mixed
29+
*/
30+
public function setupAcl($cloneNumber, $currActiveVersion)
31+
{
32+
try {
33+
$aclName = Config::MAINT_ACL_NAME;
34+
$acl = $this->api->getSingleAcl($currActiveVersion, $aclName);
35+
36+
if (!$acl) {
37+
$params = ['name' => $aclName];
38+
$acl = $this->api->createAcl($cloneNumber, $params);
39+
}
40+
return $acl;
41+
} catch (\Exception $e) {
42+
43+
return false;
44+
}
45+
}
46+
47+
}

Diff for: Model/Upload/Dictionary.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Fastly\Cdn\Model\Upload;
4+
5+
use Fastly\Cdn\Model\Api;
6+
use Fastly\Cdn\Model\Config;
7+
8+
class Dictionary
9+
{
10+
11+
/**
12+
* @var Api
13+
*/
14+
private $api;
15+
16+
/**
17+
* @param Api $api
18+
*/
19+
public function __construct(
20+
Api $api
21+
) {
22+
$this->api = $api;
23+
}
24+
25+
/**
26+
* @param $cloneNumber
27+
* @param $currActiveVersion
28+
* @return bool|mixed
29+
*/
30+
public function setupDictionary($cloneNumber, $currActiveVersion)
31+
{
32+
try {
33+
$dictionaryName = Config::CONFIG_DICTIONARY_NAME;
34+
$dictionary = $this->api->getSingleDictionary($currActiveVersion, $dictionaryName);
35+
36+
if (!$dictionary) {
37+
$params = ['name' => $dictionaryName];
38+
$dictionary = $this->api->createDictionary($cloneNumber, $params);
39+
}
40+
return $dictionary;
41+
} catch (\Exception $e) {
42+
43+
return false;
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)