Skip to content

Commit

Permalink
add typescript code
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Shchederkin committed Dec 13, 2024
1 parent fda3baa commit 0afe3a5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 26 deletions.
5 changes: 5 additions & 0 deletions aws-lambda/src/databricks_cdk/resources/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
delete_storage_credential,
)
from databricks_cdk.resources.unity_catalog.volumes import VolumeProperties, create_or_update_volume, delete_volume
from databricks_cdk.resources.service_principals.service_principal import create_or_update_service_principal, delete_service_principal, ServicePrincipalProperties
from databricks_cdk.utils import CnfResponse

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -221,6 +222,8 @@ def create_or_update_resource(event: DatabricksEvent) -> CnfResponse:
)
elif action == "volume":
return create_or_update_volume(VolumeProperties(**event.ResourceProperties), event.PhysicalResourceId)
elif action == "service-principal":
return create_or_update_service_principal(ServicePrincipalProperties(**event.ResourceProperties))
else:
raise RuntimeError(f"Unknown action: {action}")

Expand Down Expand Up @@ -325,6 +328,8 @@ def delete_resource(event: DatabricksEvent) -> CnfResponse:
)
elif action == "volume":
return delete_volume(VolumeProperties(**event.ResourceProperties), event.PhysicalResourceId)
elif action == "service-principal":
return delete_service_principal(ServicePrincipalProperties(**event.ResourceProperties).service_principal.id, event.PhysicalResourceId)
else:
raise RuntimeError(f"Unknown action: {action}")

