Пример #1
0
func (e *environ) PublicStorage() environs.StorageReader {
	e.publicStorageMutex.Lock()
	defer e.publicStorageMutex.Unlock()
	ecfg := e.ecfg()
	// If public storage has already been determined, return that instance.
	publicStorage := e.publicStorageUnlocked
	if publicStorage == nil && ecfg.publicBucket() == "" {
		// If there is no public bucket name, then there can be no public storage.
		e.publicStorageUnlocked = environs.EmptyStorage
		publicStorage = e.publicStorageUnlocked
	}
	if publicStorage != nil {
		return publicStorage
	}
	// If there is a public bucket URL defined, set up a public storage client referencing that URL,
	// otherwise create a new public bucket using the user's credentials on the authenticated client.
	publicBucketURL := e.publicBucketURL()
	if publicBucketURL == "" {
		e.publicStorageUnlocked = &storage{
			containerName: ecfg.publicBucket(),
			// this is possibly just a hack - if the ACL is swift.Private,
			// the machine won't be able to get the tools (401 error)
			containerACL: swift.PublicRead,
			swift:        swift.New(e.client)}
	} else {
		pc := client.NewPublicClient(publicBucketURL, nil)
		e.publicStorageUnlocked = &storage{
			containerName: ecfg.publicBucket(),
			containerACL:  swift.PublicRead,
			swift:         swift.New(pc)}
	}
	publicStorage = e.publicStorageUnlocked
	return publicStorage
}
Пример #2
0
func (e *environ) publicClient(ecfg *environConfig) client.Client {
	return client.NewPublicClient(ecfg.publicBucketURL(), nil)
}