diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..64bd5cee2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,132 @@ +# Distributed via https://github.com/rebuy-de/terraform-cluster-config +# Modify only there, changes in project repos will be overwritten + +root = true + +[openapi-spec.yaml] +ij_formatter_enabled = false + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 120 +tab_width = 4 +trim_trailing_whitespace = true +ij_continuation_indent_size = 8 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_visual_guides = +ij_wrap_on_typing = false + +[{*.htm,*.html,*.sht,*.shtm,*.shtml}] +ij_html_attribute_wrap = off +ij_html_do_not_indent_children_of_tags = +ij_html_keep_blank_lines = 1 +ij_html_text_wrap = off + +[{*.cjs,*.js}] +ij_javascript_do_while_brace_force = always +ij_javascript_for_brace_force = always +ij_javascript_if_brace_force = always +ij_javascript_keep_blank_lines_in_code = 1 +ij_javascript_use_double_quotes = false +ij_javascript_while_brace_force = always + +[{*.ats,*.cts,*.mts,*.ts}] +ij_typescript_do_while_brace_force = always +ij_typescript_for_brace_force = always +ij_typescript_if_brace_force = always +ij_typescript_import_prefer_absolute_path = true +ij_typescript_keep_blank_lines_in_code = 1 +ij_typescript_space_before_function_left_parenth = false +ij_typescript_use_double_quotes = false +ij_typescript_while_brace_force = always + +[*.coffee] +indent_size = 2 + +[*.java] +ij_continuation_indent_size = 4 +ij_java_blank_lines_around_field = 1 +ij_java_blank_lines_around_initializer = 0 +ij_java_class_brace_style = next_line +ij_java_class_count_to_use_import_on_demand = 99 +ij_java_do_while_brace_force = always +ij_java_doc_add_blank_line_after_param_comments = true +ij_java_doc_add_blank_line_after_return = true +ij_java_for_brace_force = always +ij_java_if_brace_force = always +ij_java_keep_blank_lines_before_right_brace = 0 +ij_java_keep_blank_lines_in_code = 1 +ij_java_keep_blank_lines_in_declarations = 0 +ij_java_keep_simple_classes_in_one_line = true +ij_java_keep_simple_lambdas_in_one_line = true +ij_java_method_brace_style = next_line +ij_java_names_count_to_use_import_on_demand = 99 +ij_java_new_line_after_lparen_in_record_header = true +ij_java_packages_to_use_import_on_demand = +ij_java_record_components_wrap = on_every_item +ij_java_rparen_on_new_line_in_record_header = true +ij_java_while_brace_force = always + +[{*.kt,*.kts}] +ij_continuation_indent_size = 4 +ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL +ij_kotlin_name_count_to_use_star_import = 2147483647 +ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 +ij_kotlin_packages_to_use_import_on_demand = + +[{*.ctp,*.hphp,*.inc,*.module,*.php,*.php4,*.php5,*.phtml}] +ij_php_align_multiline_parameters = false +ij_php_blank_lines_around_field = 1 +ij_php_blank_lines_before_return_statement = 1 +ij_php_comma_after_last_array_element = true +ij_php_force_short_declaration_array_style = true +ij_php_keep_blank_lines_before_right_brace = 0 +ij_php_keep_blank_lines_in_code = 1 +ij_php_keep_blank_lines_in_declarations = 0 +ij_php_keep_rparen_and_lbrace_on_one_line = true +ij_php_lower_case_boolean_const = true +ij_php_lower_case_null_const = true +ij_php_method_parameters_new_line_after_left_paren = true +ij_php_method_parameters_right_paren_on_new_line = true +ij_php_phpdoc_blank_line_before_tags = true +ij_php_phpdoc_blank_lines_around_parameters = true +ij_php_space_after_type_cast = true +ij_php_space_before_short_closure_left_parenthesis = true + +[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.pom,*.rng,*.tld,*.wadl,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul,phpunit.xml.dist}] +ij_xml_space_inside_empty_tag = true + +[{*.tf,*.tfvars,*.hcl}] +tab_width = 2 +ij_continuation_indent_size = 4 + +[*.less] +tab_width = 2 +ij_continuation_indent_size = 2 + +[*.sass] +tab_width = 2 +ij_continuation_indent_size = 2 + +[*.scala] +ij_scala_do_while_brace_force = always +ij_scala_for_brace_force = always +ij_scala_if_brace_force = always +ij_scala_keep_blank_lines_before_right_brace = 0 +ij_scala_keep_blank_lines_in_code = 0 +ij_scala_keep_blank_lines_in_declarations = 0 +ij_scala_multiline_string_closing_quotes_on_new_line = false + +[*.scss] +ij_continuation_indent_size = 4 + +[{*.yaml,*.yml}] +ij_yaml_spaces_within_braces = false +ij_yaml_spaces_within_brackets = false diff --git a/go.mod b/go.mod index efd776983..5aedbdbc3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/rebuy-de/aws-nuke/v2 go 1.21 require ( - github.com/aws/aws-sdk-go v1.53.10 + github.com/aws/aws-sdk-go v1.54.19 github.com/fatih/color v1.17.0 github.com/golang/mock v1.6.0 github.com/google/uuid v1.6.0 @@ -11,7 +11,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/rebuy-de/rebuy-go-sdk/v4 v4.5.1 github.com/sirupsen/logrus v1.9.3 - github.com/spf13/cobra v1.8.0 + github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 golang.org/x/sync v0.7.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 243b890e0..1cd1603ea 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ -github.com/aws/aws-sdk-go v1.53.10 h1:3enP5l5WtezT9Ql+XZqs56JBf5YUd/FEzTCg///OIGY= -github.com/aws/aws-sdk-go v1.53.10/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/aws/aws-sdk-go v1.54.19 h1:tyWV+07jagrNiCcGRzRhdtVjQs7Vy41NwsuOcl0IbVI= +github.com/aws/aws-sdk-go v1.54.19/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -44,8 +44,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -64,8 +64,6 @@ golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= @@ -84,8 +82,6 @@ golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= diff --git a/resources/bedrock-agentalias.go b/resources/bedrock-agentalias.go new file mode 100644 index 000000000..63e0edba7 --- /dev/null +++ b/resources/bedrock-agentalias.go @@ -0,0 +1,105 @@ +package resources + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/bedrockagent" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type BedrockAgentAlias struct { + svc *bedrockagent.BedrockAgent + AgentId *string + AgentAliasId *string + AgentAliasName *string +} + +func init() { + register("BedrockAgentAlias", ListBedrockAgentAliases) +} + +func ListBedrockAgentAliases(sess *session.Session) ([]Resource, error) { + svc := bedrockagent.New(sess) + resources := []Resource{} + + agentIds, err := ListBedrockAgentIds(svc) + if err != nil { + return nil, err + } + + for _, agentId := range agentIds { + params := &bedrockagent.ListAgentAliasesInput{ + MaxResults: aws.Int64(100), + AgentId: aws.String(agentId), + } + for { + output, err := svc.ListAgentAliases(params) + if err != nil { + return nil, err + } + + for _, agentAliasInfo := range output.AgentAliasSummaries { + resources = append(resources, &BedrockAgentAlias{ + svc: svc, + AgentId: aws.String(agentId), + AgentAliasName: agentAliasInfo.AgentAliasName, + AgentAliasId: agentAliasInfo.AgentAliasId, + }) + } + + if output.NextToken == nil { + break + } + params.NextToken = output.NextToken + } + + } + + return resources, nil +} + +func ListBedrockAgentIds(svc *bedrockagent.BedrockAgent) ([]string, error) { + + agentIds := []string{} + params := &bedrockagent.ListAgentsInput{ + MaxResults: aws.Int64(100), + } + for { + output, err := svc.ListAgents(params) + if err != nil { + return nil, err + } + + for _, agent := range output.AgentSummaries { + agentIds = append(agentIds, *agent.AgentId) + } + + if output.NextToken == nil { + break + } + params.NextToken = output.NextToken + } + + return agentIds, nil +} + +func (f *BedrockAgentAlias) Remove() error { + _, err := f.svc.DeleteAgentAlias(&bedrockagent.DeleteAgentAliasInput{ + AgentAliasId: f.AgentAliasId, + AgentId: f.AgentId, + }) + return err +} + +func (f *BedrockAgentAlias) Properties() types.Properties { + properties := types.NewProperties(). + Set("AgentId", f.AgentId). + Set("AgentAliasId", f.AgentAliasId). + Set("AgentAliasName", f.AgentAliasName) + + return properties +} + +func (f *BedrockAgentAlias) String() string { + return *f.AgentAliasName +} diff --git a/resources/bedrock-flowalias.go b/resources/bedrock-flowalias.go new file mode 100644 index 000000000..eca852ca6 --- /dev/null +++ b/resources/bedrock-flowalias.go @@ -0,0 +1,115 @@ +package resources + +import ( + "fmt" + "strings" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/bedrockagent" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type BedrockFlowAlias struct { + svc *bedrockagent.BedrockAgent + FlowId *string + FlowAliasId *string + FlowAliasName *string +} + +func init() { + register("BedrockFlowAlias", ListBedrockFlowAliases) +} + +func ListBedrockFlowAliases(sess *session.Session) ([]Resource, error) { + svc := bedrockagent.New(sess) + resources := []Resource{} + + flowIds, err := ListBedrockFlowIds(svc) + if err != nil { + return nil, err + } + + for _, flowId := range flowIds { + params := &bedrockagent.ListFlowAliasesInput{ + MaxResults: aws.Int64(100), + FlowIdentifier: aws.String(flowId), + } + for { + output, err := svc.ListFlowAliases(params) + if err != nil { + return nil, err + } + + for _, flowAliasInfo := range output.FlowAliasSummaries { + resources = append(resources, &BedrockFlowAlias{ + svc: svc, + FlowId: flowAliasInfo.FlowId, + FlowAliasId: flowAliasInfo.Id, + FlowAliasName: flowAliasInfo.Name, + }) + } + + if output.NextToken == nil { + break + } + params.NextToken = output.NextToken + } + + } + + return resources, nil +} + +func ListBedrockFlowIds(svc *bedrockagent.BedrockAgent) ([]string, error) { + + flowIds := []string{} + params := &bedrockagent.ListFlowsInput{ + MaxResults: aws.Int64(100), + } + for { + output, err := svc.ListFlows(params) + if err != nil { + return nil, err + } + + for _, flow := range output.FlowSummaries { + flowIds = append(flowIds, *flow.Id) + } + + if output.NextToken == nil { + break + } + params.NextToken = output.NextToken + } + + return flowIds, nil +} + +func (f *BedrockFlowAlias) Filter() error { + if strings.HasPrefix(*f.FlowAliasName, "TSTALIASID") { + return fmt.Errorf("cannot delete AWS managed Flow Alias") + } + return nil +} + +func (f *BedrockFlowAlias) Remove() error { + _, err := f.svc.DeleteFlowAlias(&bedrockagent.DeleteFlowAliasInput{ + AliasIdentifier: f.FlowAliasId, + FlowIdentifier: f.FlowId, + }) + return err +} + +func (f *BedrockFlowAlias) Properties() types.Properties { + properties := types.NewProperties(). + Set("FlowId", f.FlowId). + Set("FlowAliasId", f.FlowAliasId). + Set("FlowAliasName", f.FlowAliasName) + + return properties +} + +func (f *BedrockFlowAlias) String() string { + return *f.FlowAliasName +}