示例#1
0
 def gateway_start(self):
     deployer.chatflow_pools_check()
     self.solution_id = uuid.uuid4().hex
     self.solution_metadata = {}
     self.gateway, pool = deployer.select_gateway(bot=self)
     self.pool_id = pool.pool_id
     self.gateway_id = self.gateway.node_id
示例#2
0
    def domain_selection(self):
        # {"domain": {"gateway": gw, "pool": p}}

        gateways = deployer.list_all_gateways()
        if not gateways:
            raise StopChatFlow(
                "There are no available gateways in the farms bound to your pools"
            )

        # add managed domains
        gateway_id_dict = {}
        pool_id_dict = {}
        messages = {}
        for gw_dict in gateways.values():
            gateway_id_dict[gw_dict["gateway"].node_id] = gw_dict["gateway"]
            pool_id_dict[gw_dict["pool"].pool_id] = gw_dict["pool"]
            for dom in gw_dict["gateway"].managed_domains:
                location_list = [
                    gw_dict["gateway"].location.continent,
                    gw_dict["gateway"].location.country,
                    gw_dict["gateway"].location.city,
                ]
                location = " - ".join([
                    info for info in location_list
                    if info and info != "Unknown"
                ])
                if location:
                    location = f" Location: {location}"
                messages[f"Managed {dom}{location}"] = gw_dict

        # add delegate domains
        delegated_domains = solutions.list_delegated_domain_solutions()
        for dom in delegated_domains:
            if dom["Pool"] not in pool_id_dict:
                pool_id_dict[dom["Pool"]] = gateway_id_dict[dom["Gateway"]]
            gw_dict = {
                "gateway": gateway_id_dict[dom["Gateway"]],
                "pool": pool_id_dict[dom["Pool"]]
            }
            messages[f"Delegated {dom['Name']}"] = gw_dict

        domain_ask_list = list(messages.keys())
        # add custom_domain
        domain_ask_list.append("Custom Domain")
        chosen_domain = self.single_choice(
            "Please choose the domain you wish to use",
            domain_ask_list,
            required=True)
        if chosen_domain != "Custom Domain":
            self.domain_gateway = messages[chosen_domain]["gateway"]
            self.domain_pool = messages[chosen_domain]["pool"]
            splits = chosen_domain.split()
            self.domain_type = splits[0]
            self.domain = splits[1]
            retry = False
            while True:
                domain = self.string_ask(
                    f"Please specify the sub domain name you wish to bind to. will be (subdomain).{self.domain}",
                    retry=retry,
                    required=True,
                    is_identifier=True,
                )
                domain = j.sals.zos.gateway.correct_domain(domain)
                if "." in domain:
                    retry = True
                    self.md_show(
                        "You can't nest domains. please click next to try again."
                    )
                else:
                    if j.tools.dnstool.is_free(domain + "." + self.domain):
                        break
                    else:
                        self.md_show(
                            f"domain {domain + '.' + self.domain} is not available."
                        )

            self.domain = domain + "." + self.domain
        else:
            self.domain = self.string_ask(
                "Please specify the domain name you wish to bind to:",
                required=True)
            self.domain = j.sals.zos.gateway.correct_domain(self.domain)
            self.domain_gateway, self.domain_pool = deployer.select_gateway(
                self)
            self.domain_type = "Custom Domain"
            res = """\
            Please create a `CNAME` record in your DNS manager for domain: `{{domain}}` pointing to:
            {% for dns in gateway.dns_nameserver -%}
            - {{dns}}
            {% endfor %}
            """
            res = j.tools.jinja2.render_template(template_text=res,
                                                 gateway=self.domain_gateway,
                                                 domain=self.domain)
            self.md_show(dedent(res), md=True)
        self.name_server = self.domain_gateway.dns_nameserver[0]
        self.secret = f"{j.core.identity.me.tid}:{uuid.uuid4().hex}"