|
| 1 | +
|
| 2 | +/** |
| 3 | + * Copyright 2017 Google Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +namespace Google\Cloud\Samples\Auth; |
| 19 | + |
| 20 | +use Symfony\Component\Console\Application; |
| 21 | +use Symfony\Component\Console\Command\Command; |
| 22 | +use Symfony\Component\Console\Input\InputArgument; |
| 23 | + |
| 24 | +# Includes the autoloader for libraries installed with composer |
| 25 | +require __DIR__ . '/vendor/autoload.php'; |
| 26 | + |
| 27 | +$application = new Application('Auth'); |
| 28 | + |
| 29 | +// Create auth-cloud-implicit Command. |
| 30 | +$application->add((new Command('auth-cloud-implicit')) |
| 31 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 32 | + ->setDescription('Authenticate to a cloud client library using a service account implicitly.') |
| 33 | + ->setHelp(<< |
| 34 | +The %command.name% command authenticates to a cloud client library |
| 35 | +using a service account implicitly. |
| 36 | +
|
| 37 | + php %command.full_name% |
| 38 | +
|
| 39 | +EOF |
| 40 | + ) |
| 41 | + ->setCode(function ($input, $output) { |
| 42 | + auth_cloud_implicit($input->getArgument('projectId')); |
| 43 | + }) |
| 44 | +); |
| 45 | + |
| 46 | +// Create auth-cloud-explicit Command. |
| 47 | +$application->add((new Command('auth-cloud-explicit')) |
| 48 | + ->addArgument('serviceAccountPath', InputArgument::REQUIRED, 'Path to your service account.') |
| 49 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 50 | + ->setDescription('Authenticate to a cloud client library using a service account explicitly.') |
| 51 | + ->setHelp(<< |
| 52 | +The %command.name% command authenticates to a cloud client library |
| 53 | +using a service account explicitly. |
| 54 | +
|
| 55 | + php %command.full_name% |
| 56 | +
|
| 57 | +EOF |
| 58 | + ) |
| 59 | + ->setCode(function ($input, $output) { |
| 60 | + auth_cloud_explicit($input->getArgument('projectId'), $input->getArgument('serviceAccountPath')); |
| 61 | + }) |
| 62 | +); |
| 63 | + |
| 64 | +// Create auth-cloud-explicit-compute-engine Command. |
| 65 | +$application->add((new Command('auth-cloud-explicit-compute-engine')) |
| 66 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 67 | + ->setDescription('Authenticate to a cloud client library using Compute Engine credentials explicitly.') |
| 68 | + ->setHelp(<< |
| 69 | +The %command.name% command authenticates to a cloud client library |
| 70 | +using Compute Engine credentials explicitly. |
| 71 | +
|
| 72 | + php %command.full_name% |
| 73 | +
|
| 74 | +EOF |
| 75 | + ) |
| 76 | + ->setCode(function ($input, $output) { |
| 77 | + auth_cloud_explicit_compute_engine($input->getArgument('projectId')); |
| 78 | + }) |
| 79 | +); |
| 80 | + |
| 81 | +// Create auth-cloud-explicit-app-engine Command. |
| 82 | +$application->add((new Command('auth-cloud-explicit-app-engine')) |
| 83 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 84 | + ->setDescription('Authenticate to a cloud client library using App Engine Standard credentials explicitly.') |
| 85 | + ->setHelp(<< |
| 86 | +The %command.name% command authenticates to a cloud client library |
| 87 | +using App Engine Standard credentials explicitly. |
| 88 | +
|
| 89 | + php %command.full_name% |
| 90 | +
|
| 91 | +EOF |
| 92 | + ) |
| 93 | + ->setCode(function ($input, $output) { |
| 94 | + auth_cloud_explicit_app_engine($input->getArgument('projectId')); |
| 95 | + }) |
| 96 | +); |
| 97 | + |
| 98 | +// Create auth-api-implicit Command. |
| 99 | +$application->add((new Command('auth-api-implicit')) |
| 100 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 101 | + ->setDescription('Authenticate to a cloud API using a service account implicitly.') |
| 102 | + ->setHelp(<< |
| 103 | +The %command.name% command authenticates to a cloud API using a |
| 104 | +service account implicitly. |
| 105 | +
|
| 106 | + php %command.full_name% |
| 107 | +
|
| 108 | +EOF |
| 109 | + ) |
| 110 | + ->setCode(function ($input, $output) { |
| 111 | + auth_api_implicit($input->getArgument('projectId')); |
| 112 | + }) |
| 113 | +); |
| 114 | + |
| 115 | +// Create auth-api-explicit Command. |
| 116 | +$application->add((new Command('auth-api-explicit')) |
| 117 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 118 | + ->addArgument('serviceAccountPath', InputArgument::REQUIRED, 'Path to your service account.') |
| 119 | + ->setDescription('Authenticate to a cloud API using a service account explicitly.') |
| 120 | + ->setHelp(<< |
| 121 | +The %command.name% command authenticates to a cloud API using a |
| 122 | +service account implicitly. |
| 123 | +
|
| 124 | + php %command.full_name% |
| 125 | +
|
| 126 | +EOF |
| 127 | + ) |
| 128 | + ->setCode(function ($input, $output) { |
| 129 | + $projectId = $input->getArgument('projectId'); |
| 130 | + $serviceAccountPath = $input->getArgument('serviceAccountPath'); |
| 131 | + auth_api_explicit($projectId, $serviceAccountPath); |
| 132 | + }) |
| 133 | +); |
| 134 | + |
| 135 | +// Create auth-api-explicit-compute-engine Command. |
| 136 | +$application->add((new Command('auth-api-explicit-compute-engine')) |
| 137 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 138 | + ->setDescription('Authenticate to a cloud API using Compute Engine credentials explicitly.') |
| 139 | + ->setHelp(<< |
| 140 | +The %command.name% command authenticates to a cloud API using |
| 141 | +Compute Engine credentials explicitly. |
| 142 | +
|
| 143 | + php %command.full_name% |
| 144 | +
|
| 145 | +EOF |
| 146 | + ) |
| 147 | + ->setCode(function ($input, $output) { |
| 148 | + $projectId = $input->getArgument('projectId'); |
| 149 | + auth_api_explicit_compute_engine($projectId); |
| 150 | + }) |
| 151 | +); |
| 152 | + |
| 153 | +// Create auth-api-explicit-app-engine Command. |
| 154 | +$application->add((new Command('auth-api-explicit-app-engine')) |
| 155 | + ->addArgument('projectId', InputArgument::REQUIRED, 'Your project ID') |
| 156 | + ->setDescription('Authenticate to a cloud API using App Engine Standard credentials explicitly.') |
| 157 | + ->setHelp(<< |
| 158 | +The %command.name% command authenticates to a cloud API using |
| 159 | +Compute Engine credentials explicitly. |
| 160 | +
|
| 161 | + php %command.full_name% |
| 162 | +
|
| 163 | +EOF |
| 164 | + ) |
| 165 | + ->setCode(function ($input, $output) { |
| 166 | + $projectId = $input->getArgument('projectId'); |
| 167 | + auth_api_explicit_compute_engine($projectId); |
| 168 | + }) |
| 169 | +); |
| 170 | + |
| 171 | +if (getenv('PHPUNIT_TESTS') === '1') { |
| 172 | + return $application; |
| 173 | +} |
| 174 | + |
| 175 | +$application->run(); |
0 commit comments