-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cef45a1
commit d81337f
Showing
8 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...ot-autoconfigure/src/main/java/org/zalando/riptide/autoconfigure/AccessTokensFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.zalando.riptide.autoconfigure; | ||
|
||
import org.zalando.stups.tokens.AccessTokens; | ||
import org.zalando.stups.tokens.AccessTokensBuilder; | ||
import org.zalando.stups.tokens.JsonFileBackedClientCredentialsProvider; | ||
import org.zalando.stups.tokens.JsonFileBackedUserCredentialsProvider; | ||
import org.zalando.stups.tokens.Tokens; | ||
|
||
import javax.annotation.Nullable; | ||
import java.net.URI; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
@SuppressWarnings("unused") | ||
final class AccessTokensFactory { | ||
|
||
private AccessTokensFactory() { | ||
|
||
} | ||
|
||
public static AccessTokens createAccessTokens(final RiptideProperties properties) { | ||
final RiptideProperties.GlobalOAuth oAuth = properties.getOauth(); | ||
|
||
final URI accessTokenUrl = getAccessTokenUrl(oAuth); | ||
@Nullable final Path directory = oAuth.getCredentialsDirectory(); | ||
final TimeSpan connectTimeout = oAuth.getConnectTimeout(); | ||
final TimeSpan socketTimeout = oAuth.getSocketTimeout(); | ||
|
||
final AccessTokensBuilder builder = Tokens.createAccessTokensWithUri(accessTokenUrl) | ||
.usingClientCredentialsProvider(getClientCredentialsProvider(directory)) | ||
.usingUserCredentialsProvider(getUserCredentialsProvider(directory)) | ||
.schedulingPeriod((int) oAuth.getSchedulingPeriod().getAmount()) | ||
.schedulingTimeUnit(oAuth.getSchedulingPeriod().getUnit()) | ||
.connectTimeout((int) connectTimeout.to(TimeUnit.MILLISECONDS)) | ||
.socketTimeout((int) socketTimeout.to(TimeUnit.MILLISECONDS)); | ||
|
||
properties.getClients().forEach((id, client) -> { | ||
@Nullable final RiptideProperties.Client.OAuth clientOAuth = client.getOauth(); | ||
|
||
if (clientOAuth == null) { | ||
return; | ||
} | ||
|
||
builder.manageToken(id) | ||
.addScopesTypeSafe(clientOAuth.getScopes()) | ||
.done(); | ||
}); | ||
|
||
return builder.start(); | ||
} | ||
|
||
private static JsonFileBackedClientCredentialsProvider getClientCredentialsProvider(@Nullable final Path directory) { | ||
return directory == null ? | ||
new JsonFileBackedClientCredentialsProvider() : | ||
new JsonFileBackedClientCredentialsProvider(directory.resolve("client.json").toFile()); | ||
} | ||
|
||
private static JsonFileBackedUserCredentialsProvider getUserCredentialsProvider(@Nullable final Path directory) { | ||
return directory == null ? | ||
new JsonFileBackedUserCredentialsProvider() : | ||
new JsonFileBackedUserCredentialsProvider(directory.resolve("user.json").toFile()); | ||
} | ||
|
||
private static URI getAccessTokenUrl(final RiptideProperties.GlobalOAuth oauth) { | ||
@Nullable final URI accessTokenUrl = oauth.getAccessTokenUrl(); | ||
|
||
checkArgument(accessTokenUrl != null, "" + | ||
"Neither 'riptide.oauth.access-token-url' nor 'ACCESS_TOKEN_URL' was set, " + | ||
"but at least one client requires OAuth"); | ||
|
||
return accessTokenUrl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...riptide/spring/FailsafePluginFactory.java → .../autoconfigure/FailsafePluginFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../riptide/spring/MetricsPluginFactory.java → ...e/autoconfigure/MetricsPluginFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...riptide/spring/HttpClientFactoryTest.java → .../autoconfigure/HttpClientFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters