@@ -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,22 @@ func NewMasterKey(vaultURL string, keyName string, keyVersion string) *MasterKey
7575 }
7676}
7777
78+ // NewMasterKey creates a new MasterKey from a URL, key name and (mandatory) version,
79+ // setting the creation date to the current date.
80+ func NewMasterKey (vaultURL string , keyName string , keyVersion string ) * MasterKey {
81+ return newMasterKey (vaultURL , keyName , keyVersion )
82+ }
83+
84+ // NewMasterKey creates a new MasterKey from a URL, key name and (optional) version,
85+ // setting the creation date to the current date.
86+ func NewMasterKeyWithOptionalVersion (vaultURL string , keyName string , keyVersion string ) (* MasterKey , error ) {
87+ key := newMasterKey (vaultURL , keyName , keyVersion )
88+ if err := key .ensureKeyHasVersion (context .Background ()); err != nil {
89+ return nil , err
90+ }
91+ return key , nil
92+ }
93+
7894// NewMasterKeyFromURL takes an Azure Key Vault key URL, and returns a new
7995// MasterKey. The URL format is {vaultUrl}/keys/{keyName}/{keyVersion}.
8096func NewMasterKeyFromURL (url string ) (* MasterKey , error ) {
@@ -88,9 +104,9 @@ func NewMasterKeyFromURL(url string) (*MasterKey, error) {
88104 // version of the key. We need to put the actual version in the sops metadata block though
89105 var key * MasterKey
90106 if len (parts [3 ]) > 1 {
91- key = NewMasterKey (parts [1 ], parts [2 ], parts [3 ][1 :])
107+ key = newMasterKey (parts [1 ], parts [2 ], parts [3 ][1 :])
92108 } else {
93- key = NewMasterKey (parts [1 ], parts [2 ], "" )
109+ key = newMasterKey (parts [1 ], parts [2 ], "" )
94110 }
95111 err := key .ensureKeyHasVersion (context .Background ())
96112 return key , err
0 commit comments