diff --git a/monitor/lib/api/airgapped_api.go b/monitor/lib/api/airgapped_api.go index 483e372a74..c3bd0ae4a0 100644 --- a/monitor/lib/api/airgapped_api.go +++ b/monitor/lib/api/airgapped_api.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/http" + "os" "strings" "time" @@ -118,25 +119,15 @@ func (a *AirgappedPrimeApi) ActivateWorkspace(payload WorkspaceActivationPayload Downloads the workspace activation file from the server and returns the response and error */ func (a *AirgappedPrimeApi) SyncWorkspace(payload WorkspaceSyncPayload) (*WorkspaceActivationResponse, *APIError) { - // Step 1: Get the file URL and members list from the server - fileResponse, err := a.getWorkspaceActivationFile(payload.WorkspaceSlug) + // Step 1: Read the file from the local system + fileContent, err := os.ReadFile(payload.WorkspaceID + ".json") if err != nil { return nil, &APIError{ - Error: fmt.Sprintf("Failed to get activation file URL: %v", err), + Error: fmt.Sprintf("Failed to read activation file: %v", err), Success: false, } } - - // Step 2: Download the file content from the URL - fileContent, err := a.downloadFileFromURL(fileResponse.URL) - if err != nil { - return nil, &APIError{ - Error: fmt.Sprintf("Failed to download activation file: %v", err), - Success: false, - } - } - - // Step 3: Process the file content (decrypt and parse) + // Step 2: Process the file content (decrypt and parse) licensePayload, err := a.processActivationFile(fileContent) if err != nil { return nil, &APIError{ @@ -150,7 +141,7 @@ func (a *AirgappedPrimeApi) SyncWorkspace(payload WorkspaceSyncPayload) (*Worksp licensePayload.WorkspaceSlug = payload.WorkspaceSlug response := &licensePayload.WorkspaceActivationResponse - response.MemberList = fileResponse.MembersList + response.MemberList = payload.MembersList return response, nil } diff --git a/monitor/lib/router/airgapped_handlers.go/airgapped_activation.go b/monitor/lib/router/airgapped_handlers.go/airgapped_activation.go index 83eace7e91..d27852fdbc 100644 --- a/monitor/lib/router/airgapped_handlers.go/airgapped_activation.go +++ b/monitor/lib/router/airgapped_handlers.go/airgapped_activation.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io" + "os" "strings" "github.com/gofiber/fiber/v2" @@ -74,6 +75,16 @@ func GetAirgappedActivationHandler(api prime_api.IPrimeMonitorApi, key string) f }) } + // Create filename using workspaceId + filename := fmt.Sprintf("%s.json", workspaceId) + + // Write content to file + err = os.WriteFile(filename, content, 0644) + if err != nil { + // Let's not return an error here, as we want to continue with the activation + fmt.Println("Failed to write file to local system", err) + } + // Parse the json text file for the encrypted data var encryptedData feat_flag.EncryptedData