Skip to content

Commit

Permalink
kms.alias: filter the alias list with alias name
Browse files Browse the repository at this point in the history
Signed-off-by: Muvaffak Onus <me@muvaf.com>
(cherry picked from commit 4980bd5)
  • Loading branch information
muvaf authored and github-actions[bot] committed Nov 17, 2021
1 parent 041f076 commit 6410d9e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apis/kms/v1alpha1/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE(muvaf): This code ported from ACK-generated code. See details here:
// https://github.com/crossplane/provider-aws/pull/950#issue-1055573793

package v1alpha1

import (
Expand Down
2 changes: 1 addition & 1 deletion examples/kms/alias.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: kms.aws.crossplane.io/v1alpha1
kind: Alias
metadata:
name: dev-key
name: dev-alias
spec:
forProvider:
region: us-east-1
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/kms/alias/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE(muvaf): This code ported from ACK-generated code. See details here:
// https://github.com/crossplane/provider-aws/pull/950#issue-1055573793

package alias

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/kms/alias/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE(muvaf): This code ported from ACK-generated code. See details here:
// https://github.com/crossplane/provider-aws/pull/950#issue-1055573793

package alias

import (
Expand Down
13 changes: 13 additions & 0 deletions pkg/controller/kms/alias/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func SetupAlias(mgr ctrl.Manager, l logging.Logger, limiter workqueue.RateLimite
e.preCreate = preCreate
e.preUpdate = preUpdate
e.preDelete = preDelete
e.filterList = filterList
},
}
return ctrl.NewControllerManagedBy(mgr).
Expand All @@ -60,6 +61,18 @@ func SetupAlias(mgr ctrl.Manager, l logging.Logger, limiter workqueue.RateLimite
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}

func filterList(cr *svcapitypes.Alias, list *svcsdk.ListAliasesOutput) *svcsdk.ListAliasesOutput {
for i := range list.Aliases {
if awsclients.StringValue(list.Aliases[i].AliasName) == "alias/"+meta.GetExternalName(cr) {
return &svcsdk.ListAliasesOutput{
Aliases: []*svcsdk.AliasListEntry{
list.Aliases[i],
}}
}
}
return &svcsdk.ListAliasesOutput{}
}

func preObserve(_ context.Context, cr *svcapitypes.Alias, obj *svcsdk.ListAliasesInput) error {
obj.KeyId = cr.Spec.ForProvider.TargetKeyID
return nil
Expand Down

0 comments on commit 6410d9e

Please sign in to comment.