main.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  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. // import-boss enforces import restrictions in a given repository.
  14. //
  15. // When a directory is verified, import-boss looks for a file called
  16. // ".import-restrictions". If this file is not found, parent directories will be
  17. // recursively searched.
  18. //
  19. // If an ".import-restrictions" file is found, then all imports of the package
  20. // are checked against each "rule" in the file. A rule consists of three parts:
  21. // * A SelectorRegexp, to select the import paths that the rule applies to.
  22. // * A list of AllowedPrefixes
  23. // * A list of ForbiddenPrefixes
  24. // An import is allowed if it matches at least one allowed prefix and does not
  25. // match any forbidden prefix. An example file looks like this:
  26. //
  27. // {
  28. // "Rules": [
  29. // {
  30. // "SelectorRegexp": "k8s[.]io",
  31. // "AllowedPrefixes": [
  32. // "k8s.io/kubernetes/cmd/libs/go2idl",
  33. // "k8s.io/kubernetes/third_party"
  34. // ],
  35. // "ForbiddenPrefixes": [
  36. // "k8s.io/kubernetes/pkg/third_party/deprecated"
  37. // ]
  38. // },
  39. // {
  40. // "SelectorRegexp": "^unsafe$",
  41. // "AllowedPrefixes": [
  42. // ],
  43. // "ForbiddenPrefixes": [
  44. // ""
  45. // ]
  46. // }
  47. // ]
  48. // }
  49. //
  50. // Note the secound block explicitly matches the unsafe package, and forbids it
  51. // ("" is a prefix of everything).
  52. package main
  53. import (
  54. "os"
  55. "k8s.io/kubernetes/cmd/libs/go2idl/args"
  56. "k8s.io/kubernetes/cmd/libs/go2idl/import-boss/generators"
  57. "github.com/golang/glog"
  58. )
  59. func main() {
  60. arguments := args.Default()
  61. // Override defaults. These are Kubernetes specific input and output
  62. // locations.
  63. arguments.InputDirs = []string{
  64. "k8s.io/kubernetes/pkg/...",
  65. "k8s.io/kubernetes/cmd/...",
  66. "k8s.io/kubernetes/plugin/...",
  67. }
  68. // arguments.VerifyOnly = true
  69. if err := arguments.Execute(
  70. generators.NameSystems(),
  71. generators.DefaultNameSystem(),
  72. generators.Packages,
  73. ); err != nil {
  74. glog.Errorf("Error: %v", err)
  75. os.Exit(1)
  76. }
  77. glog.V(2).Info("Completed successfully.")
  78. }