77
88 "github.com/hashicorp/vault/logical"
99 "github.com/hashicorp/vault/logical/framework"
10+ "github.com/splunk/vault-plugin-splunk/clients/splunk"
1011)
1112
1213const secretCredsType = "creds"
@@ -35,6 +36,12 @@ func (b *backend) secretCredsRenewHandler(ctx context.Context, req *logical.Requ
3536 return nil , fmt .Errorf ("error during renew: could not find role with name %q" , roleName )
3637 }
3738
39+ nodeFQDN := ""
40+ nodeFQDNRaw , ok := req .Secret .InternalData ["node_fqdn" ]
41+ if ok {
42+ nodeFQDN = nodeFQDNRaw .(string )
43+ }
44+
3845 // Make sure we increase the VALID UNTIL endpoint for this user.
3946 ttl , _ , err := framework .CalculateTTL (b .System (), req .Secret .Increment , role .DefaultTTL , 0 , role .MaxTTL , 0 , req .Secret .IssueTime )
4047 if err != nil {
@@ -51,7 +58,7 @@ func (b *backend) secretCredsRenewHandler(ctx context.Context, req *logical.Requ
5158 if err != nil {
5259 return nil , err
5360 }
54- conn , err := b .ensureConnection (ctx , config )
61+ conn , err := b .ensureNodeConnection (ctx , config , nodeFQDN )
5562 if err != nil {
5663 return nil , err
5764 }
@@ -74,6 +81,11 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
7481 if ! ok {
7582 return nil , fmt .Errorf ("unable to convert connection name" )
7683 }
84+ nodeFQDN := ""
85+ nodeFQDNRaw , ok := req .Secret .InternalData ["node_fqdn" ]
86+ if ok {
87+ nodeFQDN = nodeFQDNRaw .(string )
88+ }
7789 usernameRaw , ok := req .Secret .InternalData ["username" ]
7890 if ! ok {
7991 return nil , fmt .Errorf ("username is missing on the lease" )
@@ -84,7 +96,7 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
8496 if err != nil {
8597 return nil , err
8698 }
87- conn , err := b .ensureConnection (ctx , config )
99+ conn , err := b .ensureNodeConnection (ctx , config , nodeFQDN )
88100 if err != nil {
89101 return nil , err
90102 }
@@ -95,3 +107,15 @@ func (b *backend) secretCredsRevokeHandler(ctx context.Context, req *logical.Req
95107 }
96108 return nil , nil
97109}
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