2019-02-21 16:58:25 +00:00
|
|
|
// Copyright 2019 Sorint.lab
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-05-03 21:48:49 +00:00
|
|
|
package action
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
import (
|
2019-04-09 12:53:00 +00:00
|
|
|
"net/http"
|
|
|
|
|
2019-07-01 09:40:20 +00:00
|
|
|
"agola.io/agola/internal/services/common"
|
|
|
|
"agola.io/agola/internal/util"
|
2019-07-31 13:39:07 +00:00
|
|
|
csclient "agola.io/agola/services/configstore/client"
|
|
|
|
rsclient "agola.io/agola/services/runservice/client"
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2019-05-03 21:48:49 +00:00
|
|
|
type ActionHandler struct {
|
2019-02-21 16:58:25 +00:00
|
|
|
log *zap.SugaredLogger
|
|
|
|
sd *common.TokenSigningData
|
2019-07-31 13:39:07 +00:00
|
|
|
configstoreClient *csclient.Client
|
|
|
|
runserviceClient *rsclient.Client
|
2019-04-30 10:13:12 +00:00
|
|
|
agolaID string
|
2019-02-21 16:58:25 +00:00
|
|
|
apiExposedURL string
|
|
|
|
webExposedURL string
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func NewActionHandler(logger *zap.Logger, sd *common.TokenSigningData, configstoreClient *csclient.Client, runserviceClient *rsclient.Client, agolaID, apiExposedURL, webExposedURL string) *ActionHandler {
|
2019-05-03 21:48:49 +00:00
|
|
|
return &ActionHandler{
|
2019-02-21 16:58:25 +00:00
|
|
|
log: logger.Sugar(),
|
|
|
|
sd: sd,
|
|
|
|
configstoreClient: configstoreClient,
|
2019-05-05 22:00:45 +00:00
|
|
|
runserviceClient: runserviceClient,
|
2019-04-30 10:13:12 +00:00
|
|
|
agolaID: agolaID,
|
2019-02-21 16:58:25 +00:00
|
|
|
apiExposedURL: apiExposedURL,
|
|
|
|
webExposedURL: webExposedURL,
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 12:53:00 +00:00
|
|
|
|
|
|
|
func ErrFromRemote(resp *http.Response, err error) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp != nil {
|
|
|
|
switch resp.StatusCode {
|
|
|
|
case http.StatusBadRequest:
|
2019-05-23 09:23:14 +00:00
|
|
|
return util.NewErrBadRequest(err)
|
2019-04-09 12:53:00 +00:00
|
|
|
case http.StatusNotFound:
|
2019-11-06 12:29:42 +00:00
|
|
|
return util.NewErrNotExist(err)
|
2019-04-09 12:53:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|