def get_credentials(args): """Select iTunes Connect login credentials depending on given command line arguments""" # for most commands an iTunes Connect access token is needed - fetched either from the command line or from Keychain... access_token = keychain.find_generic_password(None, args.access_token_keychain_item, '') if args.access_token_keychain_item else args.access_token # ...but commands for access token manipulation need the plaintext password of the iTunes Connect account password = keychain.find_generic_password(None, args.password_keychain_item, '') if args.password_keychain_item else args.password return (args.userid, access_token, password, str(args.account), args.mode)
def validate_arguments(args): """Do some additional checks on the passed arguments which argparse couldn't handle directly""" if sys.platform != 'darwin' and (args.password_keychain_item or args.access_token_keychain_item): raise ValueError("Error: Keychain support is limited to macOS") if args.access_token_keychain_item: try: keychain.find_generic_password(None, args.access_token_keychain_item, '') except: raise ValueError("Error: Could not find an item named '{0}' in the default Keychain".format(args.access_token_keychain_item)) if args.password_keychain_item: try: keychain.find_generic_password(None, args.password_keychain_item, '') except: raise ValueError("Error: Could not find an item named '{0}' in the default Keychain".format(args.password_keychain_item)) if not args.account and (args.command == 'getVendorsAndRegions' or args.command == 'getVendors' or args.command == 'getFinancialReport'): raise ValueError("Error: Argument -a/--account is needed for command '%s'" % args.command) if hasattr(args, 'fiscalyear'): try: datetime.datetime.strptime(args.fiscalyear, "%Y") except: raise ValueError("Error: Fiscal year must be specified as YYYY") if hasattr(args, 'fiscalperiod'): try: if int(args.fiscalperiod) < 1 or int(args.fiscalperiod) > 12: raise Exception except: raise ValueError("Error: Fiscal period must be a value between 1 and 12") if hasattr(args, 'datetype'): format = '%Y%m%d' error = "Date must be specified as YYYYMMDD for daily reports" if args.datetype == 'Weekly': error = "Date must be specified as YYYYMMDD for weekly reports, where the day used is the Sunday that week ends" if args.datetype == 'Monthly': error = "Date must be specified as YYYYMM for monthly reports" format = '%Y%m' if args.datetype == 'Yearly': error = "Date must be specified as YYYY for yearly reports" format = '%Y' try: datetime.datetime.strptime(args.date, format) except: raise ValueError("Error: " + error)
datetime.datetime.strptime(args.date, format) except: raise ValueError("Error: " + error) # main if __name__ == '__main__': args = parse_arguments() try: validate_arguments(args) except ValueError, e: print e exit(-1) password = keychain.find_generic_password(None, args.password_keychain_item, '') if args.password_keychain_item else args.password credentials = (args.userid, password, str(args.account), args.mode) try: if args.command == 'getStatus': get_status(credentials, args.service) elif args.command == 'getAccounts': get_accounts(credentials, args.service) elif args.command == 'getVendors': get_vendors(credentials) elif args.command == 'getVendorsAndRegions': get_vendor_and_regions(credentials) elif args.command == 'getSalesReport': get_sales_report(credentials, args.vendor, args.datetype, args.date) elif args.command == 'getFinancialReport':
datetime.datetime.strptime(args.date, format) except: raise ValueError("Error: " + error) # main if __name__ == '__main__': args = parse_arguments() try: validate_arguments(args) except ValueError, e: print e exit(-1) password = keychain.find_generic_password(None, args.password_keychain_item, '') if args.password_keychain_item else args.password access_token = keychain.find_generic_password(None, args.access_token_keychain_item, '') if args.access_token_keychain_item else args.access_token credentials = (args.userid, password, access_token, args.account, args.mode) try: if args.command == 'getStatus': get_status(credentials, args.service) elif args.command == 'getAccounts': get_accounts(credentials, args.service) elif args.command == 'getVendors': get_vendors(credentials) elif args.command == 'getVendorsAndRegions': get_vendor_and_regions(credentials) elif args.command == 'getSalesReport': get_sales_report(credentials, args.vendor, args.datetype, args.date)
raise ValueError("Error: " + error) # main if __name__ == '__main__': args = parse_arguments() try: validate_arguments(args) except ValueError, e: print e exit(-1) password = keychain.find_generic_password( None, args.password_keychain_item, '') if args.password_keychain_item else args.password credentials = (args.userid, password, str(args.account), args.mode) try: if args.command == 'getStatus': get_status(credentials, args.service) elif args.command == 'getAccounts': get_accounts(credentials, args.service) elif args.command == 'getVendors': get_vendors(credentials) elif args.command == 'getVendorsAndRegions': get_vendor_and_regions(credentials) elif args.command == 'getSalesReport': get_sales_report(credentials, args.vendor, args.datetype,