Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some changes #1375

Merged
merged 8 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"

"github.com/memphisdev/memphis/conf"

"github.com/memphisdev/memphis/models"

"context"
Expand Down Expand Up @@ -597,7 +596,7 @@ func createTables(MetadataDbClient MetadataStorage) error {
db := MetadataDbClient.Client
ctx := MetadataDbClient.Ctx

tables := []string{alterTenantsTable, tenantsTable, alterUsersTable, usersTable, alterAuditLogsTable, auditLogsTable, alterConfigurationsTable, configurationsTable, alterIntegrationsTable, integrationsTable, alterSchemasTable, schemasTable, alterTagsTable, tagsTable, alterStationsTable, stationsTable, alterDlsMsgsTable, dlsMessagesTable, alterConsumersTable, consumersTable, alterSchemaVerseTable, schemaVersionsTable, alterProducersTable, producersTable, alterConnectionsTable, asyncTasksTable, alterAsyncTasks, testEventsTable, installedFunctionsTable, attachedFunctionsTable}
tables := []string{alterTenantsTable, tenantsTable, alterUsersTable, usersTable, alterAuditLogsTable, auditLogsTable, alterConfigurationsTable, configurationsTable, alterIntegrationsTable, integrationsTable, alterSchemasTable, schemasTable, alterTagsTable, tagsTable, alterStationsTable, stationsTable, alterDlsMsgsTable, dlsMessagesTable, alterConsumersTable, consumersTable, alterSchemaVerseTable, schemaVersionsTable, alterProducersTable, producersTable, alterConnectionsTable, asyncTasksTable, alterAsyncTasks, testEventsTable, functionsTable, attachedFunctionsTable}

for _, table := range tables {
_, err := db.Exec(ctx, table)
Expand Down
2 changes: 1 addition & 1 deletion db/db_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package db

const testEventsTable = ``
const installedFunctionsTable = ``
const functionsTable = ``
const attachedFunctionsTable = ``

type FunctionSchema struct {
Expand Down
76 changes: 56 additions & 20 deletions models/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,65 @@ package models

import "time"

type FunctionsResult struct {
FunctionName string `json:"function_name"`
Description string `json:"description"`
Tags []string `json:"tags"`
RunTime string `json:"runtime"`
Memory int `json:"memory"`
Storgae int `json:"storgae"`
LastCommit time.Time `json:"last_commit"`
Link *string `json:"link"`
Repository string `json:"repository"`
Branch string `json:"branch"`
Owner string `json:"owner"`
EnvironmentVars map[string]string `json:"environment_vars"`
ScmType string `json:"scm_type"`
Language string `json:"language"`
InstallInProgress bool `json:"install_in_progress"`
UpdatesAvailable bool `json:"updates_available"`
ByMemphis bool `json:"by_memphis"`
type Function struct {
ID int `json:"id"`
FunctionName string `json:"function_name"`
Description string `json:"description"`
Tags []string `json:"tags"`
Runtime string `json:"runtime"`
Dependencies string `json:"dependencies"`
EnvironmentVars []map[string]interface{} `json:"environment_vars"`
Memory int `json:"memory"`
Storage int `json:"storage"`
Handler string `json:"handler"`
TenantName string `json:"tenant_name"`
Scm string `json:"scm"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Branch string `json:"branch"`
UpdatedAt time.Time `json:"installed_updated_at"`
Version int `json:"installed_version"`
InProgress bool `json:"installed_in_progress"`
ComputeEngine string `json:"compute_engine"`
Installed bool `json:"installed"`
IsValid bool `json:"is_valid"`
InvalidReason string `json:"invalid_reason"`
UpdatesAvailable bool `json:"updates_available"`
ByMemphis bool `json:"by_memphis"`
}

type FunctionResult struct {
ID int `json:"id"`
FunctionName string `json:"function_name"`
Description string `json:"description"`
Tags []string `json:"tags"`
Runtime string `json:"runtime"`
Dependencies string `json:"dependencies"`
EnvironmentVars []map[string]interface{} `json:"environment_vars"`
Memory int `json:"memory"`
Storage int `json:"storage"`
Handler string `json:"handler"`
TenantName string `json:"tenant_name"`
Scm string `json:"scm"`
Owner string `json:"owner"`
Repo string `json:"repo"`
Branch string `json:"branch"`
UpdatedAt time.Time `json:"installed_updated_at"`
Version int `json:"installed_version"`
InProgress bool `json:"installed_in_progress"`
ComputeEngine string `json:"compute_engine"`
Installed bool `json:"installed"`
IsValid bool `json:"is_valid"`
InvalidReason string `json:"invalid_reason"`
UpdatesAvailable bool `json:"updates_available"`
ByMemphis bool `json:"by_memphis"`
Language string `json:"language"`
Link *string `json:"link,omitempty"`
LastCommit *time.Time `json:"last_commit,omitempty"`
}
type FunctionsRes struct {
InstalledFunctions []FunctionsResult `json:"installed_functions"`
OtherFunctions []FunctionsResult `json:"other_functions"`
InstalledFunctions []FunctionResult `json:"installed_functions"`
OtherFunctions []FunctionResult `json:"other_functions"`
ScmIntegrated bool `json:"scm_integrated"`
ConnectedRepos []map[string]interface{} `json:"connected_repos"`
}
Expand Down
123 changes: 88 additions & 35 deletions server/memphis_handlers_functions_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"net/http"
"regexp"
"time"

"strings"

Expand Down Expand Up @@ -66,15 +67,52 @@ func (fh FunctionsHandler) GetFunctions(tenantName string) (models.FunctionsRes,
installedFunctions := functions["installed"]
OtherFunctions := functions["other"]
if len(installedFunctions) == 0 {
installedFunctions = []models.FunctionsResult{}
installedFunctions = []models.FunctionResult{}
}

if len(OtherFunctions) == 0 {
OtherFunctions = []models.FunctionsResult{}
OtherFunctions = []models.FunctionResult{}
}

var lastModified *time.Time
for _, function := range functions["other"] {
if function.Owner == memphisDevFunctionsOwnerName && function.Repo == memphisDevFunctionsRepoName {
otherFunctionResult := models.FunctionResult{
FunctionName: function.FunctionName,
Description: function.Description,
Tags: function.Tags,
Runtime: function.Runtime,
Dependencies: function.Dependencies,
EnvironmentVars: function.EnvironmentVars,
Memory: function.Memory,
Storage: function.Storage,
Handler: function.Handler,
Scm: "github",
Repo: function.Repo,
Branch: function.Branch,
Owner: function.Owner,
Language: function.Language,
Version: -1,
IsValid: true,
InProgress: false,
UpdatesAvailable: false,
ByMemphis: function.ByMemphis,
TenantName: function.TenantName,
}

OtherFunctions = []models.FunctionResult{otherFunctionResult}
lastModified = function.LastCommit
shohamroditimemphis marked this conversation as resolved.
Show resolved Hide resolved
}
}

memphisDevFucntions := []map[string]interface{}{}
memphisDevFucntions = append(memphisDevFucntions, memphisFunctions)
memphisFunc := map[string]interface{}{
"repo_name": memphisFunctions["repo_name"].(string),
"branch": memphisFunctions["branch"].(string),
"owner": memphisFunctions["repo_owner"].(string),
"last_modified": lastModified,
shohamroditimemphis marked this conversation as resolved.
Show resolved Hide resolved
}
memphisDevFucntions = append(memphisDevFucntions, memphisFunc)

allFunctions := models.FunctionsRes{
InstalledFunctions: installedFunctions,
Expand Down Expand Up @@ -220,8 +258,8 @@ func getRepoContent(url, accessToken string, body models.GetFunctionDetails) (in
return response, nil
}

func GetFunctionsDetails(functionsDetails map[string][]functionDetails) (map[string][]models.FunctionsResult, error) {
functions := map[string][]models.FunctionsResult{}
func GetFunctionsDetails(functionsDetails map[string][]functionDetails) (map[string][]models.FunctionResult, error) {
functions := map[string][]models.FunctionResult{}
for key, functionDetails := range functionsDetails {
for _, funcDetailsPerInstalled := range functionDetails {
fucntionContentMap := funcDetailsPerInstalled.ContentMap
Expand All @@ -230,6 +268,7 @@ func GetFunctionsDetails(functionsDetails map[string][]functionDetails) (map[str
repo := funcDetailsPerInstalled.RepoName
branch := funcDetailsPerInstalled.Branch
owner := funcDetailsPerInstalled.Owner
tenantName := funcDetailsPerInstalled.TenantName
tagsInterfaceSlice, ok := fucntionContentMap["tags"].([]interface{})
tagsStrings := []string{}
if ok {
Expand All @@ -244,55 +283,69 @@ func GetFunctionsDetails(functionsDetails map[string][]functionDetails) (map[str
}
}

var environmentVarsStrings map[string]string
environmentVarsStrings := []map[string]interface{}{}
environmentVarsInterfaceSlice, ok := fucntionContentMap["environment_vars"].([]interface{})
if ok {
environmentVarsStrings = make(map[string]string, len(fucntionContentMap["environment_vars"].([]interface{})))
for _, environmentVar := range environmentVarsInterfaceSlice {
environmentVarMap := environmentVar.(map[interface{}]interface{})
for _, environmentVarInterface := range environmentVarsInterfaceSlice {
environmentVarMap, _ := environmentVarInterface.(map[interface{}]interface{})
environmentVar := make(map[string]interface{})
for k, v := range environmentVarMap {
if str, ok := v.(string); ok {
environmentVarsStrings[k.(string)] = str
if key, ok := k.(string); ok {
if val, ok := v.(string); ok {
environmentVar[key] = val
}
}
}
environmentVarsStrings = append(environmentVarsStrings, environmentVar)
}
}
description, ok := fucntionContentMap["description"].(string)
if !ok {
description = ""
}

runtime := fucntionContentMap["runtime"].(string)
regex := regexp.MustCompile(`[0-9]+|\\.$`)
language := regex.ReplaceAllString(runtime, "")
language = strings.TrimRight(language, ".")
if strings.Contains(language, "-edge") {
language = strings.Trim(language, ".-edge")
runtime, ok := fucntionContentMap["runtime"].(string)
var language string
if ok {
regex := regexp.MustCompile(`[0-9]+|\\.$`)
language = regex.ReplaceAllString(runtime, "")
language = strings.TrimRight(language, ".")
if strings.Contains(language, "-edge") {
language = strings.Trim(language, ".-edge")
}
}

byMemphis := false
if repo == memphisDevFunctionsRepoName && owner == memphisDevFunctionsOwnerName {
byMemphis = true
}

functionDetails := models.FunctionsResult{
FunctionName: fucntionContentMap["function_name"].(string),
Description: description,
Tags: tagsStrings,
RunTime: runtime,
LastCommit: *commit.Commit.Committer.Date,
Link: link,
Repository: repo,
Branch: branch,
Owner: owner,
Memory: fucntionContentMap["memory"].(int),
Storgae: fucntionContentMap["storage"].(int),
EnvironmentVars: environmentVarsStrings,
Language: language,
ScmType: "github",
InstallInProgress: false,
UpdatesAvailable: false,
ByMemphis: byMemphis,
handler := ""
if _, ok := fucntionContentMap["handler"].(string); ok {
handler = fucntionContentMap["handler"].(string)
}

functionDetails := models.FunctionResult{
FunctionName: fucntionContentMap["function_name"].(string),
Description: description,
Tags: tagsStrings,
Runtime: runtime,
Dependencies: fucntionContentMap["dependencies"].(string),
EnvironmentVars: environmentVarsStrings,
Memory: fucntionContentMap["memory"].(int),
Storage: fucntionContentMap["storage"].(int),
Handler: handler,
Scm: "github",
Repo: repo,
Branch: branch,
Owner: owner,
LastCommit: &*commit.Commit.Committer.Date,
Link: link,
Language: language,
InProgress: false,
UpdatesAvailable: false,
ByMemphis: byMemphis,
TenantName: tenantName,
}

functions[key] = append(functions[key], functionDetails)
Expand Down
7 changes: 4 additions & 3 deletions server/source_code_management_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ type functionDetails struct {
Branch string `json:"branch"`
Scm string `json:"scm"`
Owner string `json:"owner"`
TenantName string `json:"tenant_name"`
}

func getSourceCodeDetails(tenantName string, getAllReposSchema interface{}, actionType string) (models.Integration, interface{}, error) {
return models.Integration{}, map[string]string{}, nil
}

func GetContentOfSelectedRepo(connectedRepo map[string]interface{}, contentDetails map[string][]functionDetails) (map[string][]functionDetails, error) {
func GetContentOfSelectedRepo(connectedRepo map[string]interface{}, contentDetails map[string][]functionDetails, tenantName string) (map[string][]functionDetails, error) {
var err error
contentDetails, err = GetGithubContentFromConnectedRepo(connectedRepo, contentDetails)
contentDetails, err = GetGithubContentFromConnectedRepo(connectedRepo, contentDetails, tenantName)
if err != nil {
return contentDetails, err
}
Expand All @@ -62,7 +63,7 @@ func GetContentOfSelectedRepos(tenantName string) (map[string][]functionDetails,
for _, connectedRepoPerIntegration := range connectedRepos {
for _, connectedRepo := range connectedRepoPerIntegration {
connectedRepoRes := connectedRepo.(map[string]interface{})
contentDetails, err = GetContentOfSelectedRepo(connectedRepoRes, contentDetails)
contentDetails, err = GetContentOfSelectedRepo(connectedRepoRes, contentDetails, tenantName)
if err != nil {
return contentDetails, scmIntegrated, err
}
Expand Down
Loading