Skip to content

Commit

Permalink
Use uniqid() to generate randomName for buckets (#208)
Browse files Browse the repository at this point in the history
This will reduce the possibility of bucket names being same across mint
runs on the same (object storage) endpoint.
  • Loading branch information
krisis authored and nitisht committed Oct 27, 2017
1 parent 12ed244 commit 27ac639
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions run/core/aws-sdk-php/quick-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,13 @@ function __construct(string $access_key, string $secret_key, string $host, strin
}

/**
* randomName returns a string of random characters picked from 0-9,a-z.
* randomName returns a name prefixed by aws-sdk-php using uniqid()
* from standard library
*
* By default it returns a random name of length 5.
*
* @param int $length - length of random name.
*
* @return void
* @return string
*/
function randomName(int $length=5):string {
$alphabet = array_rand(str_split('0123456789abcdefghijklmnopqrstuvwxyz'), 26);
$alphaLen = count($alphabet);
$rounds = floor($length / $alphaLen);
$remaining = $length % $alphaLen;
$bigalphabet = [];
for ($i = 0; $i < $rounds; $i++) {
$bigalphabet = array_merge($bigalphabet, $alphabet);
}
$bigalphabet = array_merge($bigalphabet, array_slice($alphabet, 0, $remaining));
$alphabet_soup = array_flip($bigalphabet);
shuffle($alphabet_soup);
return 'aws-sdk-php-bucket-' . join($alphabet_soup);
function randomName():string {
return uniqid("aws-sdk-php-");
}

/**
Expand Down

0 comments on commit 27ac639

Please sign in to comment.