This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
8 changed files
with
81 additions
and
20 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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/github/libgraviton/workerbase/GravitonAuthApi.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,45 @@ | ||
package com.github.libgraviton.workerbase; | ||
|
||
import com.github.libgraviton.gdk.GravitonApi; | ||
import com.github.libgraviton.gdk.api.header.HeaderBag; | ||
import com.github.libgraviton.gdk.util.PropertiesLoader; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Public base class for workers api calls with auth headers | ||
* | ||
* @author List of contributors {@literal <https://github.com/libgraviton/graviton-worker-base-java/graphs/contributors>} | ||
* @see <a href="http://swisscom.ch">http://swisscom.ch</a> | ||
* @version $Id: $Id | ||
*/ | ||
public class GravitonAuthApi extends GravitonApi { | ||
|
||
protected Properties properties; | ||
|
||
@Override | ||
protected HeaderBag getDefaultHeaders() { | ||
String authHeaderValue = properties.getProperty("graviton.authentication.prefix.username") | ||
.concat(properties.getProperty("graviton.workerId")); | ||
String authHeaderName = properties.getProperty("graviton.authentication.header.name"); | ||
|
||
return new HeaderBag.Builder() | ||
.set("Content-Type", "application/json") | ||
.set("Accept", "application/json") | ||
.set(authHeaderName, authHeaderValue) | ||
.build(); | ||
} | ||
|
||
|
||
// TODO remove the setup override as soon as properties is no longer private in GravitonApi | ||
@Override | ||
protected void setup() { | ||
try { | ||
this.properties = PropertiesLoader.load(); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Unable to load properties files.", e); | ||
} | ||
super.setup(); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/test/java/com/github/libgraviton/workerbase/GravitonAuthApiTest.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,21 @@ | ||
package com.github.libgraviton.workerbase; | ||
|
||
import com.github.libgraviton.gdk.api.header.Header; | ||
import com.github.libgraviton.gdk.api.header.HeaderBag; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class GravitonAuthApiTest { | ||
|
||
@Test | ||
public void testGetDefaultHeader() { | ||
GravitonAuthApi gravitonApi = new GravitonAuthApi(); | ||
HeaderBag headers = gravitonApi.getDefaultHeaders(); | ||
assertEquals(3, headers.all().size()); | ||
|
||
Header header = headers.get("x-graviton-authentication"); | ||
assertEquals("subnet-java-test", header.get(0)); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
addition=dude | ||
graviton.base.url=http://gravitonApi-base-url | ||
graviton.base.url=http://gravitonApi-base-url | ||
graviton.workerId=java-test | ||
|
||
# Graviton Api Subnet authentication | ||
graviton.authentication.prefix.username=subnet- | ||
graviton.authentication.header.name=x-graviton-authentication |
This file was deleted.
Oops, something went wrong.