From 576673cb4ef6528163ad3dfb21cb89b2871c538a Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Tue, 15 May 2018 11:33:54 +0300 Subject: [PATCH] driver: make DigitalOcean API url customizable fixes #26 --- cmd/do-csi-plugin/main.go | 4 ++-- driver/driver.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/do-csi-plugin/main.go b/cmd/do-csi-plugin/main.go index c07746ac..28eb9017 100644 --- a/cmd/do-csi-plugin/main.go +++ b/cmd/do-csi-plugin/main.go @@ -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) } diff --git a/driver/driver.go b/driver/driver.go index 3c69a3c9..e2086f22 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -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, }) @@ -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,