Skip to content

Commit

Permalink
added files
Browse files Browse the repository at this point in the history
  • Loading branch information
gaokevin1 committed Nov 13, 2024
1 parent 3bebbd6 commit dd836a7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
54 changes: 38 additions & 16 deletions lib/descope-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,44 @@ export class DescopeAuth extends Construct implements sbt.IAuth {
index: "index.py",
handler: "handler",
timeout: Duration.seconds(60),
layers: [descopeHelperLayer],
layers: lambdaFunctionsLayers,
environment: environmentVariables,
}
);
clientSecretSSMMgmtKey.grantRead(this.createMachineClientFunction);

// Define the custom resource provider
const provider = new Provider(this, "Provider", {
onEventHandler: this.createMachineClientFunction,
});

// Create the custom resource
const customResource = new CustomResource(
// // Define the custom resource provider
// const provider = new Provider(this, "Provider", {
// onEventHandler: this.createMachineClientFunction,
// });

// // Create the custom resource
// const customResource = new CustomResource(
// this,
// "machineClientCustomResource",
// {
// serviceToken: provider.serviceToken,
// properties: {
// name: "SBT Access Key",
// description: "Auto-generated Access Key for SBT",
// },
// }
// );

const machineClientResource = this.createMachineClient(
this,
"machineClientCustomResource",
"MachineClient",
{
serviceToken: provider.serviceToken,
properties: {
name: "SBT Access Key",
description: "Auto-generated Access Key for SBT",
},
name: "SBT Access Key",
description: "Auto-generated Access Key for SBT",
}
);

this.machineClientId = customResource.getAttString("ClientId");
this.machineClientId = machineClientResource.getAttString("clientId");
new cdk.CfnOutput(this, "machineClientId", { value: this.machineClientId });

this.machineClientSecret = cdk.SecretValue.resourceAttribute(
customResource.getAttString("ClientSecret")
machineClientResource.getAttString("clientSecret")
);

// Ensure the domain is valid or fallback to a generated default domain
Expand Down Expand Up @@ -302,6 +311,19 @@ export class DescopeAuth extends Construct implements sbt.IAuth {
}
);
}
createMachineClient(
scope: Construct,
id: string,
props: CreateMachineClientProps
): cdk.CustomResource {
return new CustomResource(scope, `createClientCustomResource-${id}*`, {
serviceToken: this.createMachineClientFunction.functionArn,
properties: {
Name: props.name ? props.name : id,
...(props.description && { Description: props.description }),
},
});
}
createAdminUser(scope: Construct, id: string, props: CreateAdminUserProps) {
new CustomResource(scope, `createAdminUserCustomResource-v2-${id}`, {
serviceToken: this.createAdminUserFunction.functionArn,
Expand Down
8 changes: 4 additions & 4 deletions resources/functions/create-client/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Retrieve Descope project credentials from environment variables or configuration
project_id = os.environ.get("DescopeProjectId")
descope_mgmt_key = os.environ.get("ManagementSSMKeyName")
descope_mgmt_key_name = os.environ.get("ManagementSSMKeyName")


@helper.create
Expand All @@ -26,7 +26,7 @@ def create_client(event, _):
"""

# Initialize the Descope client
descope = get_descope_handler(project_id, descope_mgmt_key)
descope = get_descope_handler(project_id, descope_mgmt_key_name)
request = event.get("ResourceProperties", {})
name = request.get("name")
description = request.get("description")
Expand Down Expand Up @@ -57,8 +57,8 @@ def create_client(event, _):
# Return data to CloudFormation
helper.Data.update(
{
"ClientId": client_id,
"ClientSecret": client_secret, # Returning both client ID and secret
"clientId": client_id,
"clientSecret": client_secret, # Returning both client ID and secret
}
)
except Exception as e:
Expand Down

0 comments on commit dd836a7

Please sign in to comment.