Search in sources :

Example 1 with NamedRef

use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.

the class AbstractGetNamedReferences method verifyReferences.

private void verifyReferences(GetNamedRefsParams params, ExpectedNamedReference... references) throws ReferenceNotFoundException {
    List<ReferenceInfo<ByteString>> expectedRefs = Arrays.stream(references).map(expectedRef -> expectedRef.expected(params)).filter(Objects::nonNull).collect(Collectors.toList());
    try (Stream<ReferenceInfo<ByteString>> refs = databaseAdapter.namedRefs(params)) {
        assertThat(refs).describedAs("GetNamedRefsParams=%s - references=%s", params, references).containsExactlyInAnyOrderElementsOf(expectedRefs);
    }
    for (ReferenceInfo<ByteString> expected : expectedRefs) {
        assertThat(databaseAdapter.namedRef(expected.getNamedRef().getName(), params)).isEqualTo(expected);
    }
    List<NamedRef> failureRefs = Arrays.stream(references).map(expectedRef -> {
        ReferenceInfo<ByteString> expected = expectedRef.expected(params);
        if (expected == null) {
            return expectedRef.ref;
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toList());
    for (NamedRef ref : failureRefs) {
        assertThatThrownBy(() -> databaseAdapter.namedRef(ref.getName(), params));
    }
}
Also used : ByteString(com.google.protobuf.ByteString) NamedRef(org.projectnessie.versioned.NamedRef) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) ImmutableReferenceInfo(org.projectnessie.versioned.ImmutableReferenceInfo)

Example 2 with NamedRef

use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.

the class TxDatabaseAdapter method fetchNamedRefs.

protected Stream<ReferenceInfo<ByteString>> fetchNamedRefs(ConnectionWrapper conn) {
    return JdbcSelectSpliterator.buildStream(conn.conn(), SqlStatements.SELECT_NAMED_REFERENCES, ps -> ps.setString(1, config.getRepositoryId()), (rs) -> {
        String type = rs.getString(1);
        String ref = rs.getString(2);
        Hash head = Hash.of(rs.getString(3));
        NamedRef namedRef = namedRefFromRow(type, ref);
        if (namedRef != null) {
            return ReferenceInfo.of(head, namedRef);
        }
        return null;
    });
}
Also used : ByteString(com.google.protobuf.ByteString) DatabaseAdapterUtil.verifyExpectedHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash) Hash(org.projectnessie.versioned.Hash) DatabaseAdapterUtil.randomHash(org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash) NamedRef(org.projectnessie.versioned.NamedRef)

Example 3 with NamedRef

use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.

the class ContentApiImpl method getMultipleContents.

@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
    try {
        WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
        List<ContentKey> externalKeys = request.getRequestedKeys();
        List<Key> internalKeys = externalKeys.stream().map(ContentApiImpl::toKey).collect(Collectors.toList());
        Map<Key, Content> values = getStore().getValues(ref.getHash(), internalKeys);
        List<ContentWithKey> output = values.entrySet().stream().map(e -> ContentWithKey.of(toContentKey(e.getKey()), e.getValue())).collect(Collectors.toList());
        return ImmutableGetMultipleContentsResponse.builder().contents(output).build();
    } catch (ReferenceNotFoundException ex) {
        throw new NessieReferenceNotFoundException(ex.getMessage(), ex);
    }
}
Also used : NamedRef(org.projectnessie.versioned.NamedRef) NessieContentNotFoundException(org.projectnessie.error.NessieContentNotFoundException) GetMultipleContentsResponse(org.projectnessie.model.GetMultipleContentsResponse) ServerConfig(org.projectnessie.services.config.ServerConfig) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentApi(org.projectnessie.api.ContentApi) GetMultipleContentsRequest(org.projectnessie.model.GetMultipleContentsRequest) Authorizer(org.projectnessie.services.authz.Authorizer) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) List(java.util.List) Principal(java.security.Principal) VersionStore(org.projectnessie.versioned.VersionStore) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) ImmutableGetMultipleContentsResponse(org.projectnessie.model.ImmutableGetMultipleContentsResponse) CommitMeta(org.projectnessie.model.CommitMeta) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) WithHash(org.projectnessie.versioned.WithHash) NamedRef(org.projectnessie.versioned.NamedRef) ContentKey(org.projectnessie.model.ContentKey) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Content(org.projectnessie.model.Content) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) Key(org.projectnessie.versioned.Key) ContentKey(org.projectnessie.model.ContentKey)

Example 4 with NamedRef

use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.

the class ContentApiImplWithAuthorization method getContent.

@Override
public Content getContent(ContentKey key, String namedRef, String hashOnRef) throws NessieNotFoundException {
    NamedRef ref = namedRefWithHashOrThrow(namedRef, hashOnRef).getValue();
    startAccessCheck().canReadEntityValue(ref, key, null).checkAndThrow();
    return super.getContent(key, namedRef, hashOnRef);
}
Also used : NamedRef(org.projectnessie.versioned.NamedRef)

Example 5 with NamedRef

use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.

the class ContentApiImplWithAuthorization method getMultipleContents.

@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
    WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
    BatchAccessChecker check = startAccessCheck();
    request.getRequestedKeys().forEach(k -> check.canReadEntityValue(ref.getValue(), k, null));
    check.checkAndThrow();
    return super.getMultipleContents(namedRef, hashOnRef, request);
}
Also used : BatchAccessChecker(org.projectnessie.services.authz.BatchAccessChecker) NamedRef(org.projectnessie.versioned.NamedRef)

Aggregations

NamedRef (org.projectnessie.versioned.NamedRef)12 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)6 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)5 CommitMeta (org.projectnessie.model.CommitMeta)5 Hash (org.projectnessie.versioned.Hash)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Content (org.projectnessie.model.Content)4 Principal (java.security.Principal)3 Map (java.util.Map)3 Nullable (javax.annotation.Nullable)3 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)3 ContentKey (org.projectnessie.model.ContentKey)3 RefUtil.toNamedRef (org.projectnessie.services.impl.RefUtil.toNamedRef)3 BranchName (org.projectnessie.versioned.BranchName)3 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)3 Preconditions (com.google.common.base.Preconditions)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ByteString (com.google.protobuf.ByteString)2 Collections (java.util.Collections)2