Skip to content

Commit

Permalink
Removing instance-identity dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored and olamy committed Aug 5, 2022
1 parent 1a24550 commit 3bb6943
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 41 deletions.
5 changes: 0 additions & 5 deletions blueocean-pipeline-api-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@
<artifactId>jsoup</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>instance-identity</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
4 changes: 0 additions & 4 deletions blueocean-rest-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@
<groupId>io.keen</groupId>
<artifactId>keen-client-api-java</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>instance-identity</artifactId>
</dependency>

<dependency>
<groupId>com.github.ua-parser</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.jenkins.blueocean.commons.DigestUtils;
import io.jenkins.blueocean.commons.ServiceException;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.main.modules.instance_identity.InstanceIdentity;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Stapler;
Expand Down Expand Up @@ -50,11 +49,9 @@ public void track(TrackRequest req) {
allProps.putAll(additionalProperties);
}
}
String server = server();
allProps.put("jenkins", server);
// Background requests do not have userId
if (Stapler.getCurrentRequest() != null) {
String identity = identity(server);
String identity = identity();
allProps.put("userId", identity);
}

Expand All @@ -71,20 +68,9 @@ public void track(TrackRequest req) {

protected abstract void doTrack(String name, Map<String, Object> allProps);

protected final String server() {
byte[] identityBytes;
try {
identityBytes = InstanceIdentity.get().getPublic().getEncoded();
} catch (AssertionError e) {
LOGGER.error("There was a problem identifying this server", e);
throw new IllegalStateException("There was a problem identifying this server", e);
}
return DigestUtils.sha256(identityBytes);
}

protected final String identity(String server) {
protected final String identity() {
User user = User.current();
String username = user == null ? "ANONYMOUS" : user.getId();
return DigestUtils.sha256(username + server, Charset.defaultCharset());
return DigestUtils.sha256(username, Charset.defaultCharset());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public void track() {
analytics.track(new TrackRequest("test", props));

Map<String, Object> expectedProps = new HashMap<>(props);
expectedProps.put("jenkins", analytics.getServer());

Assert.assertEquals("test", analytics.lastName);
Assert.assertEquals( expectedProps, analytics.lastProps);
Expand All @@ -70,7 +69,6 @@ public void trackWithoutProps() {
analytics.track(new TrackRequest("test", null));

Map<String, Object> expectedProps = new HashMap();
expectedProps.put("jenkins", analytics.getServer());
expectedProps.put("jenkinsVersion", j.jenkins.getVersion().toString());
expectedProps.put("blueoceanVersion", Jenkins.get().getPlugin("blueocean-commons").getWrapper().getVersion());

Expand Down Expand Up @@ -117,12 +115,8 @@ protected void doTrack(String name, Map<String, Object> allProps) {
lastProps = allProps;
}

public String getServer() {
return server();
}

public String getIdentity() {
return identity(server());
return identity();
}
}
}
8 changes: 0 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,6 @@
</exclusions>
</dependency>

<!-- Included in core -->
<dependency>
<groupId>org.jenkins-ci.modules</groupId>
<artifactId>instance-identity</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.ua-parser</groupId>
<artifactId>uap-java</artifactId>
Expand Down

0 comments on commit 3bb6943

Please sign in to comment.