Beispiel #1
0
def set(**kwargs):
    def set_true(k):
        kwargs[k] = True

    uc = UserConfig()
    values = [v for k, v in kwargs.items()]
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        list(map(set_true, kwargs))
        attrs = uc.get_attrs(kwargs)
        config = {}
        for attr in sorted(attrs):
            attr_value = attrs[attr]
            if attr == "secret-id":
                attr_value = "*" * 32 + attr_value[32:]
            elif attr == "secret-key":
                attr_value = "*" * 28 + attr_value[28:]
            v = click.prompt(text="TencentCloud {}({})".format(
                attr, attr_value),
                             default=attrs[attr],
                             show_default=False)
            config[attr] = v
        kwargs = config
    uc.set_attrs(kwargs)
    uc.flush()
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        v = click.prompt(
            text="Allow report information to help us optimize scfcli(Y/n)",
            default="y",
            show_default=False)
        if v in ["y", "Y"]:
            client = ScfReportClient()
            client.report()
Beispiel #2
0
def get(**kwargs):
    '''
        \b
        Get your account parameters.
        \b
        Common usage:
            \b
            * Get the configured information
              $ scf configure get
        '''
    uc = UserConfig()

    def set_true(k):
        kwargs[k] = True

    bools = [v for k, v in kwargs.items()]
    if not reduce(lambda x, y: bool(x or y), bools):
        list(map(set_true, kwargs))
    attrs = uc.get_attrs(kwargs)
    msg = "{} config:".format(UserConfig.API)
    for attr in sorted(attrs):
        attr_value = attrs[attr]
        if attr == "secret-id":
            attr_value = "*" * 32 + attr_value[32:]
        elif attr == "secret-key":
            attr_value = "*" * 28 + attr_value[28:]
        msg += click.style("\n[-] ", fg="cyan") + click.style(
            "{} = {}".format(attr, attr_value), fg="cyan")
    Operation(msg.strip()).process()
Beispiel #3
0
def get(**kwargs):
    uc = UserConfig()

    def set_true(k):
        kwargs[k] = True

    bools = [v for k, v in kwargs.items()]
    if not reduce(lambda x, y: bool(x or y), bools):
        list(map(set_true, kwargs))
    attrs = uc.get_attrs(kwargs)
    msg = "{} config:\n".format(UserConfig.API)
    for attr in sorted(attrs):
        attr_value = attrs[attr]
        if attr == "secret-id":
            attr_value = "*" * 32 + attr_value[32:]
        elif attr == "secret-key":
            attr_value = "*" * 28 + attr_value[28:]
        msg += "{} = {}\n".format(attr, attr_value)
    click.secho(msg.strip())
Beispiel #4
0
def set(**kwargs):
    '''
        \b
        Configure your account parameters.
        \b
        Common usage:
            \b
            * Configure your account parameters
              $ scf configure set
            \b
            * Modify a configuration item
              $ scf configure set --region ap-shanghai
    '''
    def set_true(k):
        kwargs[k] = True

    uc = UserConfig()

    using_cos_true = "False (By default, it isn't deployed by COS.)"
    using_cos_false = "True (By default, it is deployed by COS.)"

    if "region" in kwargs and kwargs["region"]:
        if kwargs["region"] not in REGIONS:
            Operation("The region must in %s." %
                      (", ".join(REGIONS))).warning()
            kwargs["region"] = uc.region
            return

    if "using_cos" in kwargs and kwargs["using_cos"]:
        kwargs["using_cos"] = using_cos_true if kwargs["using_cos"] not in [
            "y", "Y"
        ] else using_cos_false

    values = [v for k, v in kwargs.items()]
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        list(map(set_true, kwargs))
        attrs = uc.get_attrs(kwargs)
        config = {}
        for attr in sorted(attrs):
            if attr != "using-cos":
                while True:
                    attr_value = attrs[attr]
                    if attr == "secret-id":
                        attr_value = "*" * 32 + attr_value[32:]
                    elif attr == "secret-key":
                        attr_value = "*" * 28 + attr_value[28:]

                    v = click.prompt(text="TencentCloud {}({})".format(
                        attr, attr_value),
                                     default=attrs[attr],
                                     show_default=False)
                    config[attr] = v

                    if attr != "region":
                        break
                    else:
                        if v in REGIONS:
                            break
                        else:
                            Operation("The region must in %s." %
                                      (", ".join(REGIONS))).warning()

        v = click.prompt(
            text="Deploy SCF function by COS, it will be faster. (y/n)",
            default="y" if str(attrs["using-cos"]).startswith("True") else "n",
            show_default=False)

        if v:
            config["using_cos"] = using_cos_true if v not in [
                "y", "Y"
            ] else using_cos_false
        else:
            config["using_cos"] = attrs["using-cos"]

        kwargs = config

    uc.set_attrs(kwargs)
    uc.flush()

    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        v = click.prompt(
            text="Allow report information to help us optimize scfcli. (y/n)",
            default="y",
            show_default=False)
        if v in ["y", "Y"]:
            client = ScfReportClient()
            client.report()
