Ejemplo n.º 1
0
// GetUpdatePackage returns an update package for the instance/application
// provided. The instance details and the application it's running will be
// registered in CoreRoller (or updated if it's already registered).
func (api *API) GetUpdatePackage(instanceID, instanceIP, instanceVersion, appID, groupID string) (*Package, error) {
	instance, err := api.RegisterInstance(instanceID, instanceIP, instanceVersion, appID, groupID)
	if err != nil {
		return nil, ErrRegisterInstanceFailed
	}

	if instance.Application.Status.Valid {
		switch int(instance.Application.Status.Int64) {
		case InstanceStatusUpdateGranted, InstanceStatusDownloading, InstanceStatusDownloaded, InstanceStatusInstalled:
			return nil, ErrUpdateInProgressOnInstance
		}
	}

	group, err := api.GetGroup(groupID)
	if err != nil {
		return nil, err
	}

	if group.Channel == nil || group.Channel.Package == nil {
		_ = api.newGroupActivityEntry(activityPackageNotFound, activityWarning, "0.0.0", appID, groupID)
		return nil, ErrNoPackageFound
	}

	for _, blacklistedChannelID := range group.Channel.Package.ChannelsBlacklist {
		if blacklistedChannelID == group.Channel.ID {
			return nil, ErrNoUpdatePackageAvailable
		}
	}

	instanceSemver, _ := semver.Make(instanceVersion)
	packageSemver, _ := semver.Make(group.Channel.Package.Version)
	if !instanceSemver.LT(packageSemver) {
		return nil, ErrNoUpdatePackageAvailable
	}

	updatesStats, err := api.getGroupUpdatesStats(group)
	if err != nil {
		return nil, ErrGetUpdatesStatsFailed
	}

	if err := api.enforceRolloutPolicy(instance, group, updatesStats); err != nil {
		return nil, err
	}

	if err := api.grantUpdate(instance.ID, appID, group.Channel.Package.Version); err != nil {
		return nil, ErrGrantingUpdate
	}

	if updatesStats.UpdatesToCurrentVersionGranted == 0 {
		_ = api.newGroupActivityEntry(activityRolloutStarted, activityInfo, group.Channel.Package.Version, appID, group.ID)
	}

	if !group.RolloutInProgress {
		_ = api.setGroupRolloutInProgress(groupID, true)
	}

	_ = api.updateInstanceStatus(instance.ID, appID, InstanceStatusUpdateGranted)

	return group.Channel.Package, nil
}
Ejemplo n.º 2
0
func isUpgradeAvailable() (bool, string) {
	gh := buildGithubClient()
	release, response, err := gh.Repositories.GetLatestRelease("getcarina", "dvm")
	if err != nil {
		warnWhenRateLimitExceeded(err, response)
		writeWarning("Unable to query the latest dvm release from GitHub:")
		writeWarning("%s", err)
		return false, ""
	}
	if response.StatusCode != 200 {
		writeWarning("Unable to query the latest dvm release from GitHub (Status %s):", response.StatusCode)
		return false, ""
	}

	currentVersion, err := semver.Make(dvmVersion)
	if err != nil {
		writeWarning("Unable to parse the current dvm version as a semantic version!")
		writeWarning("%s", err)
		return false, ""
	}
	latestVersion, err := semver.Make(*release.TagName)
	if err != nil {
		writeWarning("Unable to parse the latest dvm version as a semantic version!")
		writeWarning("%s", err)
		return false, ""
	}

	return latestVersion.Compare(currentVersion) > 0, *release.TagName
}
Ejemplo n.º 3
0
func (a BugListByMilestone) Less(i, j int) bool {
	iMS := a[i].Milestone()
	jMS := a[j].Milestone()
	// If there's a "v" at the start, strip it out
	// before doing any comparisons of semantic
	// versions
	if len(iMS) > 1 && iMS[0] == "v"[0] {
		iMS = iMS[1:]
	}
	if len(jMS) > 1 && jMS[0] == "v"[0] {
		jMS = jMS[1:]
	}
	// First try semantic versioning comparison
	iVer, iVerErr := semver.Make(iMS)
	jVer, jVerErr := semver.Make(jMS)
	if iVerErr == nil && jVerErr == nil {
		return iVer.LT(jVer)
	}

	// Next try floating point comparison as an
	// approximation of real number comparison..
	iFloat, iVerErr := strconv.ParseFloat(iMS, 32)
	jFloat, jVerErr := strconv.ParseFloat(jMS, 32)
	if iVerErr == nil && jVerErr == nil {
		return iFloat < jFloat
	}

	// Finally, just use a normal string collation
	return iMS < jMS
}
Ejemplo n.º 4
0
func latestTag(client *github.Client, org, name string) string {
	opt := &github.ListOptions{PerPage: 100}

	latest, err := semver.Make("0.0.1")
	if err != nil {
		panic(err)
	}

	for {
		newTags, resp, err := client.Repositories.ListTags(org, name, opt)
		if err != nil {
			panic(err)
		}

		for _, tag := range newTags {
			version, err := semver.Make(*tag.Name)
			if err != nil {
				continue
			}

			if version.Compare(latest) > 0 {
				latest = version
			}
		}

		if resp.NextPage == 0 {
			break
		}

		opt.Page = resp.NextPage
	}

	return latest.String()
}
Ejemplo n.º 5
0
func greater(s1, s2 string) bool {
	v1, err1 := semver.Make(s1)
	v2, err2 := semver.Make(s2)
	if err1 != nil || err2 != nil {
		return s1 > s2
	}
	return v1.Compare(v2) > 0
}
Ejemplo n.º 6
0
// @return result.Result<VersionStatus, error>
func compareVersion(toolVersion, repoVersion string) result.Result {
	errorMsg := fmt.Sprintf(toolInvalidError, toolVersion, repoVersion)
	invalidErr := result.NewFailure(errors.New(errorMsg))
	vt := result.NewResult(semver.Make(toolVersion)).RecoverWith(invalidErr)
	vr := result.NewResult(semver.Make(repoVersion)).RecoverWith(invalidErr)
	return result.Combine(func(values ...interface{}) result.Result {
		vt, vr := values[0].(semver.Version), values[1].(semver.Version)
		return comparisonStatus(vt.Compare(vr))
	}, vt, vr)
}
func (m *Manifest) getLatestVersion() string {
	latestVersion, _ := semver.Make(NoVersion)

	for _, version := range m.Versions {
		if currentVersion, err := semver.Make(version.Version); err != nil {
			continue
		} else if latestVersion.LT(currentVersion) {
			latestVersion = currentVersion
		}
	}

	return latestVersion.String()
}
Ejemplo n.º 8
0
func updateSelf() error {
	up := update.New()
	if err := up.CanUpdate(); err != nil {
		logger.Warn("msg", "Can't update this binary!", "error", err)
		return err
	}

	up, err := up.VerifySignatureWithPEM([]byte(publicKey))
	if err != nil {
		logger.Error("msg", "Failed to parse public key!", "error", err)
		return err
	}
	// check for the update
	r, err := (&check.Params{
		AppId:      "ap_XZ-6toIU_0Bf0BJFDVvDpV9IVD",
		AppVersion: version,
		Channel:    "latest",
	}).CheckForUpdate(updateURI, up)
	if err != nil {
		if err == check.NoUpdateAvailable {
			logger.Info("msg", "No update available.")
			return nil
		}
		logger.Error("msg", "Checking for update", "error", err)
		return err
	}
	v1, err := semver.Make(version)
	if err != nil {
		logger.Error("msg", "Bad version", "current", version, "error", err)
		return err
	}
	v2, err := semver.Make(r.Version)
	if err != nil {
		logger.Error("msg", "Bad version", "new", r.Version, "error", err)
		return err
	}
	if !v2.GTE(v1) {
		logger.Warn("msg", "Version mismatch", "current", v1, "new", v2)
		return nil
	}

	// apply the update
	if err, _ = r.Update(); err != nil {
		logger.Error("msg", "Update failed", "error", err)
		return err
	}
	logger.Info("msg", "Update successful, exiting.")
	os.Exit(0)
	return nil
}
Ejemplo n.º 9
0
func (cmd *CliRpcCmd) IsMinCliVersion(version string, retVal *bool) error {
	actualVersion, err := semver.Make(cf.Version)
	if err != nil {
		return err
	}

	requiredVersion, err := semver.Make(version)
	if err != nil {
		return err
	}

	*retVal = actualVersion.GTE(requiredVersion)

	return nil
}
Ejemplo n.º 10
0
func IsMountainLion() bool {
	osver, err := semver.Make(OSRelease())
	if err != nil {
		return false
	}
	return runtime.GOOS == "darwin" && osver.GTE(mountainLionVer)
}
Ejemplo n.º 11
0
func (cmd *UnbindRouteService) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) []requirements.Requirement {
	if len(fc.Args()) != 2 {
		cmd.ui.Failed(T("Incorrect Usage. Requires DOMAIN and SERVICE_INSTANCE as arguments\n\n") + commandregistry.Commands.CommandUsage("unbind-route-service"))
	}

	serviceName := fc.Args()[1]
	cmd.serviceInstanceReq = requirementsFactory.NewServiceInstanceRequirement(serviceName)

	domainName := fc.Args()[0]
	cmd.domainReq = requirementsFactory.NewDomainRequirement(domainName)

	minAPIVersion, err := semver.Make("2.51.0")
	if err != nil {
		panic(err.Error())
	}

	minAPIVersionRequirement := requirementsFactory.NewMinAPIVersionRequirement(
		"unbind-route-service",
		minAPIVersion,
	)

	reqs := []requirements.Requirement{
		minAPIVersionRequirement,
		requirementsFactory.NewLoginRequirement(),
		cmd.domainReq,
		cmd.serviceInstanceReq,
	}
	return reqs
}
Ejemplo n.º 12
0
func IsWin8() bool {
	osver, err := semver.Make(OSRelease())
	if err != nil {
		return false
	}
	return runtime.GOOS == "windows" && osver.GTE(win8ver)
}
func (m *Manifest) getNextVersion() string {
	latestVersion, _ := semver.Make(m.getLatestVersion())
	latestVersion.Minor++
	latestVersion.Patch = 0

	return latestVersion.String()
}
Ejemplo n.º 14
0
func getLatestVersionFromURL(url string) (semver.Version, error) {
	r, err := GetAllVersionsFromURL(url)
	if err != nil {
		return semver.Version{}, err
	}
	return semver.Make(strings.TrimPrefix(r[0].Name, version.VersionPrefix))
}
Ejemplo n.º 15
0
func (r MaxAPIVersionRequirement) Execute() bool {
	if r.config.ApiVersion() == "" {
		r.ui.Failed(T("Unable to determine CC API Version. Please log in again."))
	}

	apiVersion, err := semver.Make(r.config.ApiVersion())
	if err != nil {
		r.ui.Failed(T("Unable to parse CC API Version '{{.APIVersion}}'", map[string]interface{}{
			"APIVersion": r.config.ApiVersion(),
		}))

		return false
	}

	if apiVersion.GT(r.maximumVersion) {
		r.ui.Failed(T(`{{.Feature}} only works up to CF API version {{.MaximumVersion}}. Your target is {{.ApiVersion}}.`,
			map[string]interface{}{
				"ApiVersion":     r.config.ApiVersion(),
				"Feature":        r.feature,
				"MaximumVersion": r.maximumVersion.String(),
			}))

		return false
	}

	return true
}
func (cmd *UnmapRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) []requirements.Requirement {
	if len(fc.Args()) != 2 {
		cmd.ui.Failed(T("Incorrect Usage. Requires app_name, domain_name as arguments\n\n") + command_registry.Commands.CommandUsage("unmap-route"))
	}

	domainName := fc.Args()[1]

	cmd.appReq = requirementsFactory.NewApplicationRequirement(fc.Args()[0])
	cmd.domainReq = requirementsFactory.NewDomainRequirement(domainName)

	requiredVersion, err := semver.Make("2.36.0")
	if err != nil {
		panic(err.Error())
	}

	var reqs []requirements.Requirement

	if fc.String("path") != "" {
		reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--path'", requiredVersion))
	}

	reqs = append(reqs, []requirements.Requirement{
		requirementsFactory.NewLoginRequirement(),
		cmd.appReq,
		cmd.domainReq,
	}...)

	return reqs
}
Ejemplo n.º 17
0
func (r MinAPIVersionRequirement) Execute() bool {
	if r.config.ApiVersion() == "" {
		r.ui.Failed(T("Unable to determine CC API Version. Please log in again."))
	}

	apiVersion, err := semver.Make(r.config.ApiVersion())
	if err != nil {
		r.ui.Failed(T("Unable to parse CC API Version '{{.APIVersion}}'", map[string]interface{}{
			"APIVersion": r.config.ApiVersion(),
		}))
	}

	if apiVersion.LT(r.requiredVersion) {
		r.ui.Failed(T(`Current CF CLI version {{.Version}}
	Current CF API version {{.ApiVersion}}
	To use the {{.CommandName}} feature, you need to upgrade the CF API to at least {{.RequiredVersion}}`,
			map[string]interface{}{
				"Version":         cf.Version,
				"ApiVersion":      r.config.ApiVersion(),
				"CommandName":     r.commandName,
				"RequiredVersion": r.requiredVersion.String(),
			}))
	}

	return true
}
Ejemplo n.º 18
0
func (cmd *DeleteRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) []requirements.Requirement {
	if len(fc.Args()) != 1 {
		cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("delete-route"))
	}

	if fc.IsSet("port") && (fc.IsSet("hostname") || fc.IsSet("path")) {
		cmd.ui.Failed(T("Cannot specify port together with hostname and/or path."))
	}

	cmd.domainReq = requirementsFactory.NewDomainRequirement(fc.Args()[0])

	requiredVersion, err := semver.Make("2.36.0")
	if err != nil {
		panic(err.Error())
	}

	var reqs []requirements.Requirement

	if fc.String("path") != "" {
		reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--path'", requiredVersion))
	}

	if fc.IsSet("port") {
		reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--port'", cf.TCPRoutingMinimumAPIVersion))
	}

	reqs = append(reqs, []requirements.Requirement{
		requirementsFactory.NewLoginRequirement(),
		cmd.domainReq,
	}...)

	return reqs
}
Ejemplo n.º 19
0
func (c *ConfigRepository) IsMinApiVersion(version string) bool {
	var apiVersion string
	c.read(func() {
		apiVersion = c.data.ApiVersion
	})

	requiredVersion, err := semver.Make(version)
	if err != nil {
		return false
	}
	actualVersion, err := semver.Make(apiVersion)
	if err != nil {
		return false
	}
	return actualVersion.GTE(requiredVersion)
}
Ejemplo n.º 20
0
func (cmd *CreateRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
	if len(fc.Args()) != 2 {
		cmd.ui.Failed(T("Incorrect Usage. Requires SPACE and DOMAIN as arguments\n\n") + command_registry.Commands.CommandUsage("create-route"))
	}

	domainName := fc.Args()[1]

	cmd.spaceReq = requirementsFactory.NewSpaceRequirement(fc.Args()[0])
	cmd.domainReq = requirementsFactory.NewDomainRequirement(domainName)

	requiredVersion, err := semver.Make("2.36.0")
	if err != nil {
		panic(err.Error())
	}

	var reqs []requirements.Requirement

	if fc.String("path") != "" {
		reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--path'", requiredVersion))
	}

	reqs = append(reqs, []requirements.Requirement{
		requirementsFactory.NewLoginRequirement(),
		requirementsFactory.NewTargetedOrgRequirement(),
		cmd.spaceReq,
		cmd.domainReq,
	}...)

	return reqs, nil
}
Ejemplo n.º 21
0
func verifyEndpoint(e endpoint.Endpoint) error {
	version, err := e.Version()
	if err != nil {
		return err
	}

	log.Infof("%s reported version %s", e.Name(), version)

	isSwarm := false
	if strings.HasPrefix(version, "swarm/") {
		isSwarm = true
		parts := strings.Split(version, "/")
		version = parts[1]
	}

	semver, err := semver.Make(version)
	if err != nil {
		return fmt.Errorf("can't understand version '%s'", version)
	}

	if isSwarm && semver.LT(RequiredSwarmAPIVersion) {
		return fmt.Errorf("Swarm API must be %s or above, but it is %s", RequiredSwarmAPIVersion, semver)
	}

	if !isSwarm && semver.LT(RequiredDockerAPIVersion) {
		return fmt.Errorf("Docker API must be %s or above, but it is %s", RequiredDockerAPIVersion, semver)
	}

	return nil
}
Ejemplo n.º 22
0
// borrowed from minishift until it supports install / download binaries
func getLatestVersionFromGitHub(githubOwner, githubRepo string) (semver.Version, error) {
	if githubClient == nil {
		token := os.Getenv("GH_TOKEN")
		var tc *http.Client
		if len(token) > 0 {
			ts := oauth2.StaticTokenSource(
				&oauth2.Token{AccessToken: token},
			)
			tc = oauth2.NewClient(oauth2.NoContext, ts)
		}
		githubClient = github.NewClient(tc)
	}
	client := githubClient
	var (
		release *github.RepositoryRelease
		resp    *github.Response
		err     error
	)
	release, resp, err = client.Repositories.GetLatestRelease(githubOwner, githubRepo)
	if err != nil {
		return semver.Version{}, err
	}
	defer resp.Body.Close()
	latestVersionString := release.TagName
	if latestVersionString != nil {
		return semver.Make(strings.TrimPrefix(*latestVersionString, "v"))

	}
	return semver.Version{}, fmt.Errorf("Cannot get release name")
}
Ejemplo n.º 23
0
func (cmd *DeleteRoute) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) {
	if len(fc.Args()) != 1 {
		cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + command_registry.Commands.CommandUsage("delete-route"))
	}

	cmd.domainReq = requirementsFactory.NewDomainRequirement(fc.Args()[0])

	requiredVersion, err := semver.Make("2.36.0")
	if err != nil {
		panic(err.Error())
	}

	var reqs []requirements.Requirement

	if fc.String("path") != "" {
		reqs = append(reqs, requirementsFactory.NewMinAPIVersionRequirement("Option '--path'", requiredVersion))
	}

	reqs = append(reqs, []requirements.Requirement{
		requirementsFactory.NewLoginRequirement(),
		cmd.domainReq,
	}...)

	return reqs, nil
}
Ejemplo n.º 24
0
func ResolveInstallStatus(version string, bundleVersion string, lastExitStatus string) (installStatus keybase1.InstallStatus, installAction keybase1.InstallAction, status keybase1.Status) {
	installStatus = keybase1.InstallStatus_UNKNOWN
	installAction = keybase1.InstallAction_UNKNOWN
	if version != "" && bundleVersion != "" {
		sv, err := semver.Make(version)
		if err != nil {
			installStatus = keybase1.InstallStatus_ERROR
			installAction = keybase1.InstallAction_REINSTALL
			status = keybase1.StatusFromCode(keybase1.StatusCode_SCInvalidVersionError, err.Error())
			return
		}
		bsv, err := semver.Make(bundleVersion)
		// Invalid bundle bersion
		if err != nil {
			installStatus = keybase1.InstallStatus_ERROR
			installAction = keybase1.InstallAction_NONE
			status = keybase1.StatusFromCode(keybase1.StatusCode_SCInvalidVersionError, err.Error())
			return
		}
		if bsv.GT(sv) {
			installStatus = keybase1.InstallStatus_INSTALLED
			installAction = keybase1.InstallAction_UPGRADE
		} else if bsv.EQ(sv) {
			installStatus = keybase1.InstallStatus_INSTALLED
			installAction = keybase1.InstallAction_NONE
		} else if bsv.LT(sv) {
			installStatus = keybase1.InstallStatus_ERROR
			installAction = keybase1.InstallAction_NONE
			status = keybase1.StatusFromCode(keybase1.StatusCode_SCOldVersionError, fmt.Sprintf("Bundle version (%s) is less than installed version (%s)", bundleVersion, version))
			return
		}
	} else if version != "" && bundleVersion == "" {
		installStatus = keybase1.InstallStatus_INSTALLED
	} else if version == "" && bundleVersion != "" {
		installStatus = keybase1.InstallStatus_NOT_INSTALLED
		installAction = keybase1.InstallAction_INSTALL
	}

	// If we have an unknown install status, then let's try to re-install.
	if bundleVersion != "" && installStatus == keybase1.InstallStatus_UNKNOWN && (version != "" || lastExitStatus != "") {
		installAction = keybase1.InstallAction_REINSTALL
		installStatus = keybase1.InstallStatus_INSTALLED
	}

	status = keybase1.StatusOK("")
	return
}
Ejemplo n.º 25
0
func getDockerStartOpt(dockerBinPath, keyFilePath, certFilePath, caFilePath string) []string {
	ver := getDockerClientVersion(dockerBinPath)
	v, err := semver.Make(ver)
	if err != nil {
		Logger.Println("Cannot get semantic version of", ver)
	}
	v1_7, err := semver.Make("1.7.0")
	v1_8, err := semver.Make("1.8.0")

	daemonOpt := "daemon"
	if v.LT(v1_8) {
		daemonOpt = "-d"
	}

	userlandProxyOpt := ""
	if v.GTE(v1_7) {
		userlandProxyOpt = " --userland-proxy=false"
	}

	debugOpt := ""
	if *FlagDebugMode {
		debugOpt = " -D"
	}

	bindOpt := fmt.Sprintf(" -H %s -H %s", DockerDefaultHost, Conf.DockerHost)

	var certOpt string
	if *FlagStandalone && !utils.FileExist(caFilePath) {
		certOpt = fmt.Sprintf(" --tlscert %s --tlskey %s --tls", certFilePath, keyFilePath)
		fmt.Fprintln(os.Stderr, "WARNING: standalone mode activated but no CA certificate found - client authentication disabled")
	} else {
		certOpt = fmt.Sprintf(" --tlscert %s --tlskey %s --tlscacert %s --tlsverify", certFilePath, keyFilePath, caFilePath)
	}

	extraOpt := ""
	if Conf.DockerOpts != "" {
		extraOpt = " " + Conf.DockerOpts
	}

	optStr := fmt.Sprintf("%s%s%s%s%s%s", daemonOpt, debugOpt, bindOpt, userlandProxyOpt, certOpt, extraOpt)

	optSlice, err := shlex.Split(optStr)
	if err != nil {
		optSlice = strings.Split(optStr, " ")
	}
	return optSlice
}
Ejemplo n.º 26
0
func ensureThinLsKernelVersion(kernelVersion string) error {
	// kernel 4.4.0 has the proper bug fixes to allow thin_ls to work without corrupting the thin pool
	minKernelVersion := semver.MustParse("4.4.0")
	// RHEL 7 kernel 3.10.0 release >= 366 has the proper bug fixes backported from 4.4.0 to allow
	// thin_ls to work without corrupting the thin pool
	minRhel7KernelVersion := semver.MustParse("3.10.0")

	matches := version_re.FindStringSubmatch(kernelVersion)
	if len(matches) < 4 {
		return fmt.Errorf("error parsing kernel version: %q is not a semver", kernelVersion)
	}

	sem, err := semver.Make(matches[0])
	if err != nil {
		return err
	}

	if sem.GTE(minKernelVersion) {
		// kernel 4.4+ - good
		return nil
	}

	// Certain RHEL/Centos 7.x kernels have a backport to fix the corruption bug
	if !strings.Contains(kernelVersion, ".el7") {
		// not a RHEL 7.x kernel - won't work
		return fmt.Errorf("kernel version 4.4.0 or later is required to use thin_ls - you have %q", kernelVersion)
	}

	// RHEL/Centos 7.x from here on
	if sem.Major != 3 {
		// only 3.x kernels *may* work correctly
		return fmt.Errorf("RHEL/Centos 7.x kernel version 3.10.0-366 or later is required to use thin_ls - you have %q", kernelVersion)
	}

	if sem.GT(minRhel7KernelVersion) {
		// 3.10.1+ - good
		return nil
	}

	if sem.EQ(minRhel7KernelVersion) {
		// need to check release
		releaseRE := regexp.MustCompile(`^[^-]+-([0-9]+)\.`)
		releaseMatches := releaseRE.FindStringSubmatch(kernelVersion)
		if len(releaseMatches) != 2 {
			return fmt.Errorf("unable to determine RHEL/Centos 7.x kernel release from %q", kernelVersion)
		}

		release, err := strconv.Atoi(releaseMatches[1])
		if err != nil {
			return fmt.Errorf("error parsing release %q: %v", releaseMatches[1], err)
		}

		if release >= 366 {
			return nil
		}
	}

	return fmt.Errorf("RHEL/Centos 7.x kernel version 3.10.0-366 or later is required to use thin_ls - you have %q", kernelVersion)
}
// Parses the version of postgres into the short version string we can use to
// match behaviors.
func parseVersion(versionString string) (semver.Version, error) {
	submatches := versionRegex.FindStringSubmatch(versionString)
	if len(submatches) > 1 {
		return semver.Make(submatches[1])
	}
	return semver.Version{},
		errors.New(fmt.Sprintln("Could not find a postgres version in string:", versionString))
}
Ejemplo n.º 28
0
func GetSemanticVersion() (semver.Version, error) {
	str, err := GetString()
	if err != nil {
		return semver.Version{}, err
	}

	return semver.Make(str)
}
Ejemplo n.º 29
0
func init() {
	var err error

	// Parses the server version string and returns a validated Version.
	serverVersion, err = semver.Make(Version)
	if err != nil {
		log.L.Fatalf("failed to parse glue server protocol version: %v", err)
	}
}
Ejemplo n.º 30
0
func NewEndpointStrategy(versionString string) EndpointStrategy {
	version, err := semver.Make(versionString)
	if err != nil {
		version, _ = semver.Make("0.0.0")
	}

	strategy := EndpointStrategy{
		EventsEndpointStrategy:  eventsEndpointStrategy{},
		DomainsEndpointStrategy: domainsEndpointStrategy{},
	}

	v210, _ := semver.Make("2.1.0")
	if version.GTE(v210) {
		strategy.EventsEndpointStrategy = globalEventsEndpointStrategy{}
		strategy.DomainsEndpointStrategy = separatedDomainsEndpointStrategy{}
	}

	return strategy
}