Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Target Server Validator #715

Merged
merged 10 commits into from
Jan 24, 2024

Conversation

payaljindal
Copy link
Contributor

@payaljindal payaljindal commented Jan 16, 2024

Description

What's changed, or what was fixed?

  • Updated the target proxy payload from one host_port combination to a json payload with multiple host_port combinations using Gson library
  • Added JSON Threat Protection Policy so that the JSON payload doesn't have more than 10 host_port combinations
  • Added run_parallel function for fetching target servers, fetching proxy bundles and making calls to the newly created target server proxy
  • Updated prints to logger
  • Fixed Target Apigee Type

Issues Fixed

  • N/A

Housekeeping

(please check all that apply [x], do not edit the text)

  • I have run all the tests locally and they all pass.
  • I have followed the relevant style guide for my changes.

Full Repo Validation Required

(please check all that apply [x], do not edit the text)

  • PR requires full pipeline run (Run for changes only by default).

CC: @apigee-devrel-reviewers

return False
else:
print(response.text)
logger.debug(f"{response.text}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need an f-string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it.

@@ -0,0 +1,190 @@
// JavaxJson.java
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License Header needed here

return (T) decode(value, beanClass);
}

private static Object decode(JsonValue jsonValue, Type targetType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for mixing getValueType Enums and instanceof? Would it be more readable to just use the enum and turn it into a switch?

if (payload != null) {
Map<String, List<Map<String, String>>> result = new HashMap<>();
result.put("hostname_portnumbers_status", new ArrayList<>());
Map<String,List<Map<String,String>>> outerMap = JavaxJson.fromJson(payload,Map.class);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation for implementing a generic json parser if we know the json format to be expected. Can't we traversing the known structure with a JsonReader.readMap() and continue from there the same way as you do with the explicit mapping operations below?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Can we not simply parse the entire JSON into HashMaps and ArrayLists with a single operation? I think this approach is suitable if unmarshalling into custom classes, but gson (and other libraries) should natively parse into HashMaps and ArrayLists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I have updated the library to Gson and removed the generic parsing.

if (payload != null) {
Map<String, List<Map<String, String>>> result = new HashMap<>();
result.put("hostname_portnumbers_status", new ArrayList<>());
Map<String,List<Map<String,String>>> outerMap = JavaxJson.fromJson(payload,Map.class);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Can we not simply parse the entire JSON into HashMaps and ArrayLists with a single operation? I think this approach is suitable if unmarshalling into custom classes, but gson (and other libraries) should natively parse into HashMaps and ArrayLists.

@OmidTahouri
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
tools/target-server-validator fail 20s
TOTAL PIPELINE pass 20s

View details in Cloud Build (permission required)

Commit version: 5b5b4e5

@danistrebel
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
tools/target-server-validator fail 17s
TOTAL PIPELINE pass 17s

View details in Cloud Build (permission required)

Commit version: ac590b6

@danistrebel
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
tools/target-server-validator fail 85s
TOTAL PIPELINE pass 85s

View details in Cloud Build (permission required)

Commit version: 1db14cc

@danistrebel
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
tools/target-server-validator pass 96s
TOTAL PIPELINE pass 96s

View details in Cloud Build (permission required)

Commit version: 83f4c98

@danistrebel danistrebel merged commit 41a09cb into apigee:main Jan 24, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants