Skip to content

Commit

Permalink
remove tgcloud paramter
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu Zhou authored and Lu Zhou committed Aug 2, 2024
1 parent d8db830 commit 27c6b61
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion chat-history/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type TgDbConfig struct {
Username string `json:"username"`
Password string `json:"password"`
GsPort string `json:"gsPort"`
TgCloud bool `json:"tgCloud"`
// GetToken string `json:"getToken"`
// DefaultTimeout string `json:"default_timeout"`
// DefaultMemThreshold string `json:"default_mem_threshold"`
Expand Down
6 changes: 2 additions & 4 deletions chat-history/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func TestLoadConfig(t *testing.T) {
}

if cfg.TgDbConfig.Hostname != "https://tg-0cdef603-3760-41c3-af6f-41e95afc40de.us-east-1.i.tgcloud.io" ||
cfg.TgDbConfig.GsPort != "14240" ||
cfg.TgDbConfig.TgCloud != true {
cfg.TgDbConfig.GsPort != "14240" {
t.Fatalf("TigerGraph config is wrong, %v", cfg.TgDbConfig)
}
}
Expand Down Expand Up @@ -54,8 +53,7 @@ func setup(t *testing.T) (string, string) {
"hostname": "https://tg-0cdef603-3760-41c3-af6f-41e95afc40de.us-east-1.i.tgcloud.io",
"gsPort": "14240",
"username": "supportai",
"password": "supportai",
"tgCloud": true
"password": "supportai"
}`
if err := os.WriteFile(tgConfigPath, []byte(tgConfigData), 0644); err != nil {
t.Fatal("error setting up tg_config.json")
Expand Down
2 changes: 1 addition & 1 deletion chat-history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
router.HandleFunc("GET /user/{userId}", routes.GetUserConversations)
router.HandleFunc("GET /conversation/{conversationId}", routes.GetConversation)
router.HandleFunc("POST /conversation", routes.UpdateConversation)
router.HandleFunc("GET /get_feedback", routes.GetFeedback(cfg.TgDbConfig.Hostname, cfg.TgDbConfig.GsPort, cfg.ChatDbConfig.ConversationAccessRoles, cfg.TgDbConfig.TgCloud))
router.HandleFunc("GET /get_feedback", routes.GetFeedback(cfg.TgDbConfig.Hostname, cfg.TgDbConfig.GsPort, cfg.ChatDbConfig.ConversationAccessRoles))

// create server with middleware
dev := strings.ToLower(os.Getenv("DEV")) == "true"
Expand Down
7 changes: 4 additions & 3 deletions chat-history/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ func auth(userId string, r *http.Request) (string, int, []byte, bool) {
}

// executeGSQL sends a GSQL query to TigerGraph with basic authentication and returns the response
func executeGSQL(hostname, username, password, query, gsPort string, tgcloud bool) (string, error) {
func executeGSQL(hostname, username, password, query, gsPort string) (string, error) {
var requestURL string
tgcloud := strings.Contains(hostname, "tgcloud")
// Construct the URL for the GSQL query endpoint
if tgcloud {
requestURL = fmt.Sprintf("%s:443/gsqlserver/gsql/file", hostname)
Expand Down Expand Up @@ -235,7 +236,7 @@ func parseUserRoles(userInfo string, userName string) []string {

// GetFeedback retrieves feedback data for conversations
// "Get /get_feedback"
func GetFeedback(hostname, gsPort string, conversationAccessRoles []string, tgCloud bool) http.HandlerFunc {
func GetFeedback(hostname, gsPort string, conversationAccessRoles []string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
usr, pass, ok := r.BasicAuth()
if !ok {
Expand All @@ -246,7 +247,7 @@ func GetFeedback(hostname, gsPort string, conversationAccessRoles []string, tgCl
}

// Verify if the user has the required role
userInfo, err := executeGSQL(hostname, usr, pass, "SHOW USER", gsPort, tgCloud)
userInfo, err := executeGSQL(hostname, usr, pass, "SHOW USER", gsPort)
if err != nil {
reason := []byte(`{"reason":"failed to retrieve feedback data"}`)
w.Header().Add("Content-Type", "application/json")
Expand Down
4 changes: 2 additions & 2 deletions chat-history/routes/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func TestExecuteGSQL(t *testing.T) {
}
query := "SHOW USER"

response, err := executeGSQL(cfg.TgDbConfig.Hostname, cfg.TgDbConfig.Username, cfg.TgDbConfig.Password, query, cfg.TgDbConfig.GsPort, cfg.TgDbConfig.TgCloud)
response, err := executeGSQL(cfg.TgDbConfig.Hostname, cfg.TgDbConfig.Username, cfg.TgDbConfig.Password, query, cfg.TgDbConfig.GsPort)
if err != nil {
t.Fatalf("Failed to execute GSQL query: %v", err)
}
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestGetFeedback(t *testing.T) {

// Record the response
rr := httptest.NewRecorder()
handler := http.HandlerFunc(GetFeedback(cfg.TgDbConfig.Hostname, cfg.TgDbConfig.GsPort, cfg.ChatDbConfig.ConversationAccessRoles, cfg.TgDbConfig.TgCloud))
handler := http.HandlerFunc(GetFeedback(cfg.TgDbConfig.Hostname, cfg.TgDbConfig.GsPort, cfg.ChatDbConfig.ConversationAccessRoles))

// Serve the request
handler.ServeHTTP(rr, req)
Expand Down

0 comments on commit 27c6b61

Please sign in to comment.