Skip to content

Commit

Permalink
Merge pull request #489 from cdonati/fix-warning
Browse files Browse the repository at this point in the history
Only warn the user once about using service creds
  • Loading branch information
menivaitsi committed Feb 24, 2016
2 parents 0d0fa44 + 9cdb586 commit e330b13
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/agents/gce_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@

try:
from appscale.appscale_logger import AppScaleLogger
from appscale.custom_exceptions import AppScaleException
from appscale.local_state import LocalState
except ImportError:
# If the module is not installed, the lib directory might be on the path.
from appscale_logger import AppScaleLogger
from custom_exceptions import AppScaleException
from local_state import LocalState


Expand Down Expand Up @@ -118,6 +116,9 @@ class GCEAgent(BaseAgent):
PARAM_STORAGE = 'oauth2_storage'


PARAM_TEST = 'test'


PARAM_VERBOSE = 'is_verbose'


Expand Down Expand Up @@ -545,7 +546,8 @@ def get_params_from_args(self, args):
self.PARAM_KEYNAME : args['keyname'],
self.PARAM_PROJECT : args['project'],
self.PARAM_STATIC_IP : args.get(self.PARAM_STATIC_IP),
self.PARAM_ZONE : args['zone']
self.PARAM_ZONE : args['zone'],
self.PARAM_TEST: args['test'],
}

# A zone in GCE looks like 'us-central2-a', which is in the region
Expand Down Expand Up @@ -624,6 +626,17 @@ def assert_required_parameters(self, parameters, _):
raise AgentConfigurationException('Could not find your credentials ' \
'file at {0}'.format(credentials_file))

# TODO: Remove this warning once service accounts have been fully tested.
secrets_location = os.path.expanduser(parameters[self.PARAM_SECRETS])
secrets_type = GCEAgent.get_secrets_type(secrets_location)
if (secrets_type == CredentialTypes.SERVICE and
not parameters[self.PARAM_TEST]):
response = raw_input('It looks like you are using service account '
'credentials, which are not currently supported for cloud '
'autoscaling.\nWould you like to continue? (y/N)')
if response.lower() not in ['y', 'yes']:
raise AgentConfigurationException('User cancelled starting AppScale.')


def describe_instances(self, parameters, pending=False):
""" Queries Google Compute Engine to see which instances are currently
Expand Down Expand Up @@ -1122,11 +1135,6 @@ def open_connection(self, parameters):
secrets_location = os.path.expanduser(parameters[self.PARAM_SECRETS])
secrets_type = GCEAgent.get_secrets_type(secrets_location)
if secrets_type == CredentialTypes.SERVICE:
response = raw_input('It looks like you are using service account '
'credentials, which are not currently supported for cloud '
'autoscaling.\nWould you like to continue? (y/N)')
if response.lower() not in ['y', 'yes']:
raise AppScaleException('User cancelled starting AppScale.')
scopes = [GCPScopes.COMPUTE]
credentials = ServiceAccountCredentials\
.from_json_keyfile_name(secrets_location, scopes=scopes)
Expand Down

0 comments on commit e330b13

Please sign in to comment.