Skip to content

Commit

Permalink
chore(iam): Refactor code structure of AWS IAM actors to align with o…
Browse files Browse the repository at this point in the history
…ther AWS services (#535)
  • Loading branch information
LaikaN57 authored Jan 7, 2025
1 parent 4145c48 commit 0fc50d5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 110 deletions.
3 changes: 1 addition & 2 deletions kingpin/actors/aws/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def default(self, obj):

# This executor is used by the tornado.concurrent.run_on_executor()
# decorator. We would like this to be a class variable so its shared
# across RightScale objects, but we see testing IO errors when we
# do this.
# across objects, but we see testing IO errors when we do this.
EXECUTOR = concurrent.futures.ThreadPoolExecutor(10)


Expand Down
16 changes: 8 additions & 8 deletions kingpin/actors/aws/iam/entities.py → kingpin/actors/aws/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Copyright 2018 Nextdoor.com, Inc

"""
:mod:`kingpin.actors.aws.iam.entities`
:mod:`kingpin.actors.aws.iam`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"""

Expand All @@ -27,7 +27,7 @@

from kingpin import utils
from kingpin.actors import exceptions
from kingpin.actors.aws.iam import base
from kingpin.actors.aws import base
from kingpin.constants import REQUIRED
from kingpin.constants import STATE

Expand All @@ -48,7 +48,7 @@
MAX_ITEMS = 1000


class EntityBaseActor(base.IAMBaseActor):
class IAMBaseActor(base.AWSBaseActor):
"""User/Group/Role Base Management Class
Managing Users, Groups and Roles in Amazon IAM is nearly identical. This
Expand All @@ -68,7 +68,7 @@ class abstracts that work, so that the actual User/Group/Role actors can be
}

def __init__(self, *args, **kwargs):
super(EntityBaseActor, self).__init__(*args, **kwargs)
super(IAMBaseActor, self).__init__(*args, **kwargs)

# These IAM Connection methods must be overridden in a subclass of this
# actor. Each of these is a "generalized" name for the method in Boto
Expand Down Expand Up @@ -505,7 +505,7 @@ def _remove_user_from_group(self, name, group):
)


class User(EntityBaseActor):
class User(IAMBaseActor):
"""Manages an IAM User.
This actor manages the state of an Amazon IAM User.
Expand Down Expand Up @@ -648,7 +648,7 @@ def _execute(self):
raise gen.Return()


class Group(EntityBaseActor):
class Group(IAMBaseActor):
"""Manages an IAM Group.
This actor manages the state of an Amazon IAM Group.
Expand Down Expand Up @@ -803,7 +803,7 @@ def _execute(self):
raise gen.Return()


class Role(EntityBaseActor):
class Role(IAMBaseActor):
"""Manages an IAM Role.
This actor manages the state of an Amazon IAM Role.
Expand Down Expand Up @@ -995,7 +995,7 @@ def _execute(self):
raise gen.Return()


class InstanceProfile(EntityBaseActor):
class InstanceProfile(IAMBaseActor):
"""Manages an IAM Instance Profile.
This actor manages the state of an Amazon IAM Instance Profile.
Expand Down
46 changes: 0 additions & 46 deletions kingpin/actors/aws/iam/__init__.py

This file was deleted.

39 changes: 0 additions & 39 deletions kingpin/actors/aws/iam/base.py

This file was deleted.

3 changes: 1 addition & 2 deletions kingpin/actors/aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

# This executor is used by the tornado.concurrent.run_on_executor()
# decorator. We would like this to be a class variable so its shared
# across RightScale objects, but we see testing IO errors when we
# do this.
# across objects, but we see testing IO errors when we do this.
EXECUTOR = concurrent.futures.ThreadPoolExecutor(10)


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from kingpin.actors import exceptions
from kingpin.actors.aws import settings
from kingpin.actors.aws.iam import entities
from kingpin.actors.aws import iam
import importlib

log = logging.getLogger(__name__)
Expand All @@ -21,17 +21,17 @@ def tornado_value(*args):
raise gen.Return(*args)


class TestEntityBaseActor(testing.AsyncTestCase):
class TestIAMBaseActor(testing.AsyncTestCase):
def setUp(self):
super(TestEntityBaseActor, self).setUp()
super(TestIAMBaseActor, self).setUp()
settings.AWS_ACCESS_KEY_ID = "unit-test"
settings.AWS_SECRET_ACCESS_KEY = "unit-test"
settings.AWS_SESSION_TOKEN = "unit-test"
importlib.reload(entities)
importlib.reload(iam)

# Create our actor object with some basics... then mock out the IAM
# connections..
self.actor = entities.EntityBaseActor(
self.actor = iam.IAMBaseActor(
"Unit Test",
{
"name": "test",
Expand Down Expand Up @@ -499,11 +499,11 @@ def setUp(self):
settings.AWS_ACCESS_KEY_ID = "unit-test"
settings.AWS_SECRET_ACCESS_KEY = "unit-test"
settings.AWS_SESSION_TOKEN = "unit-test"
importlib.reload(entities)
importlib.reload(iam)

# Create our actor object with some basics... then mock out the IAM
# connections..
self.actor = entities.User(
self.actor = iam.User(
"Unit Test",
{
"name": "test",
Expand Down Expand Up @@ -689,11 +689,11 @@ def setUp(self):
settings.AWS_ACCESS_KEY_ID = "unit-test"
settings.AWS_SECRET_ACCESS_KEY = "unit-test"
settings.AWS_SESSION_TOKEN = "unit-test"
importlib.reload(entities)
importlib.reload(iam)

# Create our actor object with some basics... then mock out the IAM
# connections..
self.actor = entities.Group(
self.actor = iam.Group(
"Unit Test",
{
"name": "test",
Expand Down Expand Up @@ -849,11 +849,11 @@ def setUp(self):
settings.AWS_ACCESS_KEY_ID = "unit-test"
settings.AWS_SECRET_ACCESS_KEY = "unit-test"
settings.AWS_SESSION_TOKEN = "unit-test"
importlib.reload(entities)
importlib.reload(iam)

# Create our actor object with some basics... then mock out the IAM
# connections..
self.actor = entities.Role(
self.actor = iam.Role(
"Unit Test",
{
"name": "test",
Expand Down Expand Up @@ -1060,11 +1060,11 @@ def setUp(self):
settings.AWS_ACCESS_KEY_ID = "unit-test"
settings.AWS_SECRET_ACCESS_KEY = "unit-test"
settings.AWS_SESSION_TOKEN = "unit-test"
importlib.reload(entities)
importlib.reload(iam)

# Create our actor object with some basics... then mock out the IAM
# connections..
self.actor = entities.InstanceProfile(
self.actor = iam.InstanceProfile(
"Unit Test", {"name": "test", "state": "present", "role": "test"}
)

Expand Down

0 comments on commit 0fc50d5

Please sign in to comment.