riferrei / srclient

Golang Client for Schema Registry
Apache License 2.0
235 stars 70 forks source link

Add ability to authenticate through the use of a bearer token #84

Closed InsomniaDev closed 2 years ago

riferrei commented 2 years ago

Hi @InsomniaDev. I did review your PR, and if you don't mind, could you please implement the following changes:

  1. Move the bearer token from SchemaRegistryClient struct to the credentials struct.
  2. Change the function SetBearerToken to write is data to the internal credentials struct.
  3. Adjust the function httpRequest to include a logic like the below:
    if client.credentials != nil {
                 if len(client.credentials.username) > 0 && len(client.credentials.password) > 0 {
                       req.SetBasicAuth(client.credentials.username, client.credentials.password)
                 } else if len(client.credentials.bearerToken) > 0 {
                       req.Header.Add("Authorization", "Bearer "+client.credentials.bearerToken)
                 }
    }
  1. Fix the mocks accordingly. 🙂

I think this way improves the code's readability.

Thanks,

— @riferrei

InsomniaDev commented 2 years ago

@riferrei - updated and also added comments in the code to aid with readability.