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

Enable checking against a schema #2027

Closed
wants to merge 1 commit into from
Closed

Enable checking against a schema #2027

wants to merge 1 commit into from

Conversation

Olympic1
Copy link
Member

@Olympic1 Olympic1 commented Apr 3, 2017

From KSP-CKAN/CKAN-core#133

Rebased PR #992

@Olympic1 Olympic1 added Core (ckan.dll) Issues affecting the core part of CKAN Enhancement Schema Issues affecting the schema labels Apr 3, 2017
@politas
Copy link
Member

politas commented Apr 3, 2017

@dbent , you're the Cake expert. Can you figure out what's happening here? These .csproj files baffle me.

@dbent
Copy link
Member

dbent commented Apr 3, 2017

Well we still need to consider if we want to do this. Json.NET Schema is not permissively licensed, but is licensed under AGPL-3.0 which is copyleft. This means the combined work (ckan.exe, netkan.exe, etc.) has to be licensed under the AGPL. Our source code is MIT licensed which is (A)GPL compatible so that doesn't have to change though.

There's a few things going on in this PR with regards to the build, specifically updating versions of libraries. I'll make a separate PR for that.

@Olympic1
Copy link
Member Author

Olympic1 commented Apr 3, 2017

I already thought that it had to do something with the lib updates.

@politas
Copy link
Member

politas commented Apr 3, 2017

That doesn't take away the MIT license from the CKAN code, does it? This whole question of multiple licenses gets pretty confusing. Would it mean that someone could fork CKAN and claim only the AGPL applies to their new fork?

Actually, aren't we already including some copyleft packages?

@dbent
Copy link
Member

dbent commented Apr 4, 2017

IANAL, but here's my understanding:

That doesn't take away the MIT license from the CKAN code, does it?

No, MIT aka Expat license, is "GPL-Compatible". GPL-Compatible source can be combined with (A)GPL source to create a derived work that doesn't force the GPL-Compatible source to be released under the (A)GPL. The derived work (ckan.exe, netkan.exe, etc) however must be.

What this means, is that if someone wants to use ckan.exe or netkan.exe as a library (which is totally possible in .NET), their work would have to released under the (A)GPL. To avoid that, they'd have to take our MIT source, excise any bits that refer to (A)GPL code and create a custom build derived only from MIT source. (This could be automated through the use of #ifdef in the source and a bit smarter build logic to avoid ILRepacking Json.NET Schema). What's more, the AGPL (and its primary difference with respect to the GPL) is that even use of an application over a network is considered distribution and thus triggers its provisions. So a web application using ckan.exe/netkan.exe would have to be distributed under AGPL.

Now, this person might also be able to avoid that by calling ckan.exe/netkan.exe as a separate process, but if the program is "specifically designed to require" ckan.exe/netkan.exe then the provisions probably apply anyway.

Would it mean that someone could fork CKAN and claim only the AGPL applies to their new fork?

No, but it probably means that different source files would have to be under different licenses. Anything that uses JSON.NET Schema would have to be relicensed under AGPL (and relicensing requires consent of all contributors to that file, since CKAN has no copyright assignment to a single individual/organization so every author owns the copyright to their own contributions).

Now that I think about, even excising code could be problematic. Since if the entire file is AGPL, then removing code just makes a new derived work that would also have to be AGPL. Can copyright be specified on a line-by-line basis? Hmmm.

Actually, aren't we already including some copyleft packages?

Nope. I went through each and every library we use, including ones only used for testing and all except one are licensed under permissive (non-copyleft) MIT, Apache, or BSD licenses. The only one that isn't licensed under a permissive license is ICSharpCode.SharpZipLib.Patched but it's licensed under the GPL with an explicit linking exception making it similar to the LGPL.

  • Autofac: MIT (permissive)
  • Castle.Core: Apache-2.0 (permissive)
  • ChinhDo.Transactions.FileManager: MIT (permissive)
  • CommandLineParser: MIT (permissive)
  • ICSharpCode.SharpZipLib.Patched: GPL w/ Linking Exception (semi-permissive)
  • ini-parser: MIT (permissive)
  • log4net: Apache-2.0 (permissive)
  • Moq: BSD 3 Clause (permissive)
  • Newtonsoft.Json: MIT (permissive)
  • NUnit: MIT (permissive)
  • TxFileManager: MIT (permissive)
  • CurlSharp: BSD 3 Clause (permissive)

The whole issue with the AGPL is a minefield of technicalities, which is why I've never bothered to incorporate JSON.NET Schema into NetKAN's validation.

FYI I've made #2028 which updates the build and all our libraries to the latest and greatest. If we want to pursue this, it should be probably be based off that.

@dbent
Copy link
Member

dbent commented Apr 4, 2017

Also, the AGPL version of JSON.NET Schema is listed as "Free with limitations (1000 validations per hour)". I'm not entirely sure what that means.

@Olympic1
Copy link
Member Author

Olympic1 commented Apr 4, 2017

Well, in that case it would be better to find another way to check the spec or just drop it.

@techman83
Copy link
Member

To note, both the indexer and Jenkins run the resulting output through a schema validator. So what makes it CKAN-meta has been validated.

It would probably be handy to have in the client for those that make custom ckans or provide early signs that a netkan will fail CI, but overall I don't think the need is exceptionally high. A nice to have for sure, but it's not really a big deal in the scheme of things.

@dbent
Copy link
Member

dbent commented Apr 5, 2017

NJsonSchema is another project that seems active and is permissively (MIT) licensed.

@Dazpoet
Copy link
Member

Dazpoet commented Apr 20, 2017

Don't we have someone cough @pjf cough who loves discussing licenses and how they work and not work?

@techman83
Copy link
Member

@Dazpoet I think it's more @pjf is exceptionally knowledgeable on the topic and has a passion for ensuring it's done correctly. If there is an MIT based plugin lets use it. Also the restriction added by JSON.NET schema may not be applicable:

https://www.gnu.org/licenses/agpl-3.0.en.html

All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term.

Also AGPL is quite at the opposite end of the spectrum when compared to MIT, I'm not super across how it would effect things when used as a library though and we'd want to be very sure we're across the implications. It would certainly effect the ability for it's use in a commercial product, so if there is an MIT licensed project available, lets use that. But we're not in a rush for such a feature and we'd need to do some indexer work if NetKAN started throwing it's own schema exceptions.

@ayan4m1
Copy link
Contributor

ayan4m1 commented Sep 28, 2017

@Olympic1 Can you resolve conflicts/rebase or close this out?

@politas
Copy link
Member

politas commented Oct 15, 2017

@Olympic1, can you have a look at NJsonSchema that @dbent mentioned and see if switching to that is possible?

@RicoSuter
Copy link

Hi everybody

Im the creator of NJsonSchema.

Switching should be very simple, only problem i see in the schema is the “required” properties which have no corresponding properties. We have an open issue for that.

Other than that just load the schema with JsonSchema4.FromJsonAsync() and call Validate().

@Olympic1
Copy link
Member Author

@dbent, @politas, I converted the PR to NJsonSchema, but not fully.

I followed @RSuter's instructions and fixed the errors. Need to look into some more.

@Olympic1 Olympic1 self-assigned this Nov 11, 2017
@Olympic1
Copy link
Member Author

Rebased. Have anyone had the time to test this PR? I want to move this forward.

Copy link
Member

@HebaruSan HebaruSan left a comment

Choose a reason for hiding this comment

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

I'm a little anxious about the Validate call, but maybe I'm misinterpreting something.

}
}

private static readonly string SchemaPath = "CKAN.CKAN.schema";
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this a const instead of static readonly, since the value is known at compile time.

JsonSchema4 schema = await JsonSchema4.FromJsonAsync(json);

IList<string> errorList = new List<string>();
var errors = schema.Validate(MetadataSchema.ToJson());
Copy link
Member

Choose a reason for hiding this comment

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

If I'm reading this correctly, we process the schema from a JSON string to a JsonSchema4 object in the static constructor, and then back from object to a JSON string in the validation function.

Can we store the return value of the ToJson function, so we don't have to pay the cost of that conversion for every CkanModule object? Presumably we can ensure that the CKAN.schema file bundled in the assembly is valid separately whenever we modify it.

if (errors.Result.Any())
{
var message = "Validation against the schema failed.\n" + string.Join("\n ", errors);
throw new BadMetadataKraken(null, message);
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to test the impact of this exception on the GUI. What would be a good way to do that? I tried corrupting my registry.json file in various ways, but I think those tests got caught by other checks (e.g., invalid licenses are already covered elsewhere).

@@ -0,0 +1,423 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Is it impossible to move the old CKAN.schema file to this new location? It will be inconvenient to have to maintain two files identically going forward.

Copy link
Member

Choose a reason for hiding this comment

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

It could be a symbolic link instead of a separate file, surely?


private static async Task<IList<string>> ValidateAgainstSchema(string json)
{
JsonSchema4 schema = await JsonSchema4.FromJsonAsync(json);
Copy link
Member

Choose a reason for hiding this comment

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

This variable represents the module we're validating, not the schema, right? Let's change its name to clarify that.

JsonSchema4 schema = await JsonSchema4.FromJsonAsync(json);

IList<string> errorList = new List<string>();
var errors = schema.Validate(MetadataSchema.ToJson());
Copy link
Member

Choose a reason for hiding this comment

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

Actually, are you sure this call is correct? The schema object appears to be the module, and the parameter with ToJson is the schema. This looks like we're trying to use the module to validate the schema rather than the other way around. The documentation passes the data to be validated to the schema's Validate function.

@Olympic1
Copy link
Member Author

Closing as this was done in #2788

@Olympic1 Olympic1 closed this Jul 21, 2019
@Olympic1 Olympic1 deleted the EnableSchema branch July 29, 2020 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core (ckan.dll) Issues affecting the core part of CKAN Enhancement Pull request Schema Issues affecting the schema
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants