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: plugin creation support #5630

Merged
merged 27 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
93b624e
wip: new plugin creation api and min plugin api with only shared plug…
prakash100198 Aug 7, 2024
da93046
wip: create new plugin version code
prakash100198 Aug 7, 2024
9b88045
wip:plugin type SHARED by default
prakash100198 Aug 7, 2024
6da2832
wip:find plugin either by identifier or by id while creating a new ve…
prakash100198 Aug 7, 2024
7dc5df6
wip: create new plugin tag logic improved
prakash100198 Aug 7, 2024
40e7365
wip: optimize GetAllFilteredPluginParentMetadata query
prakash100198 Aug 7, 2024
638a5e7
wip: create plugin tag new flow
prakash100198 Aug 8, 2024
db878ae
wip: minor fix
prakash100198 Aug 8, 2024
046fb83
wip: minor fix
prakash100198 Aug 8, 2024
309705f
wip: minor fix
prakash100198 Aug 8, 2024
eff0501
wip: newTagsPresent -> areNewTagsPresent
prakash100198 Aug 8, 2024
f43da65
wip: icon is not mandatory code incorporated
prakash100198 Aug 8, 2024
d906333
wip:minor refactoring
prakash100198 Aug 8, 2024
ff188eb
wip: prevent duplicate version from being created and save tags rela…
prakash100198 Aug 8, 2024
19e66a3
wip: minor fix
prakash100198 Aug 8, 2024
c2e7cde
wip: details api, get all plugin data or non
prakash100198 Aug 8, 2024
8dc7386
wip: code review incorp part -1
prakash100198 Aug 9, 2024
47015bc
wip: code review incorp part -2
prakash100198 Aug 9, 2024
27e79d5
wip: code review incorp part -3
prakash100198 Aug 9, 2024
5efc2c5
wip: remove code duplication
prakash100198 Aug 9, 2024
d7f077e
wip: hardcode isExposed to true
prakash100198 Aug 9, 2024
38e2c80
Merge branch 'main' into plugin-creation-oss
prakash100198 Aug 9, 2024
cbfc114
wip: hardcode StepType= inline
prakash100198 Aug 9, 2024
4060ef5
wip: set default VariableStepIndex= 1
prakash100198 Aug 12, 2024
0415cee
Merge branch 'main' into plugin-creation-oss
prakash100198 Aug 28, 2024
e619322
Merge branch 'main' into plugin-creation-oss
prakash100198 Aug 30, 2024
5f84b16
Merge branch 'main' into plugin-creation-oss
prakash100198 Sep 2, 2024
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
67 changes: 67 additions & 0 deletions api/restHandler/GlobalPluginRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

type GlobalPluginRestHandler interface {
PatchPlugin(w http.ResponseWriter, r *http.Request)
CreatePlugin(w http.ResponseWriter, r *http.Request)

GetAllGlobalVariables(w http.ResponseWriter, r *http.Request)
ListAllPlugins(w http.ResponseWriter, r *http.Request)
Expand All @@ -46,6 +47,7 @@ type GlobalPluginRestHandler interface {
GetPluginDetailByIds(w http.ResponseWriter, r *http.Request)
GetAllUniqueTags(w http.ResponseWriter, r *http.Request)
MigratePluginData(w http.ResponseWriter, r *http.Request)
GetAllPluginMinData(w http.ResponseWriter, r *http.Request)
}

func NewGlobalPluginRestHandler(logger *zap.SugaredLogger, globalPluginService plugin.GlobalPluginService,
Expand Down Expand Up @@ -420,3 +422,68 @@ func (handler *GlobalPluginRestHandlerImpl) MigratePluginData(w http.ResponseWri
}
common.WriteJsonResp(w, nil, nil, http.StatusOK)
}

func (handler *GlobalPluginRestHandlerImpl) CreatePlugin(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
token := r.Header.Get("token")
appId, err := common.ExtractIntQueryParam(w, r, "appId", 0)
if err != nil {
return
}
ok, err := handler.IsUserAuthorized(token, appId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}
decoder := json.NewDecoder(r.Body)
var pluginDataDto bean.PluginParentMetadataDto
err = decoder.Decode(&pluginDataDto)
if err != nil {
handler.logger.Errorw("request err, CreatePlugin", "error", err, "payload", pluginDataDto)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
handler.logger.Infow("request payload received for creating plugins", pluginDataDto, "userId", userId)

pluginVersionId, err := handler.globalPluginService.CreatePluginOrVersions(&pluginDataDto, userId)
if err != nil {
handler.logger.Errorw("service error, error in creating plugin", "pluginCreateRequestDto", pluginDataDto, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

common.WriteJsonResp(w, nil, bean.NewPluginMinDto().WithPluginVersionId(pluginVersionId), http.StatusOK)
}

func (handler *GlobalPluginRestHandlerImpl) GetAllPluginMinData(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
appId, err := common.ExtractIntQueryParam(w, r, "appId", 0)
if err != nil {
return
}
ok, err := handler.IsUserAuthorized(token, appId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "Unauthorized User", http.StatusForbidden)
return
}

pluginDetail, err := handler.globalPluginService.GetAllPluginMinData()
if err != nil {
handler.logger.Errorw("error in getting all unique tags", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, nil, pluginDetail, http.StatusOK)
}
5 changes: 4 additions & 1 deletion api/router/GlobalPluginRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type GlobalPluginRouterImpl struct {
func (impl *GlobalPluginRouterImpl) initGlobalPluginRouter(globalPluginRouter *mux.Router) {
globalPluginRouter.Path("/migrate").
HandlerFunc(impl.globalPluginRestHandler.MigratePluginData).Methods("PUT")

globalPluginRouter.Path("/create").
HandlerFunc(impl.globalPluginRestHandler.CreatePlugin).Methods("POST")
// versioning impact handling to be done for below apis,
globalPluginRouter.Path("").
HandlerFunc(impl.globalPluginRestHandler.PatchPlugin).Methods("POST")
Expand All @@ -68,5 +69,7 @@ func (impl *GlobalPluginRouterImpl) initGlobalPluginRouter(globalPluginRouter *m

globalPluginRouter.Path("/list/tags").
HandlerFunc(impl.globalPluginRestHandler.GetAllUniqueTags).Methods("GET")
globalPluginRouter.Path("/list/v2/min").
HandlerFunc(impl.globalPluginRestHandler.GetAllPluginMinData).Methods("GET")

}
9 changes: 9 additions & 0 deletions internal/util/ErrorUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"net/http"
"strconv"
)

type ApiError struct {
Expand All @@ -36,6 +37,14 @@ type ApiError struct {
UserDetailMessage string `json:"userDetailMessage,omitempty"`
}

func GetApiError(code int, userMessage, internalMessage string) *ApiError {
return &ApiError{
HttpStatusCode: code,
Code: strconv.Itoa(code),
InternalMessage: internalMessage,
UserMessage: userMessage,
}
}
func NewApiError() *ApiError {
return &ApiError{}
}
Expand Down
Loading
Loading