Skip to content

Commit

Permalink
Merge pull request #571 from tcmitchell/537-EXPIRED
Browse files Browse the repository at this point in the history
Fix spelling of EXPIRED
  • Loading branch information
tcmitchell authored Jun 15, 2017
2 parents e0e52e6 + 36468dd commit 82e5d64
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 81 deletions.
43 changes: 26 additions & 17 deletions bin/geni-list-member-projects
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- Mode: python -*-
#
#----------------------------------------------------------------------
# Copyright (c) 2013-2016 Raytheon BBN Technologies
# ----------------------------------------------------------------------
# Copyright (c) 2013-2017 Raytheon BBN Technologies
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
Expand All @@ -22,48 +22,52 @@
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
#----------------------------------------------------------------------
# ----------------------------------------------------------------------

#----------------------------------------------------------------------
# ----------------------------------------------------------------------
#
# Disable the given user so they can do no operations
# Lists a user's projects.
#
# Communicates with a GENI Member Authority via its public API
# Communicates with a GENI Member Authority and a GENI Slice Authority
# via their public APIs
#
#----------------------------------------------------------------------
# ----------------------------------------------------------------------

import sys
import optparse
from urlparse import urlparse
from chapiclient import chapi


def parse_args(argv):
parser = optparse.OptionParser(usage="List projects for the given user")
parser.add_option("-k", "--keyfile", metavar="FILE",
help="Invoker's private key")
parser.add_option("-c", "--certfile", metavar="FILE",
help="Invoker's GENI certificate")
parser.add_option("-u", "--url",
help="base authority URL (https://chSOMETHING)")
help="base authority URL (https://chSOMETHING)")
parser.add_option("-m", "--member", help="member id (a UUID or username)")
parser.add_option("-e", "--expired", action="store_true", default=False,
help="Show expired projects")
options,args = parser.parse_args()
options, args = parser.parse_args()
if not (options.keyfile and options.certfile and options.url
and options.member):
parser.print_usage()
raise Exception("Missing some required arguments")
return options,args
return options, args


def verify_url(url):
parsed = urlparse(url)
if (parsed.scheme in ('http', 'https')
and parsed.netloc
and parsed.path):
and parsed.netloc
and parsed.path):
return parsed.geturl()
else:
raise Exception("Invalid url %r" % (url))


def load_cert(certfile):
f = open(certfile)
cert = f.read()
Expand All @@ -72,6 +76,7 @@ def load_cert(certfile):
# Or will that be taken care of downstream, by the ch_interface?
return cert


def load_private_key(certfile):
f = open(certfile)
key = f.read()
Expand All @@ -80,18 +85,20 @@ def load_private_key(certfile):
# Or will that be taken care of downstream, by the ch_interface?
return key


def project_name_from_urn(urn):
plus_pos = urn.rfind('+')
if plus_pos == -1:
return urn
else:
return urn[plus_pos+1:]


def main(argv=None):
if argv is None:
argv = sys.argv
try:
options,args = parse_args(argv)
options, args = parse_args(argv)
ma_url = verify_url(chapi.service_url(options.url, 'MA'))
sa_url = verify_url(chapi.service_url(options.url, 'SA'))
cert = load_cert(options.certfile)
Expand All @@ -110,19 +117,20 @@ def main(argv=None):
opts = dict()
result = proxy.lookup_projects_for_member(member_urn, credentials, opts)

if not 'code' in result:
if 'code' not in result:
raise Exception("Could not list projects for user %s. Result: %s" %
(options.member, result))
status = result['code']
if not status == 0:
if result.has_key('output'):
if 'output' in result:
raise Exception("Could not list projects for user %s. Error %d: %s"
% (options.member, status, result['output']))
else:
raise Exception("Could not disable user %s" % (options.member))
raise Exception("Could not list projects for user %s" %
(options.member))
projects = result['value']
for project in projects:
project_expired = project['EXPIRED']
project_expired = project['PROJECT_EXPIRED']
if project_expired and not options.expired:
continue
project_urn = project['PROJECT_URN']
Expand All @@ -134,5 +142,6 @@ def main(argv=None):
print '%s\t%s%s' % (project_role, project_name, annotation)
return 0


if __name__ == "__main__":
sys.exit(main())
4 changes: 2 additions & 2 deletions test/travis-build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# Limits as of June 14, 2017
ERROR_LIMIT=2776
# Limits as of June 15, 2017
ERROR_LIMIT=2707
WARNING_LIMIT=46

RESULT=0
Expand Down
Loading

0 comments on commit 82e5d64

Please sign in to comment.