Skip to content

5.5 #2807

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

Merged
merged 17 commits into from
Jul 21, 2017
Merged

5.5 #2807

merged 17 commits into from
Jul 21, 2017

Conversation

Mpdreamz
Copy link
Member

This updates the json spec to 5.5 and generates the code from that. No big major changes to existing API's.

The machine learning json spec is included but we do not generate code from that folder just yet, this will follow in a 5.5.x release.

XPack security has a new role_mapping API to map roles to users, and a token based access API. Support for these have been added with tests.

The matrix_stats, sig_terms and sampler_agg have additional properties as per 5.5 which tripped up our aggregation parser.

GetAlias now return a 404 if you submit a query for e.g a,b,c and only alias a was found as per: elastic/elasticsearch#25043

Copy link
Contributor

@russcam russcam left a comment

Choose a reason for hiding this comment

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

Beast of a PR! Some questions around bitwise operators and semantics for valid Get and Delete responses

@@ -11,9 +11,9 @@ public class XPackCluster : ClusterBase
{
protected string[] XPackSettings => TestClient.VersionUnderTestSatisfiedBy(">=5.5.0")
? new[] {"xpack.security.authc.token.enabled=true"}
: Array.Empty<string>();
Copy link
Contributor

Choose a reason for hiding this comment

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

😢

@@ -38,10 +38,17 @@ protected override JsonContract CreateContract(Type objectType)
// cache contracts per connection settings
return this.ConnectionSettings.Inferrer.Contracts.GetOrAdd(objectType, o =>
{
var n = o.GetType().FullName;
Copy link
Contributor

Choose a reason for hiding this comment

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

superfluous - not used

var contract = base.CreateContract(o);

if ((typeof(IDictionary).IsAssignableFrom(o) || o.IsGenericDictionary()) && !typeof(IIsADictionary).IsAssignableFrom(o))
{
if (contract.Converter != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

not used

}

public class GetAliasResponse : ResponseBase, IGetAliasResponse
{
public IReadOnlyDictionary<string, IReadOnlyList<AliasDefinition>> Indices { get; internal set; } = EmptyReadOnly<string, IReadOnlyList<AliasDefinition>>.Dictionary;


public override bool IsValid => this.Indices.Count > 0 ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

can be shortened to

this.Indices.Count > 0;

@@ -25,14 +25,6 @@
"options" : ["open","closed","none","all"],
"default" : "open",
"description" : "Whether to expand wildcard expression to concrete indices that are open, closed or both."
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a breaking API change which is going to break binary compatibility for Elasticsearch.Net.

Reading elastic/elasticsearch#25234, it looks like these should have been removed from the rest api specs for 5.x, but given these are methods on the client, I think they should still exist as Noops in 5.x to not break binary compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed: 7c9b72a

return this._desiredPort.Value;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

++

///https://www.elastic.co/guide/en/x-pack/master/security-api-role-mapping.html#security-api-delete-role-mapping
///</pre>
///</summary>
public class DeleteRoleMappingRequestParameters : FluentRequestParameters<DeleteRoleMappingRequestParameters>
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 this should adhere to allowing a 404 status code response, similar to other Delete operations

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

///https://www.elastic.co/guide/en/x-pack/master/security-api-role-mapping.html#security-api-get-role-mapping
///</pre>
///</summary>
public class GetRoleMappingRequestParameters : FluentRequestParameters<GetRoleMappingRequestParameters>
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 this should also be consistent with other Get* responses in Elasticsearch in returning a { "found": false } body along with 404 response. Speaking with @tvernum, this behaviour is consistent across Get* responses in X-Pack Security, but going to open up an issue to collectively discuss these.

Rules =
(new DistinguishedNameRule(_dn) | new UsernameRule(_username) | new RealmRule(_realm))
& new MetadataRule(_metadata.Item1, _metadata.Item2)
& !new GroupsRule(_groups)
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to use logical operators here as opposed to bitwise, similarly to how they are used within queries? For example,

(new DistinguishedNameRule(_dn) || new UsernameRule(_username) || new RealmRule(_realm))
&& new MetadataRule(_metadata.Item1, _metadata.Item2)
&& !new GroupsRule(_groups)

Copy link
Member Author

Choose a reason for hiding this comment

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

That sadly won't be possible since we need to return a different class when they are combined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have implementations of AnyFieldRule, AllFieldRule and ExceptFieldRule that derive from FieldRuleBase and implicitly convert to the associated RoleMappingRuleBase implementations, respectively? Would that work?

I think there's potential for confusion with using bitwise operators, since we use binary operators for combining queries, aggregations and watcher actions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Implicit conversions and operator overloading are not friends :)

I hear you on the deviation from other areas though but as this is icing and not the only way to construct this (ois/fluent are also there). I am leaning more on the rtfm side of things here tbh.

We could call it out in the docs stronger though.

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 people might eat more of the icing than cake 🤣

FieldRuleCombinator a la ActionCombinator?

internal class ActionCombinator : ActionBase, IAction
{
internal List<ActionBase> Actions { get; } = new List<ActionBase>();
public ActionCombinator(ActionBase left, ActionBase right) : base(null)
{
this.AddAction(left);
this.AddAction(right);
}
private void AddAction(ActionBase agg)
{
if (agg == null) return;
var combinator = agg as ActionCombinator;
if ((combinator?.Actions.HasAny()).GetValueOrDefault(false))
{
this.Actions.AddRange(combinator.Actions);
}
else this.Actions.Add(agg);
}
public override ActionType ActionType => (ActionType)10;
}
.

Copy link
Member Author

Choose a reason for hiding this comment

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

ActionBase overloaded operators return ActionBase so binary operators work. FieldRuleBase needs to return RoleMappingRuleBase so it can't.

* NEST exposes this role rules DSL in a strongy typed fashion
*
*/
public class RoleMappingRulesTests : SerializationTestBase
Copy link
Contributor

Choose a reason for hiding this comment

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

X-Pack docs 😃

@@ -0,0 +1,23 @@
using ApiGenerator.Domain;

namespace ApiGenerator.Overrides.Descriptors
Copy link
Member Author

Choose a reason for hiding this comment

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

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 move the *.obsolete.json and *.patch.json files to a different directory to the downloaded specs? I think it'll make it easier to manage

@russcam russcam merged commit 5617675 into 5.x Jul 21, 2017
russcam pushed a commit that referenced this pull request Jul 26, 2017
* Code generation of elasticsearch's 5.5 branch

* Update existing XPack API spec files

* Add ml xpack api spec and new security endpoints

* Add CRUD support for the new role mapping security API's

* Add support for security token API's

* fix failing codestandards tests after implementing xpack security 5.5 new features

* fix overal bg_count now gets returned for sig_terms

* fix stats matrix now also returns overal doc_count

* fix change in GetAlias behavior, since 5.5 now returns 404 when some aliases suplied are not found

* Sampler agg test for bg count should only be asserted 5.5.0 and up

* Array.Empty not available for .NET 4.5

* Add force + operation_threading to RefreshRequest

Removed in REST API spec elastic/elasticsearch#25234 - patched in to maintain binary compatibility

* Set tests.default.yaml ES version to 5.5.0

* Update XML comments for LazyDocument

* Minor language tweaks

* Fix spelling

* update SkipVersion for PutRoleMapping to <5.5.0

(cherry picked from commit 5617675)
awelburn pushed a commit to Artesian/elasticsearch-net that referenced this pull request Nov 6, 2017
* Code generation of elasticsearch's 5.5 branch

* Update existing XPack API spec files

* Add ml xpack api spec and new security endpoints

* Add CRUD support for the new role mapping security API's

* Add support for security token API's

* fix failing codestandards tests after implementing xpack security 5.5 new features

* fix overal bg_count now gets returned for sig_terms

* fix stats matrix now also returns overal doc_count

* fix change in GetAlias behavior, since 5.5 now returns 404 when some aliases suplied are not found

* Sampler agg test for bg count should only be asserted 5.5.0 and up

* Array.Empty not available for .NET 4.5

* Add force + operation_threading to RefreshRequest

Removed in REST API spec elastic/elasticsearch#25234 - patched in to maintain binary compatibility

* Set tests.default.yaml ES version to 5.5.0

* Update XML comments for LazyDocument

* Minor language tweaks

* Fix spelling

* update SkipVersion for PutRoleMapping to <5.5.0

(cherry picked from commit 5617675)
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