Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preconditions Script Checks Billing Account Format #117

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import argparse
import json
import logging
import re
import sys
import os

Expand Down Expand Up @@ -301,6 +302,13 @@ def validate(self, credentials):

return req.asdict()

@classmethod
def argument_type(cls, string, pat=re.compile(r"[A-Z0-9]{6}-[A-Z0-9]{6}-[A-Z0-9]{6}")):
if not pat.match(string):
msg = "%r is not a valid billing account ID format" % string
raise argparse.ArgumentTypeError(msg)
return string


def setup():
logging.basicConfig()
Expand Down Expand Up @@ -347,7 +355,8 @@ def argparser():
)
parser.add_argument(
'--billing_account', required=True,
help='The billing account to be associated with a new project'
help='The billing account to be associated with a new project',
type=BillingAccount.argument_type
)
parser.add_argument(
'--org_id', required=True, action=EmptyStrAction,
Expand Down Expand Up @@ -411,8 +420,7 @@ def main(argv):
retcode = 1

if retcode == 1 or opts.verbose:
s = json.dumps(results, sys.stdout, indent=4)
print(s)
json.dump(results, sys.stdout, indent=4)
except FileNotFoundError as error:
print(error)
retcode = 1
Expand Down