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 apikey authenticator #46

Merged
merged 17 commits into from
Oct 22, 2021
Merged

Add apikey authenticator #46

merged 17 commits into from
Oct 22, 2021

Conversation

nan2iz
Copy link
Contributor

@nan2iz nan2iz commented Oct 12, 2021

How to call the authenticator:

CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator()
                .WithUrl($CLUSTER_URL)
                .WithUserName($USER_NAME)
                .WithApikey($API_KEY)
                .WithDisableSslVerification($DISABLE_SSL)
                .Build();
            service = new AssistantService(versionDate, authenticator);
            service.DisableSslVerification($DISABLE_SSL);
            service.SetServiceUrl($SERVICE_URL);

@nan2iz nan2iz requested a review from kevinkowa October 12, 2021 05:42
Copy link
Member

@mediumTaj mediumTaj left a comment

Choose a reason for hiding this comment

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

just some questions after a quick readthrough nan

Copy link
Contributor

@kevinkowa kevinkowa left a comment

Choose a reason for hiding this comment

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

It looks good, just a comment

}

[TestMethod]
public void TestConstructionApikeyRequried()
Copy link
Contributor

Choose a reason for hiding this comment

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

possible typo on the name of the method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Will fix it. Thank you

@mediumTaj
Copy link
Member

Also need to check on CI here

appveyor.yml Outdated
@@ -17,6 +17,7 @@ environment:
secure: gevsMhy8RTWMdf7MjOnIo5QaN6JpL9DPK6I+Go5ByZir5LDwyFsv9hO6nBjGTg8n #pragma: whitelist secret
GITHUB_TOKEN:
secure: +B2bs86RVtJtlbkB+cTf9bkqnNlFJi/PbBBPzR5jlUlLLZoOc+ZgqgQLwee4tCT+ #pragma: whitelist secret
nodejs_version: 15.6.0
Copy link
Member

Choose a reason for hiding this comment

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

FYI i made this change in another PR for core so it matches the .NET SDK node version
b422967

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I will remove this one. Thank you

/// <param name="headers">A set of user-supplied headers to be included in token server interactions</param>
public CloudPakForDataAuthenticator(string url, string username, string password, string apikey, bool? disableSslVerification = null, Dictionary<string, string> headers = null)
{
Init(url, username, password, apikey, disableSslVerification, headers);
Copy link
Member

Choose a reason for hiding this comment

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

@nan2iz did you get anywhere with the builder/fluent pattern for this?

Copy link
Member

Choose a reason for hiding this comment

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

I think if the builder pattern works, I dont think we need the 2nd overload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I will remove the overload. Thank you

Copy link
Member

@mediumTaj mediumTaj left a comment

Choose a reason for hiding this comment

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

I threw some suggestions in here for consistency

/// <param name="headers">A set of user-supplied headers to be included in token server interactions</param>
public CloudPakForDataAuthenticator(string url, string username, string password, string apikey, bool? disableSslVerification = null, Dictionary<string, string> headers = null)
{
Init(url, username, password, apikey, disableSslVerification, headers);
Copy link
Member

Choose a reason for hiding this comment

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

I think if the builder pattern works, I dont think we need the 2nd overload.


public CloudPakForDataAuthenticator SetUrl(string url)
{
this.Url = url;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.Url = url;
Url = url;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. Will fix it


public CloudPakForDataAuthenticator SetUsername(string username)
{
this.Username = username;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.Username = username;
Username = username;

}

private void Init(string url, string username, string password, bool? disableSslVerification = null, Dictionary<string, string> headers = null)
public CloudPakForDataAuthenticator setPassword(string password)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public CloudPakForDataAuthenticator setPassword(string password)
public CloudPakForDataAuthenticator SetPassword(string password)

private void Init(string url, string username, string password, bool? disableSslVerification = null, Dictionary<string, string> headers = null)
public CloudPakForDataAuthenticator setPassword(string password)
{
this.Password = this.Password;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.Password = this.Password;
Password = password;

return this;
}

public CloudPakForDataAuthenticator setApikey(string apikey)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public CloudPakForDataAuthenticator setApikey(string apikey)
public CloudPakForDataAuthenticator SetApikey(string apikey)


public CloudPakForDataAuthenticator setApikey(string apikey)
{
this.Apikey = this.Apikey;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.Apikey = this.Apikey;
Apikey = apikey;


public CloudPakForDataAuthenticator SetDisableSslVerification(bool disableSslVerification)
{
this.DisableSslVerification = disableSslVerification;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.DisableSslVerification = disableSslVerification;
DisableSslVerification = disableSslVerification;


public CloudPakForDataAuthenticator SetHeaders(Dictionary<string, string> headers)
{
this.Headers = headers;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.Headers = headers;
Headers = headers;

@nan2iz
Copy link
Contributor Author

nan2iz commented Oct 19, 2021

Note: I will need to wait until this PR #47 is merged to the master first.
Since it will fix the build issue. And then I will pull into my branch.

Copy link
Contributor

@kevinkowa kevinkowa left a comment

Choose a reason for hiding this comment

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

Looks good!

/// <param name="username">The username to be used when retrieving the access token</param>
/// <param name="password">The password to be used when retrieving the access token</param>
/// <param name="disableSslVerification">A flag indicating whether SSL hostname verification should be disabled</param>
/// <param name="headers">A set of user-supplied headers to be included in token server interactions</param>
public CloudPakForDataAuthenticator(string url, string username, string password, bool? disableSslVerification = null, Dictionary<string, string> headers = null)
{
Init(url, username, password, disableSslVerification, headers);
Init(url, username, password, null, disableSslVerification, headers);
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need apikey in init?

{
KeyValuePair<string, string> apikey = new KeyValuePair<string, string>(KeyApikey, Apikey);
content.Add(apikey);
} else
Copy link
Member

Choose a reason for hiding this comment

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

ah this else should be on a separate line

Suggested change
} else
}
else

Copy link
Member

@mediumTaj mediumTaj left a comment

Choose a reason for hiding this comment

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

One comment then i think it looks good!

Init();
}

private void Init(string url, string username, string password, string apikey, bool? disableSslVerification = null, Dictionary<string, string> headers = null)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need default values for password and apikey here? I dont think its guaranteed the values will come back from the config

Suggested change
private void Init(string url, string username, string password, string apikey, bool? disableSslVerification = null, Dictionary<string, string> headers = null)
private void Init(string url, string username, string password = null, string apikey = null, bool? disableSslVerification = null, Dictionary<string, string> headers = null)

Copy link
Member

@mediumTaj mediumTaj left a comment

Choose a reason for hiding this comment

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

👍 Looks good Thank you Nan!!

@nan2iz nan2iz merged commit 4c1ce73 into main Oct 22, 2021
@nan2iz nan2iz deleted the add-apikey-authenticator branch October 22, 2021 20:42
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.

3 participants