From 9779aaa707067462d913d0f8cf13199a231af69a Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Fri, 18 Oct 2024 11:48:09 +0200 Subject: [PATCH 1/3] [aws][fix] Ignore wrong history events --- .../aws/fix_plugin_aws/resource/bedrock.py | 113 +----------------- plugins/aws/test/collector_test.py | 4 +- .../get-agent-version__None_1_0.json | 10 -- .../resource/machinelearning.py | 6 +- 4 files changed, 6 insertions(+), 127 deletions(-) delete mode 100644 plugins/aws/test/resources/files/bedrock_agent/get-agent-version__None_1_0.json diff --git a/plugins/aws/fix_plugin_aws/resource/bedrock.py b/plugins/aws/fix_plugin_aws/resource/bedrock.py index 6fcddb36d5..febf5f9444 100644 --- a/plugins/aws/fix_plugin_aws/resource/bedrock.py +++ b/plugins/aws/fix_plugin_aws/resource/bedrock.py @@ -14,7 +14,7 @@ from fix_plugin_aws.resource.rds import AwsRdsCluster, AwsRdsInstance from fixlib.baseresources import BaseAIJob, ModelReference, BaseAIModel from fixlib.graph import Graph -from fixlib.json_bender import Bender, S, ForallBend, Bend +from fixlib.json_bender import Bender, S, ForallBend, Bend, Sort from fixlib.types import Json log = logging.getLogger("fix.plugins.aws") @@ -906,6 +906,7 @@ class AwsBedrockPromptOverrideConfiguration: mapping: ClassVar[Dict[str, Bender]] = { "override_lambda": S("overrideLambda"), "prompt_configurations": S("promptConfigurations", default=[]) + >> Sort(S("basePromptTemplate")) # The configurations are returned always in different order >> ForallBend(AwsBedrockPromptConfiguration.mapping), } override_lambda: Optional[str] = field(default=None, metadata={"description": "The ARN of the Lambda function to use when parsing the raw foundation model output in parts of the agent sequence. If you specify this field, at least one of the promptConfigurations must contain a parserMode value that is set to OVERRIDDEN. For more information, see Parser Lambda function in Agents for Amazon Bedrock."}) # fmt: skip @@ -1029,19 +1030,6 @@ def add_tags(agent: AwsResource) -> None: if tags: agent.tags.update(tags[0]) - def collect_agent_versions(agent: AwsBedrockAgent) -> None: - if not agent.agent_version or agent.agent_version == "DRAFT": - return - for result in builder.client.list( - "bedrock-agent", - "get-agent-version", - agentId=agent.id, - agentVersion=agent.agent_version, - ): - if instance := AwsBedrockAgentVersion.from_api(result, builder): - builder.add_node(instance, js) - builder.submit_work("bedrock-agent", add_tags, instance) - for js in json: for result in builder.client.list( "bedrock-agent", @@ -1052,102 +1040,6 @@ def collect_agent_versions(agent: AwsBedrockAgent) -> None: instance.agent_version = js["latestAgentVersion"] builder.add_node(instance, js) builder.submit_work("bedrock-agent", add_tags, instance) - builder.submit_work("bedrock-agent", collect_agent_versions, instance) - - -@define(eq=False, slots=False) -class AwsBedrockAgentVersion(BedrockTaggable, AwsResource): - kind: ClassVar[str] = "aws_bedrock_agent_version" - _kind_display: ClassVar[str] = "AWS Bedrock Agent Version" - _kind_description: ClassVar[str] = "AWS Bedrock Agent Version is a feature that tracks changes in Bedrock agents over time. It maintains a record of agent configurations, including knowledge bases, prompts, and action groups. Users can view, compare, and revert to previous versions, ensuring version control and facilitating collaboration across teams working on AI agent development." # fmt: skip - _docs_url: ClassVar[str] = "https://docs.aws.amazon.com/bedrock/latest/userguide/agents-version.html" - _kind_service: ClassVar[Optional[str]] = "bedrock-agent" - _aws_metadata: ClassVar[Dict[str, Any]] = { - "provider_link_tpl": "https://{region_id}.console.aws.amazon.com/bedrock/home?region={region_id}#/agents/{id}/versions/{version}" - } - _metadata: ClassVar[Dict[str, Any]] = {"icon": "version", "group": "ai"} - _reference_kinds: ClassVar[ModelReference] = { - "predecessors": {"default": [AwsIamRole.kind, AwsBedrockFoundationModel.kind]}, - "successors": {"default": [AwsBedrockGuardrail.kind, AwsKmsKey.kind]}, - } - # Collected via AwsBedrockAgent() - mapping: ClassVar[Dict[str, Bender]] = { - "id": S("agentVersion", "agentId"), - "name": S("agentVersion", "agentName"), - "ctime": S("agentVersion", "createdAt"), - "mtime": S("agentVersion", "updatedAt"), - "arn": S("agentVersion", "agentArn"), - "agent_arn": S("agentVersion", "agentArn"), - "agent_id": S("agentVersion", "agentId"), - "agent_name": S("agentVersion", "agentName"), - "agent_resource_role_arn": S("agentVersion", "agentResourceRoleArn"), - "agent_status": S("agentVersion", "agentStatus"), - "created_at": S("agentVersion", "createdAt"), - "customer_encryption_key_arn": S("agentVersion", "customerEncryptionKeyArn"), - "description": S("agentVersion", "description"), - "failure_reasons": S("agentVersion", "failureReasons", default=[]), - "foundation_model": S("agentVersion", "foundationModel"), - "guardrail_configuration": S("agentVersion", "guardrailConfiguration") - >> Bend(AwsBedrockGuardrailConfiguration.mapping), - "idle_session_ttl_in_seconds": S("agentVersion", "idleSessionTTLInSeconds"), - "instruction": S("agentVersion", "instruction"), - "memory_configuration": S("agentVersion", "memoryConfiguration") >> Bend(AwsBedrockMemoryConfiguration.mapping), - "prompt_override_configuration": S("agentVersion", "promptOverrideConfiguration") - >> Bend(AwsBedrockPromptOverrideConfiguration.mapping), - "agent_recommended_actions": S("agentVersion", "recommendedActions", default=[]), - "updated_at": S("agentVersion", "updatedAt"), - "version": S("agentVersion", "version"), - } - agent_arn: Optional[str] = field(default=None, metadata={"description": "The Amazon Resource Name (ARN) of the agent that the version belongs to."}) # fmt: skip - agent_id: Optional[str] = field(default=None, metadata={"description": "The unique identifier of the agent that the version belongs to."}) # fmt: skip - agent_name: Optional[str] = field(default=None, metadata={"description": "The name of the agent that the version belongs to."}) # fmt: skip - agent_resource_role_arn: Optional[str] = field(default=None, metadata={"description": "The Amazon Resource Name (ARN) of the IAM role with permissions to invoke API operations on the agent."}) # fmt: skip - agent_status: Optional[str] = field(default=None, metadata={"description": "The status of the agent that the version belongs to."}) # fmt: skip - created_at: Optional[datetime] = field(default=None, metadata={"description": "The time at which the version was created."}) # fmt: skip - customer_encryption_key_arn: Optional[str] = field(default=None, metadata={"description": "The Amazon Resource Name (ARN) of the KMS key that encrypts the agent."}) # fmt: skip - description: Optional[str] = field(default=None, metadata={"description": "The description of the version."}) # fmt: skip - failure_reasons: Optional[List[str]] = field(factory=list, metadata={"description": "A list of reasons that the API operation on the version failed."}) # fmt: skip - foundation_model: Optional[str] = field(default=None, metadata={"description": "The foundation model that the version invokes."}) # fmt: skip - guardrail_configuration: Optional[AwsBedrockGuardrailConfiguration] = field(default=None, metadata={"description": "Details about the guardrail associated with the agent."}) # fmt: skip - idle_session_ttl_in_seconds: Optional[int] = field(default=None, metadata={"description": "The number of seconds for which Amazon Bedrock keeps information about a user's conversation with the agent. A user interaction remains active for the amount of time specified. If no conversation occurs during this time, the session expires and Amazon Bedrock deletes any data provided before the timeout."}) # fmt: skip - instruction: Optional[str] = field(default=None, metadata={"description": "The instructions provided to the agent."}) # fmt: skip - memory_configuration: Optional[AwsBedrockMemoryConfiguration] = field(default=None, metadata={"description": "Contains details of the memory configuration on the version of the agent."}) # fmt: skip - prompt_override_configuration: Optional[AwsBedrockPromptOverrideConfiguration] = field(default=None, metadata={"description": "Contains configurations to override prompt templates in different parts of an agent sequence. For more information, see Advanced prompts."}) # fmt: skip - agent_recommended_actions: Optional[List[str]] = field(factory=list, metadata={"description": "A list of recommended actions to take for the failed API operation on the version to succeed."}) # fmt: skip - updated_at: Optional[datetime] = field(default=None, metadata={"description": "The time at which the version was last updated."}) # fmt: skip - version: Optional[str] = field(default=None, metadata={"description": "The version number."}) # fmt: skip - - def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: - if role_arn := self.agent_resource_role_arn: - builder.add_edge(self, reverse=True, clazz=AwsIamRole, arn=role_arn) - if encryption_key_arn := self.customer_encryption_key_arn: - builder.add_edge(self, clazz=AwsKmsKey, arn=encryption_key_arn) - if (g_configuration := self.guardrail_configuration) and (g_id := g_configuration.guardrail_identifier): - builder.add_edge(self, clazz=AwsBedrockGuardrail, id=g_id) - if foundation_model_name := self.foundation_model: - builder.add_edge(self, reverse=True, clazz=AwsBedrockFoundationModel, id=foundation_model_name) - - def delete_resource(self, client: AwsClient, graph: Graph) -> bool: - client.call( - aws_service="bedrock-agent", - action="delete-agent-version", - result_name=None, - agentId=self.agent_id, - agentVersion=self.version, - ) - return True - - @classmethod - def called_mutator_apis(cls) -> List[AwsApiSpec]: - return super().called_mutator_apis() + [AwsApiSpec("bedrock-agent", "delete-agent-version")] - - @classmethod - def called_collect_apis(cls) -> List[AwsApiSpec]: - return super().called_collect_apis() + [AwsApiSpec("bedrock-agent", "get-agent-version")] - - @classmethod - def service_name(cls) -> str: - return "bedrock-agent" @define(eq=False, slots=False) @@ -2022,7 +1914,6 @@ def service_name(cls) -> str: AwsBedrockModelCustomizationJob, AwsBedrockEvaluationJob, AwsBedrockAgent, - AwsBedrockAgentVersion, AwsBedrockAgentKnowledgeBase, AwsBedrockAgentPrompt, AwsBedrockAgentFlow, diff --git a/plugins/aws/test/collector_test.py b/plugins/aws/test/collector_test.py index 5d19ae5c2c..eae09ca021 100644 --- a/plugins/aws/test/collector_test.py +++ b/plugins/aws/test/collector_test.py @@ -34,8 +34,8 @@ def count_kind(clazz: Type[AwsResource]) -> int: # make sure all threads have been joined assert len(threading.enumerate()) == 1 # ensure the correct number of nodes and edges - assert count_kind(AwsResource) == 261 - assert len(account_collector.graph.edges) == 575 + assert count_kind(AwsResource) == 260 + assert len(account_collector.graph.edges) == 574 assert len(account_collector.graph.deferred_edges) == 2 for node in account_collector.graph.nodes: if isinstance(node, AwsRegion): diff --git a/plugins/aws/test/resources/files/bedrock_agent/get-agent-version__None_1_0.json b/plugins/aws/test/resources/files/bedrock_agent/get-agent-version__None_1_0.json deleted file mode 100644 index dc8a0df49a..0000000000 --- a/plugins/aws/test/resources/files/bedrock_agent/get-agent-version__None_1_0.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "agentId": "foo", - "agentName": "foo", - "version": "1.0", - "status": "ACTIVE", - "releaseNotes": "Initial release with basic features.", - "createdAt": "2024-09-12T08:00:00Z", - "lastModifiedAt": "2024-09-12T09:00:00Z" - } - \ No newline at end of file diff --git a/plugins/azure/fix_plugin_azure/resource/machinelearning.py b/plugins/azure/fix_plugin_azure/resource/machinelearning.py index 528d18d203..949e5f00d7 100644 --- a/plugins/azure/fix_plugin_azure/resource/machinelearning.py +++ b/plugins/azure/fix_plugin_azure/resource/machinelearning.py @@ -692,10 +692,8 @@ class AzureMachineLearningDataContainerBase(AzureProxyResource): } description: Optional[str] = field(default=None, metadata={"description": "The asset description text."}) is_archived: Optional[bool] = field(default=False, metadata={"description": "Is the asset archived?"}) - latest_version: Optional[str] = field( - default=None, metadata={"description": "The latest version inside this container."} - ) - next_version: Optional[str] = field(default=None, metadata={"description": "The next auto incremental version."}) + latest_version: Optional[str] = field(default=None, metadata={"ignore_history": True, "description": "The latest version inside this container."}) # fmt: skip + next_version: Optional[str] = field(default=None, metadata={"ignore_history": True, "description": "The next auto incremental version."}) # fmt: skip properties: Optional[Dict[str, Any]] = field(default=None, metadata={"description": ""}) From ed92e93d795cbe83a255bd0dcb80474d4b92926a Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Fri, 18 Oct 2024 12:10:28 +0200 Subject: [PATCH 2/3] remove unused plugins --- fixlib/fixlib/core/model_check.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/fixlib/fixlib/core/model_check.py b/fixlib/fixlib/core/model_check.py index 9d811b2035..9b4e807cd4 100644 --- a/fixlib/fixlib/core/model_check.py +++ b/fixlib/fixlib/core/model_check.py @@ -174,12 +174,10 @@ def dynamic_import(name: str) -> List[Type[Any]]: *dynamic_import("fix_plugin_github.resources.GithubResource"), *dynamic_import("fix_plugin_k8s.resources.KubernetesResource"), *dynamic_import("fix_plugin_onelogin.OneLoginResource"), - *dynamic_import("fix_plugin_onprem.resources.OnpremResource"), *dynamic_import("fix_plugin_posthog.resources.PosthogResource"), *dynamic_import("fix_plugin_random.resources.RandomResource"), *dynamic_import("fix_plugin_scarf.resources.ScarfResource"), *dynamic_import("fix_plugin_slack.resources.SlackResource"), - *dynamic_import("fix_plugin_vsphere.resources.VSphereResource"), *base, } From 8ef4a5188c906375e07846f6841dc7724bfe5bf2 Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Fri, 18 Oct 2024 12:28:11 +0200 Subject: [PATCH 3/3] fix: remove trace to version --- plugins/aws/fix_plugin_aws/resource/bedrock.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/aws/fix_plugin_aws/resource/bedrock.py b/plugins/aws/fix_plugin_aws/resource/bedrock.py index febf5f9444..e2003749f2 100644 --- a/plugins/aws/fix_plugin_aws/resource/bedrock.py +++ b/plugins/aws/fix_plugin_aws/resource/bedrock.py @@ -929,7 +929,6 @@ class AwsBedrockAgent(BedrockTaggable, AwsResource): "default": [ AwsBedrockGuardrail.kind, AwsKmsKey.kind, - "aws_bedrock_agent_version", "aws_bedrock_agent_knowledge_base", ] },