Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

# -*- coding: utf-8 -*- 

# Copyright: (c) 2021, XLAB Steampunk <steampunk@xlab.si> 

# 

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 

 

from __future__ import absolute_import, division, print_function 

 

__metaclass__ = type 

 

from ansible.module_utils.basic import env_fallback 

 

INCIDENT_MAPPING_SPEC = dict( 

type="dict", 

required=False, 

options=dict( 

state=dict(type="dict"), 

hold_reason=dict(type="dict"), 

impact=dict(type="dict"), 

urgency=dict(type="dict"), 

), 

) 

 

CHANGE_REQUEST_MAPPING_SPEC = dict( 

type="dict", 

required=False, 

options=dict( 

priority=dict(type="dict"), 

risk=dict(type="dict"), 

impact=dict(type="dict"), 

urgency=dict(type="dict"), 

state=dict(type="dict"), 

), 

) 

 

 

CHANGE_REQUEST_TASK_MAPPING_SPEC = dict( 

type="dict", 

required=False, 

options=dict( 

state=dict(type="dict"), 

), 

) 

 

 

CONFIGURATION_ITEM_MAPPING_SPEC = dict( 

type="dict", 

required=False, 

options=dict( 

environment=dict(type="dict"), 

install_status=dict(type="dict"), 

operational_status=dict(type="dict"), 

), 

) 

 

PROBLEM_MAPPING_SPEC = dict( 

type="dict", 

required=False, 

options=dict( 

impact=dict(type="dict"), 

urgency=dict(type="dict"), 

problem_state=dict(type="dict"), 

state=dict(type="dict"), 

), 

) 

 

PROBLEM_TASK_MAPPING_SPEC = dict( 

type="dict", 

required=False, 

options=dict( 

state=dict(type="dict"), 

priority=dict(type="dict"), 

), 

) 

 

SHARED_SPECS = dict( 

instance=dict( 

type="dict", 

apply_defaults=True, 

options=dict( 

host=dict( 

type="str", 

required=True, 

fallback=(env_fallback, ["SN_HOST"]), 

), 

username=dict( 

type="str", 

fallback=(env_fallback, ["SN_USERNAME"]), 

), 

password=dict( 

type="str", 

no_log=True, 

fallback=(env_fallback, ["SN_PASSWORD"]), 

), 

grant_type=dict( 

type="str", 

choices=["password", "refresh_token"], 

fallback=(env_fallback, ["SN_GRANT_TYPE"]), 

), 

api_path=dict( 

type="str", 

default="api/now", 

), 

client_id=dict( 

type="str", 

fallback=(env_fallback, ["SN_CLIENT_ID"]), 

), 

client_secret=dict( 

type="str", 

no_log=True, 

fallback=(env_fallback, ["SN_CLIENT_SECRET"]), 

), 

custom_headers=dict( 

type="dict" 

), 

refresh_token=dict( 

type="str", 

no_log=True, 

fallback=(env_fallback, ["SN_REFRESH_TOKEN"]), 

), 

access_token=dict( 

type="str", 

no_log=True, 

fallback=(env_fallback, ["SN_ACCESS_TOKEN"]), 

), 

timeout=dict( 

type="float", 

fallback=(env_fallback, ["SN_TIMEOUT"]), 

), 

validate_certs=dict( 

type="bool", 

default=True, 

), 

), 

required_together=[("client_id", "client_secret"), ("username", "password")], 

required_one_of=[("username", "refresh_token", "access_token")], 

mutually_exclusive=[ 

("username", "refresh_token", "access_token"), 

("client_id", "access_token"), 

("grant_type", "access_token"), 

], 

required_if=[ 

("grant_type", "password", ("username", "password")), 

("grant_type", "refresh_token", ("refresh_token",)), 

], 

), 

sys_id=dict(type="str"), 

number=dict(type="str"), 

query=dict(type="list", elements="dict"), 

sysparm_query=dict( 

type="str", 

fallback=(env_fallback, ["SN_SYSPARM_QUERY"]), 

), 

attachments=dict( 

type="list", 

elements="dict", 

options=dict( 

path=dict( 

type="str", 

required=True, 

), 

name=dict( 

type="str", 

), 

type=dict( 

type="str", 

), 

), 

), 

sysparm_display_value=dict( 

type="str", 

choices=[ 

"true", 

"false", 

"all", 

], 

default="false", 

), 

incident_mapping=INCIDENT_MAPPING_SPEC, 

change_request_mapping=CHANGE_REQUEST_MAPPING_SPEC, 

change_request_task_mapping=CHANGE_REQUEST_TASK_MAPPING_SPEC, 

configuration_item_mapping=CONFIGURATION_ITEM_MAPPING_SPEC, 

problem_mapping=PROBLEM_MAPPING_SPEC, 

problem_task_mapping=PROBLEM_TASK_MAPPING_SPEC, 

) 

 

 

def get_spec(*param_names): 

return dict((p, SHARED_SPECS[p]) for p in param_names)