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

feat(appsync): add authenticationConfig to HttpDataSource, fixes #9934 #9971

Conversation

haruharuharuby
Copy link
Contributor

@haruharuharuby haruharuharuby commented Aug 25, 2020

Description

Adding authorization config to HttpDatasource in aws-appsync module.
Users will be able to specify the awsIamConfig in httpConfig as parameter of HttpDataSource.

Pull Request Checklist

  • Testing
    [x] Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
    [-] CLI change?: coordinate update of integration tests with team
    [-] cdk-init template change?: coordinated update of integration tests with team

  • Docs
    [-] jsdocs: All public APIs documented
    [-] README: README and/or documentation topic updated
    [-] Design: For significant features, design document added to design folder

  • Title and Description
    [x-] Change type: title prefixed with fix, feat and module name in parens, which will appear in changelog
    [x] Title: use lower-case and doesn't end with a period
    [-] Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    [x] Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"

  • Sensitive Modules (requires 2 PR approvers)
    [-] IAM Policy Document (in @aws-cdk/aws-iam)
    [-] EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    [-] Grant APIs (only if not based on official documentation with a reference)

Fixes: #9934


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Copy link
Contributor

@BryanPan342 BryanPan342 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution 🥳 This is a great first pass!

It would be great if you could write up a section in the README talking about HTTP data source. Similar to this section!

See this PR in review right now on RDS! Just to talk about the IamConfig :)

Comment on lines 209 to 233
export interface HttpDataSourceAuthorizationConfig {
/**
* The authorization type required by the HTTP endpoint
*/
readonly authorizationType: 'AWS_IAM';
/**
* The IAM configuration required by the HTTP endpoint
*/
readonly awsIamConfig: HttpDataSourceIamConfig;
}

/**
* The IAM configuration required by the HTTP endpoint
*/
export interface HttpDataSourceIamConfig {
/**
* The signing region for AWS IAM authorization
*/
readonly signingRegion: string;

/**
* The signing service name for AWS IAM authorization
*/
readonly signingServiceName: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If the authorization type is always going to AWS_IAM as seen by these docs, I think it might be best to just expose awsIamConfig and remove that additional level of abstraction!

Copy link
Contributor Author

@haruharuharuby haruharuharuby Aug 26, 2020

Choose a reason for hiding this comment

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

@BryanPan342 I have a question.

JSII does not allow nested objects directly. I got a linting error when I tried to implement like below.

Only string-indexed map types are supported

export interface AwsIamConfig {
  /**
   * The authorization type required by the HTTP endpoint
   */
  readonly authorizationType: 'AWS_IAM';
  /**
   * The IAM configuration required by the HTTP endpoint
   */
  readonly awsIamConfig: {
    /**
     * The signing region for AWS IAM authorization
     */
    readonly signingRegion: string;

    /**
     * The signing service name for AWS IAM authorization
     */
    readonly signingServiceName: string;
  }
}

Do you know the better way to integrate it?

I still code separately. But I tried to along with Cfn definition.
4500ce8

packages/@aws-cdk/aws-appsync/lib/data-source.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/data-source.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@BryanPan342 BryanPan342 left a comment

Choose a reason for hiding this comment

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

Im still not convinced that we need the nested interface of

export interface AwsIamConfig {
  authorizationType: 'AWS_IAM',
  awsIamConfig: {
    signingRegion: 'us-east-1',
    signingServiceName: 'states,
  }
}

why can't we just expose the signing configuration?

export interface AwsIamConfig {
    signingRegion: string,
    signingServiceName: string,

and have CDK add the authorization type upon construction?

packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts Outdated Show resolved Hide resolved
});
```

## Imports
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this might have been moved on merge by accident

Copy link
Contributor

Choose a reason for hiding this comment

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

should be on line 213

packages/@aws-cdk/aws-appsync/README.md Outdated Show resolved Hide resolved
@mergify mergify bot dismissed BryanPan342’s stale review August 28, 2020 02:57

Pull request has been modified.

Copy link
Contributor

@BryanPan342 BryanPan342 left a comment

Choose a reason for hiding this comment

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

Apologies I misread the unit test :( just a little nit picks and this LGTM 🥳

packages/@aws-cdk/aws-appsync/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/README.md Outdated Show resolved Hide resolved
});
```

## Imports
Copy link
Contributor

Choose a reason for hiding this comment

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

should be on line 213

packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts Outdated Show resolved Hide resolved
@BryanPan342
Copy link
Contributor

i believe the build is failing for this reason

error TS0: @aws-cdk/aws-appsync.GraphqlApiBase#addHttpDataSource changes type of argument options when implementing @aws-cdk/aws-appsync.IGraphqlApi (expected @aws-cdk/aws-appsync.DataSourceOptions, found @aws-cdk/aws-appsync.HttpDataSourceOptions

addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource;

this needs to be changed to HttpDataSourceOptions instead of DataSourceOptions

@haruharuharuby
Copy link
Contributor Author

@BryanPan342 I've just pushed the code that removing nested construction. Thank you for reviewing.
e6250b2

