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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Using global private environment to save secrets[INS-4715] #8233

Merged
merged 46 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a41ffc0
1.add external vault context menu
cwangsmv Oct 31, 2024
29dca0c
1.Add cloud credential model
cwangsmv Nov 11, 2024
71dd8fa
1.fix main process integration issue
cwangsmv Nov 12, 2024
d46a3b1
1.adjust layout for upgrade notice
cwangsmv Nov 13, 2024
569fbfe
1.add logic to handle vault secret items(vault environment)
cwangsmv Nov 13, 2024
2eff222
1.add modal to confirm export private environment when user exports g…
cwangsmv Nov 14, 2024
6999e8e
1.fix aws secret manager tag
cwangsmv Nov 15, 2024
d787919
1.use hook to get plan detail
cwangsmv Nov 15, 2024
d842ab7
1.remove unnecessary style color
cwangsmv Nov 18, 2024
3d8aa9f
1.fix lint issue
cwangsmv Nov 18, 2024
03ffb1e
1.save work
cwangsmv Nov 21, 2024
fb8686e
1.ui changes
cwangsmv Nov 26, 2024
6de5edf
1.add logic to handle vault key reset and input request
cwangsmv Nov 27, 2024
eaa9363
1.add encrypt/decrypt and remove secret function
cwangsmv Nov 27, 2024
0a4321a
1.move removeAllSecrets function to modal
cwangsmv Nov 27, 2024
76cdfb9
1.basic integration with srp api
cwangsmv Dec 2, 2024
bcc7920
1.add new utils function
cwangsmv Dec 3, 2024
24805fa
1.add modal for secrets environment variable without vault key hint
cwangsmv Dec 3, 2024
8e0f691
1.integration with sse event of reset vault key
cwangsmv Dec 4, 2024
8e50c25
1.integrate with sse event change
cwangsmv Dec 5, 2024
897cd7d
1.fix some minor issues
cwangsmv Dec 5, 2024
7251d85
1.fix error handling
cwangsmv Dec 9, 2024
c45bd22
remove aws secret key related changes
cwangsmv Jan 6, 2025
3715425
1.remove aws related code
cwangsmv Jan 6, 2025
ebd8021
1.remove useless codes
cwangsmv Jan 6, 2025
da76f51
1.add enableVaultInScripts settings to allow using vault in script
cwangsmv Jan 7, 2025
19bdb8b
1.Add insomnia.vault to insomnia script
cwangsmv Jan 8, 2025
6120b0c
1.remove keytar and use electron safestorage instead
cwangsmv Jan 9, 2025
4ee5ab4
Do not allow set method in vault script
cwangsmv Jan 9, 2025
f1e7eaa
1.fix issue from comment
cwangsmv Jan 13, 2025
33f28cd
1.add support for legacy environment with vault as environment key
cwangsmv Jan 13, 2025
1d2a24b
1.fix issue
cwangsmv Jan 13, 2025
497f363
1.avoid duplicate rendering
cwangsmv Jan 13, 2025
c6543c5
1.fix naming
cwangsmv Jan 13, 2025
3fef1b2
1.fix issues from comment
cwangsmv Jan 15, 2025
2beeac9
1.avoid cache
cwangsmv Jan 24, 2025
f97e780
1.fix renaming issue
cwangsmv Feb 13, 2025
c0dfb77
1.fix issue
cwangsmv Feb 13, 2025
e860235
1.add smoke test and modify code to make it work
cwangsmv Jan 24, 2025
6c5918c
1.remove unnecessary changes
cwangsmv Feb 17, 2025
c7a521d
1.remove error
cwangsmv Feb 17, 2025
6ff25ed
1.remove useless codes
cwangsmv Feb 17, 2025
25eeada
1.fix hint issue
cwangsmv Feb 17, 2025
7f5fd8f
fix lint issue
cwangsmv Feb 17, 2025
4b89a00
fix smoke test failure
cwangsmv Feb 17, 2025
c05a95d
1.remove duplicate file due to rebase
cwangsmv Feb 17, 2025
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
35 changes: 35 additions & 0 deletions packages/insomnia-sdk/src/objects/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,38 @@ export class Variables {
return this.localVars.toObject();
};
}

