Skip to content

Commit

Permalink
Merge pull request #27 from digitalocean/custom-do-api
Browse files Browse the repository at this point in the history
driver: make DigitalOcean API url customizable
  • Loading branch information
fatih authored May 15, 2018
2 parents d64ba13 + 576673c commit c74f7b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/do-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func main() {
var (
endpoint = flag.String("endpoint", "unix:///var/lib/kubelet/plugins/com.digitalocean.csi.dobs/csi.sock", "CSI endpoint")
token = flag.String("token", "", "DigitalOcean access token")
url = flag.String("url", "https://api.digitalocean.com/", "DigitalOcean API URL")
)

flag.Parse()

drv, err := driver.NewDriver(*endpoint, *token)
drv, err := driver.NewDriver(*endpoint, *token, *url)
if err != nil {
log.Fatalln(err)
}
Expand Down
12 changes: 10 additions & 2 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Driver struct {
// NewDriver returns a CSI plugin that contains the necessary gRPC
// interfaces to interact with Kubernetes over unix domain sockets for
// managaing DigitalOcean Block Storage
func NewDriver(ep, token string) (*Driver, error) {
func NewDriver(ep, token, url string) (*Driver, error) {
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: token,
})
Expand All @@ -68,11 +68,19 @@ func NewDriver(ep, token string) (*Driver, error) {
region := all.Region
nodeId := strconv.Itoa(all.DropletID)

opts := []godo.ClientOpt{}
opts = append(opts, godo.SetBaseURL(url))

doClient, err := godo.New(oauthClient, opts...)
if err != nil {
return nil, fmt.Errorf("couldn't initialize DigitalOcean client: %s", err)
}

return &Driver{
endpoint: ep,
nodeId: nodeId,
region: region,
doClient: godo.NewClient(oauthClient),
doClient: doClient,
mounter: &mounter{},
log: logrus.New().WithFields(logrus.Fields{
"region": region,
Expand Down

0 comments on commit c74f7b4

Please sign in to comment.