This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
/
main.go
111 lines (98 loc) · 3.67 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2020 the Exposure Notifications Server authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This package is used to create entries in the ExportConfig table. Each ExportConfig entry is used to create rows in the ExportBatch table.
package main
import (
"context"
"flag"
"log"
"strings"
"time"
"github.com/google/exposure-notifications-server/internal/export/database"
"github.com/google/exposure-notifications-server/internal/export/model"
"github.com/google/exposure-notifications-server/internal/setup"
coredb "github.com/google/exposure-notifications-server/pkg/database"
)
var (
bucketName = flag.String("bucket-name", "", "The bucket name to store the export file.")
filenameRoot = flag.String("filename-root", "", "The root filename for the export file.")
period = flag.Duration("period", 24*time.Hour, "The frequency with which to create export files.")
region = flag.String("region", "", "The output region for the export batches/files.")
fromTimestamp = flag.String("from-timestamp", "", "The timestamp (RFC3339) when this config becomes active.")
thruTimestamp = flag.String("thru-timestamp", "", "The timestamp (RFC3339) when this config ends.")
signingKey = flag.String("signing-key", "", "The KMS resource ID to use for signing batches.")
signingKeyID = flag.String("signing-key-id", "", "The ID of the signing key (for clients).")
signingKeyVersion = flag.String("signing-key-version", "", "The version of the signing key (for clients).")
)
func main() {
flag.Parse()
if *bucketName == "" {
log.Fatal("--bucket-name is required.")
}
if *filenameRoot == "" {
log.Fatal("--filename-root is required.")
}
if *region == "" {
log.Fatal("--region is required.")
}
*region = strings.ToUpper(*region)
fromTime := time.Now()
if *fromTimestamp != "" {
var err error
fromTime, err = time.Parse(time.RFC3339, *fromTimestamp)
if err != nil {
log.Fatalf("Failed to parse --from-timestamp (use RFC3339): %v", err)
}
}
var thruTime time.Time
if *thruTimestamp != "" {
var err error
thruTime, err = time.Parse(time.RFC3339, *thruTimestamp)
if err != nil {
log.Fatalf("Failed to parse --thru-timestamp (use RFC3339): %v", err)
}
}
if *signingKey == "" {
log.Printf("WARNING - you are creating an export config without a signing key!!")
}
ctx := context.Background()
var config coredb.Config
env, err := setup.Setup(ctx, &config)
if err != nil {
log.Fatalf("failed to setup: %v", err)
}
defer env.Close(ctx)
db := database.New(env.Database())
si := model.SignatureInfo{
SigningKey: *signingKey,
SigningKeyVersion: *signingKeyVersion,
SigningKeyID: *signingKeyID,
}
if err := db.AddSignatureInfo(ctx, &si); err != nil {
log.Fatalf("AddSignatureInfo: %v", err)
}
ec := model.ExportConfig{
BucketName: *bucketName,
FilenameRoot: *filenameRoot,
Period: *period,
OutputRegion: *region,
From: fromTime,
Thru: thruTime,
SignatureInfoIDs: []int64{si.ID},
}
if err := db.AddExportConfig(ctx, &ec); err != nil {
log.Fatalf("Failure: %v", err)
}
log.Printf("Successfully created ExportConfig %d.", ec.ConfigID)
}