forked from pantheon-deprecated/terminus-deprecated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminus.drush.inc
4424 lines (3978 loc) · 137 KB
/
terminus.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Terminus: programmatic access to the Pantheon Platform via Drush.
*/
/**
* Some constants we use.
*/
define('TERMINUS_HOST', 'terminus.getpantheon.com');
define('TERMINUS_PORT', 443);
date_default_timezone_set('UTC');
/**
* An easy function to override constants to allow development internally.
*
* Also bootstraps the included library functions, which are separate so people
* can use them outside the context of Drush.
*
* TODO: use for other settings.
*/
function terminus_bootstrap($validate = TRUE) {
// TODO: something to check that terminus is up to date!
// TODO: More intelligent includes, maybe autoloading?
include_once 'terminus.backup.api.inc';
include_once 'terminus.site.api.inc';
include_once 'terminus.user.api.inc';
include_once 'terminus.tunnel.inc';
include_once 'terminus.workflow.api.inc';
include_once 'terminus.code.api.inc';
include_once 'terminus.organizations.api.inc';
include_once 'terminus.art.inc';
$session_data = terminus_session_data();
// DRY session validation.
if ($validate) {
if (!isset($session_data['user_uuid'])) {
return drush_set_error("No user UUID found. Please authenticate first using 'drush pauth'");
}
}
// Common command flags.
$session_data['nocache'] = drush_get_option('nocache');
$session_data['json_output'] = drush_get_option('json');
if (isset($session_data['onebox']) || drush_get_option('onebox')) {
$session_data['onebox'] = TRUE;
}
// Expired session.
if (isset($session_data['session_expire_time']) && time() > $session_data['session_expire_time']) {
terminus_pantheon_logout();
drush_set_error('TERMINUS_BOOTSTRAP_SESS_EXPIRED', dt('The Terminus session expired; you must log in again.'));
}
return $session_data;
}
/**
* Implementation of hook_drush_command().
*
* List of available terminus commands.
*
* @return
* An associative array describing your command(s).
*/
function terminus_drush_command() {
$items = array();
$items['pantheon-logout'] = array(
'description' => "Clear any stored session data.",
'examples' => array(
'drush plogout',
),
'aliases' => array('plogout'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-auth'] = array(
'description' => "Authenticate against the Pantheon dashboard. Required before doing anything else.",
'arguments' => array(
'email' => 'Email address of dashboard account',
),
'options' => array(
'password' => array(
'description' => 'Optional: include password for script-friendly use.',
'example-value' => 'mypassword',
),
),
'examples' => array(
'drush pauth [email protected] --password=mypassword' => 'Get authentication token.',
),
'aliases' => array('pauth'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-sites'] = array(
'description' => 'List your Pantheon sites.',
'examples' => array(
'drush psites --nocache' => 'Get a fresh list of sites.',
),
'aliases' => array('psites'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-attributes'] = array(
'description' => 'Get attributes for a particular site.',
'aliases' => array('psite-attr'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'site' => 'The site UUID in question.',
),
'options' => array(
'attribute' => array(
'description' => 'Specific attribute that you want to get.',
'example-value' => 'label',
),
),
);
$items['pantheon-site-branch-list'] = array(
'description' => 'List Git branches for a particular site.',
'aliases' => array('psite-blist'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'site' => 'The site UUID in question.',
),
);
$items['pantheon-site-branch-create'] = array(
'description' => 'Create Git branch of master for a particular site.',
'aliases' => array('psite-bcreate'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'site' => 'The site UUID in question.',
),
'options' => array(
'name' => array(
'description' => 'Branch name to be created.',
'example-value' => 'feature-123',
),
),
);
$items['pantheon-site-branch-delete'] = array(
'description' => 'Delete a Git branch from a particular site.',
'aliases' => array('psite-bdel'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'site' => 'The site UUID in question.',
),
'options' => array(
'name' => array(
'description' => 'Branch name to be deleted.',
'example-value' => 'feature-123',
),
),
);
$items['pantheon-hostname-add'] = array(
'description' => "Add a hostname to a site you control.",
'arguments' => array(
'site' => 'The site UUID you are working on.',
'environment' => 'The environment (e.g. "live").',
'hostname' => 'The hostname (e.g. "www.mysite.com")',
),
'aliases' => array('psite-hostname-add', 'psite-ha'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-hostname-remove'] = array(
'description' => "Remove a hostname from a site you control.",
'arguments' => array(
'site' => 'The site UUID you are working on.',
'environment' => 'The environemnt (e.g. "live").',
'hostname' => 'The hostname (e.g. "www.mysite.com")',
),
'aliases' => array('psite-hostname-remove', 'psite-hr'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-hostname-list'] = array(
'description' => dt('List all hostnames associated with a site.'),
'arguments' => array(
'site' => 'The site UUID you are working on.',
'environment' => 'The environemnt (e.g. "live").',
),
'aliases' => array('psite-hostname-list', 'psite-hl'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-products'] = array(
'description' => "Get the list of available Drupal product start-states.",
'aliases' => array('pproducts'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-create'] = array(
'description' => "Create a new site on Pantheon",
'arguments' => array(
'name' => 'Short name of the site to create. Will be part of the URL.',
),
'options' => array(
'label' => array(
'description' => 'Human-friendly site label.',
),
'product' => array(
'description' => 'UUID of the product you want to start with (see pantheon-products).',
),
'organization' => array(
'description' => 'UUID of an organization you want the site to be a part of.',
),
'nopoll' => array(
'description' => 'Do not hang around and wait for the site to be ready. Useful for scripting a lot of spin-ups.',
),
),
'aliases' => array('psite-create'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-import'] = array(
'description' => "Import an existing site to Pantheon",
'arguments' => array(
'name' => 'Short name of the site to create. Will be part of the URL.',
'url' => 'URL of Drush Archive.',
),
'options' => array(
'label' => array(
'description' => 'Human-friendly site label.',
),
'organization' => array(
'description' => 'UUID of an organization you want the site to be a part of.',
),
'nopoll' => array(
'description' => 'Do not hang around and wait for the site to be ready. Useful for scripting a lot of spin-ups.',
),
),
'aliases' => array('psite-import'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-delete'] = array(
'description' => "Delete a site from Pantheon.",
'arguments' => array(
'site' => 'UUID of the site you want to delete.',
),
'aliases' => array('psite-delete'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-backups'] = array(
'description' => "List site backups (and exports).",
'arguments' => array(
'site' => 'UUID of the site you want to get backups for.',
'environment' => 'The environment (e.g. "live") you want to back up.',
),
'aliases' => array('psite-backups'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-get-backup'] = array(
'description' => "Get a download link to a specific site backup.",
'arguments' => array(
'site' => 'UUID of the site you want to get backups for.',
'environment' => 'The environment (e.g. "live") you want to back up.',
'bucket' => 'Bucket for the backup.',
'element' => 'Which part of the backup do you want?',
),
'aliases' => array('psite-get-backup'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-make-backup'] = array(
'description' => "Trigger an on-demand backup for a site/environment.",
'arguments' => array(
'site' => 'UUID of the site you want to make a backup for.',
'environment' => 'The environment (e.g. "live") you want to back up.',
),
'aliases' => array('psite-backup'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-download-backup'] = array(
'description' => "Download a backup file from a specific site.",
'arguments' => array(
'site' => 'UUID of the site you want to get backups for.',
'environment' => 'The environment (e.g. "live") you want to download a backup from.',
'bucket' => 'Bucket for the backup. Use "latest" for the most recent.',
'element' => 'Which part of the backup do you want? (e.g. database, files, code)',
'destination' => 'Where would you like the backup?'
),
'aliases' => array('psite-dl-backup'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-load-backup'] = array(
'description' => "Load db with a backup file from a specific site.",
'arguments' => array(
'site' => 'UUID or name of the site you want to get backups for.',
'environment' => 'The environment (e.g. "live") you want to use a backup from.',
'bucket' => 'Bucket for the backup. Use "latest" for the most recent.',
),
'aliases' => array('psite-load-backup'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-connection-mode'] = array(
'description' => "Set or retrieve the connection mode of a specific site/environment.",
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'The dev or multidev environment you would like to target.',
'mode' => 'Connection mode like to set (e.g., "sftp" or "git"). Leave blank to retrieve the current mode.',
),
'aliases' => array('psite-cmode'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-commit'] = array(
'description' => 'Commit changes in an on-server-dev environment.',
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'Environment to commit: a dev or multidev environment',
),
'options' => array(
'message' => 'Commit message',
),
'aliases' => array('psite-commit'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-diffstat'] = array(
'description' => 'Get a list of changes (diffstat) to be commited in a remote on-server-dev environment.',
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'Environment to commit: a dev or multidev environment',
),
'aliases' => array('psite-diffs'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-environment-list'] = array(
'description' => 'Get a list of site environments.',
'arguments' => array(
'site' => 'UUID or name of the site.',
),
'aliases' => array('psite-elist'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-environment-create'] = array(
'description' => 'Create a new multidev site environment.',
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'Name of multidev site environment. If branch does not exist, it will be created.',
),
'options' => array(
'source' => 'The source environment (e.g. "live") from which content will be cloned. If omitted, will default to dev.',
),
'aliases' => array('psite-ecreate'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-environment-delete'] = array(
'description' => 'Delete a multidev site environment.',
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'Name of multidev site environment.',
),
'aliases' => array('psite-edelete'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-environment-lock'] = array(
'description' => dt('Lock a site environment.'),
'arguments' => array(
'site' => dt('UUID or name of the site.'),
'environment' => dt('Name of site environment.'),
'username' => dt('Username for HTTP Basic Auth'),
'password' => dt('Password for HTTP Basic Auth'),
),
'aliases' => array('psite-elo'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-environment-unlock'] = array(
'description' => dt('Unlock a site environment.'),
'arguments' => array(
'site' => dt('UUID or name of the site.'),
'environment' => dt('Name of site environment.'),
),
'aliases' => array('psite-eul'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-environment-lock-info'] = array(
'description' => dt('Get information about whether a site environment is locked.'),
'arguments' => array(
'site' => dt('UUID or name of the site.'),
'environment' => dt('Name of site environment.'),
),
'aliases' => array('psite-eli'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-notifications'] = array(
'description' => dt('Get a list of notifications for a site.'),
'arguments' => array(
'site' => dt('UUID of the site.'),
),
'options' => array(
'count' => dt('Number of notifications to show'),
'type' => dt('Filter notifications by type'),
),
'aliases' => array('psite-notifications'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-jobs'] = array(
'description' => dt('Get a list of jobs for a site.'),
'arguments' => array(
'site' => dt('UUID of the site.'),
),
'options' => array(
'environment' => array(
'description' => dt('Filter jobs by environment'),
'example-value' => 'dev',
),
'slot' => array(
'description' => dt('Filter by slot'),
'example-value' => 'cache_clear',
),
),
'aliases' => array('psite-jobs'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-uuid'] = array(
'description' => "Get the site UUID based on the name.",
'arguments' => array(
'sites' => 'A list of site names.',
),
'examples' => array(
'drush psite-uuid mysite --nocache' => 'Get the UUID of your site.',
),
'required-arguments' => TRUE,
'aliases' => array('psite-uuid'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-name'] = array(
'description' => dt('Get the site name from UUID.'),
'arguments' => array(
'uuid' => dt('UUID of the site.'),
),
'examples' => array(
'drush psite-name 12345678-1234-abcd-9876-fedcba09 --nocache' => dt('Get the name of your site.'),
),
'required-arguments' => TRUE,
'aliases' => array('psite-name'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-dashboard'] = array(
'description' => "Get the dashboard link for a site.",
'arguments' => array(
'site' => 'UUID of the site.',
),
'examples' => array(
'drush psite-dash mysite -y' => 'Open the dashboard for a site.',
),
'aliases' => array('psite-dash'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-service-level'] = array(
'description' => "Update the service level for the site.",
'arguments' => array(
'site' => 'UUID of the site.',
'service-level' => 'Service level to upgrade to.',
),
'examples' => array(
'drush psite-upgrade <site> <service-level>' => 'Open the dashboard for a site.',
),
'aliases' => array('psite-upgrade'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-environment-redis-clear'] = array(
'description' => 'Clear redis cache of a site environment.',
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'Name of site environment.',
),
'aliases' => array('psite-erc'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
/**
* Site team functions.
*/
$items['pantheon-site-team'] = array(
'description' => "Get the team for a site.",
'arguments' => array(
'site' => 'uuid of the site',
),
'examples' => array(
'drush psite-team 12345678-1234-abcd-9876-fedcba09 --nocache' => 'Get the team of your site.',
),
'aliases' => array('psite-team'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-team-add'] = array(
'description' => "Add someone to the team for a site.",
'arguments' => array(
'site' => 'uuid of the site',
'user' => 'user you would like to make a part of the team: uuid or email',
),
'examples' => array(
'drush psite-team-add mysite [email protected]' => 'Add josh to your site team.',
),
'aliases' => array('psite-team-add'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-team-remove'] = array(
'description' => "Remove someone from the team for a site.",
'arguments' => array(
'site' => 'uuid of the site',
'user' => 'user you would like to remove: uuid or email',
),
'examples' => array(
'drush psite-team-remove mysite [email protected]' => 'Remove josh to your site team.',
),
'aliases' => array('psite-team-remove'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-change-owner'] = array(
'description' => "Change the owner of a site.",
'arguments' => array(
'site' => 'uuid of the site',
'user' => 'team member you would like to make the new owner: uuid or email',
),
'examples' => array(
'drush psite-set-owner mysite [email protected]' => 'Make josh the site owner.',
),
'aliases' => array('psite-change-owner'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
/**
* Organization-scope functions.
*/
$items['pantheon-organizations'] = array(
'description' => "List your organization affiliations.",
'examples' => array(
'drush porgs --nocache' => 'Get a fresh list of sites.',
),
'aliases' => array('porgs'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-organization-sites'] = array(
'description' => "List the sites for an organization. Org admins only.",
'arguments' => array(
'organization' => 'UUID of the organization you want to use.',
),
'examples' => array(
'drush porg-sites --nocache' => 'Get a fresh list of sites.',
),
'aliases' => array('porg-sites'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-organization-site-add'] = array(
'description' => "Add a site to an organization. Org admins only.",
'arguments' => array(
'organization' => 'UUID of the organization.',
'site' => 'UUID of the organization.',
),
'examples' => array(
'drush porg-site-add <org> <site>' => 'Add a site to an organization.',
),
'aliases' => array('porg-site-add'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-organization-site-remove'] = array(
'description' => "Remove a site from an organization. Org admins only.",
'arguments' => array(
'organization' => 'UUID of the organization.',
'site' => 'UUID of the organization.',
),
'examples' => array(
'drush porg-site-remove <org> <site>' => 'Add a site to an organization.',
),
'aliases' => array('porg-site-remove'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
/**
* Tunnel Functions.
*/
$items['pantheon-site-tunnels'] = array(
'description' => "Get a list of open tunnels.",
'aliases' => array('psite-tunnels'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-tunnel'] = array(
'description' => "Opens a tunnel to a specific site/environment/service.",
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'The target environment (e.g. "live").',
'service' => 'The service (e.g., "mysql" or "redis") to open a tunnel for. Defaults to "mysql".',
'port' => 'Local port to connect to.',
),
'aliases' => array('psite-tunnel'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-tunnel-close'] = array(
'description' => "Closes the tunnel to a specific site/environment/service.",
'arguments' => array(
'site' => 'UUID or name of the site. If left empty, all tunnels will be closed.',
'environment' => 'The target environment (e.g. "live"). If left empty, all site tunnels will be closed.',
'service' => 'The service (e.g., "mysql" or "redis") to open a tunnel for. If empty, all site/environment tunnels will be closed.'
),
'aliases' => array('psite-tclose'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-mount'] = array(
'description' => "Mounts an environment file system to a local directory.",
'arguments' => array(
'site' => 'UUID or name of the site. If left empty, all tunnels will be closed.',
'environment' => 'The target environment (e.g. "live"). If left empty, all site tunnels will be closed.',
'destination' => 'Where would you like to mount the file system?'
),
'aliases' => array('psite-mount'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
/**
* Workflow.
*/
$items['pantheon-site-clone'] = array(
'description' => 'Clone content from one site environment to another.',
'arguments' => array(
'site' => 'UUID of the site containing content.',
'source' => 'The source environment (e.g. "live") from which content will be cloned.',
'target' => 'The target environment (e.g. "live") to which content will be cloned.',
),
'options' => array(
'db' => 'Clone database content.',
'files' => 'Clone files content.',
'update' => 'Run update.php after cloning database.',
),
'examples' => array(
'drush psite-clone SITE_UUID dev test' => 'Clone both database and files from dev to test.',
'drush psite-clone SITE_UUID dev test --db --update' => 'Clone only database from dev to test, then run update.php.',
'drush psite-clone SITE_UUID dev test --files' => 'Clone only user files from dev to test.',
),
'aliases' => array('psite-clone'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-deploy'] = array(
'description' => 'Deploy code to a particular environment.',
'arguments' => array(
'site' => 'UUID of the site.',
'target' => 'The target environment (e.g. "live") to which code will be deployed.',
),
'options' => array(
'update' => 'Run update.php after deploying code.',
'cc' => 'Clear cache after deploying code.',
),
'examples' => array(
'drush psite-deploy SITE_UUID live' => 'Deploy latest code changes to live.',
'drush psite-deploy SITE_UUID test --update --cc' => 'Deploy latest code changes to test, the run update.php and clear cache.',
),
'aliases' => array('psite-deploy'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
/**
* Utility Functions.
*/
$items['pantheon-aliases'] = array(
'description' => "Update the Pantheon Drush alias file at ~/.drush/pantheon.aliases.drushrc.php.",
'options' => array(
'destination' => array(
'description' => 'Specify the destination to save the alias file.',
),
),
'aliases' => array('paliases'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
$items['pantheon-site-info'] = array(
'description' => dt('Get Pantheon metadata on a site'),
'aliases' => array('psite-info'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'site' => dt('UUID or name of the site.'),
),
'options' => array(
'json' => array(
'description' => dt('If set, will output in JSON format.'),
),
),
);
$items['pantheon-site-nr-info'] = array(
'description' => dt('Get New Relic metadata on a site'),
'aliases' => array('psite-nri'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'site' => dt('UUID or name of the site.'),
),
'options' => array(
'json' => array(
'description' => dt('If set, will output in JSON format.'),
),
),
);
$items['pantheon-site-wake'] = array(
'description' => 'Ensure a site environment is online and not suspended due to inactivity.',
'aliases' => array('psite-wake'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'site' => 'UUID or name of the site.',
'environment' => 'The target environment (e.g. "live").',
),
);
$items['pantheon-pp'] = array(
'description' => "Direct pseudo-proxy interface. JSON only. For debugging.",
'arguments' => array(
'realm' => 'Are you asking about users or sites?',
'uuid' => 'The unique id of the thing you want to know about.',
'path' => 'Optional: path extension for more specific commands.',
),
'aliases' => array('pp'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
);
// Include standard options for all commands:
$common = array(
'nocache' => array(
'description' => 'Force a refresh of cached authentication session.',
),
'json' => array('description' => 'Return raw JSON if possible.'),
'onebox' => array('description' => 'Use onebox (Pantheon dev only).'),
);
foreach ($items as $key => $array) {
if (isset($array['options'])) {
$items[$key]['options'] = array_merge($items[$key]['options'], $common);
}
else {
$items[$key]['options'] = $common;
}
}
return $items;
}
/**
* @group Drush Commands
*
* These commands exercise various aspects of the API.
*/
/**
* Validate site info.
*/
function drush_terminus_pantheon_site_info_validate($site_uuid = FALSE) {
$session_data = terminus_bootstrap();
if ($session_data === FALSE) {
return drush_set_error('DRUSH_PSITE_INFO_NO_SESSION', dt('You must authenticate before using this command.'));
}
if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) {
return drush_set_error('DRUSH_PSITE_INFO_NO_UUID', dt('You must specify a valid site UUID.'));
}
drush_set_option('site_uuid', $site_uuid);
}
/**
* Site info.
*/
function drush_terminus_pantheon_site_info($site_uuid = FALSE) {
$site_uuid = drush_get_option('site_uuid');
$result = terminus_api_site_info($site_uuid);
if (drush_get_option('json')) {
drush_print($result['json']);
}
else {
drush_print_r(json_decode($result['json']));
}
}
/**
* Validate New Relic info.
*/
function drush_terminus_pantheon_site_nr_info_validate($site_uuid = FALSE) {
$session_data = terminus_bootstrap();
if ($session_data === FALSE) {
return drush_set_error('DRUSH_PSITE_NR_INFO_NO_SESSION', dt('You must authenticate before using this command.'));
}
if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) {
return drush_set_error('DRUSH_PSITE_NR_INFO_NO_UUID', dt('You must specify a valid site UUID.'));
}
drush_set_option('site_uuid', $site_uuid);
}
/**
* New Relic info.
*/
function drush_terminus_pantheon_site_nr_info($site_uuid = FALSE) {
$site_uuid = drush_get_option('site_uuid');
$result = terminus_api_new_relic_info($site_uuid);
if ($result['json'] != 'No NewRelic account found') {
if (drush_get_option('json')) {
drush_print($result['json']);
}
else {
drush_print_r(json_decode($result['json']));
}
}
else {
drush_set_error('DRUSH_PSITE_NR_INFO_NO_NR', dt('Site does not have New Relic enabled.'));
}
}
/**
* Validate site environment lock.
*/
function drush_terminus_pantheon_site_environment_lock_validate($site_uuid = FALSE, $environment = FALSE, $username = FALSE, $password = FALSE) {
$session_data = terminus_bootstrap();
if ($session_data === FALSE) {
return drush_set_error('DRUSH_PSITE_LOCK_NO_SESSION', dt('You must authenticate before using this command.'));
}
if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) {
return drush_set_error('DRUSH_PSITE_LOCK_INVALID_UUID', dt('You must specify a valid site UUID.'));
}
drush_set_option('site_uuid', $site_uuid);
if (!terminus_validate_environment($environment)) {
if (!$environment = terminus_session_select_data('environment', $site_uuid)) {
return drush_set_error('DRUSH_PSITE_LOCK_INVALID_ENV', dt('You must specify a valid environment name.'));
}
}
drush_set_option('environment', $environment);
$result = terminus_api_site_environment_lock_info($site_uuid, $environment);
if (!$result) {
return drush_set_error('DRUSH_PSITE_LOCK_INFO_REQFAIL', dt('Unable to get lock information.'));
}
$lock = json_decode($result['json']);
if ($lock->locked) {
return drush_set_error('DRUSH_PSITE_LOCK_ALREADY_LOCKED', dt('Already locked!'));
}
if (!$username) {
if (!$username = drush_prompt(dt('Username'))) {
return drush_user_abort();
}
}
drush_set_option('username', $username);
if (!$password) {
if (!$password = drush_prompt(dt('Password'))) {
return drush_user_abort();
}
}
drush_set_option('password', $password);
}
/**
* Lock a site environment.
*/
function drush_terminus_pantheon_site_environment_lock($site_uuid = FALSE, $environment = FALSE, $username = FALSE, $password = FALSE) {
$site_uuid = drush_get_option('site_uuid');
$environment = drush_get_option('environment');
$username = drush_get_option('username');
$password = drush_get_option('password');
$result = terminus_api_site_environment_lock($site_uuid, $environment, $username, $password);
if (!$result) {
return drush_set_error('DRUSH_PSITE_LOCK_REQFAIL', dt('Unable to lock.'));
}
drush_log(dt('@site_name @environment is now locked.', array(
'@site_name' => terminus_pantheon_site_name($site_uuid),
'@environment' => $environment,
)), 'ok');
}
/**
* Validate site environment unlock.
*/
function drush_terminus_pantheon_site_environment_unlock_validate($site_uuid = FALSE, $environment = FALSE) {
$session_data = terminus_bootstrap();
if ($session_data === FALSE) {
return drush_set_error('DRUSH_PSITE_UNLOCK_NO_SESSION', dt('You must authenticate before using this command.'));
}
if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) {
return drush_set_error('DRUSH_PSITE_UNLOCK_INVALID_UUID', dt('You must specify a valid site UUID.'));
}
drush_set_option('site_uuid', $site_uuid);
if (!terminus_validate_environment($environment)) {
if (!$environment = terminus_session_select_data('environment', $site_uuid)) {
return drush_set_error('DRUSH_PSITE_UNLOCK_INVALID_ENV', dt('You must specify a valid environment name.'));
}
}
drush_set_option('environment', $environment);
$result = terminus_api_site_environment_lock_info($site_uuid, $environment);
if (!$result) {
return drush_set_error('DRUSH_PSITE_LOCK_INFO_REQFAIL', dt('Unable to get lock information.'));
}
$lock = json_decode($result['json']);
if (!$lock->locked) {
return drush_set_error('DRUSH_PSITE_UNLOCK_ALREADY_UNLOCKED', dt('Already unlocked!'));
}
}
/**
* Unlock a site environment.
*/
function drush_terminus_pantheon_site_environment_unlock($site_uuid = FALSE, $environment = FALSE) {
$site_uuid = drush_get_option('site_uuid');
$environment = drush_get_option('environment');
$result = terminus_api_site_environment_lock_delete($site_uuid, $environment);
if (!$result) {
return drush_set_error('DRUSH_PSITE_UNLOCK_REQFAIL', dt('Unable to unlock.'));
}
drush_log(dt('@site_name @environment is now unlocked.', array(
'@site_name' => terminus_pantheon_site_name($site_uuid),
'@environment' => $environment,
)), 'ok');
}
/**
* Validate Pantheon site environment lock info.
*/
function drush_terminus_pantheon_site_environment_lock_info_validate($site_uuid = FALSE, $environment = FALSE) {
$session_data = terminus_bootstrap();
if ($session_data === FALSE) {
return drush_set_error('DRUSH_PSITE_LOCK_INFO_NO_SESSION', dt('You must authenticate before using this command.'));
}
if (!$site_uuid = terminus_site_input($site_uuid, TRUE, TRUE)) {
return drush_set_error('DRUSH_PSITE_LOCK_INFO_INVALID_UUID', dt('You must specify a valid site UUID.'));
}
drush_set_option('site_uuid', $site_uuid);
if (!terminus_validate_environment($environment)) {
if (!$environment = terminus_session_select_data('environment', $site_uuid)) {
return drush_set_error('DRUSH_PSITE_LOCK_INFO_INVALID_ENV', dt('You must specify a valid environment name.'));
}
}
drush_set_option('environment', $environment);
}
/**
* Get lock info for a site environment.
*/
function drush_terminus_pantheon_site_environment_lock_info($site_uuid = FALSE, $environment = FALSE) {
$site_uuid = drush_get_option('site_uuid');
$environment = drush_get_option('environment');
$result = terminus_api_site_environment_lock_info($site_uuid, $environment);
if (!$result) {
return drush_set_error('DRUSH_PSITE_LOCK_INFO_REQFAIL', dt('Unable to get lock information.'));
}
$lock = json_decode($result['json']);
if (!$lock->locked) {
drush_print(dt('@site_name @environment is unlocked.', array(
'@site_name' => terminus_pantheon_site_name($site_uuid),
'@environment' => $environment,
)));
}
else {
drush_print(dt('@site_name @environment is locked with username "@username" and password "@password".', array(
'@site_name' => terminus_pantheon_site_name($site_uuid),
'@environment' => $environment,
'@username' => $lock->username,
'@password' => $lock->password,
)));
}
}