Beispiel #5
0
def set(**kwargs):
    '''
        \b
        Configure your account parameters.
        \b
        Common usage:
            \b
            * Configure your account parameters
              $ scf configure set
            \b
            * Modify a configuration item
              $ scf configure set --region ap-shanghai
    '''
    def set_true(k):
        kwargs[k] = True

    uc = UserConfig()

    using_cos_true = "True (By default, it is deployed by COS.)"
    using_cos_false = "False (By default, it isn't deployed by COS.)"

    if "region" in kwargs and kwargs["region"]:
        if kwargs["region"] not in REGIONS:
            Operation("The region must in %s." %
                      (", ".join(REGIONS))).warning()
            kwargs["region"] = uc.region
            return

    if "using_cos" in kwargs and kwargs["using_cos"]:
        kwargs["using_cos"] = using_cos_false if kwargs["using_cos"] not in [
            "y", "Y"
        ] else using_cos_true

    if "allow_report" in kwargs and kwargs["allow_report"]:
        kwargs["allow_report"] = 'False' if kwargs["allow_report"] not in [
            "y", "Y"
        ] else 'True'
        if kwargs["allow_report"] == "True":
            Operation(
                '当前已开启数据收集,详情请参考 https://cloud.tencent.com/document/product/583/37766'
            ).out_infor()

    if "no_color" in kwargs and kwargs["no_color"]:
        kwargs["no_color"] = 'False' if kwargs["no_color"] not in [
            "y", "Y"
        ] else 'True'

    values = [v for k, v in kwargs.items()]
    config = {}
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        list(map(set_true, kwargs))
        attrs = uc.get_attrs(kwargs)
        skip_attr = {
            'using_cos', 'python2_path', 'python3_path', 'no_color',
            'allow_report'
        }
        for attr in sorted(attrs):
            if attr not in skip_attr:
                while True:
                    attr_value = attrs[attr]
                    if attr == "secret_id":
                        attr_value = "*" * 32 + attr_value[32:]
                    elif attr == "secret_key":
                        attr_value = "*" * 28 + attr_value[28:]

                    v = click.prompt(text="TencentCloud {}({})".format(
                        attr.replace('_', '-'), attr_value),
                                     default=attrs[attr],
                                     show_default=False)
                    config[attr] = v

                    if attr != "region":
                        break
                    else:
                        if v in REGIONS:
                            break
                        else:
                            Operation("The region must in %s." %
                                      (", ".join(REGIONS))).warning()

        #
        v1 = click.prompt(
            text=("Show the command information without color(cur:%s). (y/n)")
            % attrs["no_color"][:5],
            default="y"
            if str(attrs["no_color"]).upper().startswith("TRUE") else "n",
            show_default=False)
        if v1:
            config["no_color"] = "False" if v1 not in ["y", "Y"] else "True"
        else:
            config["no_color"] = attrs["no_color"]

        v2 = click.prompt(text=(
            "Deploy SCF function by COS, it will be faster(cur:%s).  (y/n)") %
                          attrs["using_cos"][:5],
                          default="y"
                          if str(attrs["using_cos"]).upper().startswith("TRUE")
                          else "n",
                          show_default=False)
        if v2:
            config["using_cos"] = using_cos_false if v2 not in [
                "y", "Y"
            ] else using_cos_true
        else:
            config["using_cos"] = attrs["using_cos"]

        #v3 = click.prompt(text=("Allow report information to help us optimize scfcli(cur:%s). (y/n)") % attrs["allow_report"][:5],
        #                  default="y" if str(attrs["allow_report"]).upper().startswith("TRUE") else "n",
        #                  show_default=False)
        #if v3:
        #    config["allow_report"] = "False" if v3 not in ["y", "Y"] else "True"
        #else:
        #    config["allow_report"] = attrs["allow_report"]

        # if uc.section_map[UserConfig.OTHERS]['allow_report'].upper() == 'TRUE':
        #     Operation('当前已开启数据收集,详情请参考 https://cloud.tencent.com/document/product/583/37766').out_infor()

        kwargs = config

    uc.set_attrs(kwargs)
    uc.flush()
