// ParseMinVersion parses the specified minimum TLS version for the Nomad agent
170765
func ParseMinVersion(version string) (uint16, error) {
	if version == "" {
		return supportedTLSVersions["tls12"], nil
	}

	vers, ok := supportedTLSVersions[version]
	if !ok {
		return 0, fmt.Errorf("unsupported TLS version %q", version)
	}

	return vers, nil
}
1061706
func ParseVersion(s string) (*Version, error) {
	parts := strings.Split(s, ".")
	if len(parts) != 2 {
		return &NullVersion, fmt.Errorf("incorrect number of version components, could not parse '%s'", s)
	}

	scalar, err := strconv.ParseUint(parts[0], 10, 64)
	if err != nil {
		return &NullVersion, fmt.Errorf("could not parse scalar component: '%s'", parts[0])
	}

	pid, err := strconv.ParseUint(parts[1], 10, 16)
	if err != nil {
		return &NullVersion, fmt.Errorf("could not parse pid component: '%s'", parts[1])
	}

	return &Version{scalar, uint16(pid)}, nil
}
98945
func (c *Client) AgentVersion() (params.AgentVersionResult, error) {
	if err := c.checkCanRead(); err != nil {
		return params.AgentVersionResult{}, err
	}

	return params.AgentVersionResult{Version: jujuversion.Current}, nil
}
220832
func (r *Repo) findMinVersion(ctx context.Context, id uuid.UUID, minVersion int) (eh.Entity, error) {
	entity, err := r.ReadWriteRepo.Find(ctx, id)
	if err != nil {
		return nil, err
	}

	versionable, ok := entity.(eh.Versionable)
	if !ok {
		return nil, eh.RepoError{
			Err:       eh.ErrEntityHasNoVersion,
			Namespace: eh.NamespaceFromContext(ctx),
		}
	}

	if versionable.AggregateVersion() < minVersion {
		return nil, eh.RepoError{
			Err:       eh.ErrIncorrectEntityVersion,
			Namespace: eh.NamespaceFromContext(ctx),
		}
	}

	return entity, nil
}
921217
func (cli *Client) ServerVersion(ctx context.Context) (types.Version, error) {
	resp, err := cli.get(ctx, "/version", nil, nil)
	defer ensureReaderClosed(resp)
	if err != nil {
		return types.Version{}, err
	}

	var server types.Version
	err = json.NewDecoder(resp.body).Decode(&server)
	return server, err
}
1027375
func (d *DiscoveryClient) ServerVersion() (*version.Info, error) {
	body, err := d.restClient.Get().AbsPath("/version").Do().Raw()
	if err != nil {
		return nil, err
	}
	var info version.Info
	err = json.Unmarshal(body, &info)
	if err != nil {
		return nil, fmt.Errorf("unable to parse the server version: %v", err)
	}
	return &info, nil
}
726428
func parseToolVersion(version string) toolVersion {
	match := goVersionPattern.FindStringSubmatch(version)
	if len(match) > 2 {
		// After a successful match, match[1] and match[2] are integers
		major := mustAtoi(match[1])
		minor := mustAtoi(match[2])
		return toolVersion(major*10 + minor)
	}
	return toolVersionUnknown
}
852012
func (c *Client) DaemonVersion() (string, error) {
	resp, err := c.rpc("daemon.info", rencode.List{}, rencode.Dictionary{})
	if err != nil {
		return "", err
	}
	if resp.IsError() {
		return "", resp.RPCError
	}

	var info string
	err = resp.returnValue.Scan(&info)
	if err != nil {
		return "", err
	}

	return info, nil
}
1203513
func ToParamWithVersion(version string, a Args) (string, error) {
	// this way we don't URL encode {}, just empty space
	if a.Len() == 0 {
		return "", nil
	}

	// for daemons older than v1.10, filter must be of the form map[string][]string
	buf := []byte{}
	err := errors.New("")
	if version != "" && versions.LessThan(version, "1.22") {
		buf, err = json.Marshal(convertArgsToSlice(a.fields))
	} else {
		buf, err = json.Marshal(a.fields)
	}
	if err != nil {
		return "", err
	}
	return string(buf), nil
}
745257
func (s *Server) Version(context.Context, *empty.Empty) (*VersionMessage, error) {
	vers := argocd.GetVersion()
	ksonnetVersion, err := ksutil.KsonnetVersion()
	if err != nil {
		return nil, err
	}
	return &VersionMessage{
		Version:        vers.Version,
		BuildDate:      vers.BuildDate,
		GitCommit:      vers.GitCommit,
		GitTag:         vers.GitTag,
		GitTreeState:   vers.GitTreeState,
		GoVersion:      vers.GoVersion,
		Compiler:       vers.Compiler,
		Platform:       vers.Platform,
		KsonnetVersion: ksonnetVersion,
	}, nil
}
1326203
func newVersionInconsistentError(currentVersion version.Number, agents []string) *versionInconsistentError {
	return &versionInconsistentError{currentVersion, agents}
}
736218
func ParseVersionStr(ver string) (*Semver, error) {
	var v, m, p int
	var err error

	// If this matches a string, there will be 3 submatches in addition to the
	// matched string in the result of FindStringSubmatch. Otherwise, there will
	// result will be an empty slice.
	re := regexp.MustCompile(`^v?(\d+)\.?(\d*)\.?(\d*)$`)
	subs := re.FindStringSubmatch(ver)
	if len(subs) != 4 {
		return nil, fmt.Errorf("invalid version string")
	}

	// Matched the string and captured 3 substrings. Parse each substring, some
	// of which may be empty. Empty substrings are treated as a 0.

	// patch
	if len(subs[3]) > 0 {
		p, err = strconv.Atoi(subs[3])
		if err != nil {
			return nil, err
		}
	}

	// minor
	if len(subs[2]) > 0 {
		m, err = strconv.Atoi(subs[2])
		if err != nil {
			return nil, err
		}
	}

	// major
	if len(subs[1]) > 0 {
		v, err = strconv.Atoi(subs[1])
		if err != nil {
			return nil, err
		}
	}

	s := NewSemver(uint32(v), uint32(m), uint32(p))
	return &s, nil
}
468250
func serverVersion(db *sql.DB) ([]int, error) {
	versionRx := regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)-.*`)
	var version string
	if err := db.QueryRow("SELECT VERSION()").Scan(&version); err != nil {
		return nil, fmt.Errorf("error getting MySQL server version: %v", err)
	}
	m := versionRx.FindStringSubmatch(version)
	if len(m) < 4 {
		return nil, fmt.Errorf("bogus MySQL server version: %v", version)
	}
	major, _ := strconv.Atoi(m[1])
	minor, _ := strconv.Atoi(m[2])
	rev, _ := strconv.Atoi(m[3])
	return []int{major, minor, rev}, nil
}
309350
func (c *Config) AgentVersion() (version.Number, bool) {
	if v, ok := c.defined[AgentVersionKey].(string); ok {
		n, err := version.Parse(v)
		if err != nil {
			panic(err) // We should have checked it earlier.
		}
		return n, true
	}
	return version.Zero, false
}
1030403
func IsMissingVersion(err error) bool {
	if err == nil {
		return false
	}
	_, ok := err.(*missingVersionErr)
	return ok
}
213075
func CheckVersion(minVersion []int) Check {
	return func() error {
		cli, err := newClient()
		if err != nil {
			return fmt.Errorf("creating client: %v", err)
		}
		v, err := cli.Version()
		if err != nil {
			return fmt.Errorf("getting version: %v", err)
		}
		return versionAtLeast(v.Version, minVersion)
	}
}
823309
func ParseKubernetesVersion(version string) (semver.Version, error) {
	// Strip leading 'v' prefix from version for semver parsing
	v, err := semver.Make(version[1:])
	if err != nil {
		return semver.Version{}, errors.Wrap(err, "invalid version, must begin with 'v'")
	}

	return v, nil
}