Skip to content

Commit

Permalink
INTG-1910: add web report link config option (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
atashbahar authored Aug 9, 2021
1 parent f7ae3b1 commit 8bde202
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/iauditor-exporter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func configFlags() {
inspectionFlags.String("inspection-archived", "false", "Return archived inspections, false, true or both")
inspectionFlags.String("inspection-completed", "true", "Return completed inspections, false, true or both")
inspectionFlags.Int("inspection-limit", 100, "Number of inspections fetched at once. Lower this number if the exporter fails to load the data")
inspectionFlags.String("inspection-web-report-link", "private", "Web report link format. Can be public or private")

templatesFlag = flag.NewFlagSet("templates", flag.ContinueOnError)
templatesFlag.StringSlice("template-ids", []string{}, "Template IDs to filter inspections and schedules by (default all)")
Expand Down Expand Up @@ -162,6 +163,7 @@ func bindFlags() {
util.Check(viper.BindPFlag("export.inspection.completed", inspectionFlags.Lookup("inspection-completed")), "while binding flag")
util.Check(viper.BindPFlag("export.inspection.skip_ids", inspectionFlags.Lookup("inspection-skip-ids")), "while binding flag")
util.Check(viper.BindPFlag("export.inspection.limit", inspectionFlags.Lookup("inspection-limit")), "while binding flag")
util.Check(viper.BindPFlag("export.inspection.web_report_link", inspectionFlags.Lookup("inspection-web-report-link")), "while binding flag")

util.Check(viper.BindPFlag("export.site.include_deleted", sitesFlags.Lookup("site-include-deleted")), "while binding flag")

Expand Down
2 changes: 1 addition & 1 deletion docs/iauditor-exporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ A CLI tool for extracting your iAuditor data
* [iauditor-exporter schema](iauditor-exporter_schema.md) - Print iAuditor table schemas
* [iauditor-exporter sql](iauditor-exporter_sql.md) - Export iAuditor data to SQL database

###### Auto generated by spf13/cobra on 22-Mar-2021
###### Auto generated by spf13/cobra on 5-Aug-2021
3 changes: 2 additions & 1 deletion docs/iauditor-exporter_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ iauditor-exporter configure [flags]
--inspection-include-inactive-items Include inactive items in the inspection_items table (default false)
--inspection-limit int Number of inspections fetched at once. Lower this number if the exporter fails to load the data (default 100)
--inspection-skip-ids strings Skip storing these inspection IDs
--inspection-web-report-link string Web report link format. Can be public or private (default "private")
--modified-after string Return inspections modified after this date (see readme for supported formats)
--proxy-url string Proxy URL for making API requests through
--tables strings Tables to export (default all)
Expand All @@ -43,4 +44,4 @@ iauditor-exporter configure [flags]

* [iauditor-exporter](iauditor-exporter.md) - A CLI tool for extracting your iAuditor data

###### Auto generated by spf13/cobra on 22-Mar-2021
###### Auto generated by spf13/cobra on 5-Aug-2021
4 changes: 3 additions & 1 deletion docs/iauditor-exporter_csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ iauditor-exporter csv --export-path /path/to/export/to
--inspection-include-inactive-items Include inactive items in the inspection_items table (default false)
--inspection-limit int Number of inspections fetched at once. Lower this number if the exporter fails to load the data (default 100)
--inspection-skip-ids strings Skip storing these inspection IDs
--inspection-web-report-link string Web report link format. Can be public or private (default "private")
--max-rows-per-file int Maximum number of rows in a csv file. New files will be created when reaching this limit. (default 1000000)
--modified-after string Return inspections modified after this date (see readme for supported formats)
--proxy-url string Proxy URL for making API requests through
--site-include-deleted Include deleted sites in the sites table (default false)
Expand All @@ -51,4 +53,4 @@ iauditor-exporter csv --export-path /path/to/export/to

* [iauditor-exporter](iauditor-exporter.md) - A CLI tool for extracting your iAuditor data

###### Auto generated by spf13/cobra on 22-Mar-2021
###### Auto generated by spf13/cobra on 5-Aug-2021
3 changes: 2 additions & 1 deletion docs/iauditor-exporter_inspection-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ iauditor-exporter inspection-json --export-path /path/to/export/to
--inspection-include-inactive-items Include inactive items in the inspection_items table (default false)
--inspection-limit int Number of inspections fetched at once. Lower this number if the exporter fails to load the data (default 100)
--inspection-skip-ids strings Skip storing these inspection IDs
--inspection-web-report-link string Web report link format. Can be public or private (default "private")
--modified-after string Return inspections modified after this date (see readme for supported formats)
--proxy-url string Proxy URL for making API requests through
--template-ids strings Template IDs to filter inspections and schedules by (default all)
Expand All @@ -46,4 +47,4 @@ iauditor-exporter inspection-json --export-path /path/to/export/to

* [iauditor-exporter](iauditor-exporter.md) - A CLI tool for extracting your iAuditor data

###### Auto generated by spf13/cobra on 22-Mar-2021
###### Auto generated by spf13/cobra on 5-Aug-2021
4 changes: 3 additions & 1 deletion docs/iauditor-exporter_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ iauditor-exporter report [flags]
-t, --access-token string API Access Token
--api-url string API URL (default "https://api.safetyculture.io")
--export-path string File Export Path (default "./export/")
--filename-convention string The name of the report exported, either INSPECTION_TITLE or INSPECTION_ID (default "INSPECTION_TITLE")
--format strings Export format (PDF,WORD) (default [PDF])
-h, --help help for report
--incremental Update inspections, inspection_items and templates tables incrementally (default true)
Expand All @@ -29,6 +30,7 @@ iauditor-exporter report [flags]
--inspection-include-inactive-items Include inactive items in the inspection_items table (default false)
--inspection-limit int Number of inspections fetched at once. Lower this number if the exporter fails to load the data (default 100)
--inspection-skip-ids strings Skip storing these inspection IDs
--inspection-web-report-link string Web report link format. Can be public or private (default "private")
--modified-after string Return inspections modified after this date (see readme for supported formats)
--preference-id string The report preference to apply to the document
--proxy-url string Proxy URL for making API requests through
Expand All @@ -47,4 +49,4 @@ iauditor-exporter report [flags]

* [iauditor-exporter](iauditor-exporter.md) - A CLI tool for extracting your iAuditor data

###### Auto generated by spf13/cobra on 22-Mar-2021
###### Auto generated by spf13/cobra on 5-Aug-2021
2 changes: 1 addition & 1 deletion docs/iauditor-exporter_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ iauditor-exporter schema

* [iauditor-exporter](iauditor-exporter.md) - A CLI tool for extracting your iAuditor data

###### Auto generated by spf13/cobra on 22-Mar-2021
###### Auto generated by spf13/cobra on 5-Aug-2021
3 changes: 2 additions & 1 deletion docs/iauditor-exporter_sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ iauditor-exporter sql --export-path /path/to/export/to
--inspection-include-inactive-items Include inactive items in the inspection_items table (default false)
--inspection-limit int Number of inspections fetched at once. Lower this number if the exporter fails to load the data (default 100)
--inspection-skip-ids strings Skip storing these inspection IDs
--inspection-web-report-link string Web report link format. Can be public or private (default "private")
--modified-after string Return inspections modified after this date (see readme for supported formats)
--proxy-url string Proxy URL for making API requests through
--site-include-deleted Include deleted sites in the sites table (default false)
Expand All @@ -53,4 +54,4 @@ iauditor-exporter sql --export-path /path/to/export/to

* [iauditor-exporter](iauditor-exporter.md) - A CLI tool for extracting your iAuditor data

###### Auto generated by spf13/cobra on 22-Mar-2021
###### Auto generated by spf13/cobra on 5-Aug-2021
1 change: 1 addition & 0 deletions internal/app/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ type GetFeedParams struct {
Completed string `url:"completed,omitempty"`
IncludeInactive bool `url:"include_inactive,omitempty"`
Limit int `url:"limit,omitempty"`
WebReportLink string `url:"web_report_link,omitempty"`

// Applicable only for sites
IncludeDeleted bool `url:"include_deleted,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type InspectionConfig struct {
Completed string
Incremental bool
Limit int
WebReportLink string
}

// GetInspectionConfig returns configurations that have been set for fetching inspections
Expand All @@ -25,5 +26,6 @@ func GetInspectionConfig(v *viper.Viper) *InspectionConfig {
Completed: v.GetString("export.inspection.completed"),
Limit: v.GetInt("export.inspection.limit"),
Incremental: v.GetBool("export.incremental"),
WebReportLink: v.GetString("export.inspection.web_report_link"),
}
}
1 change: 1 addition & 0 deletions internal/app/feed/export_feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func getInspectionFeed(v *viper.Viper, inspectionConfig *config.InspectionConfig
Completed: inspectionConfig.Completed,
Incremental: inspectionConfig.Incremental,
Limit: inspectionConfig.Limit,
WebReportLink: inspectionConfig.WebReportLink,
}
}

Expand Down
6 changes: 4 additions & 2 deletions internal/app/feed/feed_inspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type InspectionFeed struct {
Completed string
Incremental bool
Limit int
WebReportLink string
}

// Name is the name of the feed
Expand Down Expand Up @@ -160,14 +161,14 @@ func (f *InspectionFeed) Export(ctx context.Context, apiClient *api.Client, expo

exporter.InitFeed(f, &InitFeedOptions{
// Delete data if incremental refresh is disabled so there is no duplicates
Truncate: f.Incremental == false,
Truncate: !f.Incremental,
})

var err error
f.ModifiedAfter, err = exporter.LastModifiedAt(f, f.ModifiedAfter, orgID)
util.Check(err, "unable to load modified after")

logger.Infof("%s: exporting for org_id: %s since: %s", feedName, orgID, f.ModifiedAfter.Format(time.RFC1123))
logger.Infof("%s: exporting for org_id: %s since: %s - %s", feedName, orgID, f.ModifiedAfter.Format(time.RFC1123), f.WebReportLink)

err = apiClient.DrainFeed(ctx, &api.GetFeedRequest{
InitialURL: "/feed/inspections",
Expand All @@ -177,6 +178,7 @@ func (f *InspectionFeed) Export(ctx context.Context, apiClient *api.Client, expo
Archived: f.Archived,
Completed: f.Completed,
Limit: f.Limit,
WebReportLink: f.WebReportLink,
},
}, func(resp *api.GetFeedResponse) error {
rows := []*Inspection{}
Expand Down

0 comments on commit 8bde202

Please sign in to comment.