Skip to content

Commit 5cd9c68

Browse files
feat: apikeys - apikeysAccessList (#122)
Co-authored-by: TSowbaranika <[email protected]>
1 parent cbbc97e commit 5cd9c68

File tree

10 files changed

+680
-0
lines changed

10 files changed

+680
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2023 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import * as cdk from "aws-cdk-lib";
16+
import { Construct } from 'constructs';
17+
import { CfnAccessListApiKey} from 'awscdk-resources-mongodbatlas';
18+
19+
20+
21+
const app = new cdk.App();
22+
23+
interface AtlasStackProps {
24+
readonly orgId: string;
25+
readonly profile: string;
26+
readonly apiUserId: string;
27+
readonly ipAddress: string;
28+
}
29+
30+
export class CdkTestingStack extends cdk.Stack {
31+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
32+
super(scope, id, props);
33+
34+
const atlasProps = this.getContextProps();
35+
const accessLstApiKey = new CfnAccessListApiKey(this, 'accesslistApiKey', {
36+
profile: atlasProps.profile,
37+
orgId: atlasProps.orgId,
38+
apiUserId: atlasProps.apiUserId,
39+
ipAddress : atlasProps.ipAddress
40+
});
41+
}
42+
43+
getContextProps(): AtlasStackProps {
44+
const orgId = this.node.tryGetContext('orgId');
45+
if (!orgId){
46+
throw "No context value specified for projId. Please specify via the cdk context."
47+
}
48+
const profile = this.node.tryGetContext('profile') ?? 'default';
49+
const apiUserId = this.node.tryGetContext('apiUserId');
50+
const ipAddress = this.node.tryGetContext('ipAddress');
51+
return {
52+
orgId,
53+
profile,
54+
apiUserId,
55+
ipAddress
56+
}
57+
}
58+
}

