-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Identity Registration and Usage Reports (#85)
* Add support for Registration and Usage Reports * Add more tests * Prevent panic * go mod tidy * More panic fixing Co-authored-by: Mark Dordoy <[email protected]>
- Loading branch information
1 parent
cb52b72
commit 8e4b9d6
Showing
7 changed files
with
461 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package msgraph | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/manicminer/hamilton/odata" | ||
) | ||
|
||
// ReportsClient Client performs operations on reports. | ||
type ReportsClient struct { | ||
BaseClient Client | ||
} | ||
|
||
// NewReportsClient returns a new ReportsClient. | ||
func NewReportsClient(tenantId string) *ReportsClient { | ||
return &ReportsClient{ | ||
BaseClient: NewClient(VersionBeta, tenantId), | ||
} | ||
} | ||
|
||
func (c *ReportsClient) GetCredentialUserRegistrationCount(ctx context.Context, query odata.Query) (*[]CredentialUserRegistrationCount, int, error) { | ||
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ | ||
DisablePaging: query.Top > 0, | ||
ValidStatusCodes: []int{http.StatusOK}, | ||
Uri: Uri{ | ||
Entity: "/reports/getCredentialUserRegistrationCount", | ||
Params: query.Values(), | ||
HasTenantId: true, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ReportsClient.BaseClient.Get(): %v", err) | ||
} | ||
defer resp.Body.Close() | ||
respBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err) | ||
} | ||
var data struct { | ||
CredentialUserRegistrationCount []CredentialUserRegistrationCount `json:"value"` | ||
} | ||
if err := json.Unmarshal(respBody, &data); err != nil { | ||
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) | ||
} | ||
return &data.CredentialUserRegistrationCount, status, nil | ||
} | ||
|
||
func (c *ReportsClient) GetCredentialUserRegistrationDetails(ctx context.Context, query odata.Query) (*[]CredentialUserRegistrationDetails, int, error) { | ||
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ | ||
DisablePaging: query.Top > 0, | ||
ValidStatusCodes: []int{http.StatusOK}, | ||
Uri: Uri{ | ||
Entity: "/reports/credentialUserRegistrationDetails", | ||
Params: query.Values(), | ||
HasTenantId: true, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ReportsClient.BaseClient.Get(): %v", err) | ||
} | ||
defer resp.Body.Close() | ||
respBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err) | ||
} | ||
var data struct { | ||
CredentialUserRegistrationDetails []CredentialUserRegistrationDetails `json:"value"` | ||
} | ||
if err := json.Unmarshal(respBody, &data); err != nil { | ||
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) | ||
} | ||
return &data.CredentialUserRegistrationDetails, status, nil | ||
} | ||
|
||
func (c *ReportsClient) GetUserCredentialUsageDetails(ctx context.Context, query odata.Query) (*[]UserCredentialUsageDetails, int, error) { | ||
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ | ||
DisablePaging: query.Top > 0, | ||
ValidStatusCodes: []int{http.StatusOK}, | ||
Uri: Uri{ | ||
Entity: "/reports/userCredentialUsageDetails", | ||
Params: query.Values(), | ||
HasTenantId: true, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ReportsClient.BaseClient.Get(): %v", err) | ||
} | ||
defer resp.Body.Close() | ||
respBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err) | ||
} | ||
var data struct { | ||
UserCredentialUsageDetails []UserCredentialUsageDetails `json:"value"` | ||
} | ||
if err := json.Unmarshal(respBody, &data); err != nil { | ||
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) | ||
} | ||
return &data.UserCredentialUsageDetails, status, nil | ||
} | ||
|
||
func (c *ReportsClient) GetCredentialUsageSummary(ctx context.Context, period CredentialUsageSummaryPeriod, query odata.Query) (*[]CredentialUsageSummary, int, error) { | ||
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ | ||
DisablePaging: query.Top > 0, | ||
ValidStatusCodes: []int{http.StatusOK}, | ||
Uri: Uri{ | ||
Entity: fmt.Sprintf("/reports/getCredentialUsageSummary(period='%s')", period), | ||
Params: query.Values(), | ||
HasTenantId: true, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ReportsClient.BaseClient.Get(): %v", err) | ||
} | ||
defer resp.Body.Close() | ||
respBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err) | ||
} | ||
var data struct { | ||
CredentialUsageSummary []CredentialUsageSummary `json:"value"` | ||
} | ||
if err := json.Unmarshal(respBody, &data); err != nil { | ||
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) | ||
} | ||
return &data.CredentialUsageSummary, status, nil | ||
} | ||
|
||
func (c *ReportsClient) GetAuthenticationMethodsUsersRegisteredByFeature(ctx context.Context, query odata.Query) (*UserRegistrationFeatureSummary, int, error) { | ||
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ | ||
DisablePaging: query.Top > 0, | ||
ValidStatusCodes: []int{http.StatusOK}, | ||
Uri: Uri{ | ||
Entity: "/reports/authenticationMethods/usersRegisteredByFeature", | ||
Params: query.Values(), | ||
HasTenantId: true, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ReportsClient.BaseClient.Get(): %v", err) | ||
} | ||
defer resp.Body.Close() | ||
respBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err) | ||
} | ||
|
||
var userRegistrationFeatureSummary UserRegistrationFeatureSummary | ||
|
||
if err := json.Unmarshal(respBody, &userRegistrationFeatureSummary); err != nil { | ||
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) | ||
} | ||
return &userRegistrationFeatureSummary, status, nil | ||
} | ||
|
||
func (c *ReportsClient) GetAuthenticationMethodsUsersRegisteredByMethod(ctx context.Context, query odata.Query) (*UserRegistrationMethodSummary, int, error) { | ||
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ | ||
DisablePaging: query.Top > 0, | ||
ValidStatusCodes: []int{http.StatusOK}, | ||
Uri: Uri{ | ||
Entity: "/reports/authenticationMethods/usersRegisteredByMethod", | ||
Params: query.Values(), | ||
HasTenantId: true, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ReportsClient.BaseClient.Get(): %v", err) | ||
} | ||
defer resp.Body.Close() | ||
respBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err) | ||
} | ||
|
||
var userRegistrationMethodSummary UserRegistrationMethodSummary | ||
|
||
if err := json.Unmarshal(respBody, &userRegistrationMethodSummary); err != nil { | ||
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) | ||
} | ||
return &userRegistrationMethodSummary, status, nil | ||
} |
Oops, something went wrong.