-
Notifications
You must be signed in to change notification settings - Fork 114
Added bedrock guardails #2615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added bedrock guardails #2615
Changes from all commits
74b6e6e
5ec786a
b97c66e
5d23723
c68ea14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,181 @@ | ||||||
| package aws | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/aws/aws-sdk-go-v2/service/bedrock" | ||||||
| "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" | ||||||
| "github.com/turbot/steampipe-plugin-sdk/v5/plugin" | ||||||
| "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" | ||||||
| ) | ||||||
|
|
||||||
| // unified row used for both List and Get paths | ||||||
| type bedrockGuardrailRow struct { | ||||||
| Arn string `json:"Arn"` | ||||||
| GuardrailId string `json:"GuardrailId"` | ||||||
| Name string `json:"Name"` | ||||||
| Description string `json:"Description"` | ||||||
| Status string `json:"Status"` | ||||||
| Version string `json:"Version"` | ||||||
| CreatedAt time.Time `json:"CreatedAt"` | ||||||
| UpdatedAt time.Time `json:"UpdatedAt"` | ||||||
| } | ||||||
|
|
||||||
| func tableAwsBedrockGuardrail(_ context.Context) *plugin.Table { | ||||||
| return &plugin.Table{ | ||||||
| Name: "aws_bedrock_guardrail", | ||||||
| Description: "Amazon Bedrock Guardrail.", | ||||||
| List: &plugin.ListConfig{ | ||||||
| Hydrate: listBedrockGuardrails, | ||||||
| Tags: map[string]string{"service": "bedrock", "action": "ListGuardrails"}, | ||||||
| }, | ||||||
| Get: &plugin.GetConfig{ | ||||||
| // allow lookup by ID or ARN (both map to GuardrailIdentifier) | ||||||
| KeyColumns: plugin.AnyColumn([]string{"guardrail_id", "arn"}), | ||||||
| Hydrate: getBedrockGuardrail, | ||||||
| Tags: map[string]string{"service": "bedrock", "action": "GetGuardrail"}, | ||||||
| IgnoreConfig: &plugin.IgnoreConfig{ | ||||||
| ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}), | ||||||
| }, | ||||||
| }, | ||||||
| GetMatrixItemFunc: SupportedRegionMatrix(AWS_BEDROCK_SERVICE_ID), | ||||||
| Columns: awsRegionalColumns([]*plugin.Column{ | ||||||
| // identifiers | ||||||
| {Name: "arn", Type: proto.ColumnType_STRING, Description: "ARN of the guardrail.", Transform: transform.FromField("Arn")}, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please confirm whether we should include an explicit transform here ( Also, please review the other columns and let me know if any of them require an explicit transform. |
||||||
| {Name: "guardrail_id", Type: proto.ColumnType_STRING, Description: "ID of the guardrail.", Transform: transform.FromField("GuardrailId")}, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| // metadata | ||||||
| {Name: "name", Type: proto.ColumnType_STRING, Description: "Name of the guardrail.", Transform: transform.FromField("Name")}, | ||||||
| {Name: "description", Type: proto.ColumnType_STRING, Description: "Description of the guardrail.", Transform: transform.FromField("Description")}, | ||||||
|
|
||||||
| // status / version | ||||||
| {Name: "status", Type: proto.ColumnType_STRING, Description: "Status of the guardrail.", Transform: transform.FromField("Status")}, | ||||||
| {Name: "version", Type: proto.ColumnType_STRING, Description: "Version (DRAFT or a number).", Transform: transform.FromField("Version")}, | ||||||
|
|
||||||
| // timestamps | ||||||
| {Name: "created_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CreatedAt")}, | ||||||
| {Name: "updated_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("UpdatedAt")}, | ||||||
|
|
||||||
| // steampipe standard | ||||||
| {Name: "title", Type: proto.ColumnType_STRING, Transform: transform.FromField("Name")}, | ||||||
| {Name: "akas", Type: proto.ColumnType_JSON, Transform: transform.FromField("Arn").Transform(transform.EnsureStringArray)}, | ||||||
|
Comment on lines
+57
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the missing description. |
||||||
| }), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // LIST: map GuardrailSummary -> bedrockGuardrailRow (ensures Arn/Id are set) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| func listBedrockGuardrails(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||||||
| svc, err := BedrockClient(ctx, d) | ||||||
| if svc == nil { | ||||||
| return nil, nil | ||||||
| } | ||||||
| if err != nil { | ||||||
| plugin.Logger(ctx).Error("aws_bedrock_guardrail.listBedrockGuardrails", "connection_error", err) | ||||||
| return nil, err | ||||||
| if err != nil { | ||||||
| plugin.Logger(ctx).Error("aws_bedrock_guardrail.listBedrockGuardrails", "connection_error", err) | ||||||
| return nil, err | ||||||
| } | ||||||
| if svc == nil { | ||||||
| return nil, err | ||||||
| } | ||||||
SatoriSec marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+70
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please remove the duplicated code block? |
||||||
|
|
||||||
| p := bedrock.NewListGuardrailsPaginator(svc, &bedrock.ListGuardrailsInput{}) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you set the input parameter |
||||||
| for p.HasMorePages() { | ||||||
| out, err := p.NextPage(ctx) | ||||||
| if err != nil { | ||||||
| plugin.Logger(ctx).Error("aws_bedrock_guardrail.listBedrockGuardrails", "api_error", err) | ||||||
| return nil, err | ||||||
| } | ||||||
| for _, s := range out.Guardrails { | ||||||
| row := bedrockGuardrailRow{ | ||||||
| Arn: str(s.Arn), | ||||||
| GuardrailId: str(s.Id), | ||||||
| Name: str(s.Name), | ||||||
| Description: str(s.Description), | ||||||
| Status: string(s.Status), | ||||||
| Version: str(s.Version), | ||||||
| CreatedAt: t(s.CreatedAt), | ||||||
| UpdatedAt: t(s.UpdatedAt), | ||||||
| } | ||||||
|
Comment on lines
+92
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t think we need a custom struct—let’s stream the API response as-is. The Get API response includes more detail than the List response, so we should expose all top-level properties as table columns. For fields that are only available via Get, add per-column Hydrate functions. For reference, see the |
||||||
| d.StreamListItem(ctx, row) | ||||||
| if d.RowsRemaining(ctx) == 0 { | ||||||
| return nil, nil | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| return nil, nil | ||||||
| } | ||||||
|
|
||||||
| // GET: map GetGuardrailOutput -> bedrockGuardrailRow (ensures Arn/Id are set) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| func getBedrockGuardrail(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||||||
|
Check failure on line 112 in aws/table_aws_bedrock_guardrail.go
|
||||||
| id := d.EqualsQualString("guardrail_id") | ||||||
| if id == "" { | ||||||
| id = d.EqualsQualString("arn") | ||||||
| } | ||||||
| if id == "" { | ||||||
| return nil, nil | ||||||
| } | ||||||
|
|
||||||
| svc, err := BedrockClient(ctx, d) | ||||||
| if svc == nil { | ||||||
| return nil, nil | ||||||
| } | ||||||
| if err != nil { | ||||||
| plugin.Logger(ctx).Error("aws_bedrock_guardrail.getBedrockGuardrail", "connection_error", err) | ||||||
| return nil, err | ||||||
| if err != nil { | ||||||
| plugin.Logger(ctx).Error("aws_bedrock_guardrail.getBedrockGuardrail", "connection_error", err) | ||||||
| return nil, err | ||||||
| } | ||||||
| if svc == nil { | ||||||
| return nil, nil | ||||||
| } | ||||||
SatoriSec marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+122
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please remove the duplicated code block? |
||||||
|
|
||||||
| out, err := svc.GetGuardrail(ctx, &bedrock.GetGuardrailInput{ | ||||||
| GuardrailIdentifier: &id, // accepts ID or ARN | ||||||
| }) | ||||||
| if err != nil { | ||||||
| plugin.Logger(ctx).Error("aws_bedrock_guardrail.getBedrockGuardrail", "api_error", err) | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| row := bedrockGuardrailRow{ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is required anymore. |
||||||
| Arn: str(out.GuardrailArn), | ||||||
| GuardrailId: str(out.GuardrailId), | ||||||
| Name: str(out.Name), | ||||||
| Description: str(out.Description), | ||||||
| Status: string(out.Status), | ||||||
| Version: str(out.Version), | ||||||
| CreatedAt: t(out.CreatedAt), | ||||||
| UpdatedAt: t(out.UpdatedAt), | ||||||
| } | ||||||
| return row, nil | ||||||
| } | ||||||
|
|
||||||
| // small ptr helpers (avoid extra deps) | ||||||
| func str(p *string) string { | ||||||
|
Check failure on line 158 in aws/table_aws_bedrock_guardrail.go
|
||||||
| if p == nil { | ||||||
| return "" | ||||||
| } | ||||||
| return *p | ||||||
| } | ||||||
| func t(p *time.Time) time.Time { | ||||||
|
Check failure on line 164 in aws/table_aws_bedrock_guardrail.go
|
||||||
| if p == nil { | ||||||
| return time.Time{} | ||||||
| } | ||||||
| return *p | ||||||
| } | ||||||
| Arn: aws.ToString(out.GuardrailArn), | ||||||
| GuardrailId: aws.ToString(out.GuardrailId), | ||||||
|
Check failure on line 171 in aws/table_aws_bedrock_guardrail.go
|
||||||
| Name: aws.ToString(out.Name), | ||||||
| Description: aws.ToString(out.Description), | ||||||
| Status: string(out.Status), | ||||||
| Version: aws.ToString(out.Version), | ||||||
| CreatedAt: aws.ToTime(out.CreatedAt), | ||||||
| UpdatedAt: aws.ToTime(out.UpdatedAt), | ||||||
| } | ||||||
| return row, nil | ||||||
| } | ||||||
|
|
||||||
SatoriSec marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the custom struct necessary here?