Skip to content

Commit

Permalink
feat(project): add token check result in project check API (#8099)
Browse files Browse the repository at this point in the history
  • Loading branch information
d4x1 authored Sep 25, 2024
1 parent 0570677 commit fa6c764
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
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

0 comments on commit fa6c764

Please sign in to comment.