github.com/kubernetes-incubator/kube-aws@v0.16.4/pkg/api/assets.go (about)

     1  package api
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/kubernetes-incubator/kube-aws/fingerprint"
     8  )
     9  
    10  type AssetID struct {
    11  	StackName string
    12  	Filename  string
    13  }
    14  
    15  type Asset struct {
    16  	AssetLocation
    17  	Content string
    18  }
    19  
    20  type AssetLocation struct {
    21  	ID     AssetID
    22  	Key    string
    23  	Bucket string
    24  	Path   string
    25  	Region Region
    26  }
    27  
    28  func NewAssetID(stack string, file string) AssetID {
    29  	return AssetID{
    30  		StackName: stack,
    31  		Filename:  file,
    32  	}
    33  }
    34  
    35  func (l AssetLocation) URL() (string, error) {
    36  	if (l == AssetLocation{}) {
    37  		return "", fmt.Errorf("[bug] Empty asset location can't have URL")
    38  	}
    39  	return fmt.Sprintf("%s/%s", l.Region.S3Endpoint(l.Bucket), l.Key), nil
    40  }
    41  
    42  func (l AssetLocation) S3URL() (string, error) {
    43  	if (l == AssetLocation{}) {
    44  		return "", fmt.Errorf("[bug] Empty asset location can't have S3 URL")
    45  	}
    46  	return fmt.Sprintf("s3://%s/%s", l.Bucket, l.Key), nil
    47  }
    48  
    49  func (l Asset) S3Prefix() (string, error) {
    50  	if (l.AssetLocation == AssetLocation{}) {
    51  		return "", fmt.Errorf("[bug] Empty asset location can't have URL")
    52  	}
    53  	prefix := strings.TrimSuffix(l.Key, fmt.Sprintf("-%s", fingerprint.SHA256(l.Content)))
    54  	return fmt.Sprintf("%s/%s", l.Bucket, prefix), nil
    55  }