in gcp/dam_import/main.go [33:103]
func main() {
pre := flag.String("account_prefix", "", "when a wipe is requested, accounts matching this prefix override will be removed")
path := flag.String("path", "deploy/config", "specifies the relative or absolute path to the config file root")
wipe := flag.String("wipe", "", "specify 'unsafe_wipe_in_non_production' to remove all data for the service from the storage layer first (DO NOT USE IN PRODUCTION)")
flag.Parse()
args := flag.Args()
if len(args) != 3 {
glog.Exitf("Usage: dam_import -wipe=... -path=<config_root> -account_prefix=<service_account_prefix_to_delete> <project> <environment> <import_type>")
}
project := args[0]
env := args[1]
importType := args[2]
envPrefix := ""
service := "dam"
if len(env) > 0 {
envPrefix = "-" + env
service += envPrefix
}
accountPrefix := "ic" + envPrefix + "-dot-"
if *pre != "" {
accountPrefix = *pre
}
ctx := context.Background()
store := dsstore.NewStore(context.Background(), project, service, *path)
wh := saw.MustNew(ctx, store)
vars := map[string]string{
"${YOUR_PROJECT_ID}": project,
"${YOUR_ENVIRONMENT}": envPrefix,
}
if *wipe != "" {
if *wipe != "unsafe_wipe_in_non_production" {
glog.Exitf("attempted wipe failed: only works if specific safety value set. See -h for help.")
}
glog.Infof("WIPE STORAGE FOR SERVICE %q...", service)
if _, err := store.Wipe(ctx, storage.AllRealms, 0, 0); err != nil {
glog.Exitf("error wiping storage for service %q: %v", service, err)
}
glog.Infof("Wipe complete")
}
importConfig := false
importSecrets := false
importPermission := false
switch importType {
case "all":
importConfig = true
importSecrets = true
importPermission = true
case "config":
importConfig = true
case "security":
importSecrets = true
case "permission":
importPermission = true
default:
glog.Exitf("unknown importing config type: %s", importType)
}
if err := dam.ImportConfig(store, service, wh, vars, importConfig, importSecrets, importPermission); err != nil {
glog.Exitf("error importing files: %v", err)
}
if *wipe != "" {
cleanupServiceAccounts(ctx, accountPrefix, project, store)
}
glog.Infof("SUCCESS resetting DAM service %q", service)
}