You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.6 KiB

  1. /*
  2. Copyright © 2021 Drew Short <warricks@sothr.com>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cmd
  14. import (
  15. log "github.com/sirupsen/logrus"
  16. "os"
  17. "path"
  18. "github.com/spf13/cobra"
  19. "sothr.com/warricksothr/pinned-package-updater/internal/parser/dockerfile"
  20. )
  21. // checkCmd represents the check command
  22. var checkCmd = &cobra.Command{
  23. Use: "check",
  24. Short: "Check for updates to pinned packages in a alpine.Dockerfile",
  25. Long: `Read a alpine.Dockerfile, identify the repositories and packages it references, and locate required
  26. updates to satisfy the requirement of running the latest security version for the pinned packages.
  27. To run in standalone mode, provide a alpine.Dockerfile path to evaluate or rely on the default
  28. behavior which looks for a alpine.Dockerfile in the current directory.
  29. pinned-package-updater check [Dockerfile, ...]
  30. To run in distributed mode, provide the remote address of the service that will
  31. provide information about the remote.
  32. pinned-package-updater --remote <address of the upstream service> check [Dockerfile, ...]
  33. `,
  34. Run: func(cmd *cobra.Command, args []string) {
  35. // Handle no Dockerfile path provided
  36. if len(args) < 1 {
  37. currentDirectory, currentDirectoryErr := os.Getwd()
  38. cobra.CheckErr(currentDirectoryErr)
  39. defaultDockerfilePath := path.Join(currentDirectory, "Dockerfile")
  40. args = append(args, defaultDockerfilePath)
  41. log.Debugf("No dockerfile path provided, attempting to use the default %s dockerfile", defaultDockerfilePath)
  42. }
  43. // Aggregate the parsed updates
  44. for _, dockerfilePath := range args {
  45. log.Debugf("Parsing %s", dockerfilePath)
  46. _, err := dockerfile.Parse(dockerfilePath)
  47. if err != nil {
  48. return
  49. }
  50. }
  51. },
  52. }
  53. func init() {
  54. rootCmd.AddCommand(checkCmd)
  55. // Here you will define your flags and configuration settings.
  56. // Cobra supports Persistent Flags which will work for this command
  57. // and all subcommands, e.g.:
  58. // checkCmd.PersistentFlags().String("foo", "", "A help for foo")
  59. // Cobra supports local flags which will only run when this command
  60. // is called directly, e.g.:
  61. // checkCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
  62. }