Skip to content

Commit

Permalink
Make all unrelated APIs private
Browse files Browse the repository at this point in the history
Signed-off-by: Ed Bartosh <[email protected]>
  • Loading branch information
bart0sh committed Aug 8, 2024
1 parent 2cad149 commit b1e626c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
10 changes: 6 additions & 4 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package parser
import (
"fmt"
"strings"

specs "tags.cncf.io/container-device-interface/specs-go"
)

// QualifiedName returns the qualified name for a device.
Expand Down Expand Up @@ -107,7 +105,11 @@ func ParseDevice(device string) (string, string, string) {
// If parsing fails, an empty vendor and the class set to the
// verbatim input is returned.
func ParseQualifier(kind string) (string, string) {
return specs.ParseQualifier(kind)
parts := strings.SplitN(kind, "/", 2)
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", kind
}
return parts[0], parts[1]
}

// ValidateVendorName checks the validity of a vendor name.
Expand Down Expand Up @@ -196,7 +198,7 @@ func ValidateDeviceName(name string) error {

// IsLetter reports whether the rune is a letter.
func IsLetter(c rune) bool {
return specs.IsLetter(c)
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')
}

// IsDigit reports whether the rune is a digit.
Expand Down
8 changes: 4 additions & 4 deletions specs-go/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ package specs

import "strings"

// ParseQualifier splits a device qualifier into vendor and class.
// parseQualifier splits a device qualifier into vendor and class.
// The syntax for a device qualifier is
//
// "<vendor>/<class>"
//
// If parsing fails, an empty vendor and the class set to the
// verbatim input is returned.
func ParseQualifier(kind string) (string, string) {
func parseQualifier(kind string) (string, string) {
parts := strings.SplitN(kind, "/", 2)
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", kind
}
return parts[0], parts[1]
}

// IsLetter reports whether the rune is a letter.
func IsLetter(c rune) bool {
// isLetter reports whether the rune is an ASCII letter.
func isLetter(c rune) bool {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')
}
14 changes: 7 additions & 7 deletions specs-go/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ValidateVersion(spec *Spec) error {
if err != nil {
return fmt.Errorf("could not determine minimum required version: %w", err)
}
if newVersion(minVersion).IsGreaterThan(newVersion(spec.Version)) {
if newVersion(minVersion).isGreaterThan(newVersion(spec.Version)) {
return fmt.Errorf("the spec version must be at least v%v", minVersion)
}
return nil
Expand All @@ -97,12 +97,12 @@ func (v version) String() string {
}

// IsGreaterThan checks with a version is greater than the specified version.
func (v version) IsGreaterThan(o version) bool {
func (v version) isGreaterThan(o version) bool {
return semver.Compare(string(v), string(o)) > 0
}

// IsLatest checks whether the version is the latest supported version
func (v version) IsLatest() bool {
func (v version) isLatest() bool {
return v == vCurrent
}

Expand All @@ -126,11 +126,11 @@ func (r requiredVersionMap) requiredVersion(spec *Spec) version {
if isRequired == nil {
continue
}
if isRequired(spec) && v.IsGreaterThan(minVersion) {
if isRequired(spec) && v.isGreaterThan(minVersion) {
minVersion = v
}
// If we have already detected the latest version then no later version could be detected
if minVersion.IsLatest() {
if minVersion.isLatest() {
break
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func requiresV060(spec *Spec) bool {
}

// The v0.6.0 spec allows dots "." in Kind name label (class)
vendor, class := ParseQualifier(spec.Kind)
vendor, class := parseQualifier(spec.Kind)
if vendor != "" {
if strings.ContainsRune(class, '.') {
return true
Expand All @@ -199,7 +199,7 @@ func requiresV050(spec *Spec) bool {

for _, d := range spec.Devices {
// The v0.5.0 spec allowed device names to start with a digit instead of requiring a letter
if len(d.Name) > 0 && !IsLetter(rune(d.Name[0])) {
if len(d.Name) > 0 && !isLetter(rune(d.Name[0])) {
return true
}
edits = append(edits, &d.ContainerEdits)
Expand Down

0 comments on commit b1e626c

Please sign in to comment.