Skip to content

Commit

Permalink
Merge pull request #45 from equinix-labs/modifyFlows
Browse files Browse the repository at this point in the history
  • Loading branch information
tutkat authored Jun 4, 2024
2 parents abf8528 + 6a1d39e commit 4365129
Show file tree
Hide file tree
Showing 387 changed files with 1,971 additions and 24,244 deletions.
72 changes: 45 additions & 27 deletions .github/workflows/auto-commit-client-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,52 @@ on:

jobs:
build:

runs-on: ubuntu-latest

env:
TEST_DATA_UAT_QINQ_PORT: ${{ secrets.TEST_DATA_UAT_QINQ_PORT }}

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven

- name: Commit to branch if client is updated after executing make.
run: |
git config --global user.name 'equinix-labs@auto-commit-workflow'
git config --global user.email '[email protected]'
git config advice.addIgnoredFile false
git fetch
echo -e "\nThis is executing for branch: ${GITHUB_REF##*/}."
git checkout ${GITHUB_REF##*/}
make generate
echo -e "Make execution completed."
git add equinix-openapi-fabric/.
echo -e "\nGit status:"
echo `git status`
cdate=`date`
cmsg="Auto commit generated client changes - $cdate"
echo -e "\nCommit message created : $cmsg"
echo -e "\nCommitting if there are files to update in client dir:"
echo `git commit -m "$cmsg"`
echo `git push`
- name: Set git user and generate files
run: |
git config --global user.name 'equinix-labs@auto-commit-workflow'
git config --global user.email '[email protected]'
git config advice.addIgnoredFile false
git fetch
echo -e "\nThis is executing for branch: ${GITHUB_REF##*/}."
git checkout ${GITHUB_REF##*/}
make generate
- name: Tests
env:
TEST_HOST_URL: https://uatapi.equinix.com
CLIENT_ID: ${{ secrets.TEST_USER_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.TEST_USER_CLIENT_SECRET }}
TEST_USER_NAME: ${{ secrets.TEST_USER_NAME }}
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
shell: bash
working-directory: ./equinix-openapi-fabric
run: |-
mvn clean package -DenvUrl=${{ env.TEST_HOST_URL }} -DuserName=${{ env.TEST_USER_NAME }} \
-DuserPassword=${{ env.TEST_USER_PASSWORD }} -DclientId=${{ env.CLIENT_ID }} -DclientSecret=${{ env.CLIENT_SECRET }}
- name: Commit to branch.
run: |
git add .
echo -e "\nGit status:"
echo `git status`
cdate=`date`
cmsg="Auto commit generated client changes - $cdate"
echo -e "\nCommit message created : $cmsg"
echo -e "\nCommitting if there are files to update in client dir:"
echo `git commit -m "$cmsg"`
echo `git push`
18 changes: 13 additions & 5 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
contents: read
packages: write

env:
TEST_DATA_UAT_QINQ_PORT: ${{ secrets.TEST_DATA_UAT_QINQ_PORT }}

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
Expand All @@ -27,12 +30,17 @@ jobs:
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Maven
working-directory: ./equinix-openapi-fabric
run: mvn -B package --file pom.xml

- name: Publish to GitHub Packages Apache Maven
working-directory: ./equinix-openapi-fabric
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/equinix-labs/fabric-java

run: |-
mvn deploy -s $GITHUB_WORKSPACE/settings.xml -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/equinix-labs/fabric-java \
-DenvUrl=${{ env.TEST_HOST_URL }} -DuserName=${{ env.TEST_USER_NAME }} -DuserPassword=${{ env.TEST_USER_PASSWORD }} \
-DclientId=${{ env.CLIENT_ID }} -DclientSecret=${{ env.CLIENT_SECRET }}
env:
GITHUB_TOKEN: ${{ github.token }}
TEST_HOST_URL: https://uatapi.equinix.com
CLIENT_ID: ${{ secrets.TEST_USER_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.TEST_USER_CLIENT_SECRET }}
TEST_USER_NAME: ${{ secrets.TEST_USER_NAME }}
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
22 changes: 21 additions & 1 deletion .github/workflows/sync_sdk_with_new_api_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
java-distribution: [temurin]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

env:
TEST_DATA_UAT_QINQ_PORT: ${{ secrets.TEST_DATA_UAT_QINQ_PORT }}

steps:
- name: Get current date
id: date
Expand Down Expand Up @@ -46,9 +50,25 @@ jobs:
VERSION_UPDATE="OPENAPI_URL=\"https://app.swaggerhub.com/apiproxy/registry/equinix-api/fabric/${{ github.event.inputs.new_api_spec_version_number }}\""
sed -i 's,${{ steps.spec_versions.outputs.api_spec_line }},'"$VERSION_UPDATE"',' Makefile
make generate
- name: Tests
env:
TEST_HOST_URL: https://uatapi.equinix.com
CLIENT_ID: ${{ secrets.TEST_USER_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.TEST_USER_CLIENT_SECRET }}
TEST_USER_NAME: ${{ secrets.TEST_USER_NAME }}
TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}
shell: bash
working-directory: ./equinix-openapi-fabric
run: |-
mvn clean package -DenvUrl=${{ env.TEST_HOST_URL }} -DuserName=${{ env.TEST_USER_NAME }} \
-DuserPassword=${{ env.TEST_USER_PASSWORD }} -DclientId=${{ env.CLIENT_ID }} -DclientSecret=${{ env.CLIENT_SECRET }}
- name: Commit changes
run: |
git commit -m 'sync: fetch ${{ steps.date.outputs.date }} spec and apply patches' spec/*.json
git add equinix-openapi-fabric
git commit -m 'sync: generate client with ${{ steps.date.outputs.date }} spec'
git commit -m 'sync: generate client with ${{ steps.date.outputs.date }} spec'
- name: Create Pull Request
id: cpr
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SPEC_FETCHED_FILE:=spec/oas3.fabric.fetched.json
SPEC_PATCHED_FILE:=spec/oas3.fabric.patched.json
OPENAPI_CONFIG:=spec/oas3.fabric.config.json
OPENAPI_GENERATED_CLIENT=equinix-openapi-fabric/
TESTS_PATH=src/test/java/com/equinix/openapi/fabric/

# Patches
SPEC_FETCHED_PATCHES=patches/spec.fetched.json
Expand Down Expand Up @@ -65,4 +66,4 @@ docker_generate:
--git-user-id ${GIT_ORG}

build_client:
cd ${OPENAPI_GENERATED_CLIENT}; mvn clean package
rm -rf ${OPENAPI_GENERATED_CLIENT}${TESTS_PATH}v4; cp -r v4 ${OPENAPI_GENERATED_CLIENT}${TESTS_PATH}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.equinix.openapi.fabric.v4.api;

import com.equinix.openapi.fabric.ApiClient;
import com.equinix.openapi.fabric.ApiException;
import com.equinix.openapi.fabric.Configuration;
import com.equinix.openapi.fabric.Pair;
import com.equinix.openapi.fabric.v4.api.dto.TokenRequestDto;
import com.equinix.openapi.fabric.v4.api.dto.TokenResponseDto;
import com.equinix.openapi.fabric.v4.api.dto.port.PortDto;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class AbstractTest {
public ApiClient generateToken() {
ApiClient apiTokeClient = Configuration.getDefaultApiClient();

TokenRequestDto tokenRequestDto = new TokenRequestDto()
.setClientId(System.getProperty("clientId"))
.setClientSecret(System.getProperty("clientSecret"))
.setUserPassword(System.getProperty("userPassword"))
.setUserName(System.getProperty("userName"));

String localVarPath = "/oauth2/v1/token";

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

localVarHeaderParams.put("Content-Type", "application/json");
String[] localVarAuthNames = new String[]{"BearerAuth"};

okhttp3.Call call;
TokenResponseDto tokenResponseDto = null;

try {
call = apiTokeClient.buildCall(apiTokeClient.getBasePath(), localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams,
tokenRequestDto, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, null);

Type localVarReturnType = new TypeToken<TokenResponseDto>() {
}.getType();
tokenResponseDto = (TokenResponseDto) apiTokeClient.execute(call, localVarReturnType).getData();
} catch (ApiException e) {
throw new RuntimeException(e);
}

ApiClient apiClient = Configuration.getDefaultApiClient();
apiClient.addDefaultHeader("Authorization", "Bearer " + tokenResponseDto.getAccessToken());

return apiClient;
}

protected PortDto getPort(EnvVariable envVariable) {
ObjectMapper mapper = new ObjectMapper();
String json = System.getenv(envVariable.value);
try {
return mapper.readValue(json, PortDto.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

protected void printJson(Object object) {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
try {
String json = ow.writeValueAsString(object);
System.out.println(json);
} catch (
JsonProcessingException e) {
throw new RuntimeException(e);
}
}

public enum EnvVariable {
QINQ_PORT("TEST_DATA_UAT_QINQ_PORT");

private String value;

EnvVariable(String value) {
this.value = value;
}

@Override
public String toString() {
return String.valueOf(value);
}
}
}
Loading

0 comments on commit 4365129

Please sign in to comment.