7
7
8
8
"github.com/hashicorp/vault/logical"
9
9
"github.com/hashicorp/vault/logical/framework"
10
+ "github.com/splunk/vault-plugin-splunk/clients/splunk"
10
11
)
11
12
12
13
const secretCredsType = "creds"
@@ -35,6 +36,12 @@ func (b *backend) secretCredsRenewHandler(ctx context.Context, req *logical.Requ
35
36
return nil , fmt .Errorf ("error during renew: could not find role with name %q" , roleName )
36
37
}
37
38
39
+ nodeFQDN := ""
40
+ nodeFQDNRaw , ok := req .Secret .InternalData ["node_fqdn" ]
41
+ if ok {
42
+ nodeFQDN = nodeFQDNRaw .(string )
43
+ }
44
+
38
45
// Make sure we increase the VALID UNTIL endpoint for this user.
39
46
ttl , _ , err := framework .CalculateTTL (b .System (), req .Secret .Increment , role .DefaultTTL , 0 , role .MaxTTL , 0 , req .Secret .IssueTime )
40
47
if err != nil {
@@ -51,7 +58,7 @@ func (b *backend) secretCredsRenewHandler(ctx context.Context, req *logical.Requ
51
58
if err != nil {
52
59
return nil , err
53
60
}
54
- conn , err := b .ensureConnection (ctx , config )
61
+ conn , err := b .ensureNodeConnection (ctx , config , nodeFQDN )
55
62
if err != nil {
56
63
return nil , err
57
64
}
@@ -74,6 +81,11 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
74
81
if ! ok {
75
82
return nil , fmt .Errorf ("unable to convert connection name" )
76
83
}
84
+ nodeFQDN := ""
85
+ nodeFQDNRaw , ok := req .Secret .InternalData ["node_fqdn" ]
86
+ if ok {
87
+ nodeFQDN = nodeFQDNRaw .(string )
88
+ }
77
89
usernameRaw , ok := req .Secret .InternalData ["username" ]
78
90
if ! ok {
79
91
return nil , fmt .Errorf ("username is missing on the lease" )
@@ -84,7 +96,7 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
84
96
if err != nil {
85
97
return nil , err
86
98
}
87
- conn , err := b .ensureConnection (ctx , config )
99
+ conn , err := b .ensureNodeConnection (ctx , config , nodeFQDN )
88
100
if err != nil {
89
101
return nil , err
90
102
}
@@ -95,3 +107,15 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
95
107
}
96
108
return nil , nil
97
109
}
110
+
111
+ func (b * backend ) ensureNodeConnection (ctx context.Context , config * splunkConfig , nodeFQDN string ) (* splunk.API , error ) {
112
+ b .Logger ().Debug (fmt .Sprintf ("connection for node_fqdn: [%s]" , nodeFQDN ))
113
+ if nodeFQDN == "" {
114
+ return b .ensureConnection (ctx , config )
115
+ }
116
+
117
+ // we connect to a node, not the cluster master
118
+ nodeConfig := * config
119
+ nodeConfig .URL = "https://" + nodeFQDN + ":8089"
120
+ return nodeConfig .newConnection (ctx ) // XXX cache
121
+ }
0 commit comments