Skip to content

Commit 3c8eda9

Browse files
authored
Merge pull request #769 from rexscaria/rex/GATE-2293-added-teams-logging
GATE-2293 added teams logging settings to api
2 parents b138cfa + 726d78d commit 3c8eda9

File tree

2 files changed

+147
-5
lines changed

2 files changed

+147
-5
lines changed

teams_accounts.go

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ type TeamsConfiguration struct {
3838
}
3939

4040
type TeamsAccountSettings struct {
41-
Antivirus *TeamsAntivirus `json:"antivirus,omitempty"`
42-
TLSDecrypt *TeamsTLSDecrypt `json:"tls_decrypt,omitempty"`
43-
ActivityLog *TeamsActivityLog `json:"activity_log,omitempty"`
44-
BlockPage *TeamsBlockPage `json:"block_page,omitempty"`
45-
FIPS *TeamsFIPS `json:"fips,omitempty"`
41+
Antivirus *TeamsAntivirus `json:"antivirus,omitempty"`
42+
TLSDecrypt *TeamsTLSDecrypt `json:"tls_decrypt,omitempty"`
43+
ActivityLog *TeamsActivityLog `json:"activity_log,omitempty"`
44+
BlockPage *TeamsBlockPage `json:"block_page,omitempty"`
45+
BrowserIsolation *BrowserIsolation `json:"browser_isolation,omitempty"`
46+
FIPS *TeamsFIPS `json:"fips,omitempty"`
47+
}
48+
49+
type BrowserIsolation struct {
50+
UrlBrowserIsolationEnabled bool `json:"url_browser_isolation_enabled"`
4651
}
4752

4853
type TeamsAntivirus struct {
@@ -72,6 +77,29 @@ type TeamsBlockPage struct {
7277
Name string `json:"name,omitempty"`
7378
}
7479

80+
type TeamsRuleType = string
81+
82+
const (
83+
TeamsHttpRuleType TeamsRuleType = "http"
84+
TeamsDnsRuleType TeamsRuleType = "dns"
85+
TeamsL4RuleType TeamsRuleType = "l4"
86+
)
87+
88+
type TeamsAccountLoggingConfiguration struct {
89+
LogAll bool `json:"log_all"`
90+
LogBlocks bool `json:"log_blocks"`
91+
}
92+
93+
type TeamsLoggingSettings struct {
94+
LoggingSettingsByRuleType map[TeamsRuleType]TeamsAccountLoggingConfiguration `json:"settings_by_rule_type"`
95+
RedactPii bool `json:"redact_pii,omitempty"`
96+
}
97+
98+
type TeamsLoggingSettingsResponse struct {
99+
Response
100+
Result TeamsLoggingSettings `json:"result"`
101+
}
102+
75103
// TeamsAccount returns teams account information with internal and external ID.
76104
//
77105
// API reference: TBA.
@@ -112,6 +140,26 @@ func (api *API) TeamsAccountConfiguration(ctx context.Context, accountID string)
112140
return teamsConfigResponse.Result, nil
113141
}
114142

143+
// TeamsAccountLoggingConfiguration returns teams account logging configuration.
144+
//
145+
// API reference: TBA.
146+
func (api *API) TeamsAccountLoggingConfiguration(ctx context.Context, accountID string) (TeamsLoggingSettings, error) {
147+
uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID)
148+
149+
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
150+
if err != nil {
151+
return TeamsLoggingSettings{}, err
152+
}
153+
154+
var teamsConfigResponse TeamsLoggingSettingsResponse
155+
err = json.Unmarshal(res, &teamsConfigResponse)
156+
if err != nil {
157+
return TeamsLoggingSettings{}, errors.Wrap(err, errUnmarshalError)
158+
}
159+
160+
return teamsConfigResponse.Result, nil
161+
}
162+
115163
// TeamsAccountUpdateConfiguration updates a teams account configuration.
116164
//
117165
// API reference: TBA.
@@ -131,3 +179,23 @@ func (api *API) TeamsAccountUpdateConfiguration(ctx context.Context, accountID s
131179

132180
return teamsConfigResponse.Result, nil
133181
}
182+
183+
// TeamsAccountUpdateLoggingConfiguration updates the log settings and returns new teams account logging configuration.
184+
//
185+
// API reference: TBA.
186+
func (api *API) TeamsAccountUpdateLoggingConfiguration(ctx context.Context, accountID string, config TeamsLoggingSettings) (TeamsLoggingSettings, error) {
187+
uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID)
188+
189+
res, err := api.makeRequestContext(ctx, http.MethodPut, uri, config)
190+
if err != nil {
191+
return TeamsLoggingSettings{}, err
192+
}
193+
194+
var teamsConfigResponse TeamsLoggingSettingsResponse
195+
err = json.Unmarshal(res, &teamsConfigResponse)
196+
if err != nil {
197+
return TeamsLoggingSettings{}, errors.Wrap(err, errUnmarshalError)
198+
}
199+
200+
return teamsConfigResponse.Result, nil
201+
}

