Hadron / carthage-aws

AWS Plugin for Carthage
Other
2 stars 2 forks source link

AwsManaged and dict mobs #8

Closed srak289 closed 8 months ago

srak289 commented 2 years ago

Some objects in EC2 are not presented as Resources, so one must use the client API calls to present similar behavior to a mob. One of the recent examples is the Transit Gateway. I have found it necessary in these instances to override several methods from AwsManaged.

The format is like so:

name_of_thing = 'transit_gateway'

class Aws{name_of_thing_formatted}(AwsManaged): def docreate(): self.client.create{name_of_thing}() def find_fromname(): self.client.describe{name_of_thing}s() def doaction(): self.client.action{name_of_thing}()

I was initially thinking about something like getattr(client, f'action_{name_of_thing}').call(**kwargs) but I think there is a more elegant way to do this..with something like a factory pattern.

srak289 commented 2 years ago

After reviewing the code in connection.py and the find method I have concluded that some of my earlier issue is moot and I've switched over to using find.

find_from_name originally grew out of the difference between resources and client services but reviewing the code I see that I just have to get the resource_type right and edit the dictionary in connection.py

find_from_id is being overridden, I did not include that earlier.

The approach of looking up name from tags works as intended..perhaps find_from_name came from my own misunderstanding.

To the point; in the following set of methods we see there is a pattern.

create_rule create_listener create_load_balancer delete_rule delete_listener delete_load_balancer describe_rules describe_listeners describe_load_balancers modify_rule modify_listener modify_load_balancer

I hope to generate some of these methods (to include overriding find_from_id) given a resource_type in order to cut down on copy/paste code between classes that inherit from AwsManaged but are really just dicts and wrapped client calls at their core.

I intent to pursue this at least a bit on my own as it seems like a good opportunity.

hartmans commented 2 years ago

Okay, so perhaps something like AwsManagedNoResource (let's find a better name) that

hartmans commented 8 months ago

Is this still useful? I think we've had a number of objects that did not use the service_resource pattern, but appear to use AwsManaged without too much pain. Examples include transit gateways, nat gateways and route53 zones.

srak289 commented 8 months ago

I think this issue has aged beyond relevance.