Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ingest) - add audit actor urn to auditStamp #5264

Merged
merged 10 commits into from
Jul 8, 2022
1 change: 1 addition & 0 deletions metadata-service/restli-servlet-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
}

compile project(':metadata-service:restli-api')
compile project(':metadata-service:auth-api')
compile project(path: ':metadata-service:restli-api', configuration: 'dataTemplate')
compile project(':li-utils')
compile project(':metadata-models')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.linkedin.metadata.resources.entity;

import com.codahale.metrics.MetricRegistry;
import com.datahub.authentication.Authentication;
import com.datahub.authentication.AuthenticationContext;
import com.linkedin.common.AuditStamp;
import com.linkedin.common.UrnArray;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.LongMap;
import com.linkedin.data.template.StringArray;
import com.linkedin.entity.Entity;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.browse.BrowseResult;
import com.linkedin.metadata.entity.DeleteEntityService;
import com.linkedin.metadata.entity.EntityService;
Expand Down Expand Up @@ -193,9 +194,11 @@ public Task<Void> ingest(@ActionParam(PARAM_ENTITY) @Nonnull Entity entity,

SystemMetadata systemMetadata = populateDefaultFieldsIfEmpty(providedSystemMetadata);

// TODO Correctly audit ingestions.
final AuditStamp auditStamp =
new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(Constants.UNKNOWN_ACTOR));
Authentication authentication = AuthenticationContext.getAuthentication();
String actorUrnStr = authentication.getActor().toUrnStr();
// Getting actor from AuthenticationContext
log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this line!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjoyce0510 added actor urn for openapi-servlet as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome- thank you

final AuditStamp auditStamp = new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(actorUrnStr));

// variables referenced in lambdas are required to be final
final SystemMetadata finalSystemMetadata = systemMetadata;
Expand All @@ -219,8 +222,11 @@ public Task<Void> batchIngest(@ActionParam(PARAM_ENTITIES) @Nonnull Entity[] ent
}
}

final AuditStamp auditStamp =
new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(Constants.UNKNOWN_ACTOR));
Authentication authentication = AuthenticationContext.getAuthentication();
String actorUrnStr = authentication.getActor().toUrnStr();
// Getting actor from AuthenticationContext
log.debug(String.format("Retrieving AuthenticationContext for Actor with : %s", actorUrnStr));
neojunjie marked this conversation as resolved.
Show resolved Hide resolved
final AuditStamp auditStamp = new AuditStamp().setTime(_clock.millis()).setActor(Urn.createFromString(actorUrnStr));

if (systemMetadataList == null) {
systemMetadataList = new SystemMetadata[entities.length];
Expand Down