|
21 | 21 | package asposepdfcloud |
22 | 22 |
|
23 | 23 | import ( |
| 24 | + "encoding/json" |
24 | 25 | "os" |
| 26 | + "path/filepath" |
25 | 27 | ) |
26 | 28 |
|
27 | 29 | var BaseTestInstance *BaseTest |
@@ -50,15 +52,56 @@ func (bt *BaseTest) GetTestNumber() int { |
50 | 52 | return bt.TestNumber |
51 | 53 | } |
52 | 54 |
|
| 55 | +func getServercredsJson() string { |
| 56 | + wd, err := os.Getwd() |
| 57 | + if err != nil { |
| 58 | + panic(err) |
| 59 | + } |
| 60 | + dir := filepath.Dir(wd) |
| 61 | + for !(dir[len(dir)-1] == filepath.Separator || dir == ".") { |
| 62 | + servercreds_json := filepath.Join(dir, "Settings", "servercreds.json") |
| 63 | + if _, err := os.Stat(servercreds_json); err == nil { |
| 64 | + // fmt.Println(`Settings\servercreds.json found: ` + servercreds_json) |
| 65 | + return servercreds_json |
| 66 | + } |
| 67 | + dir = filepath.Dir(dir) |
| 68 | + } |
| 69 | + panic(`Settings\servercreds.json not found`) |
| 70 | +} |
| 71 | + |
| 72 | +type Creds struct { |
| 73 | + AppSID string |
| 74 | + AppKey string |
| 75 | +} |
| 76 | + |
| 77 | +func getCreds() (appSID, appKey string) { |
| 78 | + bbCreds, err := os.ReadFile(getServercredsJson()) |
| 79 | + if err != nil { |
| 80 | + panic(err) |
| 81 | + } |
| 82 | + var creds Creds |
| 83 | + if err := json.Unmarshal(bbCreds, &creds); err != nil { |
| 84 | + panic(err) |
| 85 | + } |
| 86 | + if len(creds.AppSID) == 0 { |
| 87 | + panic("no AppSID") |
| 88 | + } |
| 89 | + if len(creds.AppKey) == 0 { |
| 90 | + panic("no AppKey") |
| 91 | + } |
| 92 | + return creds.AppSID, creds.AppKey |
| 93 | +} |
| 94 | + |
53 | 95 | func NewBaseTest() *BaseTest { |
54 | | - bt := &BaseTest{ |
| 96 | + appSID, appKey := getCreds() |
| 97 | + bt := BaseTest{ |
55 | 98 | remoteFolder: "TempPdfCloud", |
56 | 99 | localTestDataFolder: "test_data", |
57 | 100 | TestNumber: 0, |
58 | 101 | // Get App key and App SID from https://aspose.cloud |
59 | | - PdfAPI: NewPdfApiService("AppSID", "AppKey", "https://api.aspose.cloud/v3.0"), |
| 102 | + PdfAPI: NewPdfApiService(appSID, appKey, "https://api.aspose.cloud/v3.0"), |
60 | 103 | } |
61 | | - return bt |
| 104 | + return &bt |
62 | 105 | } |
63 | 106 |
|
64 | 107 | func GetBaseTest() *BaseTest { |
|
0 commit comments