Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor anonymization functions #2705

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/optic/src/client/optic-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,7 @@ export const createOpticClient = (opticToken: string) => {
);
return opticClient;
};

export const anonymizeUserToken = (token: string) =>
token.slice(4).split('.')[0];
export const anonymizeOrgToken = (token: string) => token.split('.')[0];
3 changes: 2 additions & 1 deletion projects/optic/src/commands/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getNewTokenUrl } from '../../utils/cloud-urls';
import { errorHandler } from '../../error-handler';
import { createOpticClient } from '../../client';
import { flushEvents, identify, alias, trackEvent } from '../../segment';
import { anonymizeOrgToken } from '../../client/optic-backend';
export const registerLogin = (cli: Command, config: OpticCliConfig) => {
cli
.command('login')
Expand All @@ -28,7 +29,7 @@ export async function identifyLoginFromToken(token: string) {
trackEvent('cli.login');
await flushEvents();
} else {
const id = token.split('.')[1];
const id = anonymizeOrgToken(token);
if (id) alias(id);
}
}
Expand Down
10 changes: 7 additions & 3 deletions projects/optic/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import { compute } from './diff/compute';
import { uploadDiff } from './diff/upload-diff';
import chalk from 'chalk';
import { flushEvents, trackEvent, identify } from '../segment';
import { createOpticClient } from '../client/optic-backend';
import {
anonymizeOrgToken,
anonymizeUserToken,
createOpticClient,
} from '../client/optic-backend';
import fs from 'fs';
import {
CommentApi,
Expand Down Expand Up @@ -210,8 +214,8 @@ async function authenticateInteractive(config: OpticCliConfig) {
config.authenticationType = 'user';
config.isAuthenticated = true;
config.userId = token.startsWith('opat')
? token.slice(4).split('.')[0]
: token.split('.')[0];
? anonymizeUserToken(token)
: anonymizeOrgToken(token);

trackEvent('cli.login');
await flushEvents();
Expand Down
5 changes: 3 additions & 2 deletions projects/optic/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { logger } from './logger';
import { Static, Type } from '@sinclair/typebox';
import Handlebars from 'handlebars';
import * as dotenv from 'dotenv';
import { anonymizeOrgToken, anonymizeUserToken } from './client/optic-backend';

export enum VCS {
Git = 'git',
Expand Down Expand Up @@ -314,8 +315,8 @@ export async function initializeConfig(): Promise<OpticCliConfig> {
: undefined;
cliConfig.isAuthenticated = true;
cliConfig.userId = token.startsWith('opat')
? token.slice(4).split('.')[0]
: token.split('.')[0];
? anonymizeUserToken(token)
: anonymizeOrgToken(token);
cliConfig.client = createOpticClient(token);
}

Expand Down