Skip to content

Commit

Permalink
Merge pull request #73 from liprec/develop
Browse files Browse the repository at this point in the history
Release v.2.4.0 🚀
  • Loading branch information
liprec authored Sep 13, 2021
2 parents 26a83b3 + 4f964c5 commit ee9fb87
Show file tree
Hide file tree
Showing 56 changed files with 24,413 additions and 7,159 deletions.
2 changes: 2 additions & 0 deletions delete-adf-items/v2/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
node_modules
25 changes: 25 additions & 0 deletions delete-adf-items/v2/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended", "prettier"],
rules: {
"@typescript-eslint/consistent-type-assertions": [
"warn",
{
assertionStyle: "as",
objectLiteralTypeAssertions: "allow-as-parameter",
},
],
},
overrides: [
// Override some TypeScript rules just for .js files
{
files: ["*.js"],
rules: {
"@typescript-eslint/no-var-requires": "off", //
},
},
],
};
8 changes: 4 additions & 4 deletions delete-adf-items/v2/deleteadfitem.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Azure Pipelines Azure Datafactory Deploy Task
*
* Copyright (c) 2020 Jan Pieter Posthuma / DataScenarios
* Copyright (c) 2021 Jan Pieter Posthuma / DataScenarios
*
* All rights reserved.
*
Expand All @@ -28,8 +28,8 @@

"use strict";

import { strict as assert } from "assert";
// import { strict as assert } from "assert";

import * as ttm from "azure-pipelines-task-lib/mock-test";
// import * as ttm from "azure-pipelines-task-lib/mock-test";

describe("delete-adf-items tests", function () {});
// describe("delete-adf-items tests", function () {});
313 changes: 173 additions & 140 deletions delete-adf-items/v2/deleteadfitems.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion delete-adf-items/v2/lib/enums.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Azure Pipelines Azure Datafactory Deploy Task
*
* Copyright (c) 2020 Jan Pieter Posthuma / DataScenarios
* Copyright (c) 2021 Jan Pieter Posthuma / DataScenarios
*
* All rights reserved.
*
Expand Down
2 changes: 1 addition & 1 deletion delete-adf-items/v2/lib/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Azure Pipelines Azure Datafactory Deploy Task
*
* Copyright (c) 2020 Jan Pieter Posthuma / DataScenarios
* Copyright (c) 2021 Jan Pieter Posthuma / DataScenarios
*
* All rights reserved.
*
Expand Down
16 changes: 8 additions & 8 deletions delete-adf-items/v2/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Azure Pipelines Azure Datafactory Deploy Task
*
* Copyright (c) 2020 Jan Pieter Posthuma / DataScenarios
* Copyright (c) 2021 Jan Pieter Posthuma / DataScenarios
*
* All rights reserved.
*
Expand Down Expand Up @@ -29,7 +29,7 @@
"use strict";

import { DatafactoryTypes } from "./enums";
import { DatafactoryTaskObject } from "./interfaces";
import { ADFJson, DatafactoryTaskObject } from "./interfaces";

