Skip to content

Commit

Permalink
refreshing the values on demand
Browse files Browse the repository at this point in the history
Signed-off-by: Santhosh Gandhe <[email protected]>
  • Loading branch information
san81 committed Jan 21, 2025
1 parent 83e949d commit 7a71b40
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public interface PluginConfigVariable {
*/
void setValue(Object updatedValue);

/**
* Refresh the secret value on demand
*/
void refresh();

/**
* Returns if the variable is updatable.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public void setValue(Object newValue) {
this.secretValue = newValue;
}

@Override
public void refresh() {
secretsSupplier.refresh(secretId);
}


@Override
public boolean isUpdatable() {
return isUpdatable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -81,4 +83,11 @@ void testSetValueSuccess(final String input) {
assertThat(objectUnderTest.getValue(), equalTo(input));
}


@Test
void testRefreshSecretsWithKey() {
objectUnderTest.refresh();
verify(secretsSupplier, times(1)).refresh(secretId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public void renewCredentials() {
} catch (HttpClientErrorException ex) {
this.expireTime = Instant.ofEpochMilli(0);
this.expiresInSeconds = 0;
// Try refreshing the secrets and see if that helps
// Refreshing one of the secret refreshes the entire store so we are good to trigger refresh on just one
jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getAccessToken().refresh();
log.error("Failed to renew access token. Status code: {}, Error Message: {}",
ex.getRawStatusCode(), ex.getMessage());
throw new RuntimeException("Failed to renew access token" + ex.getMessage(), ex);
Expand Down

0 comments on commit 7a71b40

Please sign in to comment.