This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial code for kubernetes integration (#75)
* Initial code for kubernetes integration fixes #61 * drop jdk-7 * first review changes * rename to FilesystemSecrets**** * rename package 'k8s'->'fs' * handle 'clients' and 'authorizations' * update to latest version of mockito and assertj, remove config for javadoc-maven-plugin (now taken from parent-pom), fix tests according these changes, replace 'Clients','Authorizations' with 'Secrets' * do not use deprecated methods in tests * fix 'resource-leak' warning * minor updates in README * [maven-release-plugin] prepare release 0.11.0-beta-1 * [maven-release-plugin] prepare for next development iteration * remove any usage of 'k8s', 'kube' or 'kubernetes' * [maven-release-plugin] prepare release 0.11.0-beta-2 * [maven-release-plugin] prepare for next development iteration
- Loading branch information
Showing
37 changed files
with
1,142 additions
and
147 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ language: java | |
|
||
jdk: | ||
- oraclejdk8 | ||
- oraclejdk7 | ||
|
||
before_script: | ||
- pip install --user codecov | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9474746353524 |
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 @@ | ||
94747463535249474746353524947474635352494747463535249474746353524 |
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 @@ | ||
geheim |
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 @@ | ||
Basic |
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 @@ | ||
987654321123456789 |
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 @@ | ||
Bearer |
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
102 changes: 102 additions & 0 deletions
102
src/main/java/org/zalando/stups/tokens/AbstractAccessTokenRefresher.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,102 @@ | ||
/** | ||
* Copyright (C) 2015 Zalando SE (http://tech.zalando.com) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zalando.stups.tokens; | ||
|
||
import java.util.Date; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class AbstractAccessTokenRefresher implements AccessTokens { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AbstractAccessTokenRefresher.class); | ||
|
||
private static final long ONE_YEAR_SECONDS = TimeUnit.DAYS.toSeconds(365); | ||
private static final String FIXED_TOKENS_ENV_VAR = "OAUTH2_ACCESS_TOKENS"; | ||
|
||
protected final TokenRefresherConfiguration configuration; | ||
protected final ScheduledExecutorService scheduler; | ||
|
||
protected final ConcurrentHashMap<Object, AccessToken> accessTokens = new ConcurrentHashMap<>(); | ||
|
||
public AbstractAccessTokenRefresher(TokenRefresherConfiguration configuration) { | ||
this.configuration = configuration; | ||
this.scheduler = configuration.getExecutorService(); | ||
} | ||
|
||
protected void initializeFixedTokensFromEnvironment() { | ||
final String csv = getFixedToken(); | ||
if (csv != null) { | ||
LOG.info("Initializing fixed access tokens from {} environment variable..", FIXED_TOKENS_ENV_VAR); | ||
|
||
final String[] tokens = csv.split(","); | ||
final long expiresInSeconds = ONE_YEAR_SECONDS; | ||
final Date validUntil = new Date(System.currentTimeMillis() + (expiresInSeconds * 1000)); | ||
for (String token : tokens) { | ||
final String[] keyValue = token.split("="); | ||
if (keyValue.length == 2) { | ||
LOG.info("Using fixed access token {}..", keyValue[0]); | ||
accessTokens.put(keyValue[0], new AccessToken(keyValue[1], "fixed", expiresInSeconds, validUntil)); | ||
} else { | ||
LOG.error("Could not create access token from {}", token); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public abstract void start(); | ||
|
||
protected String getFixedToken() { | ||
final String tokens = System.getProperty(FIXED_TOKENS_ENV_VAR); | ||
if (tokens == null) { | ||
return System.getenv(FIXED_TOKENS_ENV_VAR); | ||
} | ||
|
||
return tokens; | ||
} | ||
|
||
@Override | ||
public String get(final Object tokenId) throws AccessTokenUnavailableException { | ||
return getAccessToken(tokenId).getToken(); | ||
} | ||
|
||
@Override | ||
public AccessToken getAccessToken(final Object tokenId) throws AccessTokenUnavailableException { | ||
final AccessToken token = accessTokens.get(tokenId); | ||
if (token == null) { | ||
throw new AccessTokenUnavailableException("no token available"); | ||
} | ||
|
||
if (token.isExpired()) { | ||
throw new AccessTokenUnavailableException("token expired"); | ||
} | ||
|
||
return token; | ||
} | ||
|
||
@Override | ||
public void invalidate(final Object tokenId) { | ||
accessTokens.remove(tokenId); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
scheduler.shutdown(); | ||
} | ||
} |
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
Oops, something went wrong.