@@ -3,8 +3,9 @@ package splunk
33import (
44 "context"
55 "fmt"
6+
67 "github.com/hashicorp/errwrap"
7- "github.com/hashicorp/go-uuid"
8+ uuid "github.com/hashicorp/go-uuid"
89 "github.com/hashicorp/vault/helper/strutil"
910 "github.com/hashicorp/vault/logical"
1011 "github.com/hashicorp/vault/logical/framework"
@@ -84,7 +85,7 @@ func (b *backend) credsReadHandlerStandalone(ctx context.Context, req *logical.R
8485 }
8586
8687 // Generate credentials
87- userUUID , err := uuid . GenerateUUID ( )
88+ userUUID , err := generateUserID ( role )
8889 if err != nil {
8990 return nil , err
9091 }
@@ -93,7 +94,7 @@ func (b *backend) credsReadHandlerStandalone(ctx context.Context, req *logical.R
9394 userPrefix = fmt .Sprintf ("%s_%s" , role .UserPrefix , req .DisplayName )
9495 }
9596 username := fmt .Sprintf ("%s_%s" , userPrefix , userUUID )
96- passwd , err := uuid . GenerateUUID ( )
97+ passwd , err := generateUserPassword ( role )
9798 if err != nil {
9899 return nil , errwrap .Wrapf ("error generating new password {{err}}" , err )
99100 }
@@ -193,7 +194,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
193194 return nil , err
194195 }
195196 // Generate credentials
196- userUUID , err := uuid . GenerateUUID ( )
197+ userUUID , err := generateUserID ( role )
197198 if err != nil {
198199 return nil , err
199200 }
@@ -202,7 +203,7 @@ func (b *backend) credsReadHandlerMulti(ctx context.Context, req *logical.Reques
202203 userPrefix = fmt .Sprintf ("%s_%s" , role .UserPrefix , req .DisplayName )
203204 }
204205 username := fmt .Sprintf ("%s_%s" , userPrefix , userUUID )
205- passwd , err := uuid . GenerateUUID ( )
206+ passwd , err := generateUserPassword ( role )
206207 if err != nil {
207208 return nil , errwrap .Wrapf ("error generating new password: {{err}}" , err )
208209 }
@@ -251,6 +252,19 @@ func (b *backend) credsReadHandler(ctx context.Context, req *logical.Request, d
251252 return b .credsReadHandlerStandalone (ctx , req , d )
252253}
253254
255+ func generateUserID (roleConfig * roleConfig ) (string , error ) {
256+ return uuid .GenerateUUID ()
257+ }
258+
259+ func generateUserPassword (roleConfig * roleConfig ) (string , error ) {
260+ passwd , err := GeneratePassword (roleConfig .PasswordSpec )
261+ if err == nil {
262+ return passwd , nil
263+ }
264+ // fallback
265+ return uuid .GenerateUUID ()
266+ }
267+
254268const pathCredsCreateHelpSyn = `
255269Request Splunk credentials for a certain role.
256270`
0 commit comments