(args: PoliciesArgs)
| 210 | } |
| 211 | |
| 212 | export async function runPolicies(args: PoliciesArgs): Promise<void> { |
| 213 | switch (args.verb) { |
| 214 | case "user": { |
| 215 | const doc = buildPolicyDocument(); |
| 216 | console.log(JSON.stringify(doc, null, 2)); |
| 217 | if (!args.json) { |
| 218 | console.error( |
| 219 | c.dim( |
| 220 | "\n# Attach the above as an inline policy to the IAM user/role that runs `hyperframes lambda *`.\n# Scope `Resource` to your stack's ARNs after the first successful deploy.", |
| 221 | ), |
| 222 | ); |
| 223 | } |
| 224 | return; |
| 225 | } |
| 226 | case "role": { |
| 227 | const trust = buildRoleTrustPolicy(); |
| 228 | const inline = buildPolicyDocument(); |
| 229 | const wrapped = { |
| 230 | TrustRelationship: trust, |
| 231 | InlinePolicy: inline, |
| 232 | }; |
| 233 | console.log(JSON.stringify(wrapped, null, 2)); |
| 234 | return; |
| 235 | } |
| 236 | case "validate": { |
| 237 | if (!args.inputPath) { |
| 238 | const msg = |
| 239 | "[lambda policies validate] usage: hyperframes lambda policies validate <policy.json>"; |
| 240 | if (args.json) { |
| 241 | console.log(JSON.stringify({ ok: false, error: msg }, null, 2)); |
| 242 | process.exitCode = 1; |
| 243 | return; |
| 244 | } |
| 245 | throw new Error(msg); |
| 246 | } |
| 247 | let result: ValidateResult; |
| 248 | try { |
| 249 | result = validatePolicy(args.inputPath); |
| 250 | } catch (err) { |
| 251 | const msg = normalizeErrorMessage(err); |
| 252 | if (args.json) { |
| 253 | console.log(JSON.stringify({ ok: false, error: msg }, null, 2)); |
| 254 | process.exitCode = 1; |
| 255 | return; |
| 256 | } |
| 257 | console.error(c.error(`Failed to validate ${args.inputPath}: ${msg}`)); |
| 258 | process.exitCode = 1; |
| 259 | return; |
| 260 | } |
| 261 | if (args.json) { |
| 262 | console.log(JSON.stringify({ ok: result.missing.length === 0, ...result }, null, 2)); |
| 263 | if (result.missing.length > 0) process.exitCode = 1; |
| 264 | return; |
| 265 | } |
| 266 | for (const warning of result.warnings) { |
| 267 | console.warn(c.dim(`Warning: ${warning}`)); |
| 268 | } |
| 269 | if (result.missing.length === 0) { |
no test coverage detected