Expand Down
60 changes: 34 additions & 26 deletions typescript/src/resources/deploy-lambda.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {Duration} from "aws-cdk-lib";
import {aws_lambda, aws_logs, aws_iam} from "aws-cdk-lib";
import {AccountCredentials, AccountCredentialsProperties} from "./account/accountCredentials";
import {AccountStorageConfig, AccountStorageConfigProperties} from "./account/account-storage-config";
import {AccountNetwork, AccountNetworkProperties} from "./account/accountNetwork";
import {Workspace, WorkspaceProperties} from "./account/workspace";
import {InstanceProfile, InstanceProfileProperties} from "./instance-profiles/instance-profile";
import {Cluster, ClusterProperties} from "./clusters/cluster";
import {ClusterPermissions, ClusterPermissionsProperties} from "./permissions/cluster-permissions";
import {VolumePermissions, VolumePermissionsProperties} from "./permissions/volumePermissions";
import {DbfsFile, DbfsFileProperties} from "./dbfs/dbfs-file";
import {SecretScope, SecretScopeProperties} from "./secrets/secret-scope";
import {Job, JobProperties} from "./jobs/job";
import {Group, GroupProperties} from "./groups/group";
import {ScimUser, ScimUserProperties} from "./scim/scimUser";
import {InstancePool, InstancePoolProperties} from "./instance-pools/instance-pools";
import {Warehouse, WarehouseProperties} from "./sql-warehouses/sql-warehouses";
import {WarehousePermissions, WarehousePermissionsProperties} from "./permissions/sql-warehouse-permissions";
import {Construct} from "constructs";
import {DockerImage} from "../docker-image";
import { Duration } from "aws-cdk-lib";
import { aws_lambda, aws_logs, aws_iam } from "aws-cdk-lib";
import { AccountCredentials, AccountCredentialsProperties } from "./account/accountCredentials";
import { AccountStorageConfig, AccountStorageConfigProperties } from "./account/account-storage-config";
import { AccountNetwork, AccountNetworkProperties } from "./account/accountNetwork";
import { Workspace, WorkspaceProperties } from "./account/workspace";
import { InstanceProfile, InstanceProfileProperties } from "./instance-profiles/instance-profile";
import { Cluster, ClusterProperties } from "./clusters/cluster";
import { ClusterPermissions, ClusterPermissionsProperties } from "./permissions/cluster-permissions";
import { VolumePermissions, VolumePermissionsProperties } from "./permissions/volumePermissions";
import { DbfsFile, DbfsFileProperties } from "./dbfs/dbfs-file";
import { SecretScope, SecretScopeProperties } from "./secrets/secret-scope";
import { Job, JobProperties } from "./jobs/job";
import { Group, GroupProperties } from "./groups/group";
import { ScimUser, ScimUserProperties } from "./scim/scimUser";
import { InstancePool, InstancePoolProperties } from "./instance-pools/instance-pools";
import { Warehouse, WarehouseProperties } from "./sql-warehouses/sql-warehouses";
import { WarehousePermissions, WarehousePermissionsProperties } from "./permissions/sql-warehouse-permissions";
import { Construct } from "constructs";
import { DockerImage } from "../docker-image";
import {
UnityCatalogVolume, UnityCatalogVolumeProperties,
UnityCatalogCatalog,
Expand All @@ -31,12 +31,13 @@ import {
UnityCatalogSchema,
UnityCatalogSchemaProperties, UnityCatalogStorageCredential, UnityCatalogStorageCredentialProperties
} from "./unity-catalog";
import {JobPermissions, JobPermissionsProperties, RegisteredModelPermissions, RegisteredModelPermissionsProperties, ExperimentPermissions, ExperimentPermissionsProperties} from "./permissions";
import {ClusterPolicy, ClusterPolicyProperties} from "./cluster-policies";
import {ClusterPolicyPermissions, ClusterPolicyPermissionsProperties} from "./permissions/cluster-policy-permissions";
import {Token, TokenProperties} from "./tokens";
import {Experiment, ExperimentProperties} from "./mlflow";
import {RegisteredModel, RegisteredModelProps} from "./mlflow/registeredModel";
import { JobPermissions, JobPermissionsProperties, RegisteredModelPermissions, RegisteredModelPermissionsProperties, ExperimentPermissions, ExperimentPermissionsProperties } from "./permissions";
import { ClusterPolicy, ClusterPolicyProperties } from "./cluster-policies";
import { ClusterPolicyPermissions, ClusterPolicyPermissionsProperties } from "./permissions/cluster-policy-permissions";
import { Token, TokenProperties } from "./tokens";
import { Experiment, ExperimentProperties } from "./mlflow";
import { RegisteredModel, RegisteredModelProps } from "./mlflow/registeredModel";
import { ServicePrincipal, ServicePrincipalProps } from "./service-principals";


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

public createServicePrincipal(scope: Construct, id: string, props: ServicePrincipalProps): ServicePrincipal {
return new ServicePrincipal(scope, id, {
...props,
serviceToken: this.serviceToken
});
}

}

export class DatabricksDeployLambdaImport extends IDatabricksDeployLambda {
Expand Down
1 change: 1 addition & 0 deletions typescript/src/resources/service-principals/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./servicePrincipal";
40 changes: 40 additions & 0 deletions typescript/src/resources/service-principals/servicePrincipal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { CustomResource } from "aws-cdk-lib";
import { Construct } from "constructs";

export interface ComplexValue {
value?: string,
}


export interface ServicePrincipalSettings {
active?: boolean
application_id?: string
display_name?: string
entitlements?: ComplexValue[]
external_id?: string
groups?: ComplexValue[]
id?: string
roles?: ComplexValue[]
}

export interface ServicePrincipalProperties {
workspace_url: string
service_principal: ServicePrincipalSettings
}

export interface ServicePrincipalProps extends ServicePrincipalProperties {
readonly serviceToken: string
}

export class ServicePrincipal extends CustomResource {
constructor(scope: Construct, id: string, props: ServicePrincipalProps) {
super(scope, id, {
serviceToken: props.serviceToken,
properties: {
action: "service-principal",
workspace_url: props.workspace_url,
service_principal: props.service_principal,
}
});
}
}

0 comments on commit 0afe3a5

Please sign in to comment.