docs: def login(anchore_config, user, passfile):
      """
      Log into Anchore service using your username/password from anchore.io.
      """
      config = anchore_config
      ecode = 0
  
      try:
          anchore_creds_file = os.path.join(anchore_config.config_dir, 'anchore_creds.json')
          anchore_stored_username = None
          anchore_stored_password = None
          if os.path.exists(anchore_creds_file):
              try:
                  with open(anchore_creds_file, 'r') as FH:
                      anchore_stored_creds = json.loads(FH.read())
                      anchore_stored_username = anchore_stored_creds.pop('username', None)
                      anchore_stored_password = anchore_stored_creds.pop('password', None)
              except Exception as err:
                  raise err
  
          if user:
              anchore_print("Using user from cmdline option: " + str(user))
              username = user
          elif os.getenv('ANCHOREUSER'):
              anchore_print("Using user from environment (ANCHOREUSER)")
              username = os.getenv('ANCHOREUSER')
          elif anchore_stored_username:
              anchore_print("Using stored username from anchore_creds.json")
              username = anchore_stored_username
          else:
              username = raw_input("Username: ")
  
          if passfile:
              anchore_print("Using password from cmdline option: " + str(passfile))
              with open(passfile, "r") as FH:
                  password = FH.read().strip()
          elif os.getenv('ANCHOREPASS'):
              anchore_print("Using password from environment (ANCHOREPASS)")
              password = os.getenv('ANCHOREPASS')
          elif anchore_stored_password:
              anchore_print("Using stored password from anchore_creds.json")
              password = anchore_stored_password
          else:
              password = getpass.getpass("Password: ")
              
          aa = contexts['anchore_auth']
  
          new_anchore_auth = anchore_auth.anchore_auth_init(username, password, aa['auth_file'], aa['client_info_url'], aa['token_url'], aa['conn_timeout'], aa['max_retries'])
          rc, ret = anchore_auth.anchore_auth_refresh(new_anchore_auth)
          if not rc:
              anchore_print("Failed to log in: check your username/password and try again!")
              raise Exception("Login failure - message from server: " + str(ret['text']))
          else:
              contexts['anchore_auth'].update(new_anchore_auth)
              anchore_print("Login successful.")
  
      except Exception as err:
          anchore_print_err('operation failed')
          ecode = 1
  
      sys.exit(ecode)