forked from hpe-storage/common-host-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activate.go
62 lines (57 loc) · 2.02 KB
/
activate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2019 Hewlett Packard Enterprise Development LP
package handler
import (
"encoding/json"
"errors"
"github.com/hpe-storage/common-host-libs/connectivity"
"github.com/hpe-storage/common-host-libs/dockerplugin/plugin"
"github.com/hpe-storage/common-host-libs/dockerplugin/provider"
log "github.com/hpe-storage/common-host-libs/logger"
"net/http"
)
//@APIVersion 1.0.0
//@Title activate the docker volume plugin
//@Description implement the /Plugin.Activate Docker end point
//@Accept json
//@Resource /Plugin.Activate
//@Success 200 PluginActivate
//@Router /Plugin.Activate [post]
//@BasePath http:/Plugin.Activate
// ActivatePlugin implement the /Plugin.Activate Docker end point
func ActivatePlugin(w http.ResponseWriter, r *http.Request) {
log.Tracef("Plugin.Activate called")
actPlugResp := &PluginActivate{}
var pluginReq PluginRequest
// Add user credentials to the request
user, err := provider.GetProviderAccessKeys()
if err != nil {
dr := DriverResponse{Err: err.Error()}
json.NewEncoder(w).Encode(dr)
return
}
if user != nil {
pluginReq.User = user
}
pluginReq.Scope = plugin.IsLocalScopeDriver()
var hostContext Host
hostContext.NodeID = "" // race condition is hit if we tried to connect to docker socket when it is not ready
pluginReq.Host = &hostContext
//get containerProviderClient
providerClient, err := provider.GetProviderClient()
if err != nil {
err = errors.New("unable to setup the container-provider client " + err.Error())
resp := &DriverResponse{Err: err.Error()}
json.NewEncoder(w).Encode(resp)
return
}
// container-provider /Plugin.Activate called
log.Trace(pluginReq)
_, err = providerClient.DoJSON(&connectivity.Request{Action: "POST", Path: provider.ActivateURI, Payload: &pluginReq, Response: &actPlugResp, ResponseError: nil})
if err != nil {
resp := &DriverResponse{Err: err.Error()}
json.NewEncoder(w).Encode(resp)
return
}
log.Infof("%s: request=(%+v) response=(%+v)", provider.ActivateURI, pluginReq, actPlugResp.Activate)
json.NewEncoder(w).Encode(actPlugResp)
}