github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/providers/security/pkcs11sec/option.go (about) 1 // Copyright (c) 2020-2022, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package pkcs11sec 6 7 import ( 8 "github.com/choria-io/go-choria/config" 9 "github.com/choria-io/go-choria/inter" 10 "github.com/sirupsen/logrus" 11 ) 12 13 type Option func(*Pkcs11Security) error 14 15 func WithChoriaConfig(c *config.Config) Option { 16 return func(p *Pkcs11Security) error { 17 cfg := Config{ 18 AllowList: c.Choria.CertnameAllowList, 19 DisableTLSVerify: c.DisableTLSVerify, 20 PrivilegedUsers: c.Choria.PrivilegedUsers, 21 CAFile: c.Choria.FileSecurityCA, 22 PKCS11DriverFile: c.Choria.PKCS11DriverFile, 23 PKCS11Slot: uint(c.Choria.PKCS11Slot), 24 } 25 26 p.conf = &cfg 27 28 return nil 29 } 30 } 31 32 // WithSigner configures a remote request signer 33 func WithSigner(signer inter.RequestSigner) Option { 34 return func(p *Pkcs11Security) error { 35 p.conf.RemoteSigner = signer 36 37 return nil 38 } 39 } 40 41 func WithLog(l *logrus.Entry) Option { 42 return func(p *Pkcs11Security) error { 43 p.log = l.WithFields(logrus.Fields{"security": "pkcs11"}) 44 45 return nil 46 } 47 } 48 49 func WithPin(pin string) Option { 50 return func(p *Pkcs11Security) error { 51 p.pin = &pin 52 53 return nil 54 } 55 }