def clientConnectionMade(self, broker):
        if self.sslContextFactory and not self.sslContextFactory.certificate_verified:
            self.remote_client.log.error(
                "A remote cloud could not prove that its security certificate is "
                "from {host}. This may cause a misconfiguration or an attacker "
                "intercepting your connection.",
                host=self.sslContextFactory.host,
            )
            return self.remote_client.disconnect()
        pb.PBClientFactory.clientConnectionMade(self, broker)
        protocol.ReconnectingClientFactory.resetDelay(self)
        self.remote_client.log.info("Successfully connected")
        self.remote_client.log.info("Authenticating")

        auth_token = None
        try:
            auth_token = AccountClient().fetch_authentication_token()
        except Exception as e:  # pylint:disable=broad-except
            d = defer.Deferred()
            d.addErrback(self.clientAuthorizationFailed)
            d.errback(pb.Error(e))
            return d

        d = self.login(
            credentials.UsernamePassword(
                auth_token.encode(),
                get_host_id().encode(),
            ),
            client=self.remote_client,
        )
        d.addCallback(self.remote_client.cb_client_authorization_made)
        d.addErrback(self.clientAuthorizationFailed)
        return d
Beispiel #2
0
def account_register(username, email, password, firstname, lastname):
    client = AccountClient()
    client.registration(username, email, password, firstname, lastname)
    return click.secho(
        "An account has been successfully created. "
        "Please check your mail to activate your account and verify your email address.",
        fg="green",
    )
Beispiel #3
0
def account_forgot(username):
    client = AccountClient()
    client.forgot_password(username)
    return click.secho(
        "If this account is registered, we will send the "
        "further instructions to your email.",
        fg="green",
    )
Beispiel #4
0
def account_token(password, regenerate, json_output):
    client = AccountClient()
    auth_token = client.auth_token(password, regenerate)
    if json_output:
        return click.echo(
            json.dumps({
                "status": "success",
                "result": auth_token
            }))
    return click.secho("Personal Authentication Token: %s" % auth_token,
                       fg="green")
Beispiel #5
0
def account_show(offline, json_output):
    client = AccountClient()
    info = client.get_account_info(offline)
    if json_output:
        return click.echo(json.dumps(info))
    click.echo()
    if info.get("profile"):
        print_profile(info["profile"])
    if info.get("packages"):
        print_packages(info["packages"])
    if info.get("subscriptions"):
        print_subscriptions(info["subscriptions"])
    return click.echo()
Beispiel #6
0
 def call_client(method, *args, **kwargs):
     try:
         client = AccountClient()
         return getattr(client, method)(*args, **kwargs)
     except Exception as e:  # pylint: disable=bare-except
         raise jsonrpc.exceptions.JSONRPCDispatchException(
             code=4003, message="PIO Account Call Error", data=str(e))
Beispiel #7
0
def account_update(current_password, **kwargs):
    client = AccountClient()
    profile = client.get_profile()
    new_profile = profile.copy()
    if not any(kwargs.values()):
        for field in profile:
            new_profile[field] = click.prompt(
                field.replace("_", " ").capitalize(), default=profile[field]
            )
            if field == "email":
                validate_email(new_profile[field])
            if field == "username":
                validate_username(new_profile[field])
    else:
        new_profile.update({key: value for key, value in kwargs.items() if value})
    client.update_profile(new_profile, current_password)
    click.secho("Profile successfully updated!", fg="green")
    username_changed = new_profile["username"] != profile["username"]
    email_changed = new_profile["email"] != profile["email"]
    if not username_changed and not email_changed:
        return None
    try:
        client.logout()
    except exception.AccountNotAuthorized:
        pass
    if email_changed:
        return click.secho(
            "Please check your mail to verify your new email address and re-login. ",
            fg="yellow",
        )
    return click.secho("Please re-login.", fg="yellow")
Beispiel #8
0
def account_login(username, password):
    client = AccountClient()
    client.login(username, password)
    return click.secho("Successfully logged in!", fg="green")
Beispiel #9
0
def account_password(old_password, new_password):
    client = AccountClient()
    client.change_password(old_password, new_password)
    return click.secho("Password successfully changed!", fg="green")
Beispiel #10
0
def account_logout():
    client = AccountClient()
    client.logout()
    return click.secho("Successfully logged out!", fg="green")
 def clientAuthorizationFailed(self, err):
     AccountClient.delete_local_session()
     self.remote_client.cb_client_authorization_failed(err)