Ejemplo n.º 1
0
Archivo: cfr.go Proyecto: 2722/lantern
func DisableDistribution(cfr *cloudfront.CloudFront, dist *Distribution) error {
	// See:
	// http://docs.aws.amazon.com/AmazonCloudFront/latest/APIReference/DeleteDistribution.html
	getreq := &cloudfront.GetDistributionConfigRequest{ID: dist.distributionId}
	getresp, err := cfr.GetDistributionConfig(getreq)
	if err != nil {
		return err
	}
	getresp.DistributionConfig.Enabled = aws.False()
	setreq := &cloudfront.UpdateDistributionRequest{
		ID:                 dist.distributionId,
		IfMatch:            getresp.ETag,
		DistributionConfig: getresp.DistributionConfig,
	}
	setresp, err := cfr.UpdateDistribution(setreq)
	if err != nil {
		return err
	}
	if *setresp.Distribution.DistributionConfig.Enabled != false {
		return fmt.Errorf("Attempt to disable distribution had no effect")
	}
	dist.Enabled = false
	dist.Status = "InProgress"
	return nil
}
Ejemplo n.º 2
0
Archivo: cfr.go Proyecto: 2722/lantern
func CreateDistribution(cfr *cloudfront.CloudFront, name string, originDomain string, comment string) (*Distribution, error) {
	nameStr := aws.String(name)
	req := cloudfront.CreateDistributionRequest{
		DistributionConfig: &cloudfront.DistributionConfig{
			Logging: &cloudfront.LoggingConfig{
				XMLName: xml.Name{
					Space: xmlSpace,
					Local: "Logging",
				},
				Bucket:         aws.String("-"),
				Enabled:        aws.False(),
				IncludeCookies: aws.False(),
				Prefix:         aws.String("-"),
			},
			Origins: &cloudfront.Origins{
				Items: []cloudfront.Origin{
					cloudfront.Origin{
						ID:         nameStr,
						DomainName: aws.String(originDomain),
						CustomOriginConfig: &cloudfront.CustomOriginConfig{
							HTTPPort:             aws.Integer(80),
							HTTPSPort:            aws.Integer(443),
							OriginProtocolPolicy: aws.String(cloudfront.OriginProtocolPolicyHTTPOnly),
						},
					},
				},
				Quantity: aws.Integer(1),
			},
			CacheBehaviors: &cloudfront.CacheBehaviors{
				Items:    []cloudfront.CacheBehavior{},
				Quantity: aws.Integer(0),
			},
			DefaultCacheBehavior: &cloudfront.DefaultCacheBehavior{
				TargetOriginID: nameStr,
				AllowedMethods: &cloudfront.AllowedMethods{
					CachedMethods: &cloudfront.CachedMethods{
						Items: []string{
							cloudfront.MethodGet,
							cloudfront.MethodHead,
						},
						Quantity: aws.Integer(2),
					},
					Items: []string{
						cloudfront.MethodPost,
						cloudfront.MethodPatch,
						cloudfront.MethodGet,
						cloudfront.MethodDelete,
						cloudfront.MethodOptions,
						cloudfront.MethodPut,
						cloudfront.MethodHead,
					},
					Quantity: aws.Integer(7),
				},
				ForwardedValues: &cloudfront.ForwardedValues{
					Cookies: &cloudfront.CookiePreference{
						XMLName: xml.Name{
							Space: xmlSpace,
							Local: "Cookies",
						},
						Forward: aws.String(cloudfront.ItemSelectionNone),
					},
					Headers: &cloudfront.Headers{
						Items: []string{
							"X-Enproxy-Id",
							"X-Enproxy-Dest-Addr",
							"X-Enproxy-EOF",
							"X-Enproxy-Proxy-Host",
							"X-Enproxy-Op",
						},
						Quantity: aws.Integer(5),
					},
					QueryString: aws.False(),
				},
				ViewerProtocolPolicy: aws.String(cloudfront.ViewerProtocolPolicyHTTPSOnly),
				MinTTL:               aws.Long(0),
				TrustedSigners: &cloudfront.TrustedSigners{
					Enabled:  aws.False(),
					Items:    []string{},
					Quantity: aws.Integer(0),
				},
			},
			Comment:           aws.String(comment),
			PriceClass:        aws.String(cloudfront.PriceClassPriceClassAll),
			Enabled:           aws.True(),
			DefaultRootObject: aws.String(""),
			Aliases: &cloudfront.Aliases{
				Items:    []string{},
				Quantity: aws.Integer(0),
			},
			CallerReference: nameStr,
		},
	}
	result, err := cfr.CreateDistribution(&req)
	if err != nil {
		return nil, err
	}
	return &Distribution{
		Status:         "InProgress",
		Domain:         *result.Distribution.DomainName,
		InstanceId:     name,
		Comment:        comment,
		Enabled:        true,
		distributionId: result.Distribution.ID,
	}, nil
}