Skip to content

Commit

Permalink
Adding schemas to the binary, continuing with pkl gen
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzbeard committed Mar 19, 2024
1 parent 71aba5d commit cc4d7af
Show file tree
Hide file tree
Showing 1,731 changed files with 283,449 additions and 18,982 deletions.
36 changes: 28 additions & 8 deletions internal/aws/cfn/cfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cfn

import (
"context"
"embed"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -56,6 +57,9 @@ const WAIT_PERIOD_IN_SECONDS = 2

var Schemas map[string]string

//go:embed schemas
var schemaFiles embed.FS

func checkTemplate(template cft.Template) (string, error) {
templateBody := format.String(template, format.Options{})

Expand Down Expand Up @@ -794,15 +798,31 @@ func GetTypeSchema(name string) (string, error) {
if exists {
return schema, nil
} else {
res, err := getClient().DescribeType(context.Background(), &cloudformation.DescribeTypeInput{
Type: "RESOURCE", TypeName: &name,
})
if err != nil {
config.Debugf("GetTypeSchema SDK error: %v", err)
return "", err
// Look in the embedded file system next
path := strings.Replace(name, "::", "/", -1)
path = strings.ToLower(path)
path = "schemas/" + path + ".json"
b, err := schemaFiles.ReadFile(path)
if err == nil {
config.Debugf("read schema from path %s", path)
s := string(b)
Schemas[name] = s
return s, nil
} else {
config.Debugf("unable to read schema from path %s: %v", path, err)

// Go ahead and download the schema from the registry

res, err := getClient().DescribeType(context.Background(), &cloudformation.DescribeTypeInput{
Type: "RESOURCE", TypeName: &name,
})
if err != nil {
config.Debugf("GetTypeSchema SDK error: %v", err)
return "", err
}
Schemas[name] = *res.Schema
return *res.Schema, nil
}
Schemas[name] = *res.Schema
return *res.Schema, nil
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/aws/cfn/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type Prop struct {
Required []string `json:"required"`
OneOf []*Prop `json:"oneOf"`
AnyOf []*Prop `json:"anyOf"`
AllOf []*Prop `json:"allOf"`
PatternProperties any `json:"patternProperties"`
Title string `json:"title"`
}

func (p *Prop) GetProperties() map[string]*Prop {
Expand Down
215 changes: 215 additions & 0 deletions internal/aws/cfn/schemas/aws/accessanalyzer/analyzer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
{
"typeName": "AWS::AccessAnalyzer::Analyzer",
"description": "The AWS::AccessAnalyzer::Analyzer type specifies an analyzer of the user's account",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-accessanalyzer.git",
"resourceLink": {
"templateUri": "/access-analyzer/home?region=${awsRegion}#/analyzer/${AnalyzerName}",
"mappings": {
"AnalyzerName": "/AnalyzerName"
}
},
"definitions": {
"ArchiveRule": {
"description": "An Access Analyzer archive rule. Archive rules automatically archive new findings that meet the criteria you define when you create the rule.",
"type": "object",
"properties": {
"Filter": {
"type": "array",
"insertionOrder": false,
"minItems": 1,
"items": {
"$ref": "#/definitions/Filter"
}
},
"RuleName": {
"type": "string",
"description": "The archive rule name"
}
},
"required": [
"Filter",
"RuleName"
],
"additionalProperties": false
},
"Filter": {
"type": "object",
"properties": {
"Contains": {
"type": "array",
"insertionOrder": false,
"items": {
"type": "string"
}
},
"Eq": {
"type": "array",
"insertionOrder": false,
"items": {
"type": "string"
}
},
"Exists": {
"type": "boolean"
},
"Property": {
"type": "string"
},
"Neq": {
"type": "array",
"insertionOrder": false,
"items": {
"type": "string"
}
}
},
"required": [
"Property"
],
"additionalProperties": false
},
"Tag": {
"description": "A key-value pair to associate with a resource.",
"type": "object",
"properties": {
"Key": {
"type": "string",
"description": "The key name of the tag. You can specify a value that is 1 to 127 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -. ",
"minLength": 1,
"maxLength": 127
},
"Value": {
"type": "string",
"description": "The value for the tag. You can specify a value that is 1 to 255 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -. ",
"minLength": 1,
"maxLength": 255
}
},
"required": [
"Key",
"Value"
],
"additionalProperties": false
},
"UnusedAccessConfiguration": {
"description": "The Configuration for Unused Access Analyzer",
"type": "object",
"properties": {
"UnusedAccessAge": {
"description": "The specified access age in days for which to generate findings for unused access. For example, if you specify 90 days, the analyzer will generate findings for IAM entities within the accounts of the selected organization for any access that hasn't been used in 90 or more days since the analyzer's last scan. You can choose a value between 1 and 180 days.",
"type": "integer",
"minimum": 1,
"maximum": 180
}
},
"additionalProperties": false
}
},
"properties": {
"AnalyzerName": {
"description": "Analyzer name",
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"ArchiveRules": {
"type": "array",
"insertionOrder": false,
"items": {
"$ref": "#/definitions/ArchiveRule"
}
},
"Arn": {
"description": "Amazon Resource Name (ARN) of the analyzer",
"type": "string",
"minLength": 1,
"maxLength": 1600
},
"Tags": {
"type": "array",
"maxItems": 50,
"insertionOrder": false,
"uniqueItems": true,
"description": "An array of key-value pairs to apply to this resource.",
"items": {
"$ref": "#/definitions/Tag"
}
},
"Type": {
"description": "The type of the analyzer, must be one of ACCOUNT, ORGANIZATION, ACCOUNT_UNUSED_ACCESS or ORGANIZATION_UNUSED_ACCESS",
"type": "string",
"minLength": 0,
"maxLength": 1024
},
"AnalyzerConfiguration": {
"description": "The configuration for the analyzer",
"type": "object",
"properties": {
"UnusedAccessConfiguration": {
"$ref": "#/definitions/UnusedAccessConfiguration"
}
},
"additionalProperties": false
}
},
"required": [
"Type"
],
"readOnlyProperties": [
"/properties/Arn"
],
"createOnlyProperties": [
"/properties/AnalyzerName",
"/properties/Type",
"/properties/AnalyzerConfiguration"
],
"primaryIdentifier": [
"/properties/Arn"
],
"additionalProperties": false,
"handlers": {
"create": {
"permissions": [
"access-analyzer:CreateAnalyzer",
"access-analyzer:TagResource",
"iam:CreateServiceLinkedRole",
"organizations:ListAWSServiceAccessForOrganization",
"organizations:ListDelegatedAdministrators"
]
},
"read": {
"permissions": [
"access-analyzer:ListAnalyzers",
"access-analyzer:GetAnalyzer",
"access-analyzer:ListArchiveRules"
]
},
"update": {
"permissions": [
"access-analyzer:CreateArchiveRule",
"access-analyzer:DeleteArchiveRule",
"access-analyzer:ListAnalyzers",
"access-analyzer:TagResource",
"access-analyzer:UntagResource",
"access-analyzer:UpdateArchiveRule"
]
},
"delete": {
"permissions": [
"access-analyzer:DeleteAnalyzer"
]
},
"list": {
"permissions": [
"access-analyzer:ListAnalyzers"
]
}
},
"tagging": {
"taggable": true,
"tagOnCreate": true,
"tagUpdatable": true,
"cloudFormationSystemTags": true,
"tagProperty": "/properties/Tags"
}
}
Loading

0 comments on commit cc4d7af

Please sign in to comment.