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

feat(project): add token check result in project check API #8099

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion backend/core/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,29 @@ type ApiOutputProject struct {
}

type ApiProjectCheck struct {
Exist bool `json:"exist" mapstructure:"exist"`
Exist bool `json:"exist" mapstructure:"exist"`
Tokens *ApiProjectCheckToken `json:"tokens,omitempty" mapstructure:"tokens"`
}

type SuccessAndMessage struct {
Success bool `json:"success" mapstructure:"success"`
Message string `json:"message" mapstructure:"message"`
}

// ApiProjectCheckToken
//
// {
// "plugin_name":
// {
// "connection_id":
// {
// "success": true,
// "message": ""
// }
// }
// }
type ApiProjectCheckToken = map[string]map[int]SuccessAndMessage

type Store struct {
StoreKey string `gorm:"primaryKey;type:varchar(255)"`
StoreValue json.RawMessage `gorm:"type:json;serializer:json"`
Expand Down
9 changes: 9 additions & 0 deletions backend/server/api/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func GetProjectCheck(c *gin.Context) {
projectOutputCheck.Exist = true
}

if c.Query("check_token") == "1" {
checkTokenResult, err := services.CheckProjectTokens(projectName)
if err != nil {
shared.ApiOutputError(c, errors.Default.Wrap(err, "error check project tokens"))
return
}
projectOutputCheck.Tokens = checkTokenResult
}

shared.ApiOutputSuccess(c, projectOutputCheck, http.StatusOK) // //shared.ApiOutputSuccess(c, projectOutputCheck, http.StatusOK)
}

Expand Down
27 changes: 27 additions & 0 deletions backend/server/services/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,33 @@ func GetProject(name string) (*models.ApiOutputProject, errors.Error) {
return makeProjectOutput(project, false)
}

func CheckProjectTokens(name string) (*models.ApiProjectCheckToken, errors.Error) {
blueprint, err := GetBlueprintByProjectName(name)
if err != nil {
return nil, err
}
ret := make(map[string]map[int]models.SuccessAndMessage)
for _, connection := range blueprint.Connections {
pluginName := connection.PluginName
connectionId := int(connection.ConnectionId)
if _, ok := ret[pluginName]; !ok {
ret[pluginName] = make(map[int]models.SuccessAndMessage)
}
connectionTokenResult := models.SuccessAndMessage{
Success: true,
Message: "success",
}
if err := checkConnectionToken(logger, *connection); err != nil {
ret[pluginName][connectionId] = models.SuccessAndMessage{
Success: false,
Message: err.Error(),
}
}
ret[pluginName][connectionId] = connectionTokenResult
}
return &ret, nil
}

// PatchProject FIXME ...
func PatchProject(name string, body map[string]interface{}) (*models.ApiOutputProject, errors.Error) {
projectInput := &models.ApiInputProject{}
Expand Down
Loading