Пример #1
0
def acquire_session(settings = None):
    if settings is not None and "token" in settings and "user_id" in settings:
        session = Session(token = settings["token"], user_id = settings["user_id"])
        resp = session.get(config.baas_host + "/v2/auth/verify")
        if resp.status_code == 200:
            return session
        elif resp.status_code == 401:
            output.write("Session has timed out. Please re-enter credentials.")
    username = os.getenv("CATALYZE_USERNAME") or config.username
    if username is None:
        username = raw_input("Username: "******"username" not in config.behavior else config.behavior["username"]
    password = os.getenv("CATALYZE_PASSWORD") or config.password
    if password is None:
        password = getpass.getpass("Password: "******"token"] = session.token
        settings["user_id"] = session.user_id
        project.save_settings(settings)
    return session
Пример #2
0
def associate(env_label, service_label, remote):
    """Associates the git repository in the current directory. This means that the service and environment IDs are stored locally, and a git remote is created (default name = "catalyze") so that code can be pushed, built, and deployed."""
    session = client.acquire_session()
    for env in environments.list(session):
        if env["data"]["name"] == env_label:
            settings = {
                    "token": session.token,
                    "user_id": session.user_id,
                    "environmentId": env["environmentId"]
                }
            code_services = [svc for svc in services.list(session, env["environmentId"]) if svc["type"] == "code"]
            selected_service = None
            if len(code_services) == 0:
                output.error("No code service found for \"%s\" environment (%s)" % (env_label, env["environmentId"]))
            elif service_label:
                for svc in code_services:
                    if svc["label"] == service_label:
                        selected_service = svc
                        break
                if selected_service is None:
                    output.error("No code service found with label '%s'. Labels found: %s" % \
                            (service_label, ", ".join([svc["label"] for svc in code_services])))
            elif len(code_services) > 1:
                output.error("Found multiple code services. Must pass one specifically to associate with. Labels found: " + \
                        ", ".join([svc["label"] for svc in code_services]))
            else:
                selected_service = code_services[0]

            if remote in git.remote_list():
                git.remote_remove(remote)
            git.remote_add(remote, selected_service["source"])
            settings["serviceId"] = selected_service["id"]
            project.save_settings(settings)
            output.write("\"%s\" remote added." % (remote,))
            return
    output.error("No environment with label \"%s\" found." % (env_label,))