examples/l1-resources/api-key.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import { Construct } from 'constructs';
3+
import { CfnApiKey,CfnApiKeyProps,ProjectAssignment,ListOptions} from 'awscdk-resources-mongodbatlas';
4+
5+
const app = new cdk.App();
6+
7+
interface AtlasStackProps {
8+
readonly orgId: string;
9+
readonly profile: string;
10+
readonly description: string;
11+
readonly awsSecretName: string;
12+
readonly projectId: string;
13+
}
14+
15+
const Roles = ["ORG_MEMBER","ORG_GROUP_CREATOR"]
16+
export class CdkTestingStack extends cdk.Stack {
17+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
18+
super(scope, id, props);
19+
20+
const atlasProps = this.getContextProps();
21+
new CfnApiKey(this, 'api-key', {
22+
profile: atlasProps.profile,
23+
orgId: atlasProps.orgId,
24+
description: atlasProps.description,
25+
awsSecretName: atlasProps.awsSecretName,
26+
proAssignments: [{
27+
projectId: atlasProps.projectId,
28+
"roles": [
29+
"GROUP_READ_ONLY"
30+
]
31+
}],
32+
roles: Roles
33+
});
34+
}
35+
36+
getContextProps(): AtlasStackProps {
37+
const projectId = this.node.tryGetContext('projId');
38+
if (!projectId){
39+
throw "No context value specified for projId. Please specify via the cdk context."
40+
}
41+
42+
const orgId = this.node.tryGetContext('orgId');
43+
if (!orgId){
44+
throw "No context value specified for projId. Please specify via the cdk context."
45+
}
46+
const profile = this.node.tryGetContext('profile') ?? 'default';
47+
const description = this.node.tryGetContext('description');
48+
const awsSecretName = this.node.tryGetContext('awsSecretName');
49+
return {
50+
orgId,
51+
profile,
52+
description,
53+
awsSecretName,
54+
projectId
55+
}
56+
}
57+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Generated by cdk-import
2+
import * as cdk from "aws-cdk-lib";
3+
import * as constructs from "constructs";
4+
5+
/**
6+
* Creates the access list entries for the specified organization API key.
7+
*
8+
* @schema CfnAccessListApiKeyProps
9+
*/
10+
export interface CfnAccessListApiKeyProps {
11+
/**
12+
* Unique 24-hexadecimal digit string that identifies the organization that contains your projects
13+
*
14+
* @schema CfnAccessListApiKeyProps#OrgId
15+
*/
16+
readonly orgId: string;
17+
18+
/**
19+
* Unique 24-hexadecimal digit string that identifies this organization API key for which you want to return access list entries.
20+
*
21+
* @schema CfnAccessListApiKeyProps#ApiUserId
22+
*/
23+
readonly apiUserId: string;
24+
25+
/**
26+
* Network address that issued the most recent request to the API.
27+
*
28+
* @schema CfnAccessListApiKeyProps#Profile
29+
*/
30+
readonly profile?: string;
31+
32+
/**
33+
* Range of network addresses that you want to add to the access list for the API key.
34+
*
35+
* @schema CfnAccessListApiKeyProps#CidrBlock
36+
*/
37+
readonly cidrBlock?: string;
38+
39+
/**
40+
* Network address that you want to add to the access list for the API key.
41+
*
42+
* @schema CfnAccessListApiKeyProps#IpAddress
43+
*/
44+
readonly ipAddress?: string;
45+
46+
/**
47+
* Number of documents returned in this response.
48+
*
49+
* @schema CfnAccessListApiKeyProps#TotalCount
50+
*/
51+
readonly totalCount?: number;
52+
}
53+
54+
/**
55+
* Converts an object of type 'CfnAccessListApiKeyProps' to JSON representation.
56+
*/
57+
/* eslint-disable max-len, quote-props */
58+
export function toJson_CfnAccessListApiKeyProps(
59+
obj: CfnAccessListApiKeyProps | undefined
60+
): Record<string, any> | undefined {
61+
if (obj === undefined) {
62+
return undefined;
63+
}
64+
const result = {
65+
OrgId: obj.orgId,
66+
APIUserId: obj.apiUserId,
67+
Profile: obj.profile,
68+
CidrBlock: obj.cidrBlock,
69+
IpAddress: obj.ipAddress,
70+
TotalCount: obj.totalCount,
71+
};
72+
// filter undefined values
73+
return Object.entries(result).reduce(
74+
(r, i) => (i[1] === undefined ? r : { ...r, [i[0]]: i[1] }),
75+
{}
76+
);
77+
}
78+
/* eslint-enable max-len, quote-props */
79+
80+
/**
81+
* A CloudFormation `MongoDB::Atlas::AccessListAPIKey`
82+
*
83+
* @cloudformationResource MongoDB::Atlas::AccessListAPIKey
84+
* @stability external
85+
*/
86+
export class CfnAccessListApiKey extends cdk.CfnResource {
87+
/**
88+
* The CloudFormation resource type name for this resource class.
89+
*/
90+
public static readonly CFN_RESOURCE_TYPE_NAME =
91+
"MongoDB::Atlas::AccessListAPIKey";
92+
93+
/**
94+
* Resource props.
95+
*/
96+
public readonly props: CfnAccessListApiKeyProps;
97+
98+
/**
99+
* Create a new `MongoDB::Atlas::AccessListAPIKey`.
100+
*
101+
* @param scope - scope in which this resource is defined
102+
* @param id - scoped id of the resource
103+
* @param props - resource properties
104+
*/
105+
constructor(
106+
scope: constructs.Construct,
107+
id: string,
108+
props: CfnAccessListApiKeyProps
109+
) {
110+
super(scope, id, {
111+
type: CfnAccessListApiKey.CFN_RESOURCE_TYPE_NAME,
112+
properties: toJson_CfnAccessListApiKeyProps(props)!,
113+
});
114+
115+
this.props = props;
116+
}
117+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import { CfnAccessListApiKey } from "./index";
3+
4+
const app = new cdk.App();
5+
const stack = new cdk.Stack(app, "access-list-api-key", {
6+
env: {
7+
region: process.env.CDK_DEFAULT_REGION,
8+
account: process.env.CDK_DEFAULT_ACCOUNT,
9+
},
10+
});
11+
12+
const orgId = "63350255419cf25e3d511c95";
13+
14+
new CfnAccessListApiKey(stack, "access-list-api-key", {
15+
orgId: orgId,
16+
apiUserId: "64ef512fab473831c9e73b58",
17+
profile: "default",
18+
ipAddress: "203.0.113.11",
19+
});

0 commit comments

Comments
 (0)