-
Notifications
You must be signed in to change notification settings - Fork 5
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
[ID-1315] Download list of Azure IP addresses #1736
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import bio.terra.service.resourcemanagement.azure.AzureResourceConfiguration; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.MapperFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
|
@@ -11,8 +12,11 @@ | |
import com.google.auth.oauth2.ServiceAccountCredentials; | ||
import com.microsoft.sqlserver.jdbc.SQLServerDataSource; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
@@ -444,4 +448,29 @@ public WebServerFactoryCustomizer<TomcatServletWebServerFactory> tomcatCustomize | |
connector -> | ||
connector.setEncodedSolidusHandling(EncodedSolidusHandling.DECODE.getValue())); | ||
} | ||
|
||
@Bean("azureIPs") | ||
public Map<Integer, List<String>> azureIPs() throws IOException { | ||
URL url = | ||
new URL( | ||
"https://download.microsoft.com/download/7/1/D/71D86715-5596-4529-9B13-DA13A5DE5B63/ServiceTags_Public_20240708.json"); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JsonNode data = objectMapper.readTree(url); | ||
JsonNode values = data.get("values"); | ||
// Map {Region ID: List of IP addresses} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm mapping based on the region id here, since we may need to only allow IPs from certain regions for AXIN. I'm still trying to find the regions those ids correspond to... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like you can maybe use this endpoint to list the regions? https://learn.microsoft.com/en-us/rest/api/resources/subscriptions/list-locations?view=rest-resources-2022-12-01&tabs=HTTP |
||
HashMap<Integer, List<String>> azureIPs = new HashMap<>(); | ||
|
||
for (JsonNode v : values) { | ||
JsonNode properties = v.get("properties"); | ||
Integer regionId = properties.get("regionId").asInt(); | ||
ArrayList<String> addressPrefixes = | ||
objectMapper.convertValue(properties.get("addressPrefixes"), ArrayList.class); | ||
if (!azureIPs.containsKey(regionId)) { | ||
azureIPs.put(regionId, addressPrefixes); | ||
} else { | ||
azureIPs.get(regionId).addAll(addressPrefixes); | ||
} | ||
} | ||
return azureIPs; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just hard-coded this url for testing btw. It actually changes when the file is updated once a week so our options are to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah dang yeah thats annoying, i think using the API endpoint is the move, not sure about the subscription we should use for that though, id ask about it in #dsp-azure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second object won't get use Azure IP ranges. It'll just list the Public IPs within a subscription, which are a specific Azure resource