Skip to content

Commit

Permalink
add typescript code for secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Shchederkin committed Dec 17, 2024
1 parent 29b95ec commit b0f2679
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
9 changes: 8 additions & 1 deletion typescript/src/resources/deploy-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { ClusterPolicyPermissions, ClusterPolicyPermissionsProperties } from "./
import { Token, TokenProperties } from "./tokens";
import { Experiment, ExperimentProperties } from "./mlflow";
import { RegisteredModel, RegisteredModelProps } from "./mlflow/registeredModel";
import { ServicePrincipal, ServicePrincipalProperties } from "./service-principals";
import { ServicePrincipal, ServicePrincipalProperties, ServicePrincipalSecrets, ServicePrincipalSecretsProperties } from "./service-principals";


export interface CustomDeployLambdaProps {
Expand Down Expand Up @@ -286,6 +286,13 @@ export abstract class IDatabricksDeployLambda extends Construct {
});
}

public createServicePrincipalSecrets(scope: Construct, id: string, props: ServicePrincipalSecretsProperties): ServicePrincipalSecrets {
return new ServicePrincipalSecrets(scope, id, {
...props,
serviceToken: this.serviceToken
});
}

}

export class DatabricksDeployLambdaImport extends IDatabricksDeployLambda {
Expand Down
1 change: 1 addition & 0 deletions typescript/src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export * from "./unity-catalog";
export * from "./tokens";
export * from "./mlflow";
export * from "./service-principals";
export * from "./service-principals/servicePrincipalSecrets";
3 changes: 2 additions & 1 deletion typescript/src/resources/service-principals/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./servicePrincipal";
export * from "./servicePrincipal";
export * from "./servicePrincipalSecrets";
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CustomResource } from "aws-cdk-lib";
import { Construct } from "constructs";


export interface ServicePrincipalSecretsProperties {
service_principal_id: number
}

export interface ServicePrincipalSecretsProps extends ServicePrincipalSecretsProperties {
readonly serviceToken: string
}

export class ServicePrincipalSecrets extends CustomResource {
constructor(scope: Construct, id: string, props: ServicePrincipalSecretsProps) {
super(scope, id, {
serviceToken: props.serviceToken,
properties: {
action: "service-principal-secrets",
service_principal_id: props.service_principal_id,
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Template } from "aws-cdk-lib/assertions";
import * as cdk from "aws-cdk-lib";
import { DatabricksDeployLambda, ServicePrincipalSecrets } from "../../../../typescript/src";


describe("ServicePrincipalSecrets", () => {
test("RegisteredModel Custom Resource synthesizes the way we expect", () => {
const app = new cdk.App();
const databricksStack = new cdk.Stack(app, "DatabricksStack");
const deployLambda = DatabricksDeployLambda.fromServiceToken(databricksStack, "DeployLambda", "some-arn");
new ServicePrincipalSecrets(databricksStack, "ServicePrincipalSecrets", {
service_principal_id: 1234,
serviceToken: deployLambda.serviceToken.toString(),
});

const template = Template.fromStack(databricksStack);

template.hasResourceProperties("AWS::CloudFormation::CustomResource",
{

"ServiceToken": "some-arn",
"action": "service-principal-secrets",
"service_principal_id": 1234,
});
});
});

0 comments on commit b0f2679

Please sign in to comment.