Skip to content

Commit

Permalink
Merge pull request #17 from jglick/RemotableGoogleCredentials.expirat…
Browse files Browse the repository at this point in the history
…ion-JENKINS-50216

[JENKINS-50216] - RemotableGoogleCredentials.expiration fix
  • Loading branch information
andreystroilov committed May 1, 2018
2 parents 62126a6 + fef8687 commit e68bbcc
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
target
work
2 changes: 2 additions & 0 deletions Jenkinsfile
@@ -0,0 +1,2 @@
// Build the plugin using https://github.com/jenkins-infra/pipeline-library
buildPlugin(platforms: ['linux'], jenkinsVersions: [null, '2.107.2'], failFast: false)
2 changes: 1 addition & 1 deletion checkstyleJavaHeader
@@ -1,5 +1,5 @@
^/\*$
^ \* Copyright 201(3|4|5) Google Inc\. All Rights Reserved\.$
^ \* Copyright 201(3|4|5|6|7|8) .*$
^ \*$
^ \* Licensed under the Apache License, Version 2\.0 \(the \"License\"\);$
^ \* you may not use this file except in compliance with the License\.$
Expand Down
65 changes: 19 additions & 46 deletions pom.xml
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.5</version>
<version>3.8</version>
</parent>

<!--
Expand All @@ -32,7 +32,7 @@
<description>
This plugin implements the OAuth Credentials interfaces to surface Google Service Account credentials to Jenkins.
</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Google+OAuth+Plugin</url>
<url>https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin</url>
<licenses>
<license>
<name>The Apache V2 License</name>
Expand All @@ -58,37 +58,19 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<version>1.96</version>
<extensions>true</extensions>
<configuration>
<disabledTestInjection>true</disabledTestInjection>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand All @@ -109,24 +91,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Max</effort>
<threshold>Medium</threshold>
<xmlOutput>true</xmlOutput>
<excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
Expand Down Expand Up @@ -160,6 +124,10 @@
<properties>
<jenkins.version>1.653</jenkins.version>
<google.api.version>1.22.0</google.api.version>
<java.level>7</java.level>
<findbugs.excludeFilterFile>findbugs-exclude.xml</findbugs.excludeFilterFile>
<findbugs.effort>Max</findbugs.effort>
<findbugs.threshold>Medium</findbugs.threshold>
</properties>

<dependencies>
Expand Down Expand Up @@ -197,12 +165,6 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
Expand Down Expand Up @@ -251,6 +213,17 @@
<version>1.16.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<!-- Required to run P12ServiceAccountConfigTestUtil-dependent tests against newer Jenkins core versions.
Dependency on it does not cause issues in the baseline core even though the plugin is formally incompatible.
Should it break at some point, the core requirement can be bumped to 2.17.x.
The BC library can be also shaded if the core requirement needs to be retained.
-->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>bouncycastle-api</artifactId>
<version>2.16.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Expand Up @@ -72,7 +72,8 @@ public RemotableGoogleCredentials(
}
this.accessToken = checkNotNull(credential.getAccessToken());
this.expiration = new DateTime().plusSeconds(
checkNotNull(credential.getExpiresInSeconds()).intValue());
checkNotNull(credential.getExpiresInSeconds()).intValue()).
getMillis();
}

/**
Expand Down Expand Up @@ -113,7 +114,7 @@ public Credential getGoogleCredential(
// TODO(mattmoor): Consider throwing an exception if the access token
// has expired.
long lifetimeSeconds =
(expiration.getMillis() - new DateTime().getMillis()) / 1000;
(expiration - new DateTime().getMillis()) / 1000;

return new GoogleCredential.Builder()
.setTransport(getModule().getHttpTransport())
Expand All @@ -136,7 +137,7 @@ public Credential getGoogleCredential(
/**
* The time at which the accessToken will expire.
*/
private final DateTime expiration;
private final long expiration;

/**
* The minimum duration to allow for an access token before attempting to
Expand Down
Expand Up @@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="${%Project Name}" field="projectId">
Expand Down
Expand Up @@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<f:entry title="${%Project Name}" field="projectId">
<f:textbox />
Expand Down
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"
xmlns:f="/lib/form">
<f:entry field="jsonKeyFile"
Expand Down
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"
xmlns:f="/lib/form">
<f:entry field="emailAddress"
Expand Down

0 comments on commit e68bbcc

Please sign in to comment.