Skip to content

Commit

Permalink
DEVX-299 add option to customize api url and auth url (#537)
Browse files Browse the repository at this point in the history
* DEVX-299 add option to customize api url and auth url

* DEVX-299 remove optional CI params

* Release v5.4.3
  • Loading branch information
lojzatran authored Dec 20, 2023
1 parent dc15de7 commit 92beee6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ jobs:
SOURCE_PROJECT_KEY: project-sync-source
SOURCE_CLIENT_ID: ${{ secrets.SOURCE_CLIENT_ID }}
SOURCE_CLIENT_SECRET: ${{ secrets.SOURCE_CLIENT_SECRET }}
SOURCE_AUTH_URL: ${{ secrets.SOURCE_AUTH_URL }}
SOURCE_API_URL: ${{ secrets.SOURCE_API_URL }}
TARGET_PROJECT_KEY: project-sync-target
TARGET_CLIENT_ID: ${{ secrets.TARGET_CLIENT_ID }}
TARGET_CLIENT_SECRET: ${{ secrets.TARGET_CLIENT_SECRET }}
TARGET_AUTH_URL: ${{ secrets.TARGET_AUTH_URL }}
TARGET_API_URL: ${{ secrets.TARGET_API_URL }}
- name: Codecov
uses: codecov/codecov-action@v3
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Example:
##### Download

```bash
docker pull commercetools/commercetools-project-sync:5.4.1
docker pull commercetools/commercetools-project-sync:5.4.3
```
##### Run

Expand All @@ -222,14 +222,14 @@ docker run \
-e TARGET_PROJECT_KEY=xxxx \
-e TARGET_CLIENT_ID=xxxx \
-e TARGET_CLIENT_SECRET=xxxx \
commercetools/commercetools-project-sync:5.4.1 -s all
commercetools/commercetools-project-sync:5.4.3 -s all
```


### Examples
- To run the all sync modules from a source project to a target project
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s all
docker run commercetools/commercetools-project-sync:5.4.3 -s all
```
This will run the following sync modules in the given order:
1. `Type` Sync and `ProductType` Sync and `States` Sync and `TaxCategory` Sync and `CustomObject` Sync in parallel.
Expand All @@ -239,70 +239,70 @@ commercetools/commercetools-project-sync:5.4.1 -s all

- To run the type sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s types
docker run commercetools/commercetools-project-sync:5.4.3 -s types
```

- To run the productType sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s productTypes
docker run commercetools/commercetools-project-sync:5.4.3 -s productTypes
```

- To run the states sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s states
docker run commercetools/commercetools-project-sync:5.4.3 -s states
```
- To run the taxCategory sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s taxCategories
docker run commercetools/commercetools-project-sync:5.4.3 -s taxCategories
```

- To run the category sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s categories
docker run commercetools/commercetools-project-sync:5.4.3 -s categories
```

- To run the product sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s products
docker run commercetools/commercetools-project-sync:5.4.3 -s products
```

- To run the cartDiscount sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s cartDiscounts
docker run commercetools/commercetools-project-sync:5.4.3 -s cartDiscounts
```

- To run the inventoryEntry sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s inventoryEntries
docker run commercetools/commercetools-project-sync:5.4.3 -s inventoryEntries
```

- To run the customObject sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s customObjects
docker run commercetools/commercetools-project-sync:5.4.3 -s customObjects
```

- To run the customer sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s customers
docker run commercetools/commercetools-project-sync:5.4.3 -s customers
```

- To run the shoppingList sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s shoppingLists
docker run commercetools/commercetools-project-sync:5.4.3 -s shoppingLists
```
- To run both products and shoppingList sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s products shoppingLists
docker run commercetools/commercetools-project-sync:5.4.3 -s products shoppingLists
```

- To run type, productType and shoppingList sync
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s types productTypes shoppingLists
docker run commercetools/commercetools-project-sync:5.4.3 -s types productTypes shoppingLists
```

- To run all sync modules using a runner name
```bash
docker run commercetools/commercetools-project-sync:5.4.1 -s all -r myRunnerName
docker run commercetools/commercetools-project-sync:5.4.3 -s all -r myRunnerName
```

## Scopes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,41 @@ private static ProjectApiRoot createCtpClient(
.build(projectKey);
}

private static Properties loadFromEnvVars(String propertiesPrefix) {
String projectKeyKey = propertiesPrefix.toUpperCase().replace(".", "_") + "PROJECT_KEY";
String projectKey = System.getenv(projectKeyKey);
String clientIdKey = propertiesPrefix.toUpperCase().replace(".", "_") + "CLIENT_ID";
String clientId = System.getenv(clientIdKey);
String clientSecretKey = propertiesPrefix.toUpperCase().replace(".", "_") + "CLIENT_SECRET";
String clientSecret = System.getenv(clientSecretKey);
Properties properties = new Properties();
properties.put(propertiesPrefix + PROPERTIES_KEY_PROJECT_KEY_SUFFIX, projectKey);
properties.put(propertiesPrefix + PROPERTIES_KEY_CLIENT_ID_SUFFIX, clientId);
properties.put(propertiesPrefix + PROPERTIES_KEY_CLIENT_SECRET_SUFFIX, clientSecret);
private static Properties loadFromEnvVars(final String propertiesPrefix) {
final Properties properties = new Properties();

final String capitalizeAndReplaceDot = propertiesPrefix.toUpperCase().replace(".", "_");

properties.put(
propertiesPrefix + PROPERTIES_KEY_PROJECT_KEY_SUFFIX,
getPropertyFromEnv(capitalizeAndReplaceDot + "PROJECT_KEY"));
properties.put(
propertiesPrefix + PROPERTIES_KEY_CLIENT_ID_SUFFIX,
getPropertyFromEnv(capitalizeAndReplaceDot + "CLIENT_ID"));
properties.put(
propertiesPrefix + PROPERTIES_KEY_CLIENT_SECRET_SUFFIX,
getPropertyFromEnv(capitalizeAndReplaceDot + "CLIENT_SECRET"));
final String authUrl = getPropertyFromEnv(capitalizeAndReplaceDot + "AUTH_URL");
if (authUrl != null) {
properties.put(propertiesPrefix + PROPERTIES_KEY_AUTH_URL_SUFFIX, authUrl);
}
final String apiUrl = getPropertyFromEnv(capitalizeAndReplaceDot + "API_URL");
if (apiUrl != null) {
properties.put(propertiesPrefix + PROPERTIES_KEY_API_URL_SUFFIX, apiUrl);
}

final String scopes = getPropertyFromEnv(capitalizeAndReplaceDot + "SCOPES");
if (scopes != null) {
properties.put(propertiesPrefix + PROPERTIES_KEY_SCOPES_SUFFIX, scopes);
}

return properties;
}

private static String getPropertyFromEnv(String key) {
return System.getenv(key);
}

private static String extract(
final Properties properties,
final String prefix,
Expand Down

0 comments on commit 92beee6

Please sign in to comment.