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

Create Access Key #129

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Create Access Key #129

wants to merge 17 commits into from

Conversation

IshamMohamed
Copy link
Contributor

This is the pull request for the "Create Access Key"

@masojus
Copy link
Contributor

masojus commented Nov 1, 2017

Thanks, I'll continue review here.

@masojus
Copy link
Contributor

masojus commented Nov 1, 2017

I'm not sure why TravisCI succeeded and AppVeyor failed, but are your tests hitting the real server?

@IshamMohamed
Copy link
Contributor Author

Strange, its coming from the last commit - I didn't see a problem in it.

@masojus
Copy link
Contributor

masojus commented Nov 1, 2017

The tests don't seem to be mocked, so if it was succeeding before it was because you hadn't switched the keys.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 56.532% when pulling 43ea621 on IshamMohamed:master into b820c2e on keenlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 57.117% when pulling 0e2cd7a on IshamMohamed:master into b820c2e on keenlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 57.177% when pulling a781c51 on IshamMohamed:master into b820c2e on keenlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 57.207% when pulling d2db292 on IshamMohamed:master into b820c2e on keenlabs:master.

var client = new KeenClient(settings);

if (UseMocks)
client.AccessKeys = new AccessKeysMock(settings,
Copy link
Contributor

Choose a reason for hiding this comment

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

If the idea is just to do unit testing on the CreateAccessKey() method of the KeenClient, we can just leverage Moq instead of creating a separate class, which might be simpler.

namespace Keen.Core.AccessKey
{
/// <summary>
/// Modal for AccessKey object
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "Modal"->"Model", and we should elaborate on XML doc comments on any public members.

public ISet<string> Allowed { get; set; }
}

public class Quaries
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "Quaries"->"Queries"

public Writes Writes { get; set; }
public Datasets Datasets { get; set; }
public CachedQueries CachedQueries { get; set; }
public Quaries Queries { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "Quaries"->"Queries"


}

public class SavedQueries
Copy link
Contributor

Choose a reason for hiding this comment

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

All these public types should have XML doc comments.

public class AccessKeys : IAccessKeys
{
private readonly IKeenHttpClient _keenHttpClient;
private readonly string _acceskeyRelativeUrl;
Copy link
Contributor

@masojus masojus Nov 3, 2017

Choose a reason for hiding this comment

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

typo: "_acceskey..."->"_accessKey...",

{
jsonResponse = JObject.Parse(responseString);
}
catch (Exception)
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this because you were seeing a 404 error or something similar and it's actually OK in this case to swallow the exception? Then will we throw below? I know we do this elsewhere, and we should really keep the inner exception around for context, but that's another issue. At least if that's the case, let's put a comment here explaining the empty catch(){} block.


/// <summary>
/// </summary>
public void CreateAccessKey(AccessKey.AccessKey accessKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need the namespace qualification?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes since namespace and class have the same name, even though I used the namespace, C# fails to understand, AccessKey is a class.

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the case it seems like we should rename to AccessKeys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the namespace? We have another class called AccessKeys

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, or does that cause other problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah in that sense, we may need to go for AccessKeys = new AccessKeys.AccessKeys(_prjSettings, keenHttpClientProvider); in the KeenClient.cs

public string Key { get; set; }
public Options Options { get; set; }

internal AccessKey(string name, bool isActive, ISet<string> permitted, Options options)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the properties all remain public, is it useful to have an internal constructor instead of using object initializer notation and giving the Key auto-prop a default?


HashSet<string> permissions = new HashSet<string>() { "queries" };
List<Core.Query.QueryFilter> qFilters = new List<Core.Query.QueryFilter>() { new Core.Query.QueryFilter("customer.id", Core.Query.QueryFilter.FilterOperator.Equals(), "asdf12345z") };
CachedQueries cachedQuaries = new CachedQueries();
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "cachedQuaries"->"cachedQueries"


///<summary>
///</summary>
private async Task<JObject> CreateAccessKeyAsync(AccessKey.AccessKey accessKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need the namespace qualification?


namespace Keen.Core.AccessKey
{
public interface IAccessKeys
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll want to flesh out XML doc comments here.

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to organize and remove unnecessary usings.

/// </summary>
/// <param name="accesskey"></param>
/// <returns></returns>
Task<JObject> CreateAccessKey(AccessKey accesskey);
Copy link
Contributor

@masojus masojus Nov 3, 2017

Choose a reason for hiding this comment

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

We prefer Task-returning methods to use the ...Async(...) naming guideline.

@@ -46,6 +47,43 @@ public static void ResetEnv()
}

[TestFixture]
public class AccessKeysTest : TestBase
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should break this out into another file.

}));

HashSet<string> permissions = new HashSet<string>() { "queries" };
List<Core.Query.QueryFilter> qFilters = new List<Core.Query.QueryFilter>() { new Core.Query.QueryFilter("customer.id", Core.Query.QueryFilter.FilterOperator.Equals(), "asdf12345z") };
Copy link
Contributor

Choose a reason for hiding this comment

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

If/when you create a new file for Access Key tests, I'd recommend adding using Keen.Core.Query; and dispensing with the explicit namespace here.

throw new KeenException("An API WriteKey is required to add events.");
}

var xcontent = accesskey.ToString();
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this xcontent var we have here?

@IshamMohamed
Copy link
Contributor Author

Agreed to all of your changes.

@masojus
Copy link
Contributor

masojus commented Nov 7, 2017

@IshamMohamed Are you actively working on this for the rest of the week? What's your ideal timeline for making these suggested revisions? Do you have plans to add the other Access Keys APIs to this, or to leave that for another PR?

@IshamMohamed
Copy link
Contributor Author

Yes I will be. Will finish the suggested revisions before end of this week and start working on the other APIs - but I don't really know if I need another PR for it? do I?

@masojus
Copy link
Contributor

masojus commented Nov 7, 2017

Well we'll need to approve and merges changes to master. Speaking of, you'll need to merge from master to get the latest and deal with any potential merge conflicts.

Copy link
Contributor Author

@IshamMohamed IshamMohamed left a comment

Choose a reason for hiding this comment

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

Agreed

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 69.682% when pulling 7abce95 on IshamMohamed:master into 676e52f on keenlabs:master.

@IshamMohamed
Copy link
Contributor Author

Reviewed all your changed and accepted them. Will work a bit on improving code coverage later today - and come back to some of your questions as well.

@masojus
Copy link
Contributor

masojus commented Nov 10, 2017

Ok, if you push some more changes I should be able to review over the weekend. Thanks!

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 69.476% when pulling b60d1b1 on IshamMohamed:master into 676e52f on keenlabs:master.

@masojus
Copy link
Contributor

masojus commented Nov 11, 2017

@IshamMohamed Let me know when you have something ready for review again. I'd love to get AccessKey creation checked in so we can flesh out the rest of the functionality around AccessKeys.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 72.512% when pulling a7e9a21 on IshamMohamed:master into 536b56b on keenlabs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 72.512% when pulling b9fbe6f on IshamMohamed:master into 536b56b on keenlabs:master.

@IshamMohamed
Copy link
Contributor Author

@masojus can you please let me know, what has to be done to improve the code coverage?

@masojus
Copy link
Contributor

masojus commented Nov 13, 2017

A difference of -0.2% isn't a huge deal, but you could look at where code isn't covered and add tests to hit those lines. For example if you look here and here there are some lines that aren't hit, so you could write tests to exercise those setters/getters and hit those error cases.

@masojus
Copy link
Contributor

masojus commented Nov 14, 2017

Also, there are some huge changes in master now in preparation for releasing a 0.4.0 .nupkg, but tomorrow I plan on taking these changes and moving them into a branch off of master with all the new stuff and continuing the PR discussion over there...that way I can help deal with all these huge changes and we can get the CreateAccessKey() logic in at least.

@masojus
Copy link
Contributor

masojus commented Nov 14, 2017

Okay, I merged master and will push a branch...I'll probably create a new PR tomorrow. You missed several of the comments and changes I requested in this PR, so we'll have to go through and clean those things up. Expect to see those changes tomorrow.

masojus added a commit that referenced this pull request Nov 14, 2017
@masojus
Copy link
Contributor

masojus commented Nov 14, 2017

Take a look at jm_CreateAccessKey_PR129 to see how things are going with porting this to the new project structure and starting some clean up. I'll make more progress tomorrow and ask for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants