|
| 1 | +import argparse |
| 2 | +from COMPS import Client |
| 3 | +from COMPS.CredentialPrompt import CredentialPrompt |
| 4 | + |
| 5 | + |
| 6 | +class StaticCredentialPrompt(CredentialPrompt): |
| 7 | + def __init__(self, comps_url, username, password): |
| 8 | + if (comps_url is None) or (username is None) or (password is None): |
| 9 | + print("Usage: python create_auth_token_args.py --comps_url url --username username --password pwd") |
| 10 | + print("\n") |
| 11 | + raise RuntimeError('Missing comps_url, or username or password') |
| 12 | + self._times_prompted = 0 |
| 13 | + self.comps_url = comps_url |
| 14 | + self.username = username |
| 15 | + self.password = password |
| 16 | + |
| 17 | + def prompt(self): |
| 18 | + print("logging in with hardcoded user/pw") |
| 19 | + self._times_prompted = self._times_prompted + 1 |
| 20 | + if self._times_prompted > 3: |
| 21 | + raise RuntimeError('Failure authenticating') |
| 22 | + print("Hit here") |
| 23 | + return {'Username': self.username, 'Password': self.password} |
| 24 | + |
| 25 | + |
| 26 | +if __name__ == '__main__': |
| 27 | + parser = argparse.ArgumentParser() |
| 28 | + |
| 29 | + parser.add_argument('--comps_url', default='https://comps2.idmod.org', help='comps url') |
| 30 | + parser.add_argument('--username', help='enter username') |
| 31 | + parser.add_argument('--password', help='enter password') |
| 32 | + |
| 33 | + args = parser.parse_args() |
| 34 | + |
| 35 | + compshost = args.comps_url |
| 36 | + |
| 37 | + Client.login(compshost, StaticCredentialPrompt(comps_url=args.comps_url, username=args.username, password=args.password)) |
0 commit comments