func (command *CheckCommand) checkByRegex(request CheckRequest) (CheckResponse, error) {
	extractions := versions.GetBucketFileVersions(command.s3client, request.Source)
	response := CheckResponse{}

	if len(extractions) == 0 {
		return response, nil
	}

	if request.Version.Path == "" {
		lastExtraction := extractions[len(extractions)-1]
		version := s3resource.Version{
			Path: lastExtraction.Path,
		}
		response = append(response, version)
	} else {
		lastVersion, ok := versions.Extract(request.Version.Path, request.Source.Regexp)
		if !ok {
			return response, fmt.Errorf("version number could not be found in: %s", request.Version.Path)
		}

		for _, extraction := range extractions {
			if extraction.Version.GreaterThan(lastVersion.Version) {
				version := s3resource.Version{
					Path: extraction.Path,
				}
				response = append(response, version)
			}
		}
	}

	return response, nil
}
Beispiel #2
0
func (command *CheckCommand) checkByRegex(request CheckRequest) CheckResponse {
	extractions := versions.GetBucketFileVersions(command.s3client, request.Source)

	if len(extractions) == 0 {
		return nil
	}

	lastVersion, matched := versions.Extract(request.Version.Path, request.Source.Regexp)
	if !matched {
		return latestVersion(extractions)
	} else {
		return newerVersions(lastVersion, extractions)
	}
}
func (command *InCommand) inByRegex(destinationDir string, request InRequest) (InResponse, error) {
	if request.Version.Path == "" {
		return InResponse{}, ErrMissingPath
	}

	remotePath := request.Version.Path

	extraction, ok := versions.Extract(remotePath, request.Source.Regexp)
	if !ok {
		return InResponse{}, fmt.Errorf("regex does not match provided version: %#v", request.Version)

	}

	err := command.writeVersionFile(extraction.VersionNumber, destinationDir)
	if err != nil {
		return InResponse{}, err
	}

	err = command.downloadFile(
		request.Source.Bucket,
		remotePath,
		"",
		destinationDir,
		path.Base(remotePath),
	)
	if err != nil {
		return InResponse{}, err
	}

	url := command.urlProvider.GetURL(request, remotePath)
	err = command.writeURLFile(
		destinationDir,
		url,
	)
	if err != nil {
		return InResponse{}, err
	}

	return InResponse{
		Version: s3resource.Version{
			Path: remotePath,
		},
		Metadata: command.metadata(remotePath, request.Source.Private, url),
	}, nil
}
Beispiel #4
0
func (command *InCommand) inByRegex(destinationDir string, request InRequest) (InResponse, error) {
	remotePath, err := command.pathToDownload(request)
	if err != nil {
		return InResponse{}, err
	}

	extraction, ok := versions.Extract(remotePath, request.Source.Regexp)
	if ok {
		err := command.writeVersionFile(extraction.VersionNumber, destinationDir)
		if err != nil {
			return InResponse{}, err
		}
	}

	err = command.downloadFile(
		request.Source.Bucket,
		remotePath,
		"",
		destinationDir,
		path.Base(remotePath),
	)
	if err != nil {
		return InResponse{}, err
	}

	url := command.urlProvider.GetURL(request, remotePath)
	err = command.writeURLFile(
		destinationDir,
		url,
	)
	if err != nil {
		return InResponse{}, err
	}

	return InResponse{
		Version: s3resource.Version{
			Path: remotePath,
		},
		Metadata: command.metadata(remotePath, request.Source.Private, url),
	}, nil
}