Example #1
0
        public HasApplyResourceChange.Result <PutResource> ApplyChange(
            HasApplyResourceChange.Input <PutResource> input)
        {
            var result = new HasApplyResourceChange.Result <PutResource>();

            LogInput(input);

            // _log.LogInformation("Got Inputs:");
            // _log.LogInformation("  * ChangeType = {@ChangeType}", input.ChangeType);
            // _log.LogInformation("  * Config = {@Config}", input.Config);
            // _log.LogInformation("  * PriorState = {@PriorState}", input.PriorState);
            // _log.LogInformation("  * PlannedState = {@PlannedState}", input.PlannedState);
            // _log.LogInformation("  * PlannedPrivate = {@PlannedPrivate}", input.PlannedPrivate);

            Dictionary <string, string> kv;

            if (File.Exists(_fullPath))
            {
                var kvContent = File.ReadAllText(_fullPath);
                kv = JsonSerializer.Deserialize <Dictionary <string, string> >(kvContent);
            }
            else
            {
                kv = new Dictionary <string, string>();
            }

            // Deletes and Updates with Changed Keys
            if (input.ChangeType == TFResourceChangeType.Delete ||
                (input.ChangeType == TFResourceChangeType.Update &&
                 input.PriorState.Name != input.PlannedState.Name))
            {
                kv.Remove(input.PriorState.Name);
            }

            // Creates and Updates with Changed Keys or Values
            if (input.ChangeType == TFResourceChangeType.Create ||
                (input.ChangeType == TFResourceChangeType.Update &&
                 (input.PriorState.Name != input.PlannedState.Name ||
                  input.PriorState.Value != input.PlannedState.Value)))
            {
                kv[input.PlannedState.Name] = input.PlannedState.Value;
            }

            File.WriteAllText(_fullPath, JsonSerializer.Serialize(kv));

            result.NewState = input.PlannedState;
            result.Private  = input.PlannedPrivate;

            LogResult(result);

            return(result);
        }
        public HasApplyResourceChange.Result <DscResResource> ApplyChange(
            HasApplyResourceChange.Input <DscResResource> input)
        {
            var result = new HasApplyResourceChange.Result <DscResResource>();

            if (input.ChangeType == TFResourceChangeType.Delete)
            {
                _log.LogWarning("DELETE REQUESTED -- DSC Delete is still an unknown quantity -- WHAT DOES IT MEAN?");
            }
            else
            {
                result.NewState = (DscResResource)DscResApplyConfig(result, input.Config, out bool reboot);
                result.NewState.RequiredReboot = reboot;
                result.Private = input.PlannedPrivate;
            }

            return(result);
        }