| 1 | { |
| 2 | "version": "1.3", |
| 3 | "parameters": { |
| 4 | "Region": { |
| 5 | "type": "string", |
| 6 | "builtIn": "AWS::Region" |
| 7 | }, |
| 8 | "Bucket": { |
| 9 | "type": "string" |
| 10 | }, |
| 11 | "TestCaseId": { |
| 12 | "type": "string" |
| 13 | } |
| 14 | }, |
| 15 | "rules": [ |
| 16 | { |
| 17 | "documentation": "tests of invalid arns", |
| 18 | "conditions": [ |
| 19 | { |
| 20 | "fn": "isSet", |
| 21 | "argv": [ |
| 22 | { |
| 23 | "ref": "TestCaseId" |
| 24 | } |
| 25 | ] |
| 26 | }, |
| 27 | { |
| 28 | "fn": "isSet", |
| 29 | "argv": [ |
| 30 | { |
| 31 | "ref": "Bucket" |
| 32 | } |
| 33 | ] |
| 34 | }, |
| 35 | { |
| 36 | "fn": "stringEquals", |
| 37 | "argv": [ |
| 38 | "{TestCaseId}", |
| 39 | "invalid-arn" |
| 40 | ] |
| 41 | } |
| 42 | ], |
| 43 | "type": "tree", |
| 44 | "rules": [ |
| 45 | { |
| 46 | "conditions": [ |
| 47 | { |
| 48 | "fn": "aws.parseArn", |
| 49 | "argv": ["{Bucket}"] |
| 50 | } |
| 51 | ], |
| 52 | "type": "error", |
| 53 | "error": "A valid ARN was parsed but `{Bucket}` is not a valid ARN" |
| 54 | }, |
| 55 | { |
| 56 | "conditions": [], |
| 57 | "type": "error", |
| 58 | "error": "Test case passed: `{Bucket}` is not a valid ARN." |
| 59 | } |
| 60 | ] |
| 61 | }, |
| 62 | { |
| 63 | "documentation": "tests of valid arns", |
| 64 | "conditions": [ |
| 65 | { |
| 66 | "fn": "isSet", |
| 67 | "argv": [ |
| 68 | { |
| 69 | "ref": "TestCaseId" |
| 70 | } |
| 71 | ] |
| 72 | }, |
| 73 | { |
| 74 | "fn": "isSet", |
| 75 | "argv": [ |
| 76 | { |
| 77 | "ref": "Bucket" |
| 78 | } |
| 79 | ] |
| 80 | }, |
| 81 | { |
| 82 | "fn": "stringEquals", |
| 83 | "argv": [ |
| 84 | "{TestCaseId}", |
| 85 | "valid-arn" |
| 86 | ] |
| 87 | } |
| 88 | ], |
| 89 | "type": "tree", |
| 90 | "rules": [ |
| 91 | { |
| 92 | "conditions": [ |
| 93 | { |
| 94 | "fn": "aws.parseArn", |
| 95 | "argv": ["{Bucket}"], |
| 96 | "assign": "arn" |
| 97 | }, |
| 98 | { |
| 99 | "fn": "getAttr", |
| 100 | "argv": [{"ref": "arn"}, "resourceId[0]"], |
| 101 | "assign": "resource" |
| 102 | } |
| 103 | ], |
| 104 | "type": "error", |
| 105 | "error": "Test case passed: A valid ARN was parsed: service: `{arn#service}`, partition: `{arn#partition}, region: `{arn#region}`, accountId: `{arn#accountId}`, resource: `{resource}`" |
| 106 | }, |
| 107 | { |
| 108 | "conditions": [], |
| 109 | "type": "error", |
| 110 | "error": "Test case failed: `{Bucket}` is a valid ARN but parseArn failed to parse it." |
| 111 | } |
| 112 | ] |
| 113 | }, |
| 114 | { |
| 115 | "documentation": "region is set", |
| 116 | "conditions": [ |
| 117 | { |
| 118 | "fn": "isSet", |
| 119 | "argv": [ |
| 120 | { |
| 121 | "ref": "Region" |
| 122 | } |
| 123 | ] |
| 124 | }, |
| 125 | { |
| 126 | "fn": "aws.partition", |
| 127 | "argv": [ |
| 128 | "{Region}" |
| 129 | ], |
| 130 | "assign": "partitionResult" |
| 131 | } |
| 132 | ], |
| 133 | "rules": [ |
| 134 | { |
| 135 | "documentation": "bucket is set, handle bucket specific endpoints", |
| 136 | "conditions": [ |
| 137 | { |
| 138 | "fn": "isSet", |
| 139 | "argv": [ |
| 140 | { |
| 141 | "ref": "Bucket" |
| 142 | } |
| 143 | ] |
| 144 | } |
| 145 | ], |
| 146 | "rules": [ |
| 147 | { |
| 148 | "documentation": "bucket is set and is an arn", |
| 149 | "conditions": [ |
| 150 | { |
| 151 | "fn": "aws.parseArn", |
| 152 | "argv": [ |
| 153 | { |
| 154 | "ref": "Bucket" |
| 155 | } |
| 156 | ], |
| 157 | "assign": "bucketArn" |
| 158 | } |
| 159 | ], |
| 160 | "rules": [ |
| 161 | { |
| 162 | "conditions": [ |
| 163 | { |
| 164 | "fn": "getAttr", |
| 165 | "argv": [ |
| 166 | { |
| 167 | "ref": "bucketArn" |
| 168 | }, |
| 169 | "resourceId[1]" |
| 170 | ], |
| 171 | "assign": "outpostId" |
| 172 | } |
| 173 | ], |
| 174 | "rules": [ |
| 175 | { |
| 176 | "conditions": [ |
| 177 | { |
| 178 | "fn": "stringEquals", |
| 179 | "argv": [ |
| 180 | "{outpostId}", |
| 181 | "" |
| 182 | ] |
| 183 | } |
| 184 | ], |
| 185 | "error": "OutpostId was empty", |
| 186 | "type": "error" |
| 187 | }, |
| 188 | { |
| 189 | "conditions": [], |
| 190 | "endpoint": { |
| 191 | "url": "https://{outpostId}-{bucketArn#accountId}.{bucketArn#region}.{partitionResult#dnsSuffix}" |
| 192 | }, |
| 193 | "type": "endpoint" |
| 194 | } |
| 195 | ], |
| 196 | "type": "tree" |
| 197 | }, |
| 198 | { |
| 199 | "conditions": [], |
| 200 | "error": "Invalid ARN: outpostId was not set", |
| 201 | "type": "error" |
| 202 | } |
| 203 | ], |
| 204 | "type": "tree" |
| 205 | }, |
| 206 | { |
| 207 | "documentation": "bucket can be used as a host label", |
| 208 | "conditions": [ |
| 209 | { |
| 210 | "fn": "isValidHostLabel", |
| 211 | "argv": [ |
| 212 | "{Bucket}", |
| 213 | false |
| 214 | ] |
| 215 | } |
| 216 | ], |
| 217 | "endpoint": { |
| 218 | "url": "https://{Bucket}.{Region}.amazonaws.com" |
| 219 | }, |
| 220 | "type": "endpoint" |
| 221 | }, |
| 222 | { |
| 223 | "conditions": [], |
| 224 | "documentation": "fallback: use bucket in the path", |
| 225 | "endpoint": { |
| 226 | "url": "https://{Region}.amazonaws.com/{Bucket}" |
| 227 | }, |
| 228 | "type": "endpoint" |
| 229 | } |
| 230 | ], |
| 231 | "type": "tree" |
| 232 | }, |
| 233 | { |
| 234 | "documentation": "region is set, bucket is not", |
| 235 | "conditions": [], |
| 236 | "endpoint": { |
| 237 | "url": "https://{Region}.{partitionResult#dnsSuffix}" |
| 238 | }, |
| 239 | "type": "endpoint" |
| 240 | } |
| 241 | ], |
| 242 | "type": "tree" |
| 243 | }, |
| 244 | { |
| 245 | "documentation": "fallback when region is unset", |
| 246 | "conditions": [], |
| 247 | "error": "Region must be set to resolve a valid endpoint", |
| 248 | "type": "error" |
| 249 | } |
| 250 | ] |
| 251 | } |