Skip to content

Conversation

@nigurr
Copy link
Contributor

@nigurr nigurr commented Aug 7, 2020

Why?

  1. Currently the AzDev Client hides http.client implementation which makes using custom http.client implementations. By exposing this users can use custom http.client implementations which can be used to access AzDev API

Proposed Solution:

  1. Client is already exposed struct and exposing struct by hiding it's members seems anti-pattern. By exposing them, an implementation can use the custom http client.

Alternative Solution:

  1. Adding another NewClient function which accepts custom http.client, however method overriding is anti-pattern. Exposing altogether separate function with httpclient argument didn't make sense as we still need another params.

suppressFedAuthRedirect: connection.SuppressFedAuthRedirect,
forceMsaPassThrough: connection.ForceMsaPassThrough,
userAgent: connection.UserAgent,
BaseUrl: baseUrl,
Copy link
Member

Choose a reason for hiding this comment

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

Can you share how you plan to use each of these properties? Once they are set on the connection they are not supposed to be changed. Clients are cached on the connection, so the properties need to match. Resource locations are cached on the client, so changing the base url would invalidate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

client := &http.Client{Transport: tr}
if connection.Timeout != nil {
	client.Timeout = *connection.Timeout
}

c :=  &azuredevops.Client{
	baseUrl:                 connection.BaseUrl,
	client:                  client,
	authorization:           connection.AuthorizationString,
	suppressFedAuthRedirect: connection.SuppressFedAuthRedirect,
	forceMsaPassThrough:     connection.ForceMsaPassThrough,
	userAgent:               connection.UserAgent,
}

currently this is not feasible. as these are not exposed variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree to the point changing properties is not the way intended. Creating Client with own configurable options should be exposed.

Copy link
Member

Choose a reason for hiding this comment

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

The intention is to create a new connection if you want to change these. Most apps should never need more than one connection unless you are trying to connect to multiple organizations or trying to sign in with multiple identities.

Copy link
Contributor Author

@nigurr nigurr Aug 7, 2020

Choose a reason for hiding this comment

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

Agree. Current issue is, http client is internally created, this limits the customisation of standard http client creation (specially TLS Client).

As mentioned two approaches, we can add NewTLSClient(c Connection, baseUrl string, tls tls.Config)
or the above approach. I am kinda favouring the NewTLSClient the more I think about it. What's your suggestion!

Copy link
Member

Choose a reason for hiding this comment

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

Can we create a new constructor for the Connection to take a delegate that will be used to construct the client? This way we ensure a consistent http client is used for each http client created from the Connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please review the changes now?

@nigurr nigurr changed the title Exposing client variables Exposing TLS Configuration via Connection Aug 7, 2020
@tedchamb tedchamb merged commit 809f645 into microsoft:dev Aug 12, 2020
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.

2 participants