Store stores a credential in the global git config
(repo repository.RepoKeyring, cred Credential)
| 190 | |
| 191 | // Store stores a credential in the global git config |
| 192 | func Store(repo repository.RepoKeyring, cred Credential) error { |
| 193 | if len(cred.Salt()) != 16 { |
| 194 | panic("credentials need to be salted") |
| 195 | } |
| 196 | |
| 197 | confs := cred.toConfig() |
| 198 | |
| 199 | confs[keyringKeyKind] = string(cred.Kind()) |
| 200 | confs[keyringKeyTarget] = cred.Target() |
| 201 | confs[keyringKeyCreateTime] = strconv.Itoa(int(cred.CreateTime().Unix())) |
| 202 | confs[keyringKeySalt] = base64.StdEncoding.EncodeToString(cred.Salt()) |
| 203 | |
| 204 | for key, val := range cred.Metadata() { |
| 205 | confs[keyringKeyPrefixMeta+key] = val |
| 206 | } |
| 207 | |
| 208 | data, err := json.Marshal(confs) |
| 209 | if err != nil { |
| 210 | return err |
| 211 | } |
| 212 | |
| 213 | return repo.Keyring().Set(repository.Item{ |
| 214 | Key: keyringKeyPrefix + cred.ID().String(), |
| 215 | Data: data, |
| 216 | }) |
| 217 | } |
| 218 | |
| 219 | // Remove removes a credential from the global git config |
| 220 | func Remove(repo repository.RepoKeyring, id entity.Id) error { |