11from cf_remote .paths import CLOUD_CONFIG_FPATH , CLOUD_STATE_FPATH
2- from cf_remote .utils import read_json , CFRUserError , is_package_url
2+ from cf_remote .utils import read_json , is_package_url
33from cf_remote .spawn import (
44 Providers ,
55 get_cloud_driver ,
1010from cf_remote .cloud_data import aws_image_criteria
1111from cf_remote .remote import Releases
1212
13+ from cfengine_cli .utils import UserError
14+
1315import os
1416import subprocess
1517
@@ -22,15 +24,15 @@ def validate_state_bootstrap(bootstrap):
2224
2325 # TODO: Change how to check this if cloud_state.json changes format
2426 if key in state and state [key ].values ()[1 ]["role" ] != "hub" :
25- raise CFRUserError ("Cannot bootstrap to an existing host that is not a hub" )
27+ raise UserError ("Cannot bootstrap to an existing host that is not a hub" )
2628
2729
2830def validate_package (package , remote_download = False ):
2931 if package is None :
3032 return
3133
3234 if remote_download and not is_package_url (package ):
33- raise CFRUserError ("Package '{}' is not a valid package URL" )
35+ raise UserError ("Package '{}' is not a valid package URL" )
3436
3537
3638def validate_version (version , edition ):
@@ -39,7 +41,7 @@ def validate_version(version, edition):
3941 if version :
4042 release = releases .pick_version (version )
4143 if release is None :
42- raise CFRUserError (
44+ raise UserError (
4345 "Could not find a release for version {}. The supported versions are {}" .format (
4446 version , releases
4547 )
@@ -55,13 +57,13 @@ def validate_vagrant_box(box):
5557 ]
5658
5759 if box not in box_list :
58- raise CFRUserError ("Box '{}' is not installed or doesn't exist" .format (box ))
60+ raise UserError ("Box '{}' is not installed or doesn't exist" .format (box ))
5961
6062
6163def validate_aws_image (platform ):
6264 platform_name = platform .split ("-" )[0 ]
6365 if platform_name not in aws_image_criteria :
64- raise CFRUserError (
66+ raise UserError (
6567 "Platform '%s' is not in our set of image criteria. (Available platforms: %s)"
6668 % (platform , ", " .join (aws_image_criteria .keys ()))
6769 )
@@ -83,7 +85,7 @@ def validate_aws_credentials():
8385 creds_data = read_json (CLOUD_CONFIG_FPATH )
8486
8587 if not creds_data :
86- raise CFRUserError ("Cloud configuration not found at %s" % CLOUD_CONFIG_FPATH )
88+ raise UserError ("Cloud configuration not found at %s" % CLOUD_CONFIG_FPATH )
8789 creds = None
8890 try :
8991 creds = _get_aws_creds_from_env () or AWSCredentials (
@@ -92,9 +94,7 @@ def validate_aws_credentials():
9294 creds_data ["aws" ].get ("token" , "" ),
9395 )
9496 except KeyError :
95- raise CFRUserError (
96- "Incomplete AWS credential info"
97- ) # TODO: report missing keys
97+ raise UserError ("Incomplete AWS credential info" ) # TODO: report missing keys
9898
9999 region = creds_data ["aws" ].get ("region" , "eu-west-1" )
100100 sec_groups = creds_data ["aws" ]["security_groups" ]
@@ -104,7 +104,7 @@ def validate_aws_credentials():
104104 try :
105105 get_cloud_driver (Providers .AWS , creds , region )
106106 except InvalidCredsError as error :
107- raise CFRUserError (
107+ raise UserError (
108108 "Invalid credentials, check cloud_config.json (%s.)" % str (error )[1 :- 1 ]
109109 )
110110 return creds , region , sec_groups , key_pair
@@ -116,17 +116,15 @@ def validate_gcp_credentials():
116116 creds_data = read_json (CLOUD_CONFIG_FPATH )
117117
118118 if not creds_data :
119- raise CFRUserError ("Cloud configuration not found at %s" % CLOUD_CONFIG_FPATH )
119+ raise UserError ("Cloud configuration not found at %s" % CLOUD_CONFIG_FPATH )
120120 try :
121121 creds = GCPCredentials (
122122 creds_data ["gcp" ]["project_id" ],
123123 creds_data ["gcp" ]["service_account_id" ],
124124 creds_data ["gcp" ]["key_path" ],
125125 )
126126 except KeyError :
127- raise CFRUserError (
128- "Incomplete AWS credential info"
129- ) # TODO: report missing keys
127+ raise UserError ("Incomplete AWS credential info" ) # TODO: report missing keys
130128
131129 region = creds_data ["gcp" ].get ("region" , "europe-west1-b" )
132130
0 commit comments