def configure(username, password): """ Configure the user and password of the GitHub user. :param username: new configuration GitHub user name :param password: new configuration GitHub user password """ configurer = GistsConfigurer() configurer.setConfigUser(username) configurer.setConfigPassword(password) return
def authorize(facade): """ Configure the user and password of the GitHub user. :param facade: The Github interface """ # check if there is already an authorization for the app response = facade.list_authorizations() if response.ok: for auth in get_json(response): authorization = model.Authorization(auth) if authorization.note == literals.APP_NAME: # write the token to the configuration file configurer = GistsConfigurer() configurer.setConfigUser(facade.username) configurer.setConfigToken(authorization.token) return build_result(True, authorization) else: return build_result(False, literals.AUTHORIZE_NOK, get_json(response)['message']) # build the authorization request auth = model.Authorization() auth.note = literals.APP_NAME auth.note_url = literals.APP_URL auth.scopes = ["gist"] response = facade.authorize(auth) if response.ok: auth = model.Authorization(get_json(response)) result = build_result(True, auth) # write the token to the configuration file configurer = GistsConfigurer() configurer.setConfigUser(facade.username) configurer.setConfigToken(auth.token) else: result = build_result(False, literals.AUTHORIZE_NOK, get_json(response)['message']) return result