Skip to content

Commit

Permalink
Merge pull request #153 from JupiterOne/int-8452
Browse files Browse the repository at this point in the history
Update/clean dependencies; Remove Cognito Auth Flow
  • Loading branch information
zemberdotnet authored Oct 23, 2023
2 parents 67a317b + 923bd3f commit 73d57eb
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 3,477 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14.x]
node-version: [18.x]
os: [ubuntu-latest]

steps:
- id: setup-node
name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -35,16 +35,16 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [14]
node: [18]

steps:
- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x

- name: Check out repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 2

Expand Down
63 changes: 31 additions & 32 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
name: 'CodeQL'

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
branches: ['main']

jobs:
analyze:
name: Analyze
Expand All @@ -30,41 +30,40 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: security-extended,security-and-quality
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { JupiterOneClient } = require('@jupiterone/jupiterone-client-nodejs');
const j1Client = await new JupiterOneClient({
account: 'my-account-id',
accessToken: 'my-api-token',
apiBaseUrl: 'https://api.us.jupiterone.io' // Optional parameter
apiBaseUrl: 'https://api.us.jupiterone.io', // Optional parameter
}).init();
const integrationInstance = await j1Client.integrationInstances.get(
'my-integration-instance-id',
Expand Down Expand Up @@ -57,7 +57,9 @@ Options:
```

#### Relevant Environment Variables
J1_API_TOKEN - Sets the JupiterOne API access token as environment variable instead of passing it through -k parameter

J1_API_TOKEN - Sets the JupiterOne API access token as environment variable
instead of passing it through -k parameter

J1_DEV_ENABLED - Alters the base url. Valid values: 'true' | 'false' (string)

Expand Down
27 changes: 13 additions & 14 deletions examples/sync-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "es2018",
"lib": ["es2018", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"pretty": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"exclude": ["dist"]
}

"compilerOptions": {
"outDir": "dist",
"target": "es2018",
"lib": ["es2018", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"pretty": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"exclude": ["dist"]
}
26 changes: 18 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
const integrationConfig = require('@jupiterone/integration-sdk-dev-tools/config/jest');

module.exports = {
...integrationConfig,
preset: 'ts-jest',
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
globals: {
'ts-jest': {
isolatedModules: true,
},
clearMocks: true,
restoreMocks: true,
testMatch: [
'<rootDir>/**/*.test.ts',
'!**/node_modules/*',
'!**/dist/*',
'!**/*.bak/*',
],
collectCoverage: false,
transform: {
'^.+\\.[tj]sx?$': [
'ts-jest',
{
isolatedModules: true,
},
],
},
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
};
26 changes: 8 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupiterone/jupiterone-client-nodejs",
"version": "0.29.0",
"version": "1.0.0",
"description": "A node.js client wrapper for JupiterOne public API",
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,35 +39,25 @@
"audit:fix": "npm_config_yes=true npx yarn-audit-fix"
},
"dependencies": {
"@jupiterone/jupiterone-alert-rules": "^0.15.2",
"@lifeomic/attempt": "^3.0.0",
"amazon-cognito-identity-js-node": "^0.0.3",
"@jupiterone/jupiterone-alert-rules": "^0.20.0",
"@lifeomic/attempt": "^3.0.3",
"apollo-cache-inmemory": "^1.5.1",
"apollo-client": "^2.5.1",
"apollo-link": "^1.2.11",
"apollo-client": "^2.6.10",
"apollo-link": "^1.2.14",
"apollo-link-batch-http": "^1.2.13",
"apollo-link-retry": "^2.2.13",
"bunyan-category": "^0.4.0",
"chalk": "^4.1.2",
"commander": "^5.0.0",
"eslint-config-prettier": "^6.10.1",
"file-set": "^2.0.0",
"fs-extra": "^5.0.0",
"graphql": "^14.6.0",
"graphql-tag": "^2.10.1",
"inquirer": "^8.2.0",
"js-yaml": "^3.13.1",
"moment": "^2.22.2",
"mustache": "^2.3.0",
"node-fetch": "^2.6.0",
"p-all": "^2.1.0",
"p-map": "^1.2.0",
"pluralize": "^7.0.0",
"progress": "^2.0.3",
"strip-ansi": "^7.0.1",
"valid-url": "^1.0.9"
"node-fetch": "^2.6.7",
"p-all": "^2.1.0"
},
"devDependencies": {
"@jupiterone/integration-sdk-dev-tools": "^7.4.1",
"@pollyjs/adapter-node-http": "^2.7.0",
"@pollyjs/core": "^2.6.3",
"@types/bunyan": "^1.8.8",
Expand Down
5 changes: 4 additions & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
module.exports = require("@jupiterone/integration-sdk-dev-tools/config/prettier");
module.exports = {
proseWrap: 'always',
singleQuote: true,
};
3 changes: 0 additions & 3 deletions src/index.new.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ describe('Core Index Tests', () => {
});

describe('Ensure JupiterOneClient Has Correct Props', () => {
test('authenticateUser', () => {
expect(j1).toHaveProperty('authenticateUser');
});
test('queryV1', () => {
expect(j1).toHaveProperty('queryV1');
});
Expand Down
47 changes: 2 additions & 45 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Cognito from 'amazon-cognito-identity-js-node';

import { ApolloClient, ApolloError, QueryOptions } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
Expand Down Expand Up @@ -45,8 +43,6 @@ import {
} from './queries';
import { query, QueryTypes } from './util/query';

const J1_USER_POOL_ID_PROD = 'us-east-2_9fnMVHuxD';
const J1_CLIENT_ID_PROD = '1hcv141pqth5f49df7o28ngq1u';
const QUERY_RESULTS_TIMEOUT = 1000 * 60 * 5; // Poll s3 location for 5 minutes before timeout.
const J1QL_SKIP_COUNT = 250;
const J1QL_LIMIT_COUNT = 250;
Expand Down Expand Up @@ -182,10 +178,6 @@ export interface QueryResult {

export interface JupiterOneClientOptions {
account: string;
username?: string;
password?: string;
poolId?: string;
clientId?: string;
accessToken?: string;
dev?: boolean;
useRulesEndpoint?: boolean;
Expand Down Expand Up @@ -289,11 +281,7 @@ export class JupiterOneClient {
graphClient: ApolloClient<any>;

Check warning on line 281 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-latest)

Unexpected any. Specify a different type
headers?: Record<string, string>;
account: string;
username: string | undefined;
password: string | undefined;
poolId: string;
clientId: string;
accessToken: string | undefined;
accessToken: string;
useRulesEndpoint: boolean;
apiUrl: string;
queryEndpoint: string;
Expand All @@ -302,21 +290,13 @@ export class JupiterOneClient {

constructor({
account,
username,
password,
poolId = J1_USER_POOL_ID_PROD,
clientId = J1_CLIENT_ID_PROD,
accessToken,
dev = false,
useRulesEndpoint = false,
apiBaseUrl = undefined,
logger = undefined,
}: JupiterOneClientOptions) {
this.account = account;
this.username = username;
this.password = password;
this.poolId = poolId;
this.clientId = clientId;
this.accessToken = accessToken;
this.useRulesEndpoint = useRulesEndpoint;

Expand All @@ -336,9 +316,7 @@ export class JupiterOneClient {
}

async init(): Promise<JupiterOneClient> {
const token = this.accessToken
? this.accessToken
: await this.authenticateUser();
const token = this.accessToken;
this.headers = {
Authorization: `Bearer ${token}`,
'LifeOmic-Account': this.account,
Expand All @@ -362,27 +340,6 @@ export class JupiterOneClient {
return this;
}

async authenticateUser() {
const authenticationDetails = new Cognito.AuthenticationDetails({
Username: this.username,
Password: this.password,
});
const Pool = new Cognito.CognitoUserPool({
UserPoolId: this.poolId,
ClientId: this.clientId,
});
const User = new Cognito.CognitoUser({ Username: this.username, Pool });

const result: any = await new Promise((resolve, reject) => {
User.authenticateUser(authenticationDetails, {
onSuccess: (result: any) => resolve(result),
onFailure: (err: any) => reject(err),
});
});

return result.getAccessToken().getJwtToken();
}

async queryV1(
j1ql: string,
options: QueryOptions | Record<string, unknown> = {},
Expand Down
6 changes: 0 additions & 6 deletions src/j1cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { program } from 'commander';

const writeFile = util.promisify(fs.writeFile);

const J1_USER_POOL_ID = process.env.J1_USER_POOL_ID;
const J1_CLIENT_ID = process.env.J1_CLIENT_ID;
const J1_API_TOKEN = process.env.J1_API_TOKEN;
const J1_DEV_ENABLED = process.env.J1_DEV_ENABLED;
const EUSAGEERROR = 126;
Expand Down Expand Up @@ -234,10 +232,6 @@ async function initializeJ1Client() {
process.stdout.write('Authenticating with JupiterOne... ');
const j1Client = await new JupiterOneClient({
account: program.account,
username: program.user,
password: program.password,
poolId: J1_USER_POOL_ID,
clientId: J1_CLIENT_ID,
accessToken: program.key || J1_API_TOKEN,
dev: J1_DEV_ENABLED === 'true',
apiBaseUrl: program.apiBaseUrl,
Expand Down
Loading

0 comments on commit 73d57eb

Please sign in to comment.