NewMasterKeyFromURI obtains the Vault address, Transit backend path and the key name from the full URI of the key.
(uri string)
| 166 | // NewMasterKeyFromURI obtains the Vault address, Transit backend path and the |
| 167 | // key name from the full URI of the key. |
| 168 | func NewMasterKeyFromURI(uri string) (*MasterKey, error) { |
| 169 | var key *MasterKey |
| 170 | if uri == "" { |
| 171 | return key, nil |
| 172 | } |
| 173 | u, err := url.Parse(uri) |
| 174 | if err != nil { |
| 175 | return nil, err |
| 176 | } |
| 177 | if u.Scheme == "" { |
| 178 | return nil, fmt.Errorf("missing scheme in Vault URL (should be like this: +"+ |
| 179 | "https://vault.example.com:8200/v1/transit/keys/keyName), got: %v", uri) |
| 180 | } |
| 181 | enginePath, keyName, err := engineAndKeyFromPath(u.RequestURI()) |
| 182 | if err != nil { |
| 183 | return nil, err |
| 184 | } |
| 185 | u.Path = "" |
| 186 | return NewMasterKey(u.String(), enginePath, keyName), nil |
| 187 | |
| 188 | } |
| 189 | |
| 190 | // NewMasterKey creates a new MasterKey from a Vault address, Transit backend |
| 191 | // path and a key name. |