teams_accounts_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,77 @@ func TestTeamsAccountUpdateConfiguration(t *testing.T) {
130130
assert.Equal(t, actual, configuration)
131131
}
132132
}
133+
134+
func TestTeamsAccountGetLoggingConfiguration(t *testing.T) {
135+
setup()
136+
defer teardown()
137+
138+
handler := func(w http.ResponseWriter, r *http.Request) {
139+
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
140+
w.Header().Set("content-type", "application/json")
141+
fmt.Fprintf(w, `{
142+
"success": true,
143+
"errors": [],
144+
"messages": [],
145+
"result": {"settings_by_rule_type":{"dns":{"log_all":false,"log_blocks":true}},"redact_pii":true}
146+
}`)
147+
}
148+
149+
mux.HandleFunc("/accounts/"+testAccountID+"/gateway/logging", handler)
150+
151+
actual, err := client.TeamsAccountLoggingConfiguration(context.Background(), testAccountID)
152+
153+
if assert.NoError(t, err) {
154+
assert.Equal(t, actual, TeamsLoggingSettings{
155+
RedactPii: true,
156+
LoggingSettingsByRuleType: map[TeamsRuleType]TeamsAccountLoggingConfiguration{
157+
TeamsDnsRuleType: {LogAll: false, LogBlocks: true},
158+
},
159+
})
160+
}
161+
}
162+
163+
func TestTeamsAccountUpdateLoggingConfiguration(t *testing.T) {
164+
setup()
165+
defer teardown()
166+
167+
handler := func(w http.ResponseWriter, r *http.Request) {
168+
assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method)
169+
w.Header().Set("content-type", "application/json")
170+
fmt.Fprintf(w, `{
171+
"success": true,
172+
"errors": [],
173+
"messages": [],
174+
"result": {"settings_by_rule_type":{"dns":{"log_all":false,"log_blocks":true}, "http":{"log_all":true,"log_blocks":false}, "l4": {"log_all": false, "log_blocks": true}},"redact_pii":true}
175+
}`)
176+
}
177+
178+
mux.HandleFunc("/accounts/"+testAccountID+"/gateway/logging", handler)
179+
180+
actual, err := client.TeamsAccountUpdateLoggingConfiguration(context.Background(), testAccountID, TeamsLoggingSettings{
181+
RedactPii: true,
182+
LoggingSettingsByRuleType: map[TeamsRuleType]TeamsAccountLoggingConfiguration{
183+
TeamsDnsRuleType: {
184+
LogAll: false,
185+
LogBlocks: true,
186+
},
187+
TeamsHttpRuleType: {
188+
LogAll: true,
189+
},
190+
TeamsL4RuleType: {
191+
LogBlocks: true,
192+
},
193+
},
194+
})
195+
196+
if assert.NoError(t, err) {
197+
assert.Equal(t, actual, TeamsLoggingSettings{
198+
RedactPii: true,
199+
LoggingSettingsByRuleType: map[TeamsRuleType]TeamsAccountLoggingConfiguration{
200+
TeamsDnsRuleType: {LogAll: false, LogBlocks: true},
201+
TeamsHttpRuleType: {LogAll: true, LogBlocks: false},
202+
TeamsL4RuleType: {LogAll: false, LogBlocks: true},
203+
},
204+
})
205+
}
206+
}

0 commit comments

Comments
 (0)