Example #1
0
// LatestVersion returns latest version for specific package
func (m *Manifest) LatestVersion(log log.T, context *updateutil.InstanceContext, packageName string) (result string, err error) {
	var version = minimumVersion
	var compareResult = 0
	for _, p := range m.Packages {
		if p.Name == packageName {
			for _, f := range p.Files {
				if f.Name == context.FileName(packageName) {
					for _, v := range f.AvailableVersions {
						if compareResult, err = updateutil.VersionCompare(v.Version, version); err != nil {
							return version, err
						}
						if compareResult > 0 {
							version = v.Version
						}
					}
				}
			}
		}
	}
	if version == minimumVersion {
		log.Debugf("Filename: %v", context.FileName(packageName))
		log.Debugf("Package Name: %v", packageName)
		log.Debugf("Manifest: %v", m)
		return version, fmt.Errorf("cannot find the latest version for package %v", packageName)
	}

	return version, nil
}
Example #2
0
// validateManifest makes sure all the fields are provided.
func validateManifest(log log.T, parsedManifest *Manifest, context *updateutil.InstanceContext, packageName string) error {
	if len(parsedManifest.URIFormat) == 0 {
		return fmt.Errorf("folder format cannot be null in the Manifest file")
	}
	fileName := context.FileName(packageName)
	foundPackage := false
	foundFile := false
	for _, p := range parsedManifest.Packages {
		if p.Name == packageName {
			log.Infof("found package %v", packageName)
			foundPackage = true
			for _, f := range p.Files {
				if f.Name == fileName {
					foundFile = true
					if len(f.AvailableVersions) == 0 {
						return fmt.Errorf("at least one available version is required for the %v", fileName)
					}

					log.Infof("found file %v", fileName)
					break
				}
			}
		}
	}

	if !foundPackage {
		return fmt.Errorf("cannot find the %v information in the Manifest file", packageName)
	}
	if !foundFile {
		return fmt.Errorf("cannot find the %v information in the Manifest file", fileName)
	}

	return nil
}
Example #3
0
// DownloadURLAndHash returns download source url and hash value
func (m *Manifest) DownloadURLAndHash(
	context *updateutil.InstanceContext,
	packageName string,
	version string) (result string, hash string, err error) {
	fileName := context.FileName(packageName)

	for _, p := range m.Packages {
		if p.Name == packageName {
			for _, f := range p.Files {
				if f.Name == fileName {
					for _, v := range f.AvailableVersions {
						if version == v.Version || version == updateutil.PipelineTestVersion {
							result = m.URIFormat
							result = strings.Replace(result, updateutil.RegionHolder, context.Region, -1)
							result = strings.Replace(result, updateutil.PackageNameHolder, packageName, -1)
							result = strings.Replace(result, updateutil.PackageVersionHolder, version, -1)
							result = strings.Replace(result, updateutil.FileNameHolder, f.Name, -1)
							if version == updateutil.PipelineTestVersion {
								return result, "", nil
							}
							return result, v.Checksum, nil
						}
					}
				}
			}
		}
	}

	return "", "", fmt.Errorf("incorrect package name or version, %v, %v", packageName, version)
}
Example #4
0
func createStubManifest(plugin *UpdatePluginInput,
	context *updateutil.InstanceContext,
	addCurrentVersion bool,
	addTargetVersion bool) *Manifest {
	manifest, _ := ParseManifest(logger, "testdata/sampleManifest.json", context, plugin.AgentName)

	for _, p := range manifest.Packages {
		if p.Name == plugin.AgentName {
			for _, f := range p.Files {
				if f.Name == context.FileName(plugin.AgentName) {
					if addCurrentVersion {
						f.AvailableVersions = append(f.AvailableVersions,
							&PackageVersion{Version: version.Version})
					}
					if addTargetVersion {
						f.AvailableVersions = append(f.AvailableVersions,
							&PackageVersion{Version: plugin.TargetVersion})
					}

				}
			}
		}
	}
	return manifest
}
Example #5
0
// HasVersion returns if manifest file has particular version for package
func (m *Manifest) HasVersion(context *updateutil.InstanceContext, packageName string, version string) bool {
	for _, p := range m.Packages {
		if p.Name == packageName {
			for _, f := range p.Files {
				if f.Name == context.FileName(packageName) {
					for _, v := range f.AvailableVersions {
						if v.Version == version || version == updateutil.PipelineTestVersion {
							return true
						}
					}
				}
			}
		}
	}

	return false
}
Example #6
0
func createStubInstanceContext() *updateutil.InstanceContext {
	context := updateutil.InstanceContext{}
	context.Arch = "amd64"
	context.CompressFormat = "tar.gz"
	context.InstallerName = updateutil.PlatformLinux
	context.Platform = updateutil.PlatformLinux
	context.PlatformVersion = "2015.9"
	return &context
}