export class Vault extends Environment {

constructor(name: string, jsonObject: object | undefined, enableVaultInScripts: boolean) {
super(name, jsonObject);
return new Proxy(this, {
// throw error on get or set method call if enableVaultInScripts is false
get: (target, prop, receiver) => {
if (!enableVaultInScripts) {
throw new Error('Vault is disabled in script');
}
return Reflect.get(target, prop, receiver);
},
set: (target, prop, value, receiver) => {
if (!enableVaultInScripts) {
throw new Error('Vault is disabled in script');
}
return Reflect.set(target, prop, value, receiver);
},
});
}

unset = () => {
throw new Error('Vault can not be unset in script');
};

clear = () => {
throw new Error('Vault can not be cleared in script');
};

set = () => {
throw new Error('Vault can not be set in script');
};

}
9 changes: 8 additions & 1 deletion packages/insomnia-sdk/src/objects/insomnia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { filterClientCertificates } from 'insomnia/src/network/certificate';
import { toPreRequestAuth } from './auth';
import { getExistingConsole } from './console';
import { CookieObject } from './cookies';
import { Environment, Variables } from './environments';
import { Environment, Variables, Vault } from './environments';
import { Execution } from './execution';
import { Folder, ParentFolders } from './folders';
import type { RequestContext } from './interfaces';
Expand All @@ -30,6 +30,7 @@ export class InsomniaObject {
public info: RequestInfo;
public response?: ScriptResponse;
public execution: Execution;
public vault?: Vault;

public clientCertificates: ClientCertificate[];
private _expect = expect;
Expand Down Expand Up @@ -60,6 +61,7 @@ export class InsomniaObject {
execution: Execution;
response?: ScriptResponse;
parentFolders: ParentFolders;
vault?: Vault;
},
) {
this.globals = rawObj.globals;
Expand All @@ -71,6 +73,7 @@ export class InsomniaObject {
this.cookies = rawObj.cookies;
this.response = rawObj.response;
this.execution = rawObj.execution;
this.vault = rawObj.vault;

this.info = rawObj.requestInfo;
this.request = rawObj.request;
Expand Down Expand Up @@ -156,6 +159,9 @@ export async function initInsomniaObject(
new Environment(rawObj.iterationData.name, rawObj.iterationData.data) : new Environment('iterationData', {});
const localVariables = rawObj.transientVariables ?
new Environment(rawObj.transientVariables.name, rawObj.transientVariables.data) : new Environment('transientVariables', {});
const enableVaultInScripts = rawObj.settings?.enableVaultInScripts || false;
const vault = rawObj.vault ?
new Vault('vault', rawObj.vault, enableVaultInScripts) : new Vault('vault', {}, enableVaultInScripts);
const cookies = new CookieObject(rawObj.cookieJar);
// TODO: update follows when post-request script and iterationData are introduced
const requestInfo = new RequestInfo({
Expand Down Expand Up @@ -255,6 +261,7 @@ export async function initInsomniaObject(
environment,
baseEnvironment,
iterationData,
vault,
variables,
request,
settings: rawObj.settings,
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia-sdk/src/objects/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface RequestContext {
timelinePath: string;
environment: IEnvironment;
baseEnvironment: IEnvironment;
vault?: IEnvironment;
collectionVariables?: object;
globals?: object;
iterationData?: Omit<IEnvironment, 'id'>;
Expand Down
271 changes: 271 additions & 0 deletions packages/insomnia-smoke-test/fixtures/vault-collection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
_type: export
__export_format: 4
__export_date: 2025-01-24T07:58:39.196Z
__export_source: insomnia.desktop.app:v10.3.1-beta.0
resources:
- _id: req_d6152608f4ca49aaadce1b379bf52fac
parentId: wrk_37e3ee9c2ce7468493378fa5e525b4b1
modified: 1737705511624
created: 1737705423707
url: localhost:4010/
name: normal
description: ""
method: GET
body:
mimeType: text/plain
text: |-
{{ _.vault.foo }}
{{ _.vault.hello }}
parameters: []
headers:
- name: Content-Type
value: text/plain
- name: User-Agent
value: insomnia/10.3.1-beta.0
authentication: {}
metaSortKey: -1737705423707
isPrivate: false
pathParameters: []
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: wrk_37e3ee9c2ce7468493378fa5e525b4b1
parentId: null
modified: 1737705410863
created: 1737705410863
name: Vault Collection
description: ""
scope: collection
_type: workspace
- _id: req_1c9ef3a2afae47d1bd960ae23de09750
parentId: wrk_37e3ee9c2ce7468493378fa5e525b4b1
modified: 1737617845875
created: 1734948333857
url: localhost:4010/
name: legacy-array-vault
description: ""
method: GET
body:
mimeType: text/plain
text: |-
{{ _.vault.secret }}
{{ _.vault[0] }}
parameters:
- id: pair_74f9877885a84128b4d5afc0dfc77945
name: ""
value: ""
description: ""
disabled: false
headers:
- name: Content-Type
value: text/plain
- name: User-Agent
value: insomnia/10.2.1-beta.1
authentication:
type: apikey
disabled: false
key: ""
value: ""
addTo: header
preRequestScript: |-
console.log('pre');
console.log(insomnia.variables.get('vault')[1]);
console.log(insomnia.vault.get('foo'));
metaSortKey: -1734948333857
isPrivate: false
pathParameters: []
afterResponseScript: |-
console.log('after');
console.log(insomnia.vault.get('hello'));
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: req_2a150b45acb242cfa2db04d929a11085
parentId: wrk_37e3ee9c2ce7468493378fa5e525b4b1
modified: 1737617920254
created: 1737617896390
url: localhost:4010/
name: legacy-invalid-vault
description: ""
method: GET
body:
mimeType: text/plain
text: ""
parameters:
- id: pair_74f9877885a84128b4d5afc0dfc77945
name: ""
value: ""
description: ""
disabled: false
headers:
- name: Content-Type
value: text/plain
- name: User-Agent
value: insomnia/10.2.1-beta.1
authentication:
type: apikey
disabled: false
key: ""
value: ""
addTo: header
metaSortKey: -1731983168815.5
isPrivate: false
pathParameters: []
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: req_fb7fb8d4345f471fb53d03b069737a07
parentId: wrk_37e3ee9c2ce7468493378fa5e525b4b1
modified: 1737617874271
created: 1737617856040
url: localhost:4010/
name: legacy-object-vault
description: ""
method: GET
body:
mimeType: text/plain
text: |-
{{ _.vault.secret }}
{{ _.vault.v1 }}
parameters:
- id: pair_74f9877885a84128b4d5afc0dfc77945
name: ""
value: ""
description: ""
disabled: false
headers:
- name: Content-Type
value: text/plain
- name: User-Agent
value: insomnia/10.2.1-beta.1
authentication:
type: apikey
disabled: false
key: ""
value: ""
addTo: header
preRequestScript: |-
console.log('pre');
console.log(insomnia.variables.get('vault').v2)
console.log(insomnia.vault.get('foo'));
metaSortKey: -1729018003774
isPrivate: false
pathParameters: []
afterResponseScript: |-
console.log('after');
console.log(insomnia.vault.get('hello'));
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: env_40681941450149a4a41f2dcbc22ec616
parentId: wrk_37e3ee9c2ce7468493378fa5e525b4b1
modified: 1737618683836
created: 1732861968102
name: Base Environment1
data:
a_hello: test
"": ""
dataPropertyOrder:
"&":
- a_hello
- ""
color: null
isPrivate: false
metaSortKey: 1732861968102
environmentType: kv
kvPairData:
- id: envPair_62a7e9c0cdb949e0abf15e0fe4b1e8d3
name: a_hello
value: test
type: str
enabled: true
- id: envPair_e479dfc1d364470eb3cd717e277953c9
name: ""
value: ""
type: str
enabled: true
_type: environment
- _id: jar_51eb1ce9f9e74e7684c8114098b1aa33
parentId: wrk_37e3ee9c2ce7468493378fa5e525b4b1
modified: 1737618683835
created: 1734948168939
name: Default Jar
cookies: []
_type: cookie_jar
- _id: env_7ace551350dc40cbbb8302234ec0af0a
parentId: env_40681941450149a4a41f2dcbc22ec616
modified: 1737618683836
created: 1736745679348
name: base with vault
data:
vault: hello
dataPropertyOrder:
"&":
- vault
color: null
isPrivate: false
metaSortKey: 1736745679348
environmentType: kv
kvPairData:
- id: envPair_4bcd80eeb9c544c8a5cca0a1a6a85ffc
name: vault
value: hello
type: str
enabled: true
_type: environment
- _id: env_fce7e052bb99440a9019a162afea7f85
parentId: env_40681941450149a4a41f2dcbc22ec616
modified: 1737617847199
created: 1736745692249
name: legacy vault value array
data:
vault:
- vault_array_a
- vault_array_b
- vault_array_c
dataPropertyOrder:
"&":
- vault
color: null
isPrivate: false
metaSortKey: 1736745679398
environmentType: json
kvPairData: []
_type: environment
- _id: env_9214888ae2dc497e87a7f8f8edaf19f2
parentId: env_40681941450149a4a41f2dcbc22ec616
modified: 1737617875350
created: 1737617352406
name: legacy vault value object
data:
vault:
v1: secv1
v2: secv2
dataPropertyOrder:
"&":
- vault
"&~|vault":
- v1
- v2
color: null
isPrivate: false
metaSortKey: 1736881902959
environmentType: json
kvPairData: []
_type: environment
Loading
Loading