couchbase-partners / google-deployment-manager-couchbase

Google Deployment Manager (DM) templates for Couchbase Enterprise
Apache License 2.0
11 stars 9 forks source link

Update truncation to help with name collisions #24

Closed deci-ftw closed 7 years ago

deci-ftw commented 7 years ago

Update references to context.env['deployment']

The changes in this PR take the deployment name, split the string on hyphens, takes the last 2 elements of the list from the split, joins them back into a string with hyphens separating them, and then truncates that to hold the last 20 chars.

Example:

deps = [
        'couchbase-enterprise-edition-byol-1',
        'couchbase-enterprise-edition-hourly-pricing-1',
        'kinda-normal-name-with-hyphens',
        'longdeploymentnamewithoutspacesjustbecause',
        'this-is-really-long-with-dashes-and-stuff-to-break-but-not-today'
       ]

for i in range(0,5):
  print 'Deployment is: ' + deps[i]
  print 'Shortened : ' + '-'.join(deps[i].split('-')[-2:])[-20:]

Will give

Deployment is: couchbase-enterprise-edition-byol-1
Shortened : byol-1
Deployment is: couchbase-enterprise-edition-hourly-pricing-1
Shortened : pricing-1
Deployment is: kinda-normal-name-with-hyphens
Shortened : with-hyphens
Deployment is: longdeploymentnamewithoutspacesjustbecause
Shortened : outspacesjustbecause
Deployment is: this-is-really-long-with-dashes-and-stuff-to-break-but-not-today
Shortened : not-today

keepend

longnodash

benofben commented 7 years ago

That is a ridiculously well put together PR. Thanks!