-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.go
65 lines (51 loc) · 2.19 KB
/
views.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
65
package messenger
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/perkbox/cloud-access-bot/internal"
"github.com/sirupsen/logrus"
"github.com/slack-go/slack"
)
func GetRequestAccessModal(tmplVals Template) (slack.ModalViewRequest, error) {
tmplVals.TimeInputID = TimeInputID
tmplVals.AccountSelectorId = AccountSelectorActionId
tmplVals.ServiceActionId = IamServicesSelectorActionID
tmplVals.ActionsActionId = IamServiceActionSelectorActionID
tmplVals.LoginRoleSelectorId = LoginRoleSelector
tmplVals.RequestDescriptionId = RequestDescriptionId
tmplVals.ActionsBlockId = fmt.Sprintf("%s:%s", IamServiceActionSelectorActionID, tmplVals.SelectedService)
tmplVals.ResourcesActionId = IamResourcesSelectorActionID
tmplVals.ResourcesBlockId = fmt.Sprintf("%s:%s", IamResourcesSelectorActionID, tmplVals.SelectedService)
tmpl, _ := renderTemplate(slashCommandAssets, "assets/acessmodal.json", tmplVals)
str, err := ioutil.ReadAll(&tmpl)
if err != nil {
logrus.Errorf(err.Error())
}
view := slack.ModalViewRequest{}
err = json.Unmarshal(str, &view)
if err != nil {
return slack.ModalViewRequest{}, fmt.Errorf("func:GetRequestAccessModal: error marshalling access modeal view.. %s", err.Error())
}
return view, nil
}
func GetRequestApprovalBlocks(auditObj internal.AuditObject, gotResponse bool, responseMSG string) ([]slack.Block, error) {
approvalTmplVals := auditObjtoApprovalBlockVars(auditObj)
approvalTmplVals.GotResponse = gotResponse
approvalTmplVals.ResponseMSG = responseMSG
tmpl, err := renderTemplate(slashCommandAssets, "assets/requestapproval.json", approvalTmplVals)
if err != nil {
return nil, fmt.Errorf("func:GetRequestApprovalBlocks: error rending template for approval messages err: %s", err.Error())
}
// we convert the view into a message struct
view := slack.Msg{}
str, err := ioutil.ReadAll(&tmpl)
if err != nil {
return nil, fmt.Errorf("func:GetRequestApprovalBlocks: error reading processed approval msg template err: %s", err.Error())
}
err = json.Unmarshal(str, &view)
if err != nil {
return nil, fmt.Errorf("GetRequestApprovalBlocks: error umarhsalling approval msg into slack.Block err: %s", err.Error())
}
return view.Blocks.BlockSet, nil
}