Skip to content

Commit

Permalink
Fixes #314 - Add Set Key (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem authored Jan 8, 2024
1 parent cae6ede commit 4675e9e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ jobs:
run: |
cd azure-keyvault
mvn -B -DskipTests=true -DskipITs=true -ntp docker:build docker:push
cd ../azure-appconfig
mvn -B -DskipTests=true -DskipITs=true -ntp docker:build docker:push
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jobs:
run: |
cd azure-keyvault
mvn -B -DskipTests=true -DskipITs=true -ntp docker:build docker:push
cd ../azure-appconfig
mvn -B -DskipTests=true -DskipITs=true -ntp docker:build docker:push
20 changes: 3 additions & 17 deletions azure-appconfig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,10 @@ For example:

Replace $PWD/certs with the local directory that contains the `keystore` file.

## What is the Key Vault URL?
## What is the App Configuration URL?

If the port used is `8201` and the name of the keyvault is 'mykeyvault' the
Key Vault URL would be:
If the port used is `8201` the App Configuration URL would be:

```text
https://localhost:8201/api/myappconfig
```

Note if you change the port number from `8201` to something else you will need
to also pass the BASE_URL environment variable on the command-line as the
simulator needs to know the outside Key Vault base URL to properly generate
ids, links and what not.

For example:

```bash
docker run --rm -it -p 7101:8101 -p 7201:8201 \
-e BASE_URL=https://localhost:7201 \
-v $PWD/certs:/home/piranha/certs manorrock/ocelot-azure-appconfig
https://localhost:8201/api
```
34 changes: 29 additions & 5 deletions azure-appconfig/src/main/java/appconfig/AppConfigResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import jakarta.inject.Singleton;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import java.util.HashMap;

/**
* REST API for Azure App Configuration.
Expand All @@ -13,6 +15,11 @@
@Path("kv")
@Singleton
public class AppConfigResource {

/**
* Stores the key/value store.
*/
private HashMap<String, KeyValueBundle> kv = new HashMap<>();

/**
* Get the key value.
Expand All @@ -23,15 +30,32 @@ public class AppConfigResource {
* </p>
*
* @param key the key.
* @return the value.
* @return the key-value bundle.
*/
@Path("{key}")
@GET
public KeyValueBundle getKeyValue(
@PathParam("key") String key) {
KeyValueBundle bundle = new KeyValueBundle();
bundle.setKey(key);
bundle.setValue("my_value");
return bundle;
return kv.get(key);
}

/**
* Set the key.
*
* <p>
* For more inforation, see
* https://learn.microsoft.com/en-us/azure/azure-app-configuration/rest-api-key-value#set-key
* </p>
*
* @param key the key.
* @param body the JSON body.
* @return the key-value bundle.
*/
@Path("{key}")
@PUT
public KeyValueBundle setKeyValue(
@PathParam("key") String key, KeyValueBundle body) {
kv.put(key, body);
return body;
}
}
1 change: 1 addition & 0 deletions azure-appconfig/src/test/java/appconfig/AppConfigIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void testGetKeyValue() {
.httpLogOptions(new HttpLogOptions().setLogLevel(BODY_AND_HEADERS))
.buildClient();

configClient.setConfigurationSetting("key", "label", "my_value");
assertEquals("my_value", configClient.getConfigurationSetting("key", "label").getValue());
}
}

0 comments on commit 4675e9e

Please sign in to comment.