Example #1
0
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
}
Example #2
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
}