Skip to content

Commit 6fe4488

Browse files
authored
Kms misc typos and adding functions (GoogleCloudPlatform#310)
1 parent 0ed567f commit 6fe4488

File tree

7 files changed

+402
-188
lines changed

7 files changed

+402
-188
lines changed

kms/api/src/KeyCommand.php

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -93,61 +93,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
9393
$projectId = $this->getProjectIdFromGcloud();
9494
}
9595
$keyRing = $input->getArgument('keyring');
96-
$key = $input->getArgument('cryptokey');
96+
$cryptoKey = $input->getArgument('cryptokey');
9797
$location = $input->getOption('location');
9898

99-
if ($key) {
99+
if ($cryptoKey) {
100100
if ($input->getOption('create')) {
101-
create_cryptokey($projectId, $keyRing, $key, $location);
101+
create_cryptokey($projectId, $keyRing, $cryptoKey, $location);
102102
} else {
103-
$cryptoKey = $this->getCryptoKey($projectId, $keyRing, $key, $location);
104-
$this->printCryptoKey($cryptoKey);
103+
get_cryptokey($projectId, $keyRing, $cryptoKey, $location);
105104
}
106105
} else {
107-
foreach ($this->getCryptoKeys($projectId, $keyRing, $location) as $cryptoKey) {
108-
$this->printCryptoKey($cryptoKey);
109-
print(PHP_EOL);
110-
}
106+
list_cryptokeys($projectId, $keyRing, $location);
111107
}
112108
}
113-
114-
private function getCryptoKey($projectId, $keyRing, $key, $location = 'global')
115-
{
116-
// The resource name of the cryptokey.
117-
$parent = sprintf('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s',
118-
$projectId,
119-
$location,
120-
$keyRing,
121-
$key
122-
);
123-
124-
// Get the crypto key.
125-
$kms = $this->getKmsClient();
126-
return $kms->projects_locations_keyRings_cryptoKeys->get($parent);
127-
}
128-
129-
private function getCryptoKeys($projectId, $keyRing, $location = 'global')
130-
{
131-
// The resource name of the cryptokey version.
132-
$parent = sprintf('projects/%s/locations/%s/keyRings/%s',
133-
$projectId,
134-
$location,
135-
$keyRing
136-
);
137-
138-
// Get the crypto key version.
139-
$kms = $this->getKmsClient();
140-
return $kms->projects_locations_keyRings_cryptoKeys
141-
->listProjectsLocationsKeyRingsCryptoKeys($parent);
142-
}
143-
144-
private function printCryptoKey($cryptoKey)
145-
{
146-
// print the crypto key
147-
printf('Name: %s' . PHP_EOL, $cryptoKey->getName());
148-
printf('Create Time: %s' . PHP_EOL, $cryptoKey->getCreateTime());
149-
printf('Purpose: %s' . PHP_EOL, $cryptoKey->getPurpose());
150-
printf('Primary Version: %s' . PHP_EOL, $cryptoKey->getPrimary()->getName());
151-
printf('Rotation Period: %s' . PHP_EOL, $cryptoKey->getRotationPeriod());
152-
}
153109
}

