Skip to content

Commit

Permalink
chore: correcting the ConnectorLabel + refac + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Pawłaszek committed Oct 26, 2023
1 parent c1f17de commit bb50b0d
Show file tree
Hide file tree
Showing 13 changed files with 733 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/microsoftsharepointonline/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0
import { CfnConnectorProfile } from 'aws-cdk-lib/aws-appflow';
import { Construct } from 'constructs';
import { MicrosoftSharepointOnlineConnectorType } from './type';
import { MicrosoftSharepointOnlineTokenUrlBuilder } from './util';
import { ConnectorAuthenticationType } from '../core/connectors/connector-authentication-type';
import { ConnectorProfileBase, ConnectorProfileProps } from '../core/connectors/connector-profile';
import { OAuth2GrantType as OAuthGrantType } from '../core/connectors/oauth2-granttype';
Expand Down Expand Up @@ -38,7 +39,7 @@ export interface MicrosoftSharepointOnlineOAuthSettings {

readonly flow?: MicrosoftSharepointOnlineOAuthFlow;

readonly endpoints: MicrosoftSharepointOnlineOAuthEndpointsSettings;
readonly endpoints?: MicrosoftSharepointOnlineOAuthEndpointsSettings;
}

export class MicrosoftSharepointOnlineConnectorProfile extends ConnectorProfileBase {
Expand All @@ -51,6 +52,8 @@ export class MicrosoftSharepointOnlineConnectorProfile extends ConnectorProfileB
return this._fromConnectorProfileAttributes(scope, id, { name }) as MicrosoftSharepointOnlineConnectorProfile;
}

private static readonly defaultTokenEndpoint = MicrosoftSharepointOnlineTokenUrlBuilder.build();

constructor(scope: Construct, id: string, props: MicrosoftSharepointOnlineConnectorProfileProps) {
super(scope, id, props, MicrosoftSharepointOnlineConnectorType.instance);
}
Expand All @@ -66,7 +69,7 @@ export class MicrosoftSharepointOnlineConnectorProfile extends ConnectorProfileB
oAuth2GrantType: OAuthGrantType.AUTHORIZATION_CODE,
// INFO: even if we provide only the access token this property is required
// TODO: think about if this is correct. token can be IResolvable
tokenUrl: properties.oAuth.endpoints?.token,
tokenUrl: properties.oAuth.endpoints?.token ?? MicrosoftSharepointOnlineConnectorProfile.defaultTokenEndpoint,
},
},
};
Expand Down
18 changes: 16 additions & 2 deletions src/microsoftsharepointonline/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
import { Fn } from 'aws-cdk-lib';
import { CfnFlow } from 'aws-cdk-lib/aws-appflow';
import { IConstruct } from 'constructs';
import { MicrosoftSharepointOnlineConnectorProfile } from './profile';
Expand All @@ -10,13 +11,18 @@ import { ConnectorType } from '../core/connectors/connector-type';
import { IFlow } from '../core/flows';
import { ISource } from '../core/vertices';

export interface MicrosoftSharepointObject {
readonly site: string;
readonly drives: string[];
}

/**
* Properties of a Google Analytics v4 Source
*/
export interface MicrosoftSharepointOnlineSourceProps {
readonly profile: MicrosoftSharepointOnlineConnectorProfile;
readonly apiVersion: string;
readonly object: string;
readonly object: MicrosoftSharepointObject;
}

/**
Expand Down Expand Up @@ -44,9 +50,17 @@ export class MicrosoftSharepointOnlineSource implements ISource {
}

private buildSourceConnectorProperties(): CfnFlow.SourceConnectorPropertiesProperty {

if (this.props.object.drives.length < 1) {
throw new Error('At least one drive must be specified');
}

return {
customConnector: {
entityName: this.props.object,
entityName: this.props.object.site,
customProperties: {
subEntities: `["${Fn.join('","', this.props.object.drives)}"]`,
},
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/microsoftsharepointonline/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export class MicrosoftSharepointOnlineConnectorType extends ConnectorType {
private static actualInstance: ConnectorType;

constructor() {
super('MS_SharePoint_Connector', true);
super('MicrosoftSharePointOnline', true);
}
}
4 changes: 2 additions & 2 deletions src/microsoftsharepointonline/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
export class MicrosoftSharepointOnlineTokenUrlBuilder {
public static buildFromTenant(tenantId: string) {
return `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
public static build(tenantId?: string) {
return `https://login.microsoftonline.com/${tenantId ?? 'common'}/oauth2/v2.0/token`;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "32.0.0",
"files": {
"350185a1069fa20a23a583e20c77f6844218bd73097902362dc94f1a108f5d89": {
"source": {
"path": "asset.350185a1069fa20a23a583e20c77f6844218bd73097902362dc94f1a108f5d89",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "350185a1069fa20a23a583e20c77f6844218bd73097902362dc94f1a108f5d89.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"6b57b7d92e5a078619ebade6f916f2f97a85517dd96d351c12af4d3b69ccaa6c": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "6b57b7d92e5a078619ebade6f916f2f97a85517dd96d351c12af4d3b69ccaa6c.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Loading

0 comments on commit bb50b0d

Please sign in to comment.