18
18
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
19
19
* @license BSD, see LICENSE_FASTLY_CDN.txt
20
20
*/
21
+
21
22
namespace Fastly \Cdn \Console \Command ;
22
23
23
24
use Fastly \Cdn \Model \Config ;
30
31
use Symfony \Component \Console \Input \InputInterface ;
31
32
use Symfony \Component \Console \Output \OutputInterface ;
32
33
use Symfony \Component \Console \Input \InputOption ;
34
+ use Symfony \Component \Console \Input \InputArgument ;
33
35
use Magento \Framework \App \Config \Storage \WriterInterface ;
34
36
use Magento \Framework \App \Cache \Manager ;
35
37
use Magento \Framework \Console \Cli ;
@@ -115,30 +117,30 @@ protected function configure() // @codingStandardsIgnoreLine - required by paren
115
117
'u ' ,
116
118
InputOption::VALUE_NONE ,
117
119
'Uploads default VCL files, Test connection must pass to proceed with VCL uploading. '
118
- . ' Add --activate argument to activate new version. '
119
- );
120
+ . ' Add activate argument to activate new version of vcl. '
121
+ )
122
+ ->addArgument (
123
+ 'activate ' ,
124
+ InputArgument::OPTIONAL ,
125
+ 'Argument to activate new version of vcl (Possible values: true / false). '
126
+ . PHP_EOL . 'This argument can be used with next options: '
127
+ . PHP_EOL . ' upload-vcl, enable-force-tls and disable-force-tls. ' ,
128
+ false );
120
129
121
130
$ this ->addOption (
122
131
'enable-force-tls ' ,
123
132
'f ' ,
124
133
InputOption::VALUE_NONE ,
125
134
'Uploads Force TLS snippets, Test connection must pass to proceed with VCL uploading. '
126
- . ' Add -- activate argument to activate new version. '
135
+ . ' Add activate argument to activate new version of vcl . '
127
136
);
128
137
129
138
$ this ->addOption (
130
139
'disable-force-tls ' ,
131
140
'l ' ,
132
141
InputOption::VALUE_NONE ,
133
142
'Removes Force TLS snippets, Test connection must pass to proceed with VCL snippet removal. '
134
- . ' Add --activate argument to activate new version. '
135
- );
136
-
137
- $ this ->addOption (
138
- 'activate ' ,
139
- 'a ' ,
140
- InputOption::VALUE_NONE ,
141
- 'Activate newly cloned version. Used with VCL upload. '
143
+ . ' Add activate argument to activate new version of vcl. '
142
144
);
143
145
144
146
$ this ->addOption (
@@ -273,15 +275,16 @@ protected function configure() // @codingStandardsIgnoreLine - required by paren
273
275
* @param Dictionary $dictionary
274
276
*/
275
277
public function __construct (
276
- Config $ config ,
277
- Api $ api ,
278
- Vcl $ vcl ,
278
+ Config $ config ,
279
+ Api $ api ,
280
+ Vcl $ vcl ,
279
281
WriterInterface $ configWriter ,
280
- Manager $ cacheManager ,
281
- Filesystem $ filesystem ,
282
- Acl $ acl ,
283
- Dictionary $ dictionary
284
- ) {
282
+ Manager $ cacheManager ,
283
+ Filesystem $ filesystem ,
284
+ Acl $ acl ,
285
+ Dictionary $ dictionary
286
+ )
287
+ {
285
288
parent ::__construct ();
286
289
$ this ->config = $ config ;
287
290
$ this ->api = $ api ;
@@ -372,18 +375,19 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
372
375
}
373
376
374
377
// Upload VCL
378
+ $ activate = filter_var ($ input ->getArgument ('activate ' ), FILTER_VALIDATE_BOOLEAN );
375
379
if ($ input ->getOption ('upload-vcl ' )) {
376
- $ this ->uploadVcl ($ input -> getOption ( ' activate ' ) );
380
+ $ this ->uploadVcl ($ activate );
377
381
}
378
382
379
383
// Enable Force TLS snippet
380
384
if ($ input ->getOption ('enable-force-tls ' )) {
381
- $ this ->enableforceTls ($ input -> getOption ( ' activate ' ) );
385
+ $ this ->enableforceTls ($ activate );
382
386
}
383
387
384
388
// Enable Force TLS snippet
385
389
if ($ input ->getOption ('disable-force-tls ' )) {
386
- $ this ->disableforceTls ($ input -> getOption ( ' activate ' ) );
390
+ $ this ->disableforceTls ($ activate );
387
391
}
388
392
389
393
// Enable
@@ -707,11 +711,11 @@ private function uploadVcl($activate)
707
711
708
712
foreach ($ snippets as $ key => $ value ) {
709
713
$ snippetData = [
710
- 'name ' => Config::FASTLY_MAGENTO_MODULE . '_ ' . $ key ,
711
- 'type ' => $ key ,
712
- 'dynamic ' => "0 " ,
713
- 'priority ' => 50 ,
714
- 'content ' => $ value
714
+ 'name ' => Config::FASTLY_MAGENTO_MODULE . '_ ' . $ key ,
715
+ 'type ' => $ key ,
716
+ 'dynamic ' => "0 " ,
717
+ 'priority ' => 50 ,
718
+ 'content ' => $ value
715
719
];
716
720
$ this ->api ->uploadSnippet ($ clone ->number , $ snippetData );
717
721
}
@@ -723,31 +727,31 @@ private function uploadVcl($activate)
723
727
$ snippetShortName = $ snippetNameData [2 ];
724
728
725
729
$ customSnippetData = [
726
- 'name ' => Config::FASTLY_MAGENTO_MODULE . '_ ' . $ snippetShortName ,
727
- 'type ' => $ snippetType ,
728
- 'priority ' => $ snippetPriority ,
729
- 'content ' => $ value ,
730
- 'dynamic ' => '0 '
730
+ 'name ' => Config::FASTLY_MAGENTO_MODULE . '_ ' . $ snippetShortName ,
731
+ 'type ' => $ snippetType ,
732
+ 'priority ' => $ snippetPriority ,
733
+ 'content ' => $ value ,
734
+ 'dynamic ' => '0 '
731
735
];
732
736
$ this ->api ->uploadSnippet ($ clone ->number , $ customSnippetData );
733
737
}
734
738
735
739
$ this ->createGzipHeader ($ clone );
736
740
737
741
$ condition = [
738
- 'name ' => Config::FASTLY_MAGENTO_MODULE . '_pass ' ,
742
+ 'name ' => Config::FASTLY_MAGENTO_MODULE . '_pass ' ,
739
743
'statement ' => 'req.http.x-pass ' ,
740
- 'type ' => 'REQUEST ' ,
741
- 'priority ' => 90
744
+ 'type ' => 'REQUEST ' ,
745
+ 'priority ' => 90
742
746
];
743
747
$ createCondition = $ this ->api ->createCondition ($ clone ->number , $ condition );
744
748
$ request = [
745
- 'action ' => 'pass ' ,
746
- 'max_stale_age ' => 3600 ,
747
- 'name ' => Config::FASTLY_MAGENTO_MODULE . '_request ' ,
749
+ 'action ' => 'pass ' ,
750
+ 'max_stale_age ' => 3600 ,
751
+ 'name ' => Config::FASTLY_MAGENTO_MODULE . '_request ' ,
748
752
'request_condition ' => $ createCondition ->name ,
749
- 'service_id ' => $ service ->id ,
750
- 'version ' => $ currActiveVersion
753
+ 'service_id ' => $ service ->id ,
754
+ 'version ' => $ currActiveVersion
751
755
];
752
756
753
757
$ this ->api ->createRequest ($ clone ->number , $ request );
@@ -760,7 +764,7 @@ private function uploadVcl($activate)
760
764
761
765
if ($ activate ) {
762
766
$ this ->api ->activateVersion ($ clone ->number );
763
- $ msg .= 'Activated Version ' . $ clone ->number ;
767
+ $ msg .= 'Activated Version ' . $ clone ->number ;
764
768
}
765
769
766
770
if ($ this ->config ->areWebHooksEnabled () && $ this ->config ->canPublishConfigChanges ()) {
@@ -788,26 +792,26 @@ private function enableForceTls($activate)
788
792
$ service = $ this ->api ->checkServiceDetails ();
789
793
$ currActiveVersion = $ this ->vcl ->getCurrentVersion ($ service ->versions );
790
794
$ clone = $ this ->api ->cloneVersion ($ currActiveVersion );
791
- $ reqName = Config::FASTLY_MAGENTO_MODULE . '_force_tls ' ;
795
+ $ reqName = Config::FASTLY_MAGENTO_MODULE . '_force_tls ' ;
792
796
$ snippets = $ this ->config ->getVclSnippets (Config::FORCE_TLS_PATH );
793
797
794
798
$ request = [
795
- 'name ' => $ reqName ,
796
- 'service_id ' => $ service ->id ,
797
- 'version ' => $ currActiveVersion ,
798
- 'force_ssl ' => true
799
+ 'name ' => $ reqName ,
800
+ 'service_id ' => $ service ->id ,
801
+ 'version ' => $ currActiveVersion ,
802
+ 'force_ssl ' => true
799
803
];
800
804
801
805
$ this ->api ->createRequest ($ clone ->number , $ request );
802
806
803
807
// Add force TLS snippet
804
808
foreach ($ snippets as $ key => $ value ) {
805
809
$ snippetData = [
806
- 'name ' => Config::FASTLY_MAGENTO_MODULE . '_force_tls_ ' . $ key ,
807
- 'type ' => $ key ,
808
- 'dynamic ' => "0 " ,
809
- 'priority ' => 10 ,
810
- 'content ' => $ value
810
+ 'name ' => Config::FASTLY_MAGENTO_MODULE . '_force_tls_ ' . $ key ,
811
+ 'type ' => $ key ,
812
+ 'dynamic ' => "0 " ,
813
+ 'priority ' => 10 ,
814
+ 'content ' => $ value
811
815
];
812
816
$ this ->api ->uploadSnippet ($ clone ->number , $ snippetData );
813
817
}
@@ -817,11 +821,11 @@ private function enableForceTls($activate)
817
821
818
822
if ($ activate ) {
819
823
$ this ->api ->activateVersion ($ clone ->number );
820
- $ msg .= 'Activated Version ' . $ clone ->number ;
824
+ $ msg .= 'Activated Version ' . $ clone ->number ;
821
825
}
822
826
823
827
if ($ this ->config ->areWebHooksEnabled () && $ this ->config ->canPublishConfigChanges ()) {
824
- $ this ->api ->sendWebHook ('*Force TLS has been turned ON in Fastly version ' . $ clone ->number . '* ' );
828
+ $ this ->api ->sendWebHook ('*Force TLS has been turned ON in Fastly version ' . $ clone ->number . '* ' );
825
829
}
826
830
827
831
$ this ->output ->writeln ('<info> ' . $ msg . '</info> ' , OutputInterface::OUTPUT_NORMAL );
@@ -843,21 +847,21 @@ private function disableForceTls($activate)
843
847
$ service = $ this ->api ->checkServiceDetails ();
844
848
$ currActiveVersion = $ this ->vcl ->getCurrentVersion ($ service ->versions );
845
849
$ clone = $ this ->api ->cloneVersion ($ currActiveVersion );
846
- $ reqName = Config::FASTLY_MAGENTO_MODULE . '_force_tls ' ;
850
+ $ reqName = Config::FASTLY_MAGENTO_MODULE . '_force_tls ' ;
847
851
$ snippets = $ this ->config ->getVclSnippets (Config::FORCE_TLS_PATH );
848
852
849
853
$ request = [
850
- 'name ' => $ reqName ,
851
- 'service_id ' => $ service ->id ,
852
- 'version ' => $ currActiveVersion ,
853
- 'force_ssl ' => false
854
+ 'name ' => $ reqName ,
855
+ 'service_id ' => $ service ->id ,
856
+ 'version ' => $ currActiveVersion ,
857
+ 'force_ssl ' => false
854
858
];
855
859
856
860
$ this ->api ->createRequest ($ clone ->number , $ request );
857
861
858
862
// Remove Force TLS snippet
859
863
foreach ($ snippets as $ key => $ value ) {
860
- $ name = Config::FASTLY_MAGENTO_MODULE . '_force_tls_ ' . $ key ;
864
+ $ name = Config::FASTLY_MAGENTO_MODULE . '_force_tls_ ' . $ key ;
861
865
862
866
if ($ this ->api ->hasSnippet ($ clone ->number , $ name )) {
863
867
$ this ->api ->removeSnippet ($ clone ->number , $ name );
@@ -869,11 +873,11 @@ private function disableForceTls($activate)
869
873
870
874
if ($ activate ) {
871
875
$ this ->api ->activateVersion ($ clone ->number );
872
- $ msg .= 'Activated Version ' . $ clone ->number ;
876
+ $ msg .= 'Activated Version ' . $ clone ->number ;
873
877
}
874
878
875
879
if ($ this ->config ->areWebHooksEnabled () && $ this ->config ->canPublishConfigChanges ()) {
876
- $ this ->api ->sendWebHook ('*Force TLS has been turned OFF in Fastly version ' . $ clone ->number . '* ' );
880
+ $ this ->api ->sendWebHook ('*Force TLS has been turned OFF in Fastly version ' . $ clone ->number . '* ' );
877
881
}
878
882
879
883
$ this ->output ->writeln ('<info> ' . $ msg . '</info> ' , OutputInterface::OUTPUT_NORMAL );
@@ -939,21 +943,21 @@ private function validateCustomSnippet($customSnippet)
939
943
private function createGzipHeader ($ clone )
940
944
{
941
945
$ condition = [
942
- 'name ' => Config::FASTLY_MAGENTO_MODULE . '_gzip_safety ' ,
946
+ 'name ' => Config::FASTLY_MAGENTO_MODULE . '_gzip_safety ' ,
943
947
'statement ' => 'beresp.http.x-esi ' ,
944
- 'type ' => 'CACHE ' ,
945
- 'priority ' => 100
948
+ 'type ' => 'CACHE ' ,
949
+ 'priority ' => 100
946
950
];
947
951
$ createCondition = $ this ->api ->createCondition ($ clone ->number , $ condition );
948
952
949
953
$ headerData = [
950
- 'name ' => Config::FASTLY_MAGENTO_MODULE . '_gzip_safety ' ,
951
- 'type ' => 'cache ' ,
952
- 'dst ' => 'gzip ' ,
953
- 'action ' => 'set ' ,
954
- 'priority ' => 1000 ,
955
- 'src ' => 'false ' ,
956
- 'cache_condition ' => $ createCondition ->name ,
954
+ 'name ' => Config::FASTLY_MAGENTO_MODULE . '_gzip_safety ' ,
955
+ 'type ' => 'cache ' ,
956
+ 'dst ' => 'gzip ' ,
957
+ 'action ' => 'set ' ,
958
+ 'priority ' => 1000 ,
959
+ 'src ' => 'false ' ,
960
+ 'cache_condition ' => $ createCondition ->name ,
957
961
];
958
962
959
963
$ this ->api ->createHeader ($ clone ->number , $ headerData );
0 commit comments