qualified-device.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Copyright © 2021 The CDI 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. package cdi
  14. import (
  15. "github.com/container-orchestrated-devices/container-device-interface/pkg/parser"
  16. )
  17. // QualifiedName returns the qualified name for a device.
  18. // The syntax for a qualified device names is
  19. //
  20. // "<vendor>/<class>=<name>".
  21. //
  22. // A valid vendor and class name may contain the following runes:
  23. //
  24. // 'A'-'Z', 'a'-'z', '0'-'9', '.', '-', '_'.
  25. //
  26. // A valid device name may contain the following runes:
  27. //
  28. // 'A'-'Z', 'a'-'z', '0'-'9', '-', '_', '.', ':'
  29. //
  30. // Deprecated: use parser.QualifiedName instead
  31. func QualifiedName(vendor, class, name string) string {
  32. return parser.QualifiedName(vendor, class, name)
  33. }
  34. // IsQualifiedName tests if a device name is qualified.
  35. //
  36. // Deprecated: use parser.IsQualifiedName instead
  37. func IsQualifiedName(device string) bool {
  38. return parser.IsQualifiedName(device)
  39. }
  40. // ParseQualifiedName splits a qualified name into device vendor, class,
  41. // and name. If the device fails to parse as a qualified name, or if any
  42. // of the split components fail to pass syntax validation, vendor and
  43. // class are returned as empty, together with the verbatim input as the
  44. // name and an error describing the reason for failure.
  45. //
  46. // Deprecated: use parser.ParseQualifiedName instead
  47. func ParseQualifiedName(device string) (string, string, string, error) {
  48. return parser.ParseQualifiedName(device)
  49. }
  50. // ParseDevice tries to split a device name into vendor, class, and name.
  51. // If this fails, for instance in the case of unqualified device names,
  52. // ParseDevice returns an empty vendor and class together with name set
  53. // to the verbatim input.
  54. //
  55. // Deprecated: use parser.ParseDevice instead
  56. func ParseDevice(device string) (string, string, string) {
  57. return parser.ParseDevice(device)
  58. }
  59. // ParseQualifier splits a device qualifier into vendor and class.
  60. // The syntax for a device qualifier is
  61. //
  62. // "<vendor>/<class>"
  63. //
  64. // If parsing fails, an empty vendor and the class set to the
  65. // verbatim input is returned.
  66. //
  67. // Deprecated: use parser.ParseQualifier instead
  68. func ParseQualifier(kind string) (string, string) {
  69. return parser.ParseQualifier(kind)
  70. }
  71. // ValidateVendorName checks the validity of a vendor name.
  72. // A vendor name may contain the following ASCII characters:
  73. // - upper- and lowercase letters ('A'-'Z', 'a'-'z')
  74. // - digits ('0'-'9')
  75. // - underscore, dash, and dot ('_', '-', and '.')
  76. //
  77. // Deprecated: use parser.ValidateVendorName instead
  78. func ValidateVendorName(vendor string) error {
  79. return parser.ValidateVendorName(vendor)
  80. }
  81. // ValidateClassName checks the validity of class name.
  82. // A class name may contain the following ASCII characters:
  83. // - upper- and lowercase letters ('A'-'Z', 'a'-'z')
  84. // - digits ('0'-'9')
  85. // - underscore, dash, and dot ('_', '-', and '.')
  86. //
  87. // Deprecated: use parser.ValidateClassName instead
  88. func ValidateClassName(class string) error {
  89. return parser.ValidateClassName(class)
  90. }
  91. // ValidateDeviceName checks the validity of a device name.
  92. // A device name may contain the following ASCII characters:
  93. // - upper- and lowercase letters ('A'-'Z', 'a'-'z')
  94. // - digits ('0'-'9')
  95. // - underscore, dash, dot, colon ('_', '-', '.', ':')
  96. //
  97. // Deprecated: use parser.ValidateDeviceName instead
  98. func ValidateDeviceName(name string) error {
  99. return parser.ValidateDeviceName(name)
  100. }