|
| 1 | +private import bicep |
| 2 | + |
| 3 | +module Containers { |
| 4 | + /** |
| 5 | + * Represents a Microsoft.ContainerApp/containerApps resource. |
| 6 | + * See: https://learn.microsoft.com/en-us/azure/templates/microsoft.app/containerapps |
| 7 | + */ |
| 8 | + class ContainerResource extends Resource { |
| 9 | + /** |
| 10 | + * Constructs a ContainerResource for Microsoft.App/containerApps resources. |
| 11 | + */ |
| 12 | + ContainerResource() { this.getResourceType().regexpMatch("^Microsoft.App/containerApps@.*") } |
| 13 | + |
| 14 | + /** |
| 15 | + * Returns the properties object for the container app resource. |
| 16 | + */ |
| 17 | + ContainerProperties::Properties getProperties() { result = this.getProperty("properties") } |
| 18 | + |
| 19 | + /** |
| 20 | + * Returns the configuration object for the container app resource. |
| 21 | + */ |
| 22 | + ContainerProperties::ContainerConfiguration getConfiguration() { |
| 23 | + result = this.getProperties().getConfiguration() |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Returns the template object for the container app resource. |
| 28 | + */ |
| 29 | + ContainerProperties::ContainerTemplate getTemplate() { |
| 30 | + result = this.getProperties().getTemplate() |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Returns the containers defined in the template. |
| 35 | + */ |
| 36 | + ContainerProperties::ContainerApp getContainers() { |
| 37 | + result = this.getTemplate().getContainers() |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns a specific container by index from the template. |
| 42 | + */ |
| 43 | + ContainerProperties::ContainerApp getContainer(int index) { |
| 44 | + result = this.getTemplate().getContainer(index) |
| 45 | + } |
| 46 | + |
| 47 | + Network::Ingress getNetworkIngress() { |
| 48 | + result = this.getConfiguration().getNetworkIngress() |
| 49 | + } |
| 50 | + |
| 51 | + Network::CorsPolicy getCorsPolicy() { |
| 52 | + result = this.getNetworkIngress().getCorsPolicy() |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns a string representation of the container app resource. |
| 57 | + */ |
| 58 | + override string toString() { result = "ContainerResource" } |
| 59 | + } |
| 60 | + |
| 61 | + module ContainerProperties { |
| 62 | + /** |
| 63 | + * Represents the properties object for a container app resource. |
| 64 | + */ |
| 65 | + class Properties extends Object { |
| 66 | + private ContainerResource containerResource; |
| 67 | + |
| 68 | + /** |
| 69 | + * Constructs a Properties object for the given container app resource. |
| 70 | + */ |
| 71 | + Properties() { this = containerResource.getProperty("properties") } |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the parent ContainerResource. |
| 75 | + */ |
| 76 | + ContainerResource getContainerResource() { result = containerResource } |
| 77 | + |
| 78 | + /** |
| 79 | + * Returns the configuration property. |
| 80 | + */ |
| 81 | + ContainerConfiguration getConfiguration() { result = this.getProperty("configuration") } |
| 82 | + |
| 83 | + /** |
| 84 | + * Returns the template property. |
| 85 | + */ |
| 86 | + ContainerTemplate getTemplate() { result = this.getProperty("template") } |
| 87 | + |
| 88 | + string toString() { result = "ContainerProperties" } |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Represents the configuration object for a container app resource. |
| 93 | + */ |
| 94 | + class ContainerConfiguration extends Object { |
| 95 | + private Properties properties; |
| 96 | + |
| 97 | + /** |
| 98 | + * Constructs a Configuration object for the given properties. |
| 99 | + */ |
| 100 | + ContainerConfiguration() { this = properties.getProperty("configuration") } |
| 101 | + |
| 102 | + /** |
| 103 | + * Returns the network ingress configuration. |
| 104 | + */ |
| 105 | + Network::Ingress getNetworkIngress() { result = this.getProperty("ingress") } |
| 106 | + |
| 107 | + /** |
| 108 | + * Returns the secrets defined in the configuration. |
| 109 | + */ |
| 110 | + ContainerSecret getSecrets() { result = this.getProperty("secrets").(Array).getElements() } |
| 111 | + |
| 112 | + /** |
| 113 | + * Returns the active revisions mode as a StringLiteral. |
| 114 | + */ |
| 115 | + StringLiteral getActiveRevisionsMode() { result = this.getProperty("activeRevisionsMode") } |
| 116 | + |
| 117 | + /** |
| 118 | + * Returns the active revisions mode as a string. |
| 119 | + */ |
| 120 | + string activeRevisionsMode() { result = this.getActiveRevisionsMode().getValue() } |
| 121 | + |
| 122 | + /** |
| 123 | + * Returns the template property. |
| 124 | + */ |
| 125 | + Expr getTemplate() { result = this.getProperty("template") } |
| 126 | + |
| 127 | + string toString() { result = "ContainerConfiguration" } |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Represents a secret defined in the container app configuration. |
| 132 | + */ |
| 133 | + class ContainerSecret extends Object { |
| 134 | + private ContainerConfiguration configuration; |
| 135 | + |
| 136 | + /** |
| 137 | + * Constructs a ContainerSecret for the given configuration. |
| 138 | + */ |
| 139 | + ContainerSecret() { this = configuration.getProperty("secrets").(Array).getElements() } |
| 140 | + |
| 141 | + /** |
| 142 | + * Returns the name of the secret. |
| 143 | + */ |
| 144 | + StringLiteral getName() { result = this.getProperty("name") } |
| 145 | + |
| 146 | + /** |
| 147 | + * Returns the value of the secret. |
| 148 | + */ |
| 149 | + StringLiteral getValue() { result = this.getProperty("value") } |
| 150 | + |
| 151 | + string toString() { result = "ContainerSecret" } |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * Represents the template object for a container app resource. |
| 156 | + */ |
| 157 | + class ContainerTemplate extends Object { |
| 158 | + private Properties properties; |
| 159 | + |
| 160 | + /** |
| 161 | + * Constructs a ContainerTemplate for the given properties. |
| 162 | + */ |
| 163 | + ContainerTemplate() { this = properties.getProperty("template") } |
| 164 | + |
| 165 | + /** |
| 166 | + * Returns the container app template. |
| 167 | + */ |
| 168 | + Expr getContainerAppTemplate() { result = this.getProperty("containerAppTemplate") } |
| 169 | + |
| 170 | + /** |
| 171 | + * Returns the containers defined in the template. |
| 172 | + */ |
| 173 | + ContainerApp getContainers() { result = this.getProperty("containers").(Array).getElements() } |
| 174 | + |
| 175 | + /** |
| 176 | + * Returns a specific container by index from the template. |
| 177 | + */ |
| 178 | + ContainerApp getContainer(int index) { |
| 179 | + result = this.getProperty("containers").(Array).getElement(index) |
| 180 | + } |
| 181 | + |
| 182 | + string toString() { result = "ContainerTemplate" } |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * Represents a container defined in the container app template. |
| 187 | + */ |
| 188 | + class ContainerApp extends Object { |
| 189 | + private ContainerTemplate template; |
| 190 | + |
| 191 | + /** |
| 192 | + * Constructs a ContainerApp for the given template. |
| 193 | + */ |
| 194 | + ContainerApp() { this = template.getProperty("containers").(Array).getElements() } |
| 195 | + |
| 196 | + /** |
| 197 | + * Returns the parent ContainerTemplate. |
| 198 | + */ |
| 199 | + ContainerTemplate getContainerTemplate() { result = template } |
| 200 | + |
| 201 | + /** |
| 202 | + * Returns the name of the container. |
| 203 | + */ |
| 204 | + StringLiteral getName() { result = this.getProperty("name") } |
| 205 | + |
| 206 | + /** |
| 207 | + * Returns the image of the container. |
| 208 | + */ |
| 209 | + StringLiteral getImage() { result = this.getProperty("image") } |
| 210 | + |
| 211 | + /** |
| 212 | + * Returns the resources object for the container. |
| 213 | + */ |
| 214 | + ContainerResources getResources() { result = this.getProperty("resources") } |
| 215 | + |
| 216 | + /** |
| 217 | + * Returns the environment variables defined for the container. |
| 218 | + */ |
| 219 | + ContainerEnv getEnvs() { result = this.getProperty("env").(Array).getElements() } |
| 220 | + |
| 221 | + /** |
| 222 | + * Returns a specific environment variable by name. |
| 223 | + */ |
| 224 | + ContainerEnv getEnv(string name) { |
| 225 | + exists(ContainerEnv env | |
| 226 | + env = this.getEnvs() and |
| 227 | + env.getName().getValue() = name |
| 228 | + | |
| 229 | + result = env |
| 230 | + ) |
| 231 | + } |
| 232 | + |
| 233 | + string toString() { result = "ContainerProperty" } |
| 234 | + } |
| 235 | + |
| 236 | + /** |
| 237 | + * Represents the resources object for a container. |
| 238 | + */ |
| 239 | + class ContainerResources extends Object { |
| 240 | + private ContainerApp container; |
| 241 | + |
| 242 | + /** |
| 243 | + * Constructs a ContainerResources object for the given container. |
| 244 | + */ |
| 245 | + ContainerResources() { this = container.getProperty("resources") } |
| 246 | + |
| 247 | + /** |
| 248 | + * Returns the properties object for the container resource. |
| 249 | + */ |
| 250 | + ContainerProperties::Properties getContainerProperties() { |
| 251 | + result = this.getProperty("properties") |
| 252 | + } |
| 253 | + |
| 254 | + /** |
| 255 | + * Returns the CPU resource allocation. |
| 256 | + */ |
| 257 | + Literals getCpu() { result = this.getProperty("cpu") } |
| 258 | + |
| 259 | + /** |
| 260 | + * Returns the memory resource allocation. |
| 261 | + */ |
| 262 | + StringLiteral getMemory() { result = this.getProperty("memory") } |
| 263 | + |
| 264 | + string toString() { result = "ContainerResourceProperties" } |
| 265 | + } |
| 266 | + |
| 267 | + /** |
| 268 | + * Represents an environment variable defined for a container. |
| 269 | + */ |
| 270 | + class ContainerEnv extends Object { |
| 271 | + private ContainerApp container; |
| 272 | + |
| 273 | + /** |
| 274 | + * Constructs a ContainerEnv for the given container. |
| 275 | + */ |
| 276 | + ContainerEnv() { this = container.getProperty("env").(Array).getElements() } |
| 277 | + |
| 278 | + /** |
| 279 | + * Returns the parent ContainerApp. |
| 280 | + */ |
| 281 | + ContainerApp getContainer() { result = container } |
| 282 | + |
| 283 | + /** |
| 284 | + * Returns the name of the environment variable. |
| 285 | + */ |
| 286 | + StringLiteral getName() { result = this.getProperty("name") } |
| 287 | + |
| 288 | + /** |
| 289 | + * Returns the value of the environment variable. |
| 290 | + */ |
| 291 | + StringLiteral getValue() { result = this.getProperty("value") } |
| 292 | + |
| 293 | + string toString() { result = "ContainerEnv" } |
| 294 | + } |
| 295 | + } |
| 296 | +} |
0 commit comments