Skip to content

Commit

Permalink
chore: revert to last known good commit
Browse files Browse the repository at this point in the history
chore: keep SendAny improvement and remove the unnecessary type casting
  • Loading branch information
superlinkx committed Nov 7, 2023
1 parent de2394d commit e433482
Show file tree
Hide file tree
Showing 83 changed files with 487 additions and 378 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewClient(config config.Config) (AzureClient, error) {
}
}

func initClientViaRM(msgraph, resourceManager rest.RestClient, tid any) (AzureClient, error) {
func initClientViaRM(msgraph, resourceManager rest.RestClient, tid interface{}) (AzureClient, error) {
client := &azureClient{
msgraph: msgraph,
resourceManager: resourceManager,
Expand Down
130 changes: 65 additions & 65 deletions client/mocks/client.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions client/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import (

type RestClient interface {
Authenticate() error
Delete(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Delete(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Get(ctx context.Context, path string, params, headers map[string]string) (*http.Response, error)
Patch(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Post(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Put(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error)
Patch(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Post(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Put(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error)
Send(req *http.Request) (*http.Response, error)
CloseIdleConnections()
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (s *restClient) Authenticate() error {
}
}

func (s *restClient) Delete(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Delete(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodDelete, endpoint, body, params, headers); err != nil {
return nil, err
Expand All @@ -173,7 +173,7 @@ func (s *restClient) Get(ctx context.Context, path string, params, headers map[s
}
}

func (s *restClient) Patch(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Patch(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodPatch, endpoint, body, params, headers); err != nil {
return nil, err
Expand All @@ -182,7 +182,7 @@ func (s *restClient) Patch(ctx context.Context, path string, body any, params, h
}
}

func (s *restClient) Post(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Post(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodPost, endpoint, body, params, headers); err != nil {
return nil, err
Expand All @@ -191,7 +191,7 @@ func (s *restClient) Post(ctx context.Context, path string, body any, params, he
}
}

func (s *restClient) Put(ctx context.Context, path string, body any, params, headers map[string]string) (*http.Response, error) {
func (s *restClient) Put(ctx context.Context, path string, body interface{}, params, headers map[string]string) (*http.Response, error) {
endpoint := s.api.ResolveReference(&url.URL{Path: path})
if req, err := NewRequest(ctx, http.MethodPost, endpoint, body, params, headers); err != nil {
return nil, err
Expand Down Expand Up @@ -275,7 +275,7 @@ func (s *restClient) send(req *http.Request) (*http.Response, error) {
continue
} else {
// Not a status code that warrants a retry
var errRes map[string]any
var errRes map[string]interface{}
if err := Decode(res.Body, &errRes); err != nil {
return nil, fmt.Errorf("malformed error response, status code: %d", res.StatusCode)
} else {
Expand Down
2 changes: 1 addition & 1 deletion client/rest/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewRequest(
ctx context.Context,
verb string,
endpoint *url.URL,
body any,
body interface{},
params map[string]string,
headers map[string]string,
) (*http.Request, error) {
Expand Down
20 changes: 10 additions & 10 deletions client/rest/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions client/rest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/youmark/pkcs8"
)

func Decode(body io.ReadCloser, v any) error {
func Decode(body io.ReadCloser, v interface{}) error {
defer body.Close()
defer io.ReadAll(body) // must read all; streaming to the json decoder does not read to EOF making the connection unavailable for reuse
return json.NewDecoder(body).Decode(v)
Expand All @@ -59,7 +59,7 @@ func NewClientAssertion(tokenUrl string, clientId string, clientCert string, sig
IssuedAt: iat.Unix(),
})

token.Header = map[string]any{
token.Header = map[string]interface{}{
"alg": "RS256",
"typ": "JWT",
"x5t": thumbprint,
Expand All @@ -73,9 +73,9 @@ func NewClientAssertion(tokenUrl string, clientId string, clientCert string, sig
}
}

func ParseBody(accessToken string) (map[string]any, error) {
func ParseBody(accessToken string) (map[string]interface{}, error) {
var (
body = make(map[string]any)
body = make(map[string]interface{})
parts = strings.Split(accessToken, ".")
)

Expand All @@ -100,7 +100,7 @@ func ParseAud(accessToken string) (string, error) {
}
}

func parseRSAPrivateKey(signingKey string, password string) (any, error) {
func parseRSAPrivateKey(signingKey string, password string) (interface{}, error) {
if decodedBlock, _ := pem.Decode([]byte(signingKey)); decodedBlock == nil {
return nil, fmt.Errorf("Unable to decode private key")
} else if key, _, err := pkcs8.ParsePrivateKey(decodedBlock.Bytes, []byte(password)); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions cmd/list-app-role-assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func listAppRoleAssignmentsCmdImpl(cmd *cobra.Command, args []string) {
log.Info("collection completed", "duration", duration.String())
}

func listAppRoleAssignments(ctx context.Context, client client.AzureClient, servicePrincipals <-chan any) <-chan any {
func listAppRoleAssignments(ctx context.Context, client client.AzureClient, servicePrincipals <-chan interface{}) <-chan interface{} {
var (
out = make(chan any)
out = make(chan interface{})
filteredSPs = make(chan models.ServicePrincipal)
streams = pipeline.Demux(ctx.Done(), filteredSPs, 25)
wg sync.WaitGroup
Expand Down Expand Up @@ -98,13 +98,14 @@ func listAppRoleAssignments(ctx context.Context, client client.AzureClient, serv
} else {
log.V(2).Info("found app role assignment", "roleAssignments", item)
count++
if ok := pipeline.SendAny(ctx.Done(), out, NewAzureWrapper(
enums.KindAZAppRoleAssignment,
models.AppRoleAssignment{
if ok := pipeline.SendAny(ctx.Done(), out, AzureWrapper{
Kind: enums.KindAZAppRoleAssignment,
Data: models.AppRoleAssignment{
AppRoleAssignment: item.Ok,
AppId: servicePrincipal.AppId,
TenantId: client.TenantInfo().TenantId,
})); !ok {
},
}); !ok {
return
}
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/list-automation-account-role-assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func listAutomationAccountRoleAssignmentImpl(cmd *cobra.Command, args []string)
log.Info("collection completed", "duration", duration.String())
}

func listAutomationAccountRoleAssignments(ctx context.Context, client client.AzureClient, automationAccounts <-chan any) <-chan any {
func listAutomationAccountRoleAssignments(ctx context.Context, client client.AzureClient, automationAccounts <-chan interface{}) <-chan interface{} {
var (
out = make(chan any)
out = make(chan interface{})
ids = make(chan string)
streams = pipeline.Demux(ctx.Done(), ids, 25)
wg sync.WaitGroup
Expand Down Expand Up @@ -110,7 +110,10 @@ func listAutomationAccountRoleAssignments(ctx context.Context, client client.Azu
automationAccountRoleAssignments.RoleAssignments = append(automationAccountRoleAssignments.RoleAssignments, automationAccountRoleAssignment)
}
}
if ok := pipeline.SendAny(ctx.Done(), out, NewAzureWrapper(enums.KindAZAutomationAccountRoleAssignment, automationAccountRoleAssignments)); !ok {
if ok := pipeline.SendAny(ctx.Done(), out, AzureWrapper{
Kind: enums.KindAZAutomationAccountRoleAssignment,
Data: automationAccountRoleAssignments,
}); !ok {
return
}
log.V(1).Info("finished listing automation account role assignments", "automationAccountId", id, "count", count)
Expand Down
9 changes: 6 additions & 3 deletions cmd/list-automation-accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func listAutomationAccountsCmdImpl(cmd *cobra.Command, args []string) {
log.Info("collection completed", "duration", duration.String())
}

func listAutomationAccounts(ctx context.Context, client client.AzureClient, subscriptions <-chan any) <-chan any {
func listAutomationAccounts(ctx context.Context, client client.AzureClient, subscriptions <-chan interface{}) <-chan interface{} {
var (
out = make(chan any)
out = make(chan interface{})
ids = make(chan string)
streams = pipeline.Demux(ctx.Done(), ids, 25)
wg sync.WaitGroup
Expand Down Expand Up @@ -99,7 +99,10 @@ func listAutomationAccounts(ctx context.Context, client client.AzureClient, subs
}
log.V(2).Info("found automation account", "automationAccount", automationAccount)
count++
if ok := pipeline.SendAny(ctx.Done(), out, NewAzureWrapper(enums.KindAZAutomationAccount, automationAccount)); !ok {
if ok := pipeline.SendAny(ctx.Done(), out, AzureWrapper{
Kind: enums.KindAZAutomationAccount,
Data: automationAccount,
}); !ok {
return
}
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/list-azure-ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ func listAzureADCmdImpl(cmd *cobra.Command, args []string) {
log.Info("collection completed", "duration", duration.String())
}

func listAllAD(ctx context.Context, client client.AzureClient) <-chan any {
func listAllAD(ctx context.Context, client client.AzureClient) <-chan interface{} {
var (
devices = make(chan any)
devices2 = make(chan any)
devices = make(chan interface{})
devices2 = make(chan interface{})

groups = make(chan any)
groups2 = make(chan any)
groups3 = make(chan any)
groups = make(chan interface{})
groups2 = make(chan interface{})
groups3 = make(chan interface{})

roles = make(chan any)
roles2 = make(chan any)
roles = make(chan interface{})
roles2 = make(chan interface{})

servicePrincipals = make(chan any)
servicePrincipals2 = make(chan any)
servicePrincipals3 = make(chan any)
servicePrincipals = make(chan interface{})
servicePrincipals2 = make(chan interface{})
servicePrincipals3 = make(chan interface{})

tenants = make(chan any)
tenants = make(chan interface{})
)

// Enumerate Apps, AppOwners and AppMembers
Expand Down
Loading

0 comments on commit e433482

Please sign in to comment.