Skip to content

Instantly share code, notes, and snippets.

@Froosh
Created December 10, 2022 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Froosh/33f15fab95674fb5982ad959ad6e9501 to your computer and use it in GitHub Desktop.
Save Froosh/33f15fab95674fb5982ad959ad6e9501 to your computer and use it in GitHub Desktop.
Combine the primary and secondary endpoints from a storage account into one object of arrays, rather than two separate objects
var storage = {
properties: {
primaryEndpoints: {
dfs: 'https://frooshtinkering.dfs.core/'
web: 'https://frooshtinkering.z26.web.core/'
blob: 'https://frooshtinkering.blob.core/'
queue: 'https://frooshtinkering.queue.core/'
table: 'https://frooshtinkering.table.core/'
file: 'https://frooshtinkering.file.core/'
}
secondaryEndpoints: {
dfs: 'https://frooshtinkering-secondary.dfs.core/'
web: 'https://frooshtinkering-secondary.z26.web.core/'
blob: 'https://frooshtinkering-secondary.blob.core/'
queue: 'https://frooshtinkering-secondary.queue.core/'
table: 'https://frooshtinkering-secondary.table.core/'
}
}
}
var hasSecondaryEndPoints = contains(storage.properties, 'secondaryEndpoints')
var primaryEndPointItems = items(storage.properties.primaryEndpoints)
var secondaryEndPointItems = hasSecondaryEndPoints ? items(storage.properties.secondaryEndpoints) : []
var endpointNames = filter(map(primaryEndPointItems, item => item.key), item => item != 'file')
output endpoints object = union(
{ file: [ storage.properties.primaryEndpoints.file ] },
reduce(map(endpointNames, name => {
'${name}': union([
filter(primaryEndPointItems, item => item.key == name)[0].value
], hasSecondaryEndPoints ? [
filter(secondaryEndPointItems, item => item.key == name)[0].value
] : []
)
}
), {}, (cur, next) => union(cur, next)
)
)
@Froosh
Copy link
Author

Froosh commented Dec 10, 2022

"outputs": {
  "endpoints": {
    "type": "Object",
    "value": {
      "blob": [
        "https://frooshtinkering.blob.core/",
        "https://frooshtinkering-secondary.blob.core/"
      ],
      "dfs": [
        "https://frooshtinkering.dfs.core/",
        "https://frooshtinkering-secondary.dfs.core/"
      ],
      "file": [
        "https://frooshtinkering.file.core/"
      ],
      "queue": [
        "https://frooshtinkering.queue.core/",
        "https://frooshtinkering-secondary.queue.core/"
      ],
      "table": [
        "https://frooshtinkering.table.core/",
        "https://frooshtinkering-secondary.table.core/"
      ],
      "web": [
        "https://frooshtinkering.z26.web.core/",
        "https://frooshtinkering-secondary.z26.web.core/"
      ]
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment