-import logging
-from cliff.command import Command
+from testapiclient import command
from testapiclient import identity
-class Auth(Command):
+class Auth(command.Command):
"Handle Authentication for users"
- log = logging.getLogger(__name__)
-
def get_parser(self, prog_name):
parser = super(Auth, self).get_parser(prog_name)
- parser.add_argument('-u',
- type=str,
- required=True,
- help='Username for authentication')
- parser.add_argument('-p',
- type=str,
- required=True,
- help='Password for authentication')
return parser
+ @identity.authenticate
def take_action(self, parsed_args):
- response = identity.authenticate(parsed_args.u, parsed_args.p)
- if "login" in response.text:
- print "Authentication has failed."
- else:
- print "Authentication has been successful!"
+ print "Authentication has been successful!"
from cliff import command
-# from testapiclient import identity
class Command(command.Command):
from user import User
from config import Config
import urllib
+import functools
-def authenticate(username, password):
+def _authenticate(username, password):
session = requests.Session()
hostname = '{}{}{}'.format(
Config.config.get("cas", "auth_url"),
response = session.post(hostname, data)
User.session = session
return response
+
+
+def authenticate(xstep):
+ @functools.wraps(xstep)
+ def wrapper(self, parsed_args):
+ username = parsed_args.u
+ password = parsed_args.p
+ if(username and password):
+ response = _authenticate(username, password)
+ if "login" in response.text:
+ print "Authentication has failed."
+ else:
+ xstep(self, parsed_args)
+ return wrapper
'mode should be either "metal" or "virtual.')
return parser
+ @identity.authenticate
def take_action(self, parsed_args):
http_client = HTTPClient.get_Instance()
- if(parsed_args.u and parsed_args.p):
- response = identity.authenticate(parsed_args.u, parsed_args.p)
- if "login" in response.text:
- print "Authentication has failed."
- return
response = http_client.post(PODS_URL,
User.session,
parsed_args.pod)
help='Delete pods using name')
return parser
+ @identity.authenticate
def take_action(self, parsed_args):
http_client = HTTPClient.get_Instance()
- if(parsed_args.u and parsed_args.p):
- response = identity.authenticate(parsed_args.u, parsed_args.p)
- if "login" in response.text:
- print "Authentication has failed."
- return
- pods = http_client.delete(PODS_URL + "/" + parsed_args.name,
- User.session)
- print pods
+ print http_client.delete(PODS_URL + "/" + parsed_args.name,
+ User.session)
import json
-from user import User
+
from testapiclient import command
-from httpClient import HTTPClient
from testapiclient import identity
-from config import Config
+from config import Config
+from httpClient import HTTPClient
+from user import User
PROJECTS_URL = Config.config.get("api", "url") + "/projects"
'"description": (optional)""}')
return parser
+ @identity.authenticate
def take_action(self, parsed_args):
httpClient = HTTPClient.get_Instance()
- if(parsed_args.u and parsed_args.p):
- response = identity.authenticate(parsed_args.u, parsed_args.p)
- if "login" in response.text:
- print "Authentication has failed."
- return
response = httpClient.post(ProjectCreate.projects_url,
User.session,
parsed_args.project)
help='Delete project by name')
return parser
+ @identity.authenticate
def take_action(self, parsed_args):
httpClient = HTTPClient.get_Instance()
- if(parsed_args.u and parsed_args.p):
- response = identity.authenticate(parsed_args.u, parsed_args.p)
- if "login" in response.text:
- print "Authentication has failed."
- return
projects = httpClient.delete(
PROJECTS_URL + "/" + parsed_args.name,
User.session)
'"description": (optional)""}')
return parser
+ @identity.authenticate
def take_action(self, parsed_args):
httpClient = HTTPClient.get_Instance()
- if(parsed_args.u and parsed_args.p):
- response = identity.authenticate(parsed_args.u, parsed_args.p)
- if "login" in response.text:
- print "Authentication has failed."
- return
projects = httpClient.put(
PROJECTS_URL + "/" + parsed_args.name,
User.session,