@@ -64,9 +64,9 @@ type MasterKey struct {
6464 clientOptions * azkeys.ClientOptions
6565}
6666
67- // NewMasterKey creates a new MasterKey from a URL, key name and version,
67+ // newMasterKey creates a new MasterKey from a URL, key name and version,
6868// setting the creation date to the current date.
69- func NewMasterKey (vaultURL string , keyName string , keyVersion string ) * MasterKey {
69+ func newMasterKey (vaultURL string , keyName string , keyVersion string ) * MasterKey {
7070 return & MasterKey {
7171 VaultURL : vaultURL ,
7272 Name : keyName ,
@@ -75,6 +75,14 @@ func NewMasterKey(vaultURL string, keyName string, keyVersion string) *MasterKey
7575 }
7676}
7777
78+ // NewMasterKey creates a new MasterKey from a URL, key name and (optional) version,
79+ // setting the creation date to the current date.
80+ func NewMasterKey (vaultURL string , keyName string , keyVersion string ) (* MasterKey , error ) {
81+ key := newMasterKey (vaultURL , keyName , keyVersion )
82+ err := key .ensureKeyHasVersion (context .Background ())
83+ return key , err
84+ }
85+
7886// NewMasterKeyFromURL takes an Azure Key Vault key URL, and returns a new
7987// MasterKey. The URL format is {vaultUrl}/keys/{keyName}/{keyVersion}.
8088func NewMasterKeyFromURL (url string ) (* MasterKey , error ) {
@@ -88,9 +96,9 @@ func NewMasterKeyFromURL(url string) (*MasterKey, error) {
8896 // version of the key. We need to put the actual version in the sops metadata block though
8997 var key * MasterKey
9098 if len (parts [3 ]) > 1 {
91- key = NewMasterKey (parts [1 ], parts [2 ], parts [3 ][1 :])
99+ key = newMasterKey (parts [1 ], parts [2 ], parts [3 ][1 :])
92100 } else {
93- key = NewMasterKey (parts [1 ], parts [2 ], "" )
101+ key = newMasterKey (parts [1 ], parts [2 ], "" )
94102 }
95103 err := key .ensureKeyHasVersion (context .Background ())
96104 return key , err
0 commit comments