Skip to content

Commit

Permalink
GATE-2293 added teams logging settings to api
Browse files Browse the repository at this point in the history
  • Loading branch information
Rex Scaria committed Jan 11, 2022
1 parent b138cfa commit 726d78d
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 5 deletions.
78 changes: 73 additions & 5 deletions teams_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ type TeamsConfiguration struct {
}

type TeamsAccountSettings struct {
Antivirus *TeamsAntivirus `json:"antivirus,omitempty"`
TLSDecrypt *TeamsTLSDecrypt `json:"tls_decrypt,omitempty"`
ActivityLog *TeamsActivityLog `json:"activity_log,omitempty"`
BlockPage *TeamsBlockPage `json:"block_page,omitempty"`
FIPS *TeamsFIPS `json:"fips,omitempty"`
Antivirus *TeamsAntivirus `json:"antivirus,omitempty"`
TLSDecrypt *TeamsTLSDecrypt `json:"tls_decrypt,omitempty"`
ActivityLog *TeamsActivityLog `json:"activity_log,omitempty"`
BlockPage *TeamsBlockPage `json:"block_page,omitempty"`
BrowserIsolation *BrowserIsolation `json:"browser_isolation,omitempty"`
FIPS *TeamsFIPS `json:"fips,omitempty"`
}

type BrowserIsolation struct {
UrlBrowserIsolationEnabled bool `json:"url_browser_isolation_enabled"`
}

type TeamsAntivirus struct {
Expand Down Expand Up @@ -72,6 +77,29 @@ type TeamsBlockPage struct {
Name string `json:"name,omitempty"`
}

type TeamsRuleType = string

const (
TeamsHttpRuleType TeamsRuleType = "http"
TeamsDnsRuleType TeamsRuleType = "dns"
TeamsL4RuleType TeamsRuleType = "l4"
)

type TeamsAccountLoggingConfiguration struct {
LogAll bool `json:"log_all"`
LogBlocks bool `json:"log_blocks"`
}

type TeamsLoggingSettings struct {
LoggingSettingsByRuleType map[TeamsRuleType]TeamsAccountLoggingConfiguration `json:"settings_by_rule_type"`
RedactPii bool `json:"redact_pii,omitempty"`
}

type TeamsLoggingSettingsResponse struct {
Response
Result TeamsLoggingSettings `json:"result"`
}

// TeamsAccount returns teams account information with internal and external ID.
//
// API reference: TBA.
Expand Down Expand Up @@ -112,6 +140,26 @@ func (api *API) TeamsAccountConfiguration(ctx context.Context, accountID string)
return teamsConfigResponse.Result, nil
}

// TeamsAccountLoggingConfiguration returns teams account logging configuration.
//
// API reference: TBA.
func (api *API) TeamsAccountLoggingConfiguration(ctx context.Context, accountID string) (TeamsLoggingSettings, error) {
uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID)

res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return TeamsLoggingSettings{}, err
}

var teamsConfigResponse TeamsLoggingSettingsResponse
err = json.Unmarshal(res, &teamsConfigResponse)
if err != nil {
return TeamsLoggingSettings{}, errors.Wrap(err, errUnmarshalError)
}

return teamsConfigResponse.Result, nil
}

// TeamsAccountUpdateConfiguration updates a teams account configuration.
//
// API reference: TBA.
Expand All @@ -131,3 +179,23 @@ func (api *API) TeamsAccountUpdateConfiguration(ctx context.Context, accountID s

return teamsConfigResponse.Result, nil
}

// TeamsAccountUpdateLoggingConfiguration updates the log settings and returns new teams account logging configuration.
//
// API reference: TBA.
func (api *API) TeamsAccountUpdateLoggingConfiguration(ctx context.Context, accountID string, config TeamsLoggingSettings) (TeamsLoggingSettings, error) {
uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID)

res, err := api.makeRequestContext(ctx, http.MethodPut, uri, config)
if err != nil {
return TeamsLoggingSettings{}, err
}

var teamsConfigResponse TeamsLoggingSettingsResponse
err = json.Unmarshal(res, &teamsConfigResponse)
if err != nil {
return TeamsLoggingSettings{}, errors.Wrap(err, errUnmarshalError)
}

return teamsConfigResponse.Result, nil
}
74 changes: 74 additions & 0 deletions teams_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,77 @@ func TestTeamsAccountUpdateConfiguration(t *testing.T) {
assert.Equal(t, actual, configuration)
}
}

func TestTeamsAccountGetLoggingConfiguration(t *testing.T) {
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {"settings_by_rule_type":{"dns":{"log_all":false,"log_blocks":true}},"redact_pii":true}
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/gateway/logging", handler)

actual, err := client.TeamsAccountLoggingConfiguration(context.Background(), testAccountID)

if assert.NoError(t, err) {
assert.Equal(t, actual, TeamsLoggingSettings{
RedactPii: true,
LoggingSettingsByRuleType: map[TeamsRuleType]TeamsAccountLoggingConfiguration{
TeamsDnsRuleType: {LogAll: false, LogBlocks: true},
},
})
}
}

func TestTeamsAccountUpdateLoggingConfiguration(t *testing.T) {
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
"errors": [],
"messages": [],
"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}
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/gateway/logging", handler)

actual, err := client.TeamsAccountUpdateLoggingConfiguration(context.Background(), testAccountID, TeamsLoggingSettings{
RedactPii: true,
LoggingSettingsByRuleType: map[TeamsRuleType]TeamsAccountLoggingConfiguration{
TeamsDnsRuleType: {
LogAll: false,
LogBlocks: true,
},
TeamsHttpRuleType: {
LogAll: true,
},
TeamsL4RuleType: {
LogBlocks: true,
},
},
})

if assert.NoError(t, err) {
assert.Equal(t, actual, TeamsLoggingSettings{
RedactPii: true,
LoggingSettingsByRuleType: map[TeamsRuleType]TeamsAccountLoggingConfiguration{
TeamsDnsRuleType: {LogAll: false, LogBlocks: true},
TeamsHttpRuleType: {LogAll: true, LogBlocks: false},
TeamsL4RuleType: {LogAll: false, LogBlocks: true},
},
})
}
}

0 comments on commit 726d78d

Please sign in to comment.