Beispiel #6
0
def add(**kwargs):
    '''
        \b
        Add a user.
        \b
        Common usage:
            \b
            * Add a user.
              $ scf configure add
    '''
    def set_true(k):
        kwargs[k] = True

    uc = UserConfig()

    using_cos_true = "False (By default, it isn't deployed by COS.)"
    using_cos_false = "True (By default, it is deployed by COS.)"

    if "region" in kwargs and kwargs["region"]:
        if kwargs["region"] not in REGIONS:
            Operation("The region must in %s." %
                      (", ".join(REGIONS))).warning()
            kwargs["region"] = uc.section_map[
                UserConfig.USER_QCLOUD_CONFIG]['region']
            return
    if "using_cos" in kwargs and kwargs["using_cos"]:
        kwargs["using_cos"] = using_cos_true if kwargs["using_cos"] not in [
            "y", "Y"
        ] else using_cos_false

    values = [v for k, v in kwargs.items()]
    if not reduce(lambda x, y: (bool(x) or bool(y)), values):
        list(map(set_true, kwargs))
        attrs = uc.get_attrs(kwargs)
        config = {}
        skip_attr = {'using_cos'}
        for attr in sorted(attrs):
            if attr not in skip_attr:
                while True:
                    v = click.prompt(text="TencentCloud {}".format(attr),
                                     default=None,
                                     show_default=False)
                    config[attr] = v

                    if attr != "region":
                        break
                    else:
                        if v in REGIONS:
                            break
                        else:
                            Operation("The region must in %s." %
                                      (", ".join(REGIONS))).warning()

        v = click.prompt(
            text="Deploy SCF function by COS, it will be faster. (y/n)",
            default="y" if str(attrs["using_cos"]).startswith("True") else "n",
            show_default=False)

        if v:
            config["using_cos"] = using_cos_true if v not in [
                "y", "Y"
            ] else using_cos_false
        else:
            config["using_cos"] = attrs["using_cos"]

        kwargs = config

    user = uc.add_user(data=kwargs)
    uc.flush()
    Operation('Add User %s success!' % user).success()
    Operation(user).process()
    Operation('%-10s %-15s %-15s %-15s %-15s %-10s' %
              ('UserId', 'AppId', 'region', 'secret_id', 'secret_key',
               'using_cos')).process()
    userinfo = uc.get_user_info(user)
    secret_id = ("*" * 3 + userinfo['secret_id'][32:]
                 ) if userinfo['secret_id'].upper() != 'NONE' else 'None'
    secret_key = ("*" * 3 + userinfo['secret_key'][28:]
                  ) if userinfo['secret_key'].upper() != 'NONE' else 'None'
    Operation('%-10s %-15s %-15s %-15s %-15s %-10s' %
              (user.strip('USER_'), userinfo['appid'], userinfo['region'],
               secret_id, secret_key, userinfo['using_cos'][:5])).process()
    Operation('You can use `scf configure change -u %s` to switch user.' %
              (user.strip('USER_'))).process()