Beispiel #1
0
    def test_with_file_and_no_overrides(self):
        config = {
            "default": {
                "a": "b",
                "x": "y",
            },
            "staging": {
                "x": "k",
            },
            "prod": {
                "x": "x",
            },
        }
        with tempfile.NamedTemporaryFile("w") as f:
            ydump(config, f)
            expected = {"a": "b", "x": "k"}
            found = read_env_config_from_file("staging",
                                              overrideOptions={},
                                              filePath=f.name)
            self.assertDictEqual(expected, found)

            # testing the default case
            expected = {
                "a": "b",
                "x": "y",
            }
            found = read_env_config_from_file("newenv",
                                              overrideOptions={},
                                              filePath=f.name)
            self.assertDictEqual(expected, found)
Beispiel #2
0
def env_update(env_name, target=None, config=None, aws_key=None, aws_secret=None):
    settings = get_project_settings()
    report_async({"command": f"dg env update"}, settings=settings, status="start")

    projectName = settings["project"]["name"]
    envDetails = api.get_environment_details(projectName, env_name)
    envPk = envDetails["pk"]

    data = {}
    if target is not None:
        data["target"] = target
    if config is not None:
        data["config_options"] = parse_env_config_options(config)
        cliOptions = parse_env_config_options(config)
        try:
            configOptions = read_env_config_from_file(env_name, overrideOptions=cliOptions)
        except yaml.YAMLError as ex:
            print(f"Could not parse config file: {exc}")
            return
        data["config_options"] = configOptions
        data["config_options"] = data["config_options"]
    if aws_key is not None:
        data["aws_key"] = aws_key
    if aws_secret is not None:
        data["aws_secret"] = aws_secret

    response = api.update_environment(projectName, envPk, data)
    Bcolors.okgreen("environment udpated succesfully")
    report_async({"command": f"dg env update"}, settings=settings, status="stop")
Beispiel #3
0
def env_create(
    env_name, 
    target=None,
    region=None,
    aws_key=None,
    aws_secret=None,
    config=[],
    prompt=True
):

    try:
        env_name_validate(env_name)
    except ValueError as e:
        Bcolors.warn(str(e))
        sys.exit()

    # parsing config options

    cliOptions = parse_env_config_options(config)
    try:
        configOptions = read_env_config_from_file(env_name, overrideOptions=cliOptions)
    except yaml.YAMLError as ex:
        print(f"Could not read config file: {exc}")
        return

    targets = DiggerTargets.TARGETS
    settings = get_project_settings()
    report_async({"command": f"dg env create"}, settings=settings, status="start")
    project_name = settings["project"]["name"]

    if target is None:
        questions = [
            {
                'type': 'list',
                'name': 'target',
                'message': 'Select target',
                'choices': targets.keys()
            },
        ]

        answers = pyprompt(questions)
        target_key = answers["target"]
        target = targets[target_key]

        if target == "other":

            ok = "n"
            while (ok.lower() != "y"):
                print("Enter target: ", end="")
                target = input()
                print(f"Confirm Target {target} (Y/N)?", end="")
                ok = input()

        elif target_key not in [DiggerTargets.FARGATE, DiggerTargets.LAMBDA]:
            Bcolors.fail("This option is currently unsupported! Please try again")
            return
    else:
        # use target from cli arg
        target = target

    if region is None:
        questions = [
            {
                'type': 'list',
                'name': 'region',
                'message': 'Select region',
                'choices': AWS_REGIONS,
                'default': "us-east-1"
            },
        ]
        answers = pyprompt(questions)
        region = answers["region"]

    if region not in AWS_REGIONS:
        Bcolors.fail("This region is not valid! Please try again")
        return

    credentials = retreive_aws_creds(project_name, env_name, aws_key=aws_key, aws_secret=aws_secret, prompt=prompt)
    aws_key = credentials["aws_key"]
    aws_secret = credentials["aws_secret"]

    spinner = Halo(text="Creating environment", spinner="dots")
    spinner.start()

    response = api.create_environment(project_name, {
        "name": env_name,
        "target": target,
        "region": region,
        "aws_key": aws_key,
        "aws_secret": aws_secret,
        "config_options": configOptions
    })
    spinner.stop()

    Bcolors.okgreen("Environment created successfully")
    Bcolors.okgreen(f"Use this command to run it: dg env apply {env_name}")
Beispiel #4
0
 def test_without_file(self):
     options = {"a": "b"}
     expected = options
     found = read_env_config_from_file("staging", overrideOptions=options)
     self.assertDictEqual(expected, found)