export function addSummary(
totalItems: number,
Expand All @@ -38,7 +38,7 @@ export function addSummary(
action: string,
size: number | undefined,
duration: number
) {
): void {
console.log(``);
if (issues > 0) console.log(`${issues} ${datafactoryType}(s) failed`);
console.log(`${totalItems - issues} ${datafactoryType}(s) ${action}.\n\nStats:`);
Expand All @@ -50,8 +50,8 @@ export function addSummary(
}

export function getReadableFileSize(fileSizeInBytes: number): string {
var i = 0;
var byteUnits = [" bytes", " kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"];
let i = 0;
const byteUnits = [" bytes", " kB", " MB", " GB", " TB", "PB", "EB", "ZB", "YB"];
while (fileSizeInBytes > 1024) {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
Expand Down Expand Up @@ -99,18 +99,18 @@ export function splitBuckets(detectDependency: boolean, items: DatafactoryTaskOb
return numberOfBuckets;
}

export function findDependency(json: any, type: string): string[] {
export function findDependency(json: ADFJson, type: string): string[] {
let refs: string[] = [];
if (json.referenceName && json.type === type) {
return [json.referenceName];
}
for (const key in json) {
if (typeof json[key] === typeof [Object]) refs = refs.concat(findDependency(json[key], type));
if (typeof json[key] === typeof [Object]) refs = refs.concat(findDependency(json[key] as ADFJson, type));
}
return refs.filter((current: string, index: number, array: string[]) => array.indexOf(current) === index);
}

export function wildcardFilter(value: string, rule: string) {
export function wildcardFilter(value: string, rule: string): boolean {
if (RegExp(/\*$|\w\*.*/g).test(rule)) return new RegExp("^" + rule.split("*").join(".*") + "$").test(value);
else return new RegExp(rule).test(value);
}
18 changes: 14 additions & 4 deletions delete-adf-items/v2/lib/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Azure Pipelines Azure Datafactory Deploy Task
*
* Copyright (c) 2020 Jan Pieter Posthuma / DataScenarios
* Copyright (c) 2021 Jan Pieter Posthuma / DataScenarios
*
* All rights reserved.
*
Expand All @@ -28,9 +28,7 @@

"use strict";

import * as msRestAzure from "ms-rest-azure";

import AzureServiceClient = msRestAzure.AzureServiceClient;
import { AzureServiceClient } from "@azure/ms-rest-azure-js";

import { SortingDirection, DatafactoryTypes } from "./enums";

Expand All @@ -56,3 +54,15 @@ export interface DatafactoryTaskObject {
dependency: string[];
bucket: number;
}

export type DeleteTask = {
filter: string;
type: DatafactoryTypes;
};

export type ADFJson = {
name: string;
referenceName: string;
type: string;
[keys: string]: ADFJson | boolean | number | string;
};
67 changes: 41 additions & 26 deletions delete-adf-items/v2/models/azureModels.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Azure Pipelines Azure Datafactory Delete Items Task
*
* Copyright (c) 2020 Jan Pieter Posthuma / DataScenarios
* Copyright (c) 2021 Jan Pieter Posthuma / DataScenarios
*
* All rights reserved.
*
Expand All @@ -26,9 +26,17 @@
* THE SOFTWARE.
*/

import * as task from "azure-pipelines-task-lib/task";
import {
getInput,
getEndpointDataParameter,
getEndpointAuthorizationParameter,
getEndpointUrl,
loc,
getEndpointAuthorizationScheme,
} from "azure-pipelines-task-lib";

export class AzureModels {
private authScheme?: string;
private connectedServiceName: string;
private subscriptionId: string;
private subscriptionName: string;
Expand All @@ -43,41 +51,48 @@ export class AzureModels {
this.connectedServiceName = connectedServiceName;
if (this.connectedServiceName === "local") {
// local debug
this.subscriptionId = <string>task.getInput("subscriptionid", true);
this.subscriptionName = <string>task.getInput("subscriptionname", true);
this.servicePrincipalClientId = <string>task.getInput("serviceprincipalid", true);
this.servicePrincipalKey = <string>task.getInput("serviceprincipalkey", true);
this.environmentAuthorityUrl = <string>task.getInput("environmentAuthorityUrl", true);
this.tenantId = <string>task.getInput("tenantid", true);
this.url = <string>task.getInput("connectedServiceNameUrl", true);
this.subscriptionId = getInput("subscriptionid", true) as string;
this.subscriptionName = getInput("subscriptionname", true) as string;
this.servicePrincipalClientId = getInput("serviceprincipalid", true) as string;
this.servicePrincipalKey = getInput("serviceprincipalkey", true) as string;
this.environmentAuthorityUrl = getInput("environmentAuthorityUrl", true) as string;
this.tenantId = getInput("tenantid", true) as string;
this.url = getInput("connectedServiceNameUrl", true) as string;
} else {
this.subscriptionId = task.getEndpointDataParameter(this.connectedServiceName, "subscriptionid", true);
this.subscriptionName = task.getEndpointDataParameter(
this.authScheme = getEndpointAuthorizationScheme(this.connectedServiceName, false);
this.subscriptionId = getEndpointDataParameter(this.connectedServiceName, "subscriptionid", true);
this.subscriptionName = getEndpointDataParameter(this.connectedServiceName, "subscriptionname", true);
this.servicePrincipalClientId = getEndpointAuthorizationParameter(
this.connectedServiceName,
"subscriptionname",
"serviceprincipalid",
true
);
this.servicePrincipalClientId = <string>(
task.getEndpointAuthorizationParameter(this.connectedServiceName, "serviceprincipalid", true)
);
this.servicePrincipalKey = <string>(
task.getEndpointAuthorizationParameter(this.connectedServiceName, "serviceprincipalkey", true)
);
this.environmentAuthorityUrl = task.getEndpointDataParameter(
) as string;
this.servicePrincipalKey = getEndpointAuthorizationParameter(
this.connectedServiceName,
"serviceprincipalkey",
true
) as string;
this.environmentAuthorityUrl = getEndpointDataParameter(
this.connectedServiceName,
"environmentAuthorityUrl",
true
);
this.tenantId = <string>(
task.getEndpointAuthorizationParameter(this.connectedServiceName, "tenantid", false)
);
this.url = task.getEndpointUrl(this.connectedServiceName, true);
this.tenantId = getEndpointAuthorizationParameter(
this.connectedServiceName,
"tenantid",
false
) as string;
this.url = getEndpointUrl(this.connectedServiceName, true);
}
} catch (err) {
throw new Error(task.loc("AzureModels_ConstructorFailed", err.message));
} catch (err: unknown) {
throw new Error(loc("AzureModels_ConstructorFailed", (err as Error).message));
}
}

public get AuthScheme(): string {
return this.authScheme || "ServicePrincipal";
}

public getSubscriptionId(): string {
return this.subscriptionId;
}
Expand Down
35 changes: 17 additions & 18 deletions delete-adf-items/v2/models/taskParameters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Azure Pipelines Azure Datafactory Delete Items Task
*
* Copyright (c) 2020 Jan Pieter Posthuma / DataScenarios
* Copyright (c) 2021 Jan Pieter Posthuma / DataScenarios
*
* All rights reserved.
*
Expand All @@ -26,8 +26,7 @@
* THE SOFTWARE.
*/

import * as task from "azure-pipelines-task-lib/task";
import { exit } from "process";
import { getBoolInput, getInput, loc } from "azure-pipelines-task-lib";

import { SortingDirection } from "../lib/enums";

Expand All @@ -49,27 +48,27 @@ export class TaskParameters {

constructor() {
try {
this.connectedServiceName = <string>task.getInput("ConnectedServiceName", true);
this.resourceGroupName = <string>task.getInput("ResourceGroupName", true);
this.datafactoryName = <string>task.getInput("DatafactoryName", true);
this.connectedServiceName = getInput("ConnectedServiceName", true) as string;
this.resourceGroupName = getInput("ResourceGroupName", true) as string;
this.datafactoryName = getInput("DatafactoryName", true) as string;

this.serviceFilter = task.getInput("ServiceFilter", false);
this.pipelineFilter = task.getInput("PipelineFilter", false);
this.dataflowFilter = task.getInput("DataflowFilter", false);
this.datasetFilter = task.getInput("DatasetFilter", false);
this.triggerFilter = task.getInput("TriggerFilter", false);
this.serviceFilter = getInput("ServiceFilter", false);
this.pipelineFilter = getInput("PipelineFilter", false);
this.dataflowFilter = getInput("DataflowFilter", false);
this.datasetFilter = getInput("DatasetFilter", false);
this.triggerFilter = getInput("TriggerFilter", false);

this.serviceFilter = this.serviceFilter === "" ? undefined : this.serviceFilter;
this.pipelineFilter = this.pipelineFilter === "" ? undefined : this.pipelineFilter;
this.dataflowFilter = this.dataflowFilter === "" ? undefined : this.dataflowFilter;
this.datasetFilter = this.datasetFilter === "" ? undefined : this.datasetFilter;
this.triggerFilter = this.triggerFilter === "" ? undefined : this.triggerFilter;

this.continue = task.getBoolInput("Continue", false);
this.throttle = Number.parseInt(<string>task.getInput("Throttle", false));
this.throttle = this.throttle === NaN ? 5 : this.throttle;
this.detectDependency = task.getBoolInput("detectDependency", false);
let sorting = <string>task.getInput("Sorting", true);
this.continue = getBoolInput("Continue", false) as boolean;
this.throttle = Number.parseInt(getInput("Throttle", false) as string);
this.throttle = isNaN(this.throttle) ? 5 : this.throttle;
this.detectDependency = getBoolInput("detectDependency", false);
const sorting = getInput("Sorting", true) as string;
switch (sorting.toLowerCase()) {
case "ascending":
this.sorting = SortingDirection.Ascending;
Expand All @@ -78,8 +77,8 @@ export class TaskParameters {
this.sorting = SortingDirection.Descending;
break;
}
} catch (err) {
throw new Error(task.loc("TaskParameters_ConstructorFailed", err.message));
} catch (err: unknown) {
throw new Error(loc("TaskParameters_ConstructorFailed", (err as Error).message));
}
}

Expand Down
Loading

0 comments on commit ee9fb87

Please sign in to comment.