func TestComponentGetters(t *testing.T) {
	testSatisfies := []Satisfies{{Narrative: "Narrative"}, {}, {}, {}}
	component := Component{
		Name:          "Amazon Elastic Compute Cloud",
		Key:           "EC2",
		References:    common.GeneralReferences{{}},
		Verifications: common.VerificationReferences{{}, {}},
		Satisfies:     testSatisfies,
		SchemaVersion: semver.MustParse("2.0.0"),
	}
	// Test the getters
	assert.Equal(t, "EC2", component.GetKey())
	assert.Equal(t, "Amazon Elastic Compute Cloud", component.GetName())
	assert.Equal(t, &common.GeneralReferences{{}}, component.GetReferences())
	assert.Equal(t, &common.VerificationReferences{{}, {}}, component.GetVerifications())
	assert.Equal(t, semver.MustParse("2.0.0"), component.GetVersion())
	assert.Equal(t, "", component.GetResponsibleRole())
	assert.Equal(t, len(testSatisfies), len(component.GetAllSatisfies()))
	for idx, satisfies := range component.GetAllSatisfies() {
		assert.Equal(t, satisfies.GetControlKey(), testSatisfies[idx].GetControlKey())
		assert.Equal(t, satisfies.GetStandardKey(), testSatisfies[idx].GetStandardKey())
		assert.Equal(t, satisfies.GetNarratives(), testSatisfies[idx].GetNarratives())
		for i, narrative := range satisfies.GetNarratives() {
			assert.Equal(t, "", narrative.GetKey())
			assert.Equal(t, satisfies.GetNarratives()[i].GetText(), narrative.GetText())
		}
		assert.Equal(t, satisfies.GetParameters(), testSatisfies[idx].GetParameters())
		assert.Equal(t, satisfies.GetCoveredBy(), testSatisfies[idx].GetCoveredBy())
		assert.Equal(t, "", satisfies.GetControlOrigin())
	}
}
예제 #2
0
파일: factory.go 프로젝트: jbeda/kubernetes
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)
}
func TestComponentSetters(t *testing.T) {
	component := Component{}
	// Test the setters.
	// Change the version.
	component.SetVersion(semver.MustParse("3.0.0"))
	assert.Equal(t, semver.MustParse("3.0.0"), component.GetVersion())
	// Change the key.
	component.SetKey("FooKey")
	assert.Equal(t, "FooKey", component.GetKey())
}
func TestComponentGetters(t *testing.T) {
	testSatisfies := []Satisfies{
		{
			ControlOrigin:          "inherited",
			ControlOrigins:         []string{"inherited"},
			ImplementationStatus:   "partial",
			ImplementationStatuses: []string{"partial"},
			Parameters:             []Section{Section{Key: "key", Text: "text"}},
			Narrative: []NarrativeSection{
				NarrativeSection{Key: "key", Text: "text"},
				NarrativeSection{Text: "text"},
			},
		}, {}}
	component := Component{
		Name:            "Amazon Elastic Compute Cloud",
		Key:             "EC2",
		ResponsibleRole: "AWS Staff",
		References:      common.GeneralReferences{{}},
		Verifications:   common.VerificationReferences{{}, {}},
		Satisfies:       testSatisfies,
		SchemaVersion:   semver.MustParse("3.1.0"),
	}
	// Test the getters
	assert.Equal(t, "EC2", component.GetKey())
	assert.Equal(t, "Amazon Elastic Compute Cloud", component.GetName())
	assert.Equal(t, &common.GeneralReferences{{}}, component.GetReferences())
	assert.Equal(t, &common.VerificationReferences{{}, {}}, component.GetVerifications())
	assert.Equal(t, semver.MustParse("3.1.0"), component.GetVersion())
	assert.Equal(t, "AWS Staff", component.GetResponsibleRole())
	assert.Equal(t, len(testSatisfies), len(component.GetAllSatisfies()))
	for idx, satisfies := range component.GetAllSatisfies() {
		assert.Equal(t, satisfies.GetControlKey(), testSatisfies[idx].GetControlKey())
		assert.Equal(t, satisfies.GetStandardKey(), testSatisfies[idx].GetStandardKey())
		assert.Equal(t, satisfies.GetNarratives(), testSatisfies[idx].GetNarratives())
		for i, narrative := range satisfies.GetNarratives() {
			assert.Equal(t, satisfies.GetNarratives()[i].GetKey(), narrative.GetKey())
			assert.Equal(t, satisfies.GetNarratives()[i].GetText(), narrative.GetText())
		}
		assert.Equal(t, satisfies.GetParameters(), testSatisfies[idx].GetParameters())
		for i, parameter := range satisfies.GetParameters() {
			assert.Equal(t, satisfies.GetParameters()[i].GetKey(), parameter.GetKey())
			assert.Equal(t, satisfies.GetParameters()[i].GetText(), parameter.GetText())
		}
		assert.Equal(t, satisfies.GetCoveredBy(), testSatisfies[idx].GetCoveredBy())
		assert.Equal(t, satisfies.GetControlOrigin(), testSatisfies[idx].GetControlOrigin())
		assert.Equal(t, satisfies.GetControlOrigins(), testSatisfies[idx].GetControlOrigins())
		assert.Equal(t, satisfies.GetImplementationStatus(), testSatisfies[idx].GetImplementationStatus())
		assert.Equal(t, satisfies.GetImplementationStatuses(), testSatisfies[idx].GetImplementationStatuses())
	}
}
예제 #5
0
func checkVersion() {
	server := new(Version)
	mustGetObject("/version", nil, server)
	grindCurrent := semver.MustParse(CurrentVersion.Version)
	grindRequired := semver.MustParse(server.GrindVersionRequired)
	if grindRequired.GT(grindCurrent) {
		log.Printf("this is grind version %s, but the server requires %s or higher", CurrentVersion.Version, server.GrindVersionRequired)
		log.Fatalf("  you must upgrade to continue")
	}
	grindRecommended := semver.MustParse(server.GrindVersionRecommended)
	if grindRecommended.GT(grindCurrent) {
		log.Printf("this is grind version %s, but the server recommends %s or higher", CurrentVersion.Version, server.GrindVersionRecommended)
		log.Printf("  please upgrade as soon as possible")
	}
}
예제 #6
0
파일: dvm-helper.go 프로젝트: getcarina/dvm
func use(version dockerversion.Version) {
	writeDebug("dvm use %s", version)

	if version.IsEmpty() {
		die("The use command requires that a version is specified or the DOCKER_VERSION environment variable is set.", nil, retCodeInvalidOperation)
	}

	if version.HasAlias() && aliasExists(version.Alias) {
		aliasedVersion, _ := ioutil.ReadFile(getAliasPath(version.Alias))
		version.SemVer = semver.MustParse(string(aliasedVersion))
		writeDebug("Using alias: %s -> %s", version.Alias, version.SemVer)
	}

	ensureVersionIsInstalled(version)

	if version.IsSystem() {
		version, _ = getSystemDockerVersion()
	} else if version.IsExperimental() {
		version, _ = getExperimentalDockerVersion()
	}

	removePreviousDockerVersionFromPath()
	if !version.IsSystem() {
		prependDockerVersionToPath(version)
	}

	writePathScript()
	writeInfo("Now using Docker %s", version)
}
예제 #7
0
func TestUnmarshal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error
	version := semver.MustParse("0.0.1")

	jsonData := []byte(`{
        "version": "0.0.1",
        "path": "./test_artifacts"
    }`)

	cfg := config.NewConfig(version)

	err = json.Unmarshal(jsonData, &cfg)
	w.BailIfErrorf(err, "deserializazion failed: %v", err)

	provider, err := FromConfig(cfg)
	w.BailIfErrorf(err, "instantiation failed: %v", err)

	root, err := provider.Root()
	w.BailIfError(err)

	_, err = checkDirectoryContents(root, expectedRootEntries())

	w.BailIfErrorf(err, "provider path differs")
}
예제 #8
0
func getLatestVersion(zipFile []byte, prefix, suffix string) (string, error) {
	r, err := zip.NewReader(bytes.NewReader(zipFile), int64(len(zipFile)))
	if err != nil {
		return "", err
	}
	latest := ""
	for _, f := range r.File {
		artifact := path.Base(f.Name)
		if strings.HasPrefix(artifact, prefix) && strings.HasSuffix(artifact, suffix) {
			v := extractVersion(artifact)
			if latest == "" {
				latest = v
			}
			v1, err := semver.Parse(v)
			if err != nil {
				return "", err
			}
			l := semver.MustParse(latest)
			if v1.GT(l) {
				latest = v
			}
		}
	}
	return latest, nil
}
예제 #9
0
파일: os.go 프로젝트: carriercomm/dlite
func getReleases() ([]semver.Version, map[string]Version, error) {
	res, err := http.Get("https://api.github.com/repos/nlf/dhyve-os/releases")
	if err != nil {
		return nil, nil, err
	}

	defer res.Body.Close()
	vers := []Version{}
	decoder := json.NewDecoder(res.Body)
	err = decoder.Decode(vers)
	if err != nil {
		return nil, nil, err
	}

	versions := map[string]Version{}
	rng, err := semver.ParseRange(">= 3.0.0-beta0")
	if err != nil {
		return nil, nil, err
	}

	svers := []semver.Version{}
	for _, vers := range versions {
		v := semver.MustParse(vers.Tag)
		if rng(v) {
			versions[vers.Tag] = vers
			svers = append(svers, v)
		}
	}

	semver.Sort(svers)
	return svers, versions, nil
}
예제 #10
0
func TestMarshalUnmarshal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error
	version := semver.MustParse("0.0.1")

	provider, err := local.NewLocalFS("./test_artifacts")

	w.BailIfError(err)

	cfg := provider.Marshal()
	jsonData, err := json.Marshal(cfg)

	w.BailIfErrorf(err, "serialization failed: %v", err)

	if !strings.Contains(string(jsonData), "test_artifacts") {
		t.Fatalf("JSON does not contain the proper path: %s", string(jsonData))
	}

	unmarshalledConfig := config.NewConfig(version)
	err = json.Unmarshal(jsonData, &unmarshalledConfig)

	w.BailIfErrorf(err, "deserialization failed: %v", err)

	_, err = FromConfig(unmarshalledConfig)

	w.BailIfErrorf(err, "reinstation of fs provider failed: %v", err)
}
예제 #11
0
func TestMarshalUnmarshal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error
	version := semver.MustParse("0.0.1")

	provider := getFSInstace()
	cfg := provider.Marshal()

	jsonData, err := json.Marshal(cfg)
	w.BailIfErrorf(err, "serialization failed: %v", err)

	unmarshalCfg := config.NewConfig(version)

	err = json.Unmarshal(jsonData, &unmarshalCfg)
	w.BailIfErrorf(err, "deserialization failed: %v", err)

	unmarshalledProvider, err := FromConfig(unmarshalCfg)
	w.BailIfErrorf(err, "instatiation failed: %v", err)

	root, err := unmarshalledProvider.Root()
	w.BailIfError(err)

	_, err = checkDirectoryContents(root, expectedRootEntries())

	w.BailIfErrorf(err, "provider path differs")
}
예제 #12
0
파일: os.go 프로젝트: nlf/dlite
func getOSReleases() (Releases, error) {
	res, err := http.Get("https://api.github.com/repos/nlf/dlite-os/releases")
	if err != nil {
		return nil, err
	}

	defer res.Body.Close()
	releases := Releases{}
	decoder := json.NewDecoder(res.Body)
	err = decoder.Decode(&releases)
	if err != nil {
		return nil, err
	}

	allowedReleases := Releases{}
	for _, release := range releases {
		release.Version = semver.MustParse(strings.TrimPrefix(release.Tag, "v"))
		if allowedRange(release.Version) {
			allowedReleases = append(allowedReleases, release)
		}
	}

	sort.Sort(allowedReleases)
	return allowedReleases, nil
}
예제 #13
0
파일: up.go 프로젝트: bmeng/origin
// CheckDockerVersion checks that the appropriate Docker version is installed based on whether we are using the nsenter mounter
// or shared volumes for OpenShift
func (c *ClientStartConfig) CheckDockerVersion(io.Writer) error {
	var minDockerVersion semver.Version
	if c.UseNsenterMount {
		minDockerVersion = semver.MustParse("1.8.1")
	} else {
		minDockerVersion = semver.MustParse("1.10.0")
	}
	ver, err := c.DockerHelper().Version()
	if err != nil {
		return err
	}
	glog.V(5).Infof("Checking that docker version is at least %v", minDockerVersion)
	if ver.LT(minDockerVersion) {
		return fmt.Errorf("Docker version is %v, it needs to be %v", ver, minDockerVersion)
	}
	return nil
}
예제 #14
0
func validate(deps map[string][]semver.Version, expected map[string]string, t *testing.T) {
	for name, ver := range expected {
		vers, ok := deps[name]
		if !ok || !exists(vers, semver.MustParse(ver)) {
			t.Fatalf("Expected ver %s for %s, got: %v", ver, name, vers)
		}
	}
}
예제 #15
0
파일: main.go 프로젝트: zerok/gensemver
func main() {
	customRawPrevVersion := flag.String("prev", "", "Force a previous version number")
	var customPrevVersion *semver.Version
	flag.Parse()

	if *customRawPrevVersion != "" {
		tmp := semver.MustParse(*customRawPrevVersion)
		customPrevVersion = &tmp
	}

	args := flag.Args()
	endRev := "HEAD"
	startRev := ""

	repoPath, err := GetRepoPath()
	tags := getTags(repoPath)

	var newVersion *semver.Version
	var oldVersion *semver.Version
	if err != nil {
		log.Fatalf("Failed to open repository: %s", err.Error())
	}
	if len(args) == 0 {
		startRev, oldVersion, err = getPreviousVersionRev(repoPath, tags)
		if err != nil {
			log.Fatalf("Failed to retrieve previous version: %s", err.Error())
		}
	} else if len(args) == 1 {
		_, oldVersion, err = getPreviousVersionRev(repoPath, tags)
		startRev = args[0]
	} else {
		startRev = args[0]
		_, oldVersion, err = getPreviousVersionRev(repoPath, tags)
		endRev = args[1]
	}

	if customPrevVersion != nil {
		oldVersion = customPrevVersion
	}

	if oldVersion == nil {
		log.Println("No previous version found")
		newVersion = &semver.Version{Major: 1, Minor: 0, Patch: 0}
	}

	if oldVersion != nil {
		log.Printf("Previous version: %s (%s)\n", oldVersion, startRev)
	}

	if newVersion == nil {
		newVersion, err = getNewVersion(repoPath, startRev, endRev, oldVersion, tags)
		if err != nil {
			log.Fatalf("Failed to generate new version: %s", err.Error())
		}
	}

	fmt.Println(newVersion)
}
예제 #16
0
// UnmarshalYAML is a overridden implementation of YAML parsing the component.yaml
// This method is similar to the one found here: http://choly.ca/post/go-json-marshalling/
// This is necessary because we want to have backwards compatibility with parsing the old types of version 2.0
// (type =float).
// To compensate for that, we have to hand roll our own UnmarshalYAML that can decide what to do for parsing
// the older version of type float and converting it into semver. In addition, we will use this logic to parse strings
// into semver.
func (b *Base) UnmarshalYAML(unmarshal func(v interface{}) error) error {
	// When we call "unmarshal" callback on an object, it will call that object's "UnmarshalYAML" if defined.
	// Since we are currently in the implementation of Component's "UnmarshalYAML", when finally we call
	// unmarshal again, if it's on type Component, we would end up in a recursive infinite loop.
	// To prevent this, we create a separate type, called Alias.
	type Alias Base
	// Create an anonymous struct with an interface{} type for the schema_version that we want to parse
	aux := &struct {
		SchemaVersion interface{} `yaml:"schema_version" json:"schema_version"`
		Alias         `yaml:",inline"`
	}{
		Alias: (Alias)(*b),
	}

	// Call unmarshal on the new Alias type. Don't return the error yet because we want to gather more information
	// if we can below.
	err := unmarshal(&aux)

	// Create a placeholder variable for the converted semver.
	var ver semver.Version
	// Create a placeholder variable for the error.
	var versionErr error

	// Store the version value for conciseness.
	value := aux.SchemaVersion

	// Try to cast the value from interface{} to certain types.
	switch v := value.(type) {
	// For float types, which are the old types, we need to upcast it to semver if it's an older version.
	case float32, float64:
		switch v {
		// Schema Version started being documented with "2.0".
		// We should be able to parse it for backwards compatibility.
		// All future versioning should be in semver format already.
		case 2.0:
			ver = semver.MustParse("2.0.0")
		// If not the older version, it needs to be in semver format, send an error.
		default:
			return BaseComponentParseError{fmt.Sprintf("Version %v is not in semver format", v)}

		}
	// The interface type will default to string if not numeric which is what all semver types will be initially.
	case string:
		ver, versionErr = semver.Parse(v)
		if versionErr != nil {
			return BaseComponentParseError{constants.ErrMissingVersion}
		}
	// In the case, it's just missing completely.
	default:
		return BaseComponentParseError{constants.ErrMissingVersion}
	}
	// Copy everything from the Alias back to the original component.
	*b = (Base)(aux.Alias)

	// Get the version
	b.SchemaVersion = ver
	return err
}
예제 #17
0
// useDiscoveryRESTMapper checks the server version to see if its recent enough to have
// enough discovery information available to reliably build a RESTMapper.  If not, use the
// hardcoded mapper in this client (legacy behavior)
func useDiscoveryRESTMapper(serverVersion string) bool {
	if len(serverVersion) == 0 {
		return false
	}
	serverSemVer, err := semver.Parse(serverVersion[1:])
	if err != nil {
		return false
	}
	return serverSemVer.GE(semver.MustParse("1.3.0"))
}
예제 #18
0
// useDiscoveryRESTMapper checks the server version to see if its recent enough to have
// enough discovery information avaiable to reliably build a RESTMapper.  If not, use the
// hardcoded mapper in this client (legacy behavior)
func useDiscoveryRESTMapper(serverVersion string) bool {
	serverSemVer, err := semver.Parse(serverVersion[1:])
	if err != nil {
		return false
	}
	if serverSemVer.LT(semver.MustParse("1.3.0")) {
		return false
	}
	return true
}
예제 #19
0
파일: os.go 프로젝트: carriercomm/dlite
func Specific(vers string) (Version, error) {
	sv := semver.MustParse(vers)
	svers, mvers, err := getReleases()
	if err != nil {
		return Version{}, err
	}

	for _, v := range svers {
		if v.Equals(sv) {
			return mvers[v.String()], nil
		}
	}

	return Version{}, fmt.Errorf("Cannot find version %s", vers)
}
예제 #20
0
func TestUnmarshalLocalWithInvalidJSON(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	version := semver.MustParse("0.0.1")
	jsonData := `{
	           "type": "local",
	           "path": "."
	       `

	cfg := config.NewConfig(version)
	err = json.Unmarshal([]byte(jsonData), &cfg)

	w.ShouldFailf(err, "unmarshalling should fail due to invalid JSON")
}
예제 #21
0
func TestUnmarshalWithLocalFS(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	version := semver.MustParse("0.0.1")

	jsonData := []byte(`{
        "foo": {
            "plain": true,
            "storage": {
                "type": "local",
                "path": "."
            }
        },
        "bar": {
            "plain": true,
            "storage": {
                "type": "local",
                "path": ".."
            }
        }
    }`)

	cfg := config.NewConfig(version)

	err = json.Unmarshal(jsonData, &cfg)
	w.BailIfErrorf(err, "deserialization failed: %v", err)

	registry, err := CreateFromConfig(cfg)
	w.BailIfErrorf(err, "unmarshalling failed: %v", err)

	if registry.Size() != 2 {
		t.Fatalf("registry has the wrong size; expected 2, got %d", registry.Size())
	}

	if registry.Get("foo") == nil {
		t.Fatalf("foo: no such key")
	}

	if registry.Get("bar") == nil {
		t.Fatalf("bar: no such key")
	}
}
예제 #22
0
func TestMarshall(t *testing.T) {
	w := testutils.Wrap(t)
	version := semver.MustParse("1.2.3")

	var err error

	config := NewMutableConfig(version)
	jsonData, err := marshalConfig(config)

	w.BailIfError(err)

	unmarshalledConfig, err := unmarshalConfig(jsonData)

	w.BailIfError(err)

	if actualVersion := unmarshalledConfig.CsyncVersion(); actualVersion.NE(version) {
		t.Fatalf("unmarshalled wrong version: expected %s, got %s", version, actualVersion)
	}
}
예제 #23
0
func TestUnmarshalLocal(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	version := semver.MustParse("0.0.1")
	jsonData := `{
	           "type": "local",
	           "path": "."
	       }`

	cfg := config.NewConfig(version)
	err = json.Unmarshal([]byte(jsonData), &cfg)

	w.BailIfErrorf(err, "unmarshalling failed: %v", err)

	_, err = FromConfig(cfg)

	w.BailIfErrorf(err, "creating the provider failed: %v", err)
}
예제 #24
0
func TestUnmarshalLocalWithInvalidPath(t *testing.T) {
	w := testutils.Wrap(t)

	var err error

	version := semver.MustParse("0.0.1")
	jsonData := `{
	           "type": "local",
	           "path": "./INVALID_PATH"
	       }`

	cfg := config.NewConfig(version)
	err = json.Unmarshal([]byte(jsonData), &cfg)

	w.BailIfErrorf(err, "unmarshalling failed: %v", err)

	_, err = FromConfig(cfg)

	w.ShouldFailf(err, "unmarshalling should fail due to the invalid path")
}
예제 #25
0
func Client() (rktapi.PublicAPIClient, error) {
	once.Do(func() {
		conn, err := net.DialTimeout("tcp", defaultRktAPIServiceAddr, timeout)
		if err != nil {
			rktClient = nil
			rktClientErr = fmt.Errorf("rkt: cannot tcp Dial rkt api service: %v", err)
			return
		}

		conn.Close()

		apisvcConn, err := grpc.Dial(defaultRktAPIServiceAddr, grpc.WithInsecure(), grpc.WithTimeout(timeout))
		if err != nil {
			rktClient = nil
			rktClientErr = fmt.Errorf("rkt: cannot grpc Dial rkt api service: %v", err)
			return
		}

		apisvc := rktapi.NewPublicAPIClient(apisvcConn)

		resp, err := apisvc.GetInfo(context.Background(), &rktapi.GetInfoRequest{})
		if err != nil {
			rktClientErr = fmt.Errorf("rkt: GetInfo() failed: %v", err)
			return
		}

		binVersion, err := semver.Make(resp.Info.RktVersion)
		if err != nil {
			rktClientErr = fmt.Errorf("rkt: couldn't parse RtVersion: %v", err)
			return
		}
		if binVersion.LT(semver.MustParse(minimumRktBinVersion)) {
			rktClientErr = fmt.Errorf("rkt: binary version is too old(%v), requires at least %v", resp.Info.RktVersion, minimumRktBinVersion)
			return
		}

		rktClient = apisvc
	})

	return rktClient, rktClientErr
}
예제 #26
0
func init() {
	loadConfig()

	var numDownloaders int
	if cfg.NumDownloaders == 0 {
		numDownloaders = 10
	} else {
		numDownloaders = cfg.NumDownloaders
	}

	var requestRate int
	if cfg.RequestRate == 0 {
		requestRate = 4
	} else {
		requestRate = cfg.RequestRate
	}

	var downloadDirectory string
	if len(cfg.DownloadDirectory) == 0 {
		downloadDirectory = "."
	} else {
		downloadDirectory = cfg.DownloadDirectory

	}

	flag.BoolVar(&cfg.IgnorePhotos, "ignore-photos", cfg.IgnorePhotos, "Ignore any photos found in the selected tumblrs.")
	flag.BoolVar(&cfg.IgnoreVideos, "ignore-videos", cfg.IgnoreVideos, "Ignore any videos found in the selected tumblrs.")
	flag.BoolVar(&cfg.IgnoreAudio, "ignore-audio", cfg.IgnoreAudio, "Ignore any audio files found in the selected tumblrs.")
	flag.BoolVar(&cfg.UseProgressBar, "p", cfg.UseProgressBar, "Use a progress bar to show download status.")
	flag.BoolVar(&cfg.ForceCheck, "force", cfg.ForceCheck, "Force checking an entire blog for new files.")

	flag.IntVar(&cfg.NumDownloaders, "d", numDownloaders, "Number of simultaneous downloads allowed.")
	flag.IntVar(&cfg.RequestRate, "r", requestRate, "Number of requests per second allowed. Do not exceed 15, as tumblr begins throttling at that point.")
	flag.StringVar(&cfg.DownloadDirectory, "dir", downloadDirectory, "The directory which will store all downloads.")

	cfg.version = semver.MustParse(VERSION)

	flag.Parse()
}
예제 #27
0
파일: install_osx.go 프로젝트: qbit/client
// RunApp starts the app
func RunApp(context Context, log Log) error {
	appPath, err := AppBundleForPath()
	if err != nil {
		return err
	}
	ver, err := OSVersion()
	if err != nil {
		log.Errorf("Error trying to determine OS version: %s", err)
		return nil
	}
	if ver.LT(semver.MustParse("10.0.0")) {
		return fmt.Errorf("App isn't supported on this OS version: %s", ver)
	}

	log.Info("Opening %s", appPath)
	// If app is already open this is a no-op, the -g option will cause to open
	// in background.
	out, err := exec.Command("/usr/bin/open", "-g", appPath).Output()
	if err != nil {
		return fmt.Errorf("Error trying to open %s: %s; %s", appPath, err, out)
	}
	return nil
}
예제 #28
0
func TestSave(t *testing.T) {
	w := testutils.Wrap(t)
	version := semver.MustParse("1.2.3")

	var err error

	locator, err := newMockLocator()
	w.BailIfError(err)
	defer locator.Destroy()

	manager := NewManager(locator)
	err = manager.Save(NewMutableConfig(version))

	w.BailIfErrorf(err, "saving the config failed: %v", err)

	config, err := manager.Load()

	w.BailIfErrorf(err, "loading the config failed: %v", err)

	if actualVersion := config.CsyncVersion(); actualVersion.NE(version) {
		t.Fatalf("loaded wrong version: expected %s, got %s", version, actualVersion)
	}
}
예제 #29
0
파일: app.go 프로젝트: ts33kr/boot
// Create and initialize a new application. This is a front gate for
// the framework, since you should start by creating a new app struct.
// Every application should have a valid name (tag) and a version. So
// this function makes sure they have been passed and are all valid.
// Generally, you should not be creating more than one application.
func New(name, version string) *App {
	var room = make(map[string]interface{})
	const url = "https://github.com/ts33kr/boot"
	const ename = "name is not of correct format"
	const eversion = "version is not valid semver"
	pattern := regexp.MustCompile("^[a-zA-Z0-9-_]+$")
	var parsed semver.Version = semver.MustParse(version)
	if !pattern.MatchString(name) {
		panic(ename)
	}
	if parsed.Validate() != nil {
		panic(eversion)
	}
	application := &App{Name: name, Version: parsed}
	application.Storage = Storage{Container: room}
	application.CronEngine = cron.New() // create CRON
	application.Servers = make(map[string]*http.Server)
	application.Reference = shortuuid.New() // V4
	application.Providers = make([]*Provider, 0)
	application.Services = make([]*Service, 0)
	application.TimeLayout = time.RFC850
	application.Namespace = url // set
	return application          // prepared app
}
예제 #30
0
func TestOSVersion(t *testing.T) {
	ver, err := OSVersion()
	require.NoError(t, err)
	t.Logf("Version: %s", ver)
	require.True(t, ver.GTE(semver.MustParse("10.0.0")))
}