@haruharuharuby
Copy link
Contributor Author

@BryanPan342 I want to solve the CodeBuild error. Can you show me how to look for the Error in the CodeBuild log?

@BryanPan342
Copy link
Contributor

i believe the build is failing for this reason

error TS0: @aws-cdk/aws-appsync.GraphqlApiBase#addHttpDataSource changes type of argument options when implementing @aws-cdk/aws-appsync.IGraphqlApi (expected @aws-cdk/aws-appsync.DataSourceOptions, found @aws-cdk/aws-appsync.HttpDataSourceOptions

addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource;

this needs to be changed to HttpDataSourceOptions instead of DataSourceOptions

@haruharuharuby this is the error + fix

if you hit the build logs link in the AWS CodeBuild CI Report then you will get directed to the output

then Ctrl-F for the !!!!! or scroll all the way to the bottom of the log.

@haruharuharuby
Copy link
Contributor Author

#9934

Copy link
Contributor

@BryanPan342 BryanPan342 left a comment

Choose a reason for hiding this comment

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

@haruharuharuby
I had an idea on how we could clean up the if/else statement.. thoughts?

name: 'custom',
description: 'custom description',
authorizationConfig: {
authorizationType: 'AWS_IAM',
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this line necessary? the authorizationType is fixed to AWS_IAM no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, It true. AWS_IAM takes only a single value. I remove it.

/**
* The authorization type required by the HTTP endpoint
*/
readonly authorizationType: 'AWS_IAM';
Copy link
Contributor

Choose a reason for hiding this comment

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

is this field necessary if it's fixed?

could we just make the interface

export interface AwsIamConfig {
  readonly signingRegion: string;
  readonly signingServiceName: string;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the authorizationType removes from the caller. Building it Constructor in DataSource.

packages/@aws-cdk/aws-appsync/lib/data-source.ts Outdated Show resolved Hide resolved
@haruharuharuby
Copy link
Contributor Author

@BryanPan342 I've just passed CI process. (fixed some linting and Unit test)

@BryanPan342 BryanPan342 added the pr/do-not-merge This PR should not be merged at this time. label Aug 31, 2020
BryanPan342
BryanPan342 previously approved these changes Aug 31, 2020
Copy link
Contributor

@BryanPan342 BryanPan342 left a comment

Choose a reason for hiding this comment

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

Woooo LGTM 🎉

Thanks for the contribution this looks great!

I'll let @MrArnoldPalmer give his blessing before its shipped 😊

@haruharuharuby
Copy link
Contributor Author

@BryanPan342 Thank you for a lot of reviews. :)

MrArnoldPalmer
MrArnoldPalmer previously approved these changes Sep 2, 2020
@MrArnoldPalmer MrArnoldPalmer removed the pr/do-not-merge This PR should not be merged at this time. label Sep 2, 2020
@mergify
Copy link
Contributor

mergify bot commented Sep 2, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@BryanPan342
Copy link
Contributor

BryanPan342 commented Sep 2, 2020

@haruharuharuby I think you need to allow maintainers to edit your PR in order for Mergify to work

@haruharuharuby
Copy link
Contributor Author

haruharuharuby commented Sep 3, 2020

@BryanPan342 Sorry I made this PR from my org account. So suppose from this doc, I can't edit permission.
So I could not find that menu.

https://github.community/t/how-can-we-enable-allow-edits-from-maintainers-by-default/2847

is it necessary to remake PR on my regular account (haruharuharuby)

@mergify mergify bot dismissed stale reviews from BryanPan342 and MrArnoldPalmer September 3, 2020 07:07

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 7f608ba
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@BryanPan342
Copy link
Contributor

@BryanPan342 Sorry I made this PR from my org account. So suppose from this doc, I can't edit permission.
So I could not find that menu.

https://github.community/t/how-can-we-enable-allow-edits-from-maintainers-by-default/2847

is it necessary to remake PR on my regular account (haruharuharuby)

@haruharuharuby im guessing that's the right move? if you upload it with the same edits i can approve of it right away

@haruharuharuby
Copy link
Contributor Author

@BryanPan342 Thank you for following up. I made another PR by @haruharuharuby the same as this PR.
Please check it.

#10171

@haruharuharuby
Copy link
Contributor Author

haruharuharuby commented Sep 4, 2020

@haruharuharuby im guessing that's the right move? if you upload it with the same edits i can approve of it right away

Yes, I think the only way to mearging is to make another PR. looking over in this PR(coming from Org account), I could not find any way that displaying the "allow changes by maintainers".

@BryanPan342

@BryanPan342
Copy link
Contributor

Closing in favor of #10171

@BryanPan342 BryanPan342 closed this Sep 4, 2020
mergify bot pushed a commit that referenced this pull request Sep 8, 2020
This PR supersedes #9971 

### Description
Adding authorization config to HttpDatasource in aws-appsync module.
Users will be able to specify the awsIamConfig in httpConfig as parameter of HttpDataSource.

Fixes: #9934 

----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-appsync] Adding AuthorizationConfig within construction HttpDataSource of the appsync module.
4 participants