Skip to content

Commit

Permalink
Merge pull request #135 from hossted/accesinfo
Browse files Browse the repository at this point in the history
WIP DO NOT MERGE Accesinfo
  • Loading branch information
AdheipSingh committed Sep 4, 2024
2 parents e2bea12 + d063906 commit 1be4364
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 17 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ BUILD_TIMESTAMP=$(shell date '+%Y-%m-%d')
LDFLAGS="-X '${PACKAGE}/cmd.VERSION=${VERSION}' \
-X '${PACKAGE}/cmd.ENVIRONMENT=prod' \
-X '${PACKAGE}/cmd.COMMITHASH=${COMMIT_HASH}' \
-X '${PACKAGE}/cmd.BUILDTIME=${BUILD_TIMESTAMP}' \
-X '${SERVICE_COMMON_PACKAGE}.LOKI_PASSWORD=${LOKI_PASSWORD}' \
-X '${SERVICE_COMMON_PACKAGE}.LOKI_URL=${LOKI_URL}' \
-X '${SERVICE_COMMON_PACKAGE}.LOKI_USERNAME=${LOKI_USERNAME}' \
Expand All @@ -25,7 +24,6 @@ LDFLAGS="-X '${PACKAGE}/cmd.VERSION=${VERSION}' \
DEVFLAGS="-X '${PACKAGE}/cmd.VERSION=dev' \
-X '${PACKAGE}/cmd.ENVIRONMENT=dev' \
-X '${PACKAGE}/cmd.COMMITHASH=${COMMIT_HASH}' \
-X '${PACKAGE}/cmd.BUILDTIME=${BUILD_TIMESTAMP}' \
-X '${SERVICE_COMMON_PACKAGE}.LOKI_PASSWORD=${LOKI_PASSWORD}' \
-X '${SERVICE_COMMON_PACKAGE}.LOKI_URL=${LOKI_URL}' \
-X '${SERVICE_COMMON_PACKAGE}.LOKI_USERNAME=${LOKI_USERNAME}' \
Expand Down
4 changes: 1 addition & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

Expand All @@ -12,7 +11,6 @@ import (

var (
COMMITHASH = "-"
BUILDTIME = "-"
)

// versionCmd represents the version command
Expand All @@ -22,7 +20,7 @@ var versionCmd = &cobra.Command{
Long: `[v] Get the version of the hossted CLI program`,
Aliases: []string{"v"},
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("hossted version %s.\nBuilt on %s (%s)\n", VERSION, BUILDTIME, COMMITHASH)
fmt.Printf("hossted version %s.\nBuilt on (%s)\n", VERSION, COMMITHASH)
return nil
},
}
Expand Down
71 changes: 62 additions & 9 deletions hossted/service/compose/reconcile_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,37 @@ func sendComposeInfo(appFilePath string, osInfo OsInfo) error {
composeUrl := hosstedAPIUrl + "/compose/hosts"
containersUrl := hosstedAPIUrl + "/compose/containers"

var access_info = &AccessInfo{}
path, err := getSoftwarePath()
projectName, err := getProjectName()
if err != nil {
fmt.Println("Error getting software path", err)
return err
}

access_info := getAccessInfo("/opt/" + projectName + "/.env")

// its a market place VM, access info object will exist
if path == "/opt/hossted/run/software.txt" {
access_info = getAccessInfo("/opt/" + osInfo.ProjectName + "/.env")
} else if path == "" {
fmt.Println("Contact hossted support to make add Access Info object")
}
// if path == "/opt/hossted/run/software.txt" {
// // read the file in this path
// // file will have this convention - Linnovate-AWS-keycloak
// // capture the last word ie keycloak in this case.
// // and use this last work ie instead of osInfo.ProjectName
// data, err := os.ReadFile(path)
// if err != nil {
// fmt.Println("Error reading file:", err)
// return err
// }

// // The file will have the convention Linnovate-AWS-keycloak
// // Capture the last word (i.e., keycloak in this case)
// softwareName := strings.TrimSpace(string(data))
// words := strings.Split(softwareName, "-")
// if len(words) > 0 {
// projectName := words[len(words)-1]
// // Use this last word (i.e., keycloak) instead of osInfo.ProjectName
// access_info = getAccessInfo("/opt/" + projectName + "/.env")
// }
// } else if path == "" {
// fmt.Println("Contact Hossted support to add Access Info object")
// }

var data map[string]AppRequest
err = json.Unmarshal(composeInfo, &data)
Expand Down Expand Up @@ -639,7 +658,7 @@ func runMonitoringCompose(monitoringEnable, osUUID, appUUID string) error {
func getAccessInfo(filepath string) *AccessInfo {
file, err := os.Open(filepath)
if err != nil {
log.Fatalf("Failed to open file for Access Info: %s", err)
return &AccessInfo{}
}
defer file.Close()

Expand Down Expand Up @@ -688,3 +707,37 @@ func getSoftwarePath() (string, error) {
}

}

func getProjectName() (string, error) {
path, err := getSoftwarePath()
if err != nil {
fmt.Println("Error getting software path", err)
}

// its a market place VM, access info object will exist
if path == "/opt/hossted/run/software.txt" {
// read the file in this path
// file will have this convention - Linnovate-AWS-keycloak
// capture the last word ie keycloak in this case.
// and use this last work ie instead of osInfo.ProjectName
data, err := os.ReadFile(path)
if err != nil {
fmt.Println("Error reading file:", err)
return "", err
}

// The file will have the convention Linnovate-AWS-keycloak
// Capture the last word (i.e., keycloak in this case)
softwareName := strings.TrimSpace(string(data))
words := strings.Split(softwareName, "-")
if len(words) > 0 {
projectName := words[len(words)-1]
// Use this last word (i.e., keycloak) instead of osInfo.ProjectName
return projectName, nil
}
} else if path == "" {
fmt.Println("Contact Hossted support to add Access Info object")
return "", nil
}
return "", nil
}
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ Copyright © 2022 NAME HERE <EMAIL ADDRESS>
package main

import (
"fmt"

"github.com/hossted/cli/cmd"
)

func main() {
fmt.Println(cmd.BUILDTIME)
cmd.Execute()
}

0 comments on commit 1be4364

Please sign in to comment.