ocket8888 commented on a change in pull request #5913: URL: https://github.com/apache/trafficcontrol/pull/5913#discussion_r645759820
########## File path: traffic_ops/app/db/reencrypt/reencrypt.go ########## @@ -0,0 +1,406 @@ +package main + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import ( + "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/trafficvault/backends/postgres" + + "github.com/jmoiron/sqlx" + _ "github.com/lib/pq" + + "crypto/aes" + "encoding/base64" + "encoding/json" + "errors" + "flag" + "fmt" + "io/ioutil" + "os" + "path/filepath" + "time" +) + +const PROPERTIES_FILE = "./reencrypt.conf" + +func main() { + previousKeyLocation := flag.String("previousKey", "", "The file path for the previous base64 encoded AES key.") + newKeyLocation := flag.String("newKey", "", "The file path for the new base64 encoded AES key.") + flag.Parse() + + if previousKeyLocation == nil || *previousKeyLocation == "" { + fmt.Println("previousKey flag is required.") + os.Exit(0) + } + if newKeyLocation == nil || *newKeyLocation == "" { + fmt.Println("newKey flag is required.") + os.Exit(0) + } Review comment: Alternatively, you can also just make them optional by providing default values. For example, most GNU/POSIX/Unix utilities, when they can read input from a file and output to a file, will, by default, read from `stdin` and output to `stdout`. `grep` is one such utility that will read from `stdin` if not given a file argument. This allows for commands to make use of powerful Unix piping, so I could do something like `sudo cat /path/to/aes/key | reencrypt > /ouput/location` to read input from a file that is read-protected so only root can read it, or something like `reencript --previous-key=/path/to/aes/key | tee /output/path | wc -c` to write the key out and report the number of bytes written. Of course, that stuff won't work if you print success messages and error messages to `stdout`. Normally, command output goes on `stdout` and error/informational/debugging output goes on `stderr`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
