1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
package common
import (
"os"
"runtime"
)
type Config struct {
/* Constants */
AppVersion string
UserAgent string
/* Login */
FirstLoginCredential *FirstLoginCredentialData
ReusableCredential *ReusableCredentialData
UseReusableLogin bool
CredentialCacheFile string // If CredentialCacheFile is empty, no credential will be logged
/* Setting */
DestructiveIntegrationTest bool // CAUTION: the integration test requires a clean proton drive
EmptyTrashAfterIntegrationTest bool // CAUTION: the integration test will clean up all the data in the trash
ReplaceExistingDraft bool // for the file upload replace or keep it as-is option
EnableCaching bool // link node caching
ConcurrentBlockUploadCount int
ConcurrentFileCryptoCount int
/* Drive */
DataFolderName string
}
type FirstLoginCredentialData struct {
Username string
Password string
MailboxPassword string
TwoFA string
}
type ReusableCredentialData struct {
UID string
AccessToken string
RefreshToken string
SaltedKeyPass string // []byte <-> base64
}
func NewConfigWithDefaultValues() *Config {
return &Config{
AppVersion: "",
UserAgent: "",
FirstLoginCredential: &FirstLoginCredentialData{
Username: "",
Password: "",
MailboxPassword: "",
TwoFA: "",
},
ReusableCredential: &ReusableCredentialData{
UID: "",
AccessToken: "",
RefreshToken: "",
SaltedKeyPass: "", // []byte <-> base64
},
UseReusableLogin: false,
CredentialCacheFile: "",
DestructiveIntegrationTest: false,
EmptyTrashAfterIntegrationTest: false,
ReplaceExistingDraft: false,
EnableCaching: true,
ConcurrentBlockUploadCount: 20, // let's be a nice citizen and not stress out proton engineers :)
ConcurrentFileCryptoCount: runtime.GOMAXPROCS(0),
DataFolderName: "data",
}
}
func NewConfigForIntegrationTests() *Config {
appVersion := os.Getenv("PROTON_API_BRIDGE_APP_VERSION")
userAgent := os.Getenv("PROTON_API_BRIDGE_USER_AGENT")
username := os.Getenv("PROTON_API_BRIDGE_TEST_USERNAME")
password := os.Getenv("PROTON_API_BRIDGE_TEST_PASSWORD")
twoFA := os.Getenv("PROTON_API_BRIDGE_TEST_TWOFA")
useReusableLoginStr := os.Getenv("PROTON_API_BRIDGE_TEST_USE_REUSABLE_LOGIN")
useReusableLogin := false
if useReusableLoginStr == "1" {
useReusableLogin = true
}
uid := os.Getenv("PROTON_API_BRIDGE_TEST_UID")
accessToken := os.Getenv("PROTON_API_BRIDGE_TEST_ACCESS_TOKEN")
refreshToken := os.Getenv("PROTON_API_BRIDGE_TEST_REFRESH_TOKEN")
saltedKeyPass := os.Getenv("PROTON_API_BRIDGE_TEST_SALTEDKEYPASS")
return &Config{
AppVersion: appVersion,
UserAgent: userAgent,
FirstLoginCredential: &FirstLoginCredentialData{
Username: username,
Password: password,
MailboxPassword: "",
TwoFA: twoFA,
},
ReusableCredential: &ReusableCredentialData{
UID: uid,
AccessToken: accessToken,
RefreshToken: refreshToken,
SaltedKeyPass: saltedKeyPass, // []byte <-> base64
},
UseReusableLogin: useReusableLogin,
CredentialCacheFile: ".credential",
DestructiveIntegrationTest: true,
EmptyTrashAfterIntegrationTest: true,
ReplaceExistingDraft: false,
EnableCaching: true,
ConcurrentBlockUploadCount: 20,
ConcurrentFileCryptoCount: runtime.GOMAXPROCS(0),
DataFolderName: "data",
}
}
|