Skip to content

Commit

Permalink
All AuthProviders must implement a non silent check. (#936)
Browse files Browse the repository at this point in the history
## Changes
* Moving forward, we want to avoid having silent checks to make
reasoning about auth easier. This PR makes it so that all AuthProviders
must implement the `check` method.
* Each check method must handle it's own Retry Loop, error handling and
display. Since now checks are always interactive, we do not want calling
code to manage the interactions.

## Tests
* manual
  • Loading branch information
kartikgupta-db authored Nov 11, 2023
1 parent a2c3df0 commit 237e629
Show file tree
Hide file tree
Showing 33 changed files with 7,232 additions and 84 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish nightly release

on:
push:
branches: [main]
branches: [main, bundle-integ]
workflow_dispatch:

jobs:
Expand All @@ -24,8 +24,8 @@ jobs:
- name: Update nightly release
uses: softprops/action-gh-release@v1
with:
name: Nightly
name: Nightly - ${{ github.ref_name }}
prerelease: true
tag_name: nightly
tag_name: nightly-${{ github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
files: "packages/databricks-vscode/databricks*/*.vsix"
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: VSCode Extensions CI

on:
push:
branches: [main]
branches: [main, bundle-integ]
pull_request:
branches: [main]
branches: [main, bundle-integ]

jobs:
run-tests:
Expand Down
6 changes: 6 additions & 0 deletions packages/databricks-vscode/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": ["eslint-plugin-local-rules"],
"rules": {
"local-rules/mutex-synchronised-decorator": "error"
}
}
12 changes: 12 additions & 0 deletions packages/databricks-vscode/eslint-local-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
require("ts-node").register({
transpileOnly: true,
compilerOptions: {
module: "commonjs",
},
});

module.exports = {
"mutex-synchronised-decorator":
require("./rules/mutexSynchronisedDecorator").default,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable no-console */
import {ESLintUtils, AST_NODE_TYPES} from "@typescript-eslint/utils";

const rule = ESLintUtils.RuleCreator.withoutDocs({
create(context) {
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
Decorator(node) {
if (
node.expression.type === "CallExpression" &&
node.expression.callee.type ===
AST_NODE_TYPES.MemberExpression &&
node.expression.callee.object.type ===
AST_NODE_TYPES.Identifier &&
node.expression.callee.object.name === "Mutex" &&
node.expression.callee.property.type ===
AST_NODE_TYPES.Identifier &&
node.expression.callee.property.name === "synchronise" &&
node.expression.arguments.length > 0
) {
const mutexName =
node.expression.arguments[0].type ===
AST_NODE_TYPES.Literal
? (node.expression.arguments[0].value as string)
: "";

if (node.parent.parent?.type !== AST_NODE_TYPES.ClassBody) {
return context.report({
node,
messageId: "decoratorNotInClass",
});
}

const exists = node.parent.parent.body.some((element) => {
return (
element.type ===
AST_NODE_TYPES.PropertyDefinition &&
element.key.type === AST_NODE_TYPES.Identifier &&
element.key.name === mutexName
);
});

const className =
node.parent.parent.parent?.type ===
AST_NODE_TYPES.ClassDeclaration
? node.parent.parent.parent.id?.name
: undefined;

if (!exists) {
return context.report({
node,
messageId: "synchronisedMutexNotInClass",
data: {
mutexName,
className,
},
});
}
}
},
};
},
meta: {
type: "problem",
schema: [],
messages: {
decoratorNotInClass:
"Mutex.synchronized() should be used inside a class",
synchronisedMutexNotInClass:
'Mutex "{{mutexName}}" is not defined in class "{{className}}".',
},
},
defaultOptions: [],
});

export default rule;
6 changes: 6 additions & 0 deletions packages/databricks-vscode/eslint-local-rules/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"transpileOnly": true,
"compilerOptions": {
"module": "Node16"
}
}
10 changes: 8 additions & 2 deletions packages/databricks-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@
"package:cli:link": "rm -f ./bin/databricks && mkdir -p bin && ln -s ../../../../cli/cli bin/databricks",
"package:wrappers:write": "ts-node ./scripts/writeIpynbWrapper.ts -s ./resources/python/notebook.workflow-wrapper.py -o ./resources/python/generated/notebook.workflow-wrapper.json",
"package:jupyter-init-script:write": "ts-node ./scripts/writeJupyterInitFileWithVersion.ts",
"package:bundle-schema:write": "yarn package:cli:fetch && ts-node ./scripts/writeBundleSchema.ts ./bin/databricks ./src/bundle/BundleSchema.d.ts",
"package:compile": "yarn run esbuild:base",
"package:copy-webview-toolkit": "cp ./node_modules/@vscode/webview-ui-toolkit/dist/toolkit.js ./out/toolkit.js",
"esbuild:base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node --sourcemap --target=es2019",
Expand All @@ -687,6 +688,7 @@
"dependencies": {
"@databricks/databricks-sdk": "file:../../vendor/databricks-sdk.tgz",
"@databricks/databricks-vscode-types": "workspace:^",
"@types/lodash": "^4.14.199",
"@vscode/debugadapter": "^1.61.0",
"@vscode/extension-telemetry": "^0.9.0",
"@vscode/webview-ui-toolkit": "^1.2.2",
Expand All @@ -702,8 +704,9 @@
"@sinonjs/fake-timers": "^11.2.2",
"@types/bcryptjs": "^2.4.2",
"@types/chai": "^4.3.5",
"@types/eslint": "^8.44.6",
"@types/fs-extra": "^11.0.1",
"@types/mocha": "^10.0.1",
"@types/mocha": "^10.0.2",
"@types/mock-require": "^2.0.1",
"@types/node": "^20.4.2",
"@types/sinonjs__fake-timers": "^8.1.2",
Expand All @@ -713,6 +716,7 @@
"@types/yargs": "^17.0.24",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@typescript-eslint/utils": "^6.9.0",
"@vscode/test-electron": "^2.3.3",
"@wdio/cli": "^8.12.2",
"@wdio/local-runner": "^8.12.1",
Expand All @@ -722,8 +726,10 @@
"chai": "^4.3.7",
"esbuild": "^0.19.4",
"eslint": "^8.51.0",
"eslint-plugin-local-rules": "^2.0.0",
"fs-extra": "^11.1.1",
"glob": "^10.3.3",
"glob": "^10.3.10",
"json-schema-to-typescript": "^13.1.1",
"mocha": "^10.2.0",
"mock-require": "^3.0.3",
"nyc": "^15.1.0",
Expand Down
25 changes: 25 additions & 0 deletions packages/databricks-vscode/scripts/writeBundleSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* This script generates the BundleSchema.d.ts file from the bundle schema.
* It MUST be run after a yarn package:cli:fetch
*/

import * as cp from "child_process";
import * as fs from "fs";
import {compileFromFile} from "json-schema-to-typescript";
import {tmpdir} from "os";
import path from "path";
import {argv} from "process";

const output = cp.execFileSync(argv[2], ["bundle", "schema"]);

const tmpFile = path.join(tmpdir(), "BundleSchema.json");
fs.writeFileSync(tmpFile, output);

// eslint-disable-next-line no-console
console.log("Bundle schema written to", tmpFile);

// compile from file
compileFromFile(tmpFile).then((ts) => fs.writeFileSync(argv[3], ts));

// eslint-disable-next-line no-console
console.log("BundleSchema.d.ts written to", argv[3]);
Loading

0 comments on commit 237e629

Please sign in to comment.