Skip to content
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

iamrole, internetgateway: use awsclient err wrapper #571

Merged
merged 1 commit into from
Mar 3, 2021

Conversation

chlunde
Copy link
Collaborator

@chlunde chlunde commented Mar 2, 2021

Using semgrep I found som additional places where awsclient.Wrap was not
used on an error from the AWS API.

docker run --rm -v "${PWD}:/src" returntocorp/semgrep --force-color -f ./err.yaml --lang=go ./pkg/controller/

err.yaml:

rules:
  - id: unclean-aws-err
    patterns:
	- pattern-either:
	    - patterns:
		- pattern: |
		    return managed.ExternalCreation{}, errors.Wrap(err, ...);

		- pattern-inside: |-
		    func ($T $TYPE) Create(...) {
			...
		    }
	      patterns:
		- pattern: |
		    return managed.ExternalUpdate{}, errors.Wrap(err, ...);

		- pattern-inside: |-
		    func ($T $TYPE) Update(...) {
			...
		    }
	      patterns:
		- pattern: |
		    return errors.Wrap(...);

		- pattern-inside: |-
		    func ($T $TYPE) Delete(...)  {
			...
		    }
	- pattern-not-inside: |
	    if err := $X.preCreate(...); err != nil {
	       ...
	    }

	- pattern-not-inside: |
	    if err := $X.preUpdate(...); err != nil {
	       ...
	    }

	- pattern-not-inside: |
	    if err := $X.preDelete(...); err != nil {
	       ...
	    }

	- pattern-not-inside: |
	    if err := e.kube.Status().Update(ctx, ...); err != nil {
		...
	    }

	- pattern-not-inside: |
	    if err := e.kube.Update(ctx, ...); err != nil {
		...
	    }

	- pattern-not: |
	    err = retry.OnError(..., func() error {
		...
	    })
	    if err != nil {
	       return ..., errors.Wrap(...)
	    }

	- pattern-not: |
	    return errors.Wrap(..., "pre-delete failed")

	- pattern-not: |
	    return ..., errors.Wrap(err, errPatchCreationFailed)

	- pattern-not: |
	    return ..., errors.Wrap(err, errCreatePatch)

    message: "errors.Wrap should be awsclient.Wrap with error from AWS API"
    languages: [go]
    severity: ERROR

Signed-off-by: Carl Henrik Lunde chlunde@ifi.uio.no

Description of your changes

Fixes #

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Using semgrep I found som additional places where awsclient.Wrap was not
used on an error from the AWS API.

    docker run --rm -v "${PWD}:/src" returntocorp/semgrep --force-color -f ./err.yaml --lang=go ./pkg/controller/

err.yaml:

	rules:
	  - id: unclean-aws-err
	    patterns:
		- pattern-either:
		    - patterns:
			- pattern: |
			    return managed.ExternalCreation{}, errors.Wrap(err, ...);

			- pattern-inside: |-
			    func ($T $TYPE) Create(...) {
				...
			    }
		      patterns:
			- pattern: |
			    return managed.ExternalUpdate{}, errors.Wrap(err, ...);

			- pattern-inside: |-
			    func ($T $TYPE) Update(...) {
				...
			    }
		      patterns:
			- pattern: |
			    return errors.Wrap(...);

			- pattern-inside: |-
			    func ($T $TYPE) Delete(...)  {
				...
			    }
		- pattern-not-inside: |
		    if err := $X.preCreate(...); err != nil {
		       ...
		    }

		- pattern-not-inside: |
		    if err := $X.preUpdate(...); err != nil {
		       ...
		    }

		- pattern-not-inside: |
		    if err := $X.preDelete(...); err != nil {
		       ...
		    }

		- pattern-not-inside: |
		    if err := e.kube.Status().Update(ctx, ...); err != nil {
			...
		    }

		- pattern-not-inside: |
		    if err := e.kube.Update(ctx, ...); err != nil {
			...
		    }

		- pattern-not: |
		    err = retry.OnError(..., func() error {
			...
		    })
		    if err != nil {
		       return ..., errors.Wrap(...)
		    }

		- pattern-not: |
		    return errors.Wrap(..., "pre-delete failed")

		- pattern-not: |
		    return ..., errors.Wrap(err, errPatchCreationFailed)

		- pattern-not: |
		    return ..., errors.Wrap(err, errCreatePatch)

	    message: "errors.Wrap should be awsclient.Wrap with error from AWS API"
	    languages: [go]
	    severity: ERROR

Signed-off-by: Carl Henrik Lunde <chlunde@ifi.uio.no>
Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muvaf this looks like one we should get in 👍

Copy link
Member

@muvaf muvaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chlunde !

@muvaf muvaf marked this pull request as ready for review March 3, 2021 08:03
@muvaf muvaf merged commit a9baa23 into crossplane-contrib:master Mar 3, 2021
@muvaf
Copy link
Member

muvaf commented Mar 3, 2021

It was in draft but I wanted to merge it before the release since it looks like a fairly contained and known change.

@chlunde chlunde deleted the awsclient-wrap branch March 3, 2021 08:04
namku pushed a commit to namku/provider-aws that referenced this pull request Mar 9, 2021
iamrole, internetgateway: use awsclient err wrapper
@chlunde chlunde mentioned this pull request Aug 20, 2021
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants