Skip to content

Commit

Permalink
feat: updated keycloak config for docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
AdheipSingh committed Aug 29, 2024
1 parent 1930786 commit 3bd5aa1
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions hossted/service/compose/reconcile_compose.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compose

import (
"bufio"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -45,15 +46,17 @@ func ReconcileCompose(osInfo OsInfo, enableMonitoring string) error {
if err != nil {
return err
}

err = sendComposeInfo(appFilePath, osInfo)
if err != nil {
return err
}
if isComposeStateChange {
// send compose info
err = sendComposeInfo(appFilePath, osInfo)
if err != nil {
return err
}
}

return nil

}
Expand Down Expand Up @@ -191,6 +194,16 @@ type optionsState struct {
CVEScan bool `json:"cve_scan"`
}

type URLInfo struct {
URL string `json:"url"`
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
}

type AccessInfo struct {
URLs []URLInfo `json:"urls"`
}

type request struct {
UUID string `json:"uuid"`
OsUUID string `json:"osuuid"`
Expand All @@ -202,6 +215,7 @@ type request struct {
Memory string `json:"memory"`
OptionsState optionsState `json:"options_state"`
ComposeFile string `json:"compose_file"`
AccessInfo AccessInfo `json:"access_info"`
}

type dockerInstance struct {
Expand Down Expand Up @@ -230,6 +244,8 @@ func sendComposeInfo(appFilePath string, osInfo OsInfo) error {

composeUrl := hosstedAPIUrl + "/compose/hosts"
containersUrl := hosstedAPIUrl + "/compose/containers"
keycloak_file := "/opt/keycloak/.env"

This comment has been minimized.

Copy link
@liorkesos

liorkesos Sep 2, 2024

Contributor

This should not be hardcoded for keyclock but instead generic.
Its in. the config,yaml in application.appName
image

access_info := getAccessInfo(keycloak_file)

var data map[string]AppRequest
err = json.Unmarshal(composeInfo, &data)
Expand All @@ -250,6 +266,7 @@ func sendComposeInfo(appFilePath string, osInfo OsInfo) error {
UUID: compose.AppAPIInfo.AppUUID,
OsUUID: compose.AppAPIInfo.OsUUID,
Email: compose.AppAPIInfo.EmailID,
AccessInfo: *access_info,
OrgID: orgID,
Type: "compose",
Product: appName,
Expand Down Expand Up @@ -607,3 +624,46 @@ func runMonitoringCompose(monitoringEnable, osUUID, appUUID string) error {
}
return nil
}

func getAccessInfo(filepath string) *AccessInfo {
file, err := os.Open(filepath)
if err != nil {
log.Fatalf("Failed to open file:", err)
}
defer file.Close()

config := AccessInfo{
URLs: []URLInfo{
{},
},
}

scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if line == "" || strings.HasPrefix(line, "#") {
continue
}
parts := strings.SplitN(line, "=", 2)
if len(parts) != 2 {
fmt.Println("Invalid line:", line)
continue
}
key := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])

switch key {
case "PROJECT_BASE_URL":
config.URLs[0].URL = value
case "H_EMAIL":
config.URLs[0].User = value
case "APP_PASSWORD":
config.URLs[0].Password = value
}
}

if err := scanner.Err(); err != nil {
fmt.Println("Error reading file:", err)
}
return &config
}

0 comments on commit 3bd5aa1

Please sign in to comment.