-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9708499
commit ff8eb69
Showing
25 changed files
with
2,491 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
|
||
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-reference.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package config | ||
|
||
import ( | ||
"go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin" | ||
"go.mondoo.com/cnquery/v11/providers/cloudformation/provider" | ||
) | ||
|
||
var Config = plugin.Provider{ | ||
Name: "cloudformation", | ||
ID: "go.mondoo.com/cnquery/v11/providers/cloudformation", | ||
Version: "11.0.0", | ||
ConnectionTypes: []string{provider.DefaultConnectionType}, | ||
Connectors: []plugin.Connector{ | ||
{ | ||
Name: "cloudformation", | ||
Use: "cloudformation PATH", | ||
Short: "AWS Cloudformation template or AWS SAM template", | ||
MinArgs: 1, | ||
MaxArgs: 1, | ||
Discovery: []string{}, | ||
Flags: []plugin.Flag{}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package connection | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/aws-cloudformation/rain/cft" | ||
"github.com/aws-cloudformation/rain/cft/parse" | ||
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory" | ||
"go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin" | ||
) | ||
|
||
var _ plugin.Connection = (*CloudformationConnection)(nil) | ||
|
||
type CloudformationConnection struct { | ||
plugin.Connection | ||
Conf *inventory.Config | ||
asset *inventory.Asset | ||
// Add custom connection fields here | ||
path string | ||
cftTemplate cft.Template | ||
} | ||
|
||
func NewCloudformationConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*CloudformationConnection, error) { | ||
conn := &CloudformationConnection{ | ||
Connection: plugin.NewConnection(id, asset), | ||
Conf: conf, | ||
asset: asset, | ||
} | ||
// initialize your connection here | ||
cc := asset.Connections[0] | ||
path := cc.Options["path"] | ||
conn.path = path | ||
|
||
f, err := os.Open(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
cftTemplate, err := parse.Reader(f) | ||
if err != nil { | ||
return nil, err | ||
} | ||
conn.cftTemplate = cftTemplate | ||
|
||
return conn, nil | ||
} | ||
|
||
func (c *CloudformationConnection) Name() string { | ||
return "cloudformation" | ||
} | ||
|
||
func (c *CloudformationConnection) Asset() *inventory.Asset { | ||
return c.asset | ||
} | ||
|
||
func (c *CloudformationConnection) CftTemplate() cft.Template { | ||
return c.cftTemplate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package connection | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/aws-cloudformation/rain/cft" | ||
"github.com/aws-cloudformation/rain/cft/parse" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParse(t *testing.T) { | ||
testTemplate, err := os.ReadFile("testdata/json/ec2instance.json") | ||
require.NoError(t, err) | ||
cftTemplate, err := parse.Reader(bytes.NewReader(testTemplate)) | ||
require.NoError(t, err) | ||
require.NotNil(t, cftTemplate) | ||
|
||
resource, err := cftTemplate.GetResource("myLaunchTemplate") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resource == nil { | ||
t.Error("Unexpected: resource is nil") | ||
} | ||
|
||
section, err := cftTemplate.GetSection(cft.Resources) | ||
require.NoError(t, err) | ||
require.NotNil(t, section) | ||
|
||
for i := 0; i < len(section.Content); i += 2 { | ||
logicalId := section.Content[i].Value | ||
resource := section.Content[i+1] | ||
fmt.Print(logicalId, resource) | ||
} | ||
|
||
types, err := cftTemplate.GetTypes() | ||
require.NoError(t, err) | ||
fmt.Println(types) | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
providers/cloudformation/connection/testdata/json/ec2instance.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"Resources":{ | ||
"myLaunchTemplate":{ | ||
"Type":"AWS::EC2::LaunchTemplate", | ||
"Properties":{ | ||
"LaunchTemplateName":{ "Fn::Sub": "${AWS::StackName}-launch-template" }, | ||
"LaunchTemplateData":{ | ||
"ImageId":"ami-02354e95b3example", | ||
"InstanceType":"t3.micro", | ||
"IamInstanceProfile":{ | ||
"Name":{ | ||
"Ref":"myInstanceProfile" | ||
} | ||
}, | ||
"SecurityGroupIds":[ | ||
{ | ||
"Ref":"myNewEC2SecurityGroup" | ||
}, | ||
"sg-083cd3bfb8example" | ||
], | ||
"UserData":{ | ||
"Fn::Base64":{ | ||
"Fn::Join": [ | ||
"", [ | ||
"#!/bin/bash\n", | ||
"cd /tmp\n", | ||
"yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm\n", | ||
"systemctl enable amazon-ssm-agent\n", | ||
"systemctl start amazon-ssm-agent\n" | ||
] | ||
] | ||
} | ||
}, | ||
"TagSpecifications":[ | ||
{ | ||
"ResourceType":"instance", | ||
"Tags":[ | ||
{ | ||
"Key":"environment", | ||
"Value":"development" | ||
} | ||
] | ||
}, | ||
{ | ||
"ResourceType":"volume", | ||
"Tags":[ | ||
{ | ||
"Key":"environment", | ||
"Value":"development" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"myInstanceRole":{ | ||
"Type":"AWS::IAM::Role", | ||
"Properties":{ | ||
"RoleName":"InstanceRole", | ||
"AssumeRolePolicyDocument":{ | ||
"Version":"2012-10-17", | ||
"Statement":[ | ||
{ | ||
"Effect":"Allow", | ||
"Principal":{ | ||
"Service":[ | ||
"ec2.amazonaws.com" | ||
] | ||
}, | ||
"Action":[ | ||
"sts:AssumeRole" | ||
] | ||
} | ||
] | ||
}, | ||
"ManagedPolicyArns":[ | ||
"arn:aws:iam::aws:policy/myCustomerManagedPolicy" | ||
] | ||
} | ||
}, | ||
"myInstanceProfile":{ | ||
"Type":"AWS::IAM::InstanceProfile", | ||
"Properties":{ | ||
"Path":"/", | ||
"Roles":[ | ||
{ | ||
"Ref":"myInstanceRole" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package main | ||
|
||
import ( | ||
"go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin/gen" | ||
"go.mondoo.com/cnquery/v11/providers/cloudformation/config" | ||
) | ||
|
||
func main() { | ||
gen.CLI(&config.Config) | ||
} |
Oops, something went wrong.