Skip to content

Commit

Permalink
FEATURE: enable --report for preview (not just push) (#3149)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeffrey Cafferata <jeffrey@jcid.nl>
  • Loading branch information
tlimoncelli and cafferata authored Oct 10, 2024
1 parent ee610bf commit bbc6892
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
14 changes: 7 additions & 7 deletions commands/ppreviewPush.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type PPreviewArgs struct {
ConcurMode string
NoPopulate bool
DePopulate bool
Report string
Full bool
}

Expand Down Expand Up @@ -116,6 +117,11 @@ func (args *PPreviewArgs) flags() []cli.Flag {
Destination: &bindserial.ForcedValue,
Usage: `Force BIND serial numbers to this value (for reproducibility)`,
})
flags = append(flags, &cli.StringFlag{
Name: "report",
Destination: &args.Report,
Usage: `Generate a machine-parseable report of corrections.`,
})
return flags
}

Expand All @@ -135,7 +141,6 @@ var _ = cmd(catMain, func() *cli.Command {
type PPushArgs struct {
PPreviewArgs
Interactive bool
Report string
}

func (args *PPushArgs) flags() []cli.Flag {
Expand All @@ -145,17 +150,12 @@ func (args *PPushArgs) flags() []cli.Flag {
Destination: &args.Interactive,
Usage: "Interactive. Confirm or Exclude each correction before they run",
})
flags = append(flags, &cli.StringFlag{
Name: "report",
Destination: &args.Report,
Usage: `Generate a machine-parseable report of performed corrections.`,
})
return flags
}

// PPreview implements the preview subcommand.
func PPreview(args PPreviewArgs) error {
return prun(args, false, false, printer.DefaultPrinter, "")
return prun(args, false, false, printer.DefaultPrinter, args.Report)
}

// PPush implements the push subcommand.
Expand Down
14 changes: 7 additions & 7 deletions commands/previewPush.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type PreviewArgs struct {
WarnChanges bool
NoPopulate bool
Full bool
Report string
}

// ReportItem is a record of corrections for a particular domain/provider/registrar.
Expand Down Expand Up @@ -92,6 +93,11 @@ func (args *PreviewArgs) flags() []cli.Flag {
Destination: &bindserial.ForcedValue,
Usage: `Force BIND serial numbers to this value (for reproducibility)`,
})
flags = append(flags, &cli.StringFlag{
Name: "report",
Destination: &args.Report,
Usage: `Generate a machine-parseable report of corrections counts.`,
})
return flags
}

Expand All @@ -111,7 +117,6 @@ var _ = cmd(catMain, func() *cli.Command {
type PushArgs struct {
PreviewArgs
Interactive bool
Report string
}

func (args *PushArgs) flags() []cli.Flag {
Expand All @@ -121,17 +126,12 @@ func (args *PushArgs) flags() []cli.Flag {
Destination: &args.Interactive,
Usage: "Interactive. Confirm or Exclude each correction before they run",
})
flags = append(flags, &cli.StringFlag{
Name: "report",
Destination: &args.Report,
Usage: `Generate a machine-parseable report of performed corrections.`,
})
return flags
}

// Preview implements the preview subcommand.
func Preview(args PreviewArgs) error {
return run(args, false, false, printer.DefaultPrinter, nil)
return run(args, false, false, printer.DefaultPrinter, &args.Report)
}

// Push implements the push subcommand.
Expand Down
17 changes: 14 additions & 3 deletions documentation/json-reports.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# JSON Reports

DNSControl has build in functionality to generate a machine-parseable report after pushing changes. This report is JSON formated and contains the zonename, the provider or registrar name and the amount of performed changes.
DNSControl can generate a machine-parseable report of changes.

## Usage
The report is JSON formated and contains the zonename, the provider or
registrar name, and the number of changes.

To enable the report option you must use the `push` operation in combination with the `--report <filename>` option. This generates the json file.
To generate the report, add the `--report <filename>` option to a preview or
push command (this includes `preview`, `ppreview`, `push`,
`ppush`).


The report lists the changes that would be (preview) or are (push) attempted,
whether they are successful or not.

If a fatal error happens during the run, no report is generated.

## Sample output

{% code title="report.json" %}
```json
Expand Down
8 changes: 4 additions & 4 deletions documentation/preview-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ OPTIONS:
--no-populate Use this flag to not auto-create non-existing zones at the provider (default: false)
--full Add headings, providers names, notifications of no changes, etc (default: false)
--bindserial value Force BIND serial numbers to this value (for reproducibility) (default: 0)
--report value (push) Generate a JSON-formatted report of the number of changes made.
--report value Generate a JSON-formatted report of the number of changes.
--help, -h show help
```
Expand Down Expand Up @@ -92,9 +92,9 @@ OPTIONS:
generally used for reproducibility in testing pipelines.
* `--report name`
* (`push` only!) Generate a machine-parseable report of
performed corrections in the file named `name`. If no name is specified, no
report is generated.
* Write a machine-parseable report of
corrections to the file named `name`. If no name is specified, no
report is generated. See [JSON Reports](json-reports.md)
## ppreview/ppush
Expand Down

0 comments on commit bbc6892

Please sign in to comment.