summaryrefslogtreecommitdiff
path: root/vendor/github.com/containernetworking/cni/pkg/version
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/containernetworking/cni/pkg/version')
-rw-r--r--vendor/github.com/containernetworking/cni/pkg/version/conf.go37
-rw-r--r--vendor/github.com/containernetworking/cni/pkg/version/plugin.go144
-rw-r--r--vendor/github.com/containernetworking/cni/pkg/version/reconcile.go49
-rw-r--r--vendor/github.com/containernetworking/cni/pkg/version/version.go83
4 files changed, 0 insertions, 313 deletions
diff --git a/vendor/github.com/containernetworking/cni/pkg/version/conf.go b/vendor/github.com/containernetworking/cni/pkg/version/conf.go
deleted file mode 100644
index 3cca58b..0000000
--- a/vendor/github.com/containernetworking/cni/pkg/version/conf.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2016 CNI authors
-//
-// Licensed 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.
-
-package version
-
-import (
- "encoding/json"
- "fmt"
-)
-
-// ConfigDecoder can decode the CNI version available in network config data
-type ConfigDecoder struct{}
-
-func (*ConfigDecoder) Decode(jsonBytes []byte) (string, error) {
- var conf struct {
- CNIVersion string `json:"cniVersion"`
- }
- err := json.Unmarshal(jsonBytes, &conf)
- if err != nil {
- return "", fmt.Errorf("decoding version from network config: %s", err)
- }
- if conf.CNIVersion == "" {
- return "0.1.0", nil
- }
- return conf.CNIVersion, nil
-}
diff --git a/vendor/github.com/containernetworking/cni/pkg/version/plugin.go b/vendor/github.com/containernetworking/cni/pkg/version/plugin.go
deleted file mode 100644
index 1df4272..0000000
--- a/vendor/github.com/containernetworking/cni/pkg/version/plugin.go
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2016 CNI authors
-//
-// Licensed 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.
-
-package version
-
-import (
- "encoding/json"
- "fmt"
- "io"
- "strconv"
- "strings"
-)
-
-// PluginInfo reports information about CNI versioning
-type PluginInfo interface {
- // SupportedVersions returns one or more CNI spec versions that the plugin
- // supports. If input is provided in one of these versions, then the plugin
- // promises to use the same CNI version in its response
- SupportedVersions() []string
-
- // Encode writes this CNI version information as JSON to the given Writer
- Encode(io.Writer) error
-}
-
-type pluginInfo struct {
- CNIVersion_ string `json:"cniVersion"`
- SupportedVersions_ []string `json:"supportedVersions,omitempty"`
-}
-
-// pluginInfo implements the PluginInfo interface
-var _ PluginInfo = &pluginInfo{}
-
-func (p *pluginInfo) Encode(w io.Writer) error {
- return json.NewEncoder(w).Encode(p)
-}
-
-func (p *pluginInfo) SupportedVersions() []string {
- return p.SupportedVersions_
-}
-
-// PluginSupports returns a new PluginInfo that will report the given versions
-// as supported
-func PluginSupports(supportedVersions ...string) PluginInfo {
- if len(supportedVersions) < 1 {
- panic("programmer error: you must support at least one version")
- }
- return &pluginInfo{
- CNIVersion_: Current(),
- SupportedVersions_: supportedVersions,
- }
-}
-
-// PluginDecoder can decode the response returned by a plugin's VERSION command
-type PluginDecoder struct{}
-
-func (*PluginDecoder) Decode(jsonBytes []byte) (PluginInfo, error) {
- var info pluginInfo
- err := json.Unmarshal(jsonBytes, &info)
- if err != nil {
- return nil, fmt.Errorf("decoding version info: %s", err)
- }
- if info.CNIVersion_ == "" {
- return nil, fmt.Errorf("decoding version info: missing field cniVersion")
- }
- if len(info.SupportedVersions_) == 0 {
- if info.CNIVersion_ == "0.2.0" {
- return PluginSupports("0.1.0", "0.2.0"), nil
- }
- return nil, fmt.Errorf("decoding version info: missing field supportedVersions")
- }
- return &info, nil
-}
-
-// ParseVersion parses a version string like "3.0.1" or "0.4.5" into major,
-// minor, and micro numbers or returns an error
-func ParseVersion(version string) (int, int, int, error) {
- var major, minor, micro int
- if version == "" {
- return -1, -1, -1, fmt.Errorf("invalid version %q: the version is empty", version)
- }
-
- parts := strings.Split(version, ".")
- if len(parts) >= 4 {
- return -1, -1, -1, fmt.Errorf("invalid version %q: too many parts", version)
- }
-
- major, err := strconv.Atoi(parts[0])
- if err != nil {
- return -1, -1, -1, fmt.Errorf("failed to convert major version part %q: %v", parts[0], err)
- }
-
- if len(parts) >= 2 {
- minor, err = strconv.Atoi(parts[1])
- if err != nil {
- return -1, -1, -1, fmt.Errorf("failed to convert minor version part %q: %v", parts[1], err)
- }
- }
-
- if len(parts) >= 3 {
- micro, err = strconv.Atoi(parts[2])
- if err != nil {
- return -1, -1, -1, fmt.Errorf("failed to convert micro version part %q: %v", parts[2], err)
- }
- }
-
- return major, minor, micro, nil
-}
-
-// GreaterThanOrEqualTo takes two string versions, parses them into major/minor/micro
-// numbers, and compares them to determine whether the first version is greater
-// than or equal to the second
-func GreaterThanOrEqualTo(version, otherVersion string) (bool, error) {
- firstMajor, firstMinor, firstMicro, err := ParseVersion(version)
- if err != nil {
- return false, err
- }
-
- secondMajor, secondMinor, secondMicro, err := ParseVersion(otherVersion)
- if err != nil {
- return false, err
- }
-
- if firstMajor > secondMajor {
- return true, nil
- } else if firstMajor == secondMajor {
- if firstMinor > secondMinor {
- return true, nil
- } else if firstMinor == secondMinor && firstMicro >= secondMicro {
- return true, nil
- }
- }
- return false, nil
-}
diff --git a/vendor/github.com/containernetworking/cni/pkg/version/reconcile.go b/vendor/github.com/containernetworking/cni/pkg/version/reconcile.go
deleted file mode 100644
index 25c3810..0000000
--- a/vendor/github.com/containernetworking/cni/pkg/version/reconcile.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2016 CNI authors
-//
-// Licensed 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.
-
-package version
-
-import "fmt"
-
-type ErrorIncompatible struct {
- Config string
- Supported []string
-}
-
-func (e *ErrorIncompatible) Details() string {
- return fmt.Sprintf("config is %q, plugin supports %q", e.Config, e.Supported)
-}
-
-func (e *ErrorIncompatible) Error() string {
- return fmt.Sprintf("incompatible CNI versions: %s", e.Details())
-}
-
-type Reconciler struct{}
-
-func (r *Reconciler) Check(configVersion string, pluginInfo PluginInfo) *ErrorIncompatible {
- return r.CheckRaw(configVersion, pluginInfo.SupportedVersions())
-}
-
-func (*Reconciler) CheckRaw(configVersion string, supportedVersions []string) *ErrorIncompatible {
- for _, supportedVersion := range supportedVersions {
- if configVersion == supportedVersion {
- return nil
- }
- }
-
- return &ErrorIncompatible{
- Config: configVersion,
- Supported: supportedVersions,
- }
-}
diff --git a/vendor/github.com/containernetworking/cni/pkg/version/version.go b/vendor/github.com/containernetworking/cni/pkg/version/version.go
deleted file mode 100644
index 8f3508e..0000000
--- a/vendor/github.com/containernetworking/cni/pkg/version/version.go
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2016 CNI authors
-//
-// Licensed 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.
-
-package version
-
-import (
- "encoding/json"
- "fmt"
-
- "github.com/containernetworking/cni/pkg/types"
- "github.com/containernetworking/cni/pkg/types/020"
- "github.com/containernetworking/cni/pkg/types/current"
-)
-
-// Current reports the version of the CNI spec implemented by this library
-func Current() string {
- return "0.4.0"
-}
-
-// Legacy PluginInfo describes a plugin that is backwards compatible with the
-// CNI spec version 0.1.0. In particular, a runtime compiled against the 0.1.0
-// library ought to work correctly with a plugin that reports support for
-// Legacy versions.
-//
-// Any future CNI spec versions which meet this definition should be added to
-// this list.
-var Legacy = PluginSupports("0.1.0", "0.2.0")
-var All = PluginSupports("0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0")
-
-var resultFactories = []struct {
- supportedVersions []string
- newResult types.ResultFactoryFunc
-}{
- {current.SupportedVersions, current.NewResult},
- {types020.SupportedVersions, types020.NewResult},
-}
-
-// Finds a Result object matching the requested version (if any) and asks
-// that object to parse the plugin result, returning an error if parsing failed.
-func NewResult(version string, resultBytes []byte) (types.Result, error) {
- reconciler := &Reconciler{}
- for _, resultFactory := range resultFactories {
- err := reconciler.CheckRaw(version, resultFactory.supportedVersions)
- if err == nil {
- // Result supports this version
- return resultFactory.newResult(resultBytes)
- }
- }
-
- return nil, fmt.Errorf("unsupported CNI result version %q", version)
-}
-
-// ParsePrevResult parses a prevResult in a NetConf structure and sets
-// the NetConf's PrevResult member to the parsed Result object.
-func ParsePrevResult(conf *types.NetConf) error {
- if conf.RawPrevResult == nil {
- return nil
- }
-
- resultBytes, err := json.Marshal(conf.RawPrevResult)
- if err != nil {
- return fmt.Errorf("could not serialize prevResult: %v", err)
- }
-
- conf.RawPrevResult = nil
- conf.PrevResult, err = NewResult(conf.CNIVersion, resultBytes)
- if err != nil {
- return fmt.Errorf("could not parse prevResult: %v", err)
- }
-
- return nil
-}