Skip to content

Commit

Permalink
add security settings++
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Weber <[email protected]>
  • Loading branch information
mm-weber committed Jan 14, 2025
1 parent 9cc721b commit a704ff0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions providers/azure/resources/armsecurity.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func getPolicyAssignments(ctx context.Context, conn armSecurityConn) (PolicyAssi

// the armsecurity.NewListPager is broken, see https://github.com/Azure/azure-sdk-for-go/issues/19740.
// until it's fixed, we can fetch them manually
func getSecurityContacts(ctx context.Context, conn armSecurityConn) ([]security.Contact, error) {
func getSecurityContacts(ctx context.Context, conn armSecurityConn) ([], error) {
token, err := conn.GetToken()
if err != nil {
return []security.Contact{}, err
Expand Down Expand Up @@ -133,18 +133,18 @@ func getSecurityContacts(ctx context.Context, conn armSecurityConn) ([]security.
return result, err
}

func getMCAS(ctx context.Context, conn armSecurityConn) ([]security.Contact, error) {
func getSettingsClient(ctx context.Context, conn armSecurityConn) ([]security.SettingsClient, error) {
token, err := conn.GetToken()
if err != nil {
return []security.Contact{}, err
return []security.SettingsClient{}, err
}
urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Security/settings"
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(conn.subscriptionId))
urlPath = runtime.JoinPaths(conn.host, urlPath)
client := http.Client{}
req, err := http.NewRequest("GET", urlPath, nil)
if err != nil {
return []security.Contact{}, err
return []security.SettingsClient{}, err
}
q := req.URL.Query()
q.Set("api-version", "2021-06-01")
Expand All @@ -154,23 +154,23 @@ func getMCAS(ctx context.Context, conn armSecurityConn) ([]security.Contact, err

resp, err := client.Do(req)
if err != nil {
return []security.Contact{}, err
return []security.SettingsClient{}, err
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
return []security.Contact{}, errors.New("failed to fetch security contacts from " + urlPath + ": " + resp.Status)
return [][]security.SettingsClient{}, errors.New("failed to fetch security contacts from " + urlPath + ": " + resp.Status)
}

raw, err := io.ReadAll(resp.Body)
if err != nil {
return []security.Contact{}, err
return [][]security.SettingsClient{}, err
}
result := []security.Contact{}
result := [][]security.SettingsClient{}
err = json.Unmarshal(raw, &result)
if err != nil {
// fallback, try to unmarshal to ContactList
contactList := &security.ContactList{}
contactList := &security.SettingsList{}
err = json.Unmarshal(raw, contactList)
if err != nil {
return nil, err
Expand Down

0 comments on commit a704ff0

Please sign in to comment.