Skip to content

Commit

Permalink
cross domain/project scoping (#10)
Browse files Browse the repository at this point in the history
* update github.com/gophercloud/gophercloud

* fix cross domain scoping
  • Loading branch information
auhlig authored and jdolitsky committed Apr 25, 2019
1 parent 643d16e commit 567c198
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 55 deletions.
42 changes: 42 additions & 0 deletions openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
pathutil "path"

"github.com/gophercloud/gophercloud"
Expand Down Expand Up @@ -75,6 +76,17 @@ func NewOpenstackOSBackend(container string, prefix string, region string, caCer
}
authOptions.AllowReauth = true

if authScope := getAuthScope(); authScope != nil {
authOptions.Scope = authScope
}

if userDomainName := os.Getenv("OS_USER_DOMAIN_NAME"); userDomainName != "" {
authOptions.DomainName = userDomainName
}
if userDomainID := os.Getenv("OS_USER_DOMAIN_ID"); userDomainID != "" {
authOptions.DomainID = userDomainID
}

// Create a custom HTTP client to handle reauth retry and custom CACERT if needed
roundTripper := ReauthRoundTripper{}
if caCert != "" {
Expand Down Expand Up @@ -199,3 +211,33 @@ func (b OpenstackOSBackend) DeleteObject(path string) error {
_, err := osObjects.Delete(b.Client, b.Container, pathutil.Join(b.Prefix, path), nil).Extract()
return err
}

func getAuthScope() *gophercloud.AuthScope {
scope := &gophercloud.AuthScope{}

// Scope to project by ID.
if projectID := os.Getenv("OS_PROJECT_ID"); projectID != "" {
scope.ProjectID = projectID
return scope
}

// Scope to project by name. Requires the project domain name or ID as well.
projectName := os.Getenv("OS_PROJECT_NAME")
if projectName == "" {
return nil
}
scope.ProjectName = projectName

projectDomainName := os.Getenv("OS_PROJECT_DOMAIN_NAME")
projectDomainID := os.Getenv("OS_PROJECT_DOMAIN_ID")

if projectDomainName == "" && projectDomainID == "" {
return nil
}

if projectDomainName != "" {
scope.DomainName = projectDomainName
}
scope.DomainID = projectDomainID
return nil
}
14 changes: 9 additions & 5 deletions vendor/github.com/gophercloud/gophercloud/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions vendor/github.com/gophercloud/gophercloud/.zuul.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 28 additions & 10 deletions vendor/github.com/gophercloud/gophercloud/auth_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/github.com/gophercloud/gophercloud/auth_result.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/gophercloud/gophercloud/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/gophercloud/gophercloud/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/gophercloud/gophercloud/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/gophercloud/gophercloud/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 37 additions & 10 deletions vendor/github.com/gophercloud/gophercloud/openstack/auth_env.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 567c198

Please sign in to comment.