kms/api/src/KeyRingCommand.php

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,49 +93,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9393
if ($input->getOption('create')) {
9494
create_keyring($projectId, $ring, $location);
9595
} else {
96-
$keyRing = $this->getKeyRing($projectId, $ring, $location);
97-
$this->printKeyRing($keyRing);
96+
get_keyring($projectId, $ring, $location);
9897
}
9998
} else {
100-
foreach ($this->getKeyRings($projectId, $location) as $keyRing) {
101-
$this->printKeyRing($keyRing);
102-
print(PHP_EOL);
103-
}
99+
list_keyrings($projectId, $location);
104100
}
105101
}
106-
107-
private function getKeyRing($projectId, $keyRing, $location = 'global')
108-
{
109-
// The resource name of the keyring.
110-
$parent = sprintf('projects/%s/locations/%s/keyRings/%s',
111-
$projectId,
112-
$location,
113-
$keyRing
114-
);
115-
116-
// Get the key ring.
117-
$kms = $this->getKmsClient();
118-
return $kms->projects_locations_keyRings->get($parent);
119-
}
120-
121-
private function getKeyRings($projectId, $location = 'global')
122-
{
123-
// The resource name of the cryptokey version.
124-
$parent = sprintf('projects/%s/locations/%s',
125-
$projectId,
126-
$location
127-
);
128-
129-
// Get the crypto key version.
130-
$kms = $this->getKmsClient();
131-
return $kms->projects_locations_keyRings
132-
->listProjectsLocationsKeyRings($parent);
133-
}
134-
135-
private function printKeyRing($keyRing)
136-
{
137-
// print the key ring.
138-
printf('Name: %s' . PHP_EOL, $keyRing->getName());
139-
printf('Create time: %s' . PHP_EOL, $keyRing->getCreateTime());
140-
}
141102
}

kms/api/src/VersionCommand.php

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -145,56 +145,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
145145
} elseif ($input->getOption('set-primary')) {
146146
set_cryptokey_primary_version($projectId, $keyRing, $cryptoKey, $cryptoKeyVersion, $location);
147147
} else {
148-
$version = $this->getCryptoKeyVersion($projectId, $keyRing, $cryptoKey, $cryptoKeyVersion, $location);
149-
$this->printCryptoKeyVersion($version);
148+
get_cryptokey_version($projectId, $keyRing, $cryptoKey, $cryptoKeyVersion, $location);
150149
}
151150
} else {
152-
foreach ($this->getCryptoKeyVersions($projectId, $keyRing, $cryptoKey, $location) as $version) {
153-
$this->printCryptoKeyVersion($version);
154-
print(PHP_EOL);
155-
}
151+
list_cryptokey_versions($projectId, $keyRing, $cryptoKey, $location);
156152
}
157153
}
158-
159-
private function getCryptoKeyVersion($projectId, $keyRing, $cryptoKey, $cryptoKeyVersion, $location = 'global')
160-
{
161-
// The resource name of the cryptokey version.
162-
$parent = sprintf('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s',
163-
$projectId,
164-
$location,
165-
$keyRing,
166-
$cryptoKey,
167-
$cryptoKeyVersion
168-
);
169-
170-
// Get the crypto key version.
171-
$kms = $this->getKmsClient();
172-
return $kms->projects_locations_keyRings_cryptoKeys_cryptoKeyVersions->get($parent);
173-
}
174-
175-
private function getCryptoKeyVersions($projectId, $keyRing, $cryptoKey, $location = 'global')
176-
{
177-
// The resource name of the cryptokey version.
178-
$parent = sprintf('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s',
179-
$projectId,
180-
$location,
181-
$keyRing,
182-
$cryptoKey
183-
);
184-
185-
// Get the crypto key version.
186-
$kms = $this->getKmsClient();
187-
return $kms->projects_locations_keyRings_cryptoKeys_cryptoKeyVersions
188-
->listProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersions($parent);
189-
}
190-
191-
private function printCryptoKeyVersion($cryptoKeyVersion)
192-
{
193-
// print the crypto key version
194-
printf('Name: %s' . PHP_EOL, $cryptoKeyVersion->getName());
195-
printf('Create Time: %s' . PHP_EOL, $cryptoKeyVersion->getCreateTime());
196-
printf('State: %s' . PHP_EOL, $cryptoKeyVersion->getState());
197-
printf('Destroy Event Time: %s' . PHP_EOL, $cryptoKeyVersion->getDestroyEventTime());
198-
printf('Destroy Time: %s' . PHP_EOL, $cryptoKeyVersion->getDestroyEventTime());
199-
}
200154
}

0 commit comments

Comments
 (0)