Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AgentResolver #40

Merged
merged 21 commits into from
Feb 6, 2024
Merged

add AgentResolver #40

merged 21 commits into from
Feb 6, 2024

Conversation

volodymyr-basiuk
Copy link
Contributor

No description provided.

}

// AgentResolverConfig options for credential status verification
type AgentResolverConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use an options pattern? Or if it required field pass the PackageManager directly to NewAgentResolver constructor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it looks like you missed our discussions

return out, errors.WithStack(err)
}

idUUID, err := uuid.NewV4()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use github.com/google/uuid to generate uuid

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return out, errors.WithStack(err)
}

resp, err := http.DefaultClient.Post(status.ID, "application/json", bytes.NewBuffer(iden3commMsg))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass the http client as option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


agentResolver := NewAgentResolver(agentConfig)

httpmock.Activate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
defer func() {
err2 := resp.Body.Close()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err2 != nil?
In this case if err == nil but err2 != nil you retrun an nil error. But expected an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return revocationStatus.RevocationStatus, err in the end of the function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}()

if resp.StatusCode != http.StatusOK {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accept range of 2xx codes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

200 is expected on all other clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

resolvers/agent.go Show resolved Hide resolved
@ilya-korotya
Copy link
Contributor

ilya-korotya commented Feb 1, 2024

In general, try to add context for all errors. A good example of why need to do it.
If one of these methods throws an error, not be clear which one. Or wrap to errors.WithStack()

	idUUID, err := uuid.NewV4()
	if err != nil {
		return out, err
	}
	threadUUID, err := uuid.NewV4()
	if err != nil {
		return out, err
	}

Copy link
Contributor

@vmidyllic vmidyllic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments from Illiya are ok

// AgentResolverConfig options for credential status verification
type AgentResolverConfig struct {
PackageManager *iden3comm.PackageManager
customHTTPClient *http.Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible to set customHTTPClient from the external package, since the field is private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made public

return out, errors.WithStack(err)
}

var httpClient *http.Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor to

httpClient := http.DefaultClient
if r.config.customHTTPClient != nil {
		httpClient = r.config.customHTTPClient
}

@ilya-korotya ilya-korotya self-requested a review February 6, 2024 12:33
ilya-korotya
ilya-korotya previously approved these changes Feb 6, 2024
go.mod Outdated
Comment on lines 7 to 8
github.com/gofrs/uuid/v5 v5.0.0
github.com/google/uuid v1.6.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have to uuid packages? I know Illiya aksed to use goohle uuid, but in this case let's remove gofrs completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@ilya-korotya ilya-korotya self-requested a review February 6, 2024 15:33
@vmidyllic vmidyllic merged commit 2e71583 into main Feb 6, 2024
5 checks passed
@vmidyllic vmidyllic deleted the feature/agent-resolver branch February 6, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants