/
check_access.go
64 lines (60 loc) · 2.19 KB
/
check_access.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package executionService
// TODO: automation_id isn't important for plan manager and should be deleted from CheckAccess function
func (manager *executionManager) CheckAccess(accountId string, excutionId int) (bool, error) {
// NOTE: currently we ignore limitation because body of this request should change based on project type
// dt := automationDto{AccountId: accountId, AutomationId: strconv.Itoa(excutionId)}
// json_data, err := json.Marshal(dt)
// if err != nil {
// return false, errors.New("bad input body")
// }
// token, err := utils.GeneratToken()
// if err != nil {
// return false, err
// }
// Requestheaders := []utils.Header{
// {
// Key: "Authorization",
// Value: token,
// },
// {
// Key: "Content-Type",
// Value: "application/json",
// },
// }
// httpHelper := utils.NewHttpHelper(utils.NewHttpClient())
// out, err, status, _ := httpHelper.HttpRequest(http.MethodPost, config.Configs.Endpoints.Admin+"/internal/user/access/executionMinutes", bytes.NewBuffer(json_data), Requestheaders, time.Minute, true)
// if err != nil {
// return false, err
// }
// //fmt.Println(string(out))
// if status != http.StatusOK && status != http.StatusAccepted {
// logrus.Println(string(out))
// return false, errors.New("not ok with status: " + strconv.Itoa(status))
// }
// var res struct {
// Access bool `json:"access"`
// }
// if err := json.Unmarshal(out, &res); err != nil {
// return false, err
// }
// if !res.Access {
// return false, nil
// }
// out, err, status, _ = httpHelper.HttpRequest(http.MethodPost, config.Configs.Endpoints.Admin+"/internal/user/access/executionTasks", bytes.NewBuffer(json_data), Requestheaders, time.Minute, true)
// if err != nil {
// return false, err
// }
// if status != http.StatusOK && status != http.StatusAccepted {
// logrus.Println(string(out))
// return false, errors.New("not ok with status: " + strconv.Itoa(status))
// }
// if err := json.Unmarshal(out, &res); err != nil {
// return false, err
// }
// return res.Access, nil
return true, nil
}
type automationDto struct {
AccountId string `json:"account_id" binding:"required"`
AutomationId string `json:"automation_id" binding:"required"`
}