-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into auto-updater
- Loading branch information
Showing
63 changed files
with
1,852 additions
and
415 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
docs/* @jfermi | ||
|
||
* @devcatalin @topliceanurazvan @mortada-codes @olensmar | ||
* @devcatalin @topliceanurazvan @olensmar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {app} from 'electron'; | ||
|
||
import {join} from 'path'; | ||
|
||
import {Authenticator, StorageHandlerAuth, createDefaultMonokleAuthenticator} from '@monokle/synchronizer'; | ||
|
||
let authenticator: Authenticator | undefined; | ||
|
||
const initAuthenticator = async (cloudStorageDir: string) => { | ||
const newAuthenticator = createDefaultMonokleAuthenticator(new StorageHandlerAuth(cloudStorageDir)); | ||
authenticator = newAuthenticator; | ||
return newAuthenticator; | ||
}; | ||
|
||
export const getAuthenticator = async () => { | ||
const userDataDir = app.getPath('userData'); | ||
const cloudStorageDir = join(userDataDir, 'cloud'); | ||
if (!authenticator) { | ||
await initAuthenticator(cloudStorageDir); | ||
} | ||
return authenticator; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {handleIpc} from '../../utils/ipc'; | ||
import {cloudLogin, cloudLogout} from './login'; | ||
import {getPolicy} from './policy'; | ||
import {getInfo} from './project'; | ||
import {getSerializedUser} from './user'; | ||
|
||
handleIpc('cloud:login', cloudLogin); | ||
handleIpc('cloud:logout', cloudLogout); | ||
handleIpc('cloud:getUser', getSerializedUser); | ||
handleIpc('cloud:getPolicy', getPolicy); | ||
handleIpc('cloud:getInfo', getInfo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {shell} from 'electron'; | ||
|
||
import {CloudLoginResponse} from '@shared/models/cloud'; | ||
|
||
import {getAuthenticator} from './authenticator'; | ||
import {serializeUser} from './user'; | ||
|
||
export const cloudLogin = async (): Promise<CloudLoginResponse> => { | ||
const authenticator = await getAuthenticator(); | ||
if (!authenticator) { | ||
throw new Error('Something went wrong with the authenticator'); | ||
} | ||
const loginResponse = await authenticator.login('device code'); | ||
if (!loginResponse.handle) { | ||
throw new Error('Something went wrong with the login response'); | ||
} | ||
shell.openExternal(loginResponse.handle.verification_uri_complete); | ||
const user = await loginResponse.onDone; | ||
if (!user) { | ||
throw new Error('Login to Cloud has failed. Please try again later.'); | ||
} | ||
return {user: serializeUser(user)}; | ||
}; | ||
|
||
export const cloudLogout = async (): Promise<void> => { | ||
const authenticator = await getAuthenticator(); | ||
await authenticator?.logout(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import log from 'loglevel'; | ||
|
||
import {getSynchronizer} from './synchronizer'; | ||
import {getUser} from './user'; | ||
|
||
export const getPolicy = async (repoPath: string) => { | ||
const synchronizer = await getSynchronizer(); | ||
const user = await getUser(); | ||
if (!user?.token || !synchronizer) { | ||
return null; | ||
} | ||
|
||
try { | ||
const policy = await synchronizer.getPolicy(repoPath, true, user.token); | ||
return policy; | ||
} catch (e: any) { | ||
if (e instanceof Error) { | ||
log.warn(e.message); | ||
} | ||
log.warn('Failed to synchronize policy'); | ||
} | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {CloudPolicyInfo, CloudProjectInfo} from '@shared/models/cloud'; | ||
|
||
import {getSynchronizer} from './synchronizer'; | ||
import {getUser} from './user'; | ||
|
||
export const getInfo = async ( | ||
repoPath: string | ||
): Promise<{projectInfo: CloudProjectInfo; policyInfo: CloudPolicyInfo} | null> => { | ||
const synchronizer = await getSynchronizer(); | ||
const user = await getUser(); | ||
if (!user?.token || !synchronizer) { | ||
return null; | ||
} | ||
|
||
try { | ||
const project = await synchronizer?.getProjectInfo(repoPath, user.token, true); | ||
return project | ||
? { | ||
projectInfo: {...project, link: synchronizer.generateDeepLinkProject(project.slug)}, | ||
policyInfo: {link: synchronizer.generateDeepLinkProjectPolicy(project.slug)}, | ||
} | ||
: null; | ||
} catch { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {app} from 'electron'; | ||
|
||
import {join} from 'path'; | ||
|
||
import {StorageHandlerPolicy, Synchronizer, createDefaultMonokleSynchronizer} from '@monokle/synchronizer'; | ||
|
||
let synchronizer: Synchronizer | undefined; | ||
|
||
const initSynchronizer = async (cloudStorageDir: string) => { | ||
const newSynchronizer = createDefaultMonokleSynchronizer(new StorageHandlerPolicy(cloudStorageDir)); | ||
synchronizer = newSynchronizer; | ||
return newSynchronizer; | ||
}; | ||
|
||
export const getSynchronizer = async () => { | ||
const userDataDir = app.getPath('userData'); | ||
const cloudStorageDir = join(userDataDir, 'cloud'); | ||
if (!synchronizer) { | ||
await initSynchronizer(cloudStorageDir); | ||
} | ||
return synchronizer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import log from 'loglevel'; | ||
|
||
import {User} from '@monokle/synchronizer'; | ||
import {CloudUser} from '@shared/models/cloud'; | ||
|
||
import {getAuthenticator} from './authenticator'; | ||
|
||
export const getUser = async (): Promise<User | undefined> => { | ||
const authenticator = await getAuthenticator(); | ||
if (!authenticator) { | ||
return undefined; | ||
} | ||
try { | ||
const user = await authenticator.getUser(); | ||
if (!user.isAuthenticated) { | ||
return undefined; | ||
} | ||
return user; | ||
} catch (e: any) { | ||
log.warn(e.message); | ||
return undefined; | ||
} | ||
}; | ||
|
||
export const getSerializedUser = async (): Promise<CloudUser | undefined> => { | ||
const user = await getUser(); | ||
if (!user) { | ||
return undefined; | ||
} | ||
try { | ||
const serializedUser = serializeUser(user); | ||
return serializedUser; | ||
} catch { | ||
return undefined; | ||
} | ||
}; | ||
|
||
export const serializeUser = (user: User): CloudUser => { | ||
if (!user.email) { | ||
throw new Error('User not found'); | ||
} | ||
return { | ||
email: user.email, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.