use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class ExternalIdIT method readExternalIdWithAccountIdThatCanBeExpressedInKiB.
@Test
public void readExternalIdWithAccountIdThatCanBeExpressedInKiB() throws Exception {
ExternalId.Key extIdKey = ExternalId.Key.parse("foo:bar");
Account.Id accountId = new Account.Id(1024 * 100);
extIdsUpdate.create().insert(ExternalId.create(extIdKey, accountId));
ExternalId extId = externalIds.get(extIdKey);
assertThat(extId.accountId()).isEqualTo(accountId);
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class ExternalIdIT method addExtId.
private void addExtId(TestRepository<?> testRepo, ExternalId... extIds) throws IOException, OrmDuplicateKeyException, ConfigInvalidException {
ObjectId rev = ExternalIdReader.readRevision(testRepo.getRepository());
try (ObjectInserter ins = testRepo.getRepository().newObjectInserter()) {
NoteMap noteMap = ExternalIdReader.readNoteMap(testRepo.getRevWalk(), rev);
for (ExternalId extId : extIds) {
ExternalIdsUpdate.insert(testRepo.getRevWalk(), ins, noteMap, extId);
}
ExternalIdsUpdate.commit(testRepo.getRepository(), testRepo.getRevWalk(), ins, rev, noteMap, "Add external ID", admin.getIdent(), admin.getIdent());
}
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class GpgKeys method parseFingerprint.
static byte[] parseFingerprint(String str, Iterable<ExternalId> existingExtIds) throws ResourceNotFoundException {
str = CharMatcher.whitespace().removeFrom(str).toUpperCase();
if ((str.length() != 8 && str.length() != 40) || !CharMatcher.anyOf("0123456789ABCDEF").matchesAllOf(str)) {
throw new ResourceNotFoundException(str);
}
byte[] fp = null;
for (ExternalId extId : existingExtIds) {
String fpStr = extId.key().id();
if (!fpStr.endsWith(str)) {
continue;
} else if (fp != null) {
throw new ResourceNotFoundException("Multiple keys found for " + str);
}
fp = BaseEncoding.base16().decode(fpStr);
if (str.length() == 40) {
break;
}
}
if (fp == null) {
throw new ResourceNotFoundException(str);
}
return fp;
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class Schema_144 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
Set<ExternalId> toAdd = new HashSet<>();
try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
ResultSet rs = stmt.executeQuery("SELECT " + "account_id, " + "email_address, " + "password, " + "external_id " + "FROM account_external_ids")) {
while (rs.next()) {
Account.Id accountId = new Account.Id(rs.getInt(1));
String email = rs.getString(2);
String password = rs.getString(3);
String externalId = rs.getString(4);
toAdd.add(ExternalId.create(ExternalId.Key.parse(externalId), accountId, email, password));
}
}
try {
try (Repository repo = repoManager.openRepository(allUsersName);
RevWalk rw = new RevWalk(repo);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId rev = ExternalIdReader.readRevision(repo);
NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
for (ExternalId extId : toAdd) {
ExternalIdsUpdate.upsert(rw, ins, noteMap, extId);
}
ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, COMMIT_MSG, serverIdent, serverIdent);
}
} catch (IOException | ConfigInvalidException e) {
throw new OrmException("Failed to migrate external IDs to NoteDb", e);
}
}
use of com.google.gerrit.server.account.externalids.ExternalId in project gerrit by GerritCodeReview.
the class Schema_148 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
try (Repository repo = repoManager.openRepository(allUsersName);
RevWalk rw = new RevWalk(repo);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId rev = ExternalIdReader.readRevision(repo);
NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
boolean dirty = false;
for (Note note : noteMap) {
byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB).getCachedBytes(ExternalIdReader.MAX_NOTE_SZ);
try {
ExternalId extId = ExternalId.parse(note.getName(), raw);
if (needsUpdate(extId)) {
ExternalIdsUpdate.upsert(rw, ins, noteMap, extId);
dirty = true;
}
} catch (ConfigInvalidException e) {
ui.message(String.format("Warning: Ignoring invalid external ID note %s", note.getName()));
}
}
if (dirty) {
ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, COMMIT_MSG, serverUser, serverUser);
}
} catch (IOException e) {
throw new OrmException("Failed to update external IDs", e);
}
}
Aggregations