[INFRA-190]chore: update monitor to save and read file from the local system when running in airgap mode (#3435)

* refactor: update SyncWorkspace to read activation file from local system and handle file writing in activation handler

* fix: update MemberList assignment in SyncWorkspace to use payload data

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
This commit is contained in:
sriram veeraghanta
2025-06-18 01:26:45 +05:30
committed by GitHub
parent 7f33b6e692
commit a3ea0b665e
2 changed files with 17 additions and 15 deletions

View File

@@ -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
}

View File

@@ -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