code0-license 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.tool-versions +1 -1
- data/Gemfile.lock +3 -1
- data/README.md +7 -7
- data/lib/code0/license/version.rb +1 -1
- data/lib/code0/license.rb +12 -8
- data/sig/code0/license.rbs +3 -1
- metadata +17 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b31c49c94ebb8a5d019f33114cb5b4c14a679a86824b48b3e96cb0e5eb837cd
|
|
4
|
+
data.tar.gz: 8ada22784f937ac2052a45176709c0f7cc4b07cd592cf4c346395633f00811f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9017c312c7d3e2e66cfab92483b42eb24423aa1db0bcb2db300d32bd92fe522c2d228538f13ff71133f28351af43cc8e18965c8ca7291be700ab8e1ed96bbeff
|
|
7
|
+
data.tar.gz: 57a55a96fafb50fde8caf7d6c71af8cb01531a4b5181550ab71eda2acb05326625691505382b7bd6c7e23827a93e38d251282987431d505648c43cd7b93e3d5a
|
data/.rubocop.yml
CHANGED
data/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby 3.
|
|
1
|
+
ruby 3.4.7
|
data/Gemfile.lock
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
code0-license (0.
|
|
4
|
+
code0-license (0.3.0)
|
|
5
|
+
base64 (~> 0.3.0)
|
|
5
6
|
|
|
6
7
|
GEM
|
|
7
8
|
remote: https://rubygems.org/
|
|
8
9
|
specs:
|
|
9
10
|
ast (2.4.2)
|
|
11
|
+
base64 (0.3.0)
|
|
10
12
|
diff-lcs (1.5.1)
|
|
11
13
|
json (2.7.2)
|
|
12
14
|
language_server-protocol (3.17.0.3)
|
data/README.md
CHANGED
|
@@ -32,11 +32,11 @@ Code0::License.encryption_key = private_key
|
|
|
32
32
|
# create a license
|
|
33
33
|
license = Code0::License.new(
|
|
34
34
|
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
licensee: { company: 'Code0' }, # content of licensee can be as you want, it just can't be empty
|
|
36
|
+
start_date: '2024-05-01', # when is the first date where this license is valid?
|
|
37
|
+
end_date: '2025-05-01', # until when is the license valid?
|
|
38
|
+
restrictions: {}, # content can be as you wish, can be used to semantically store some restrictions that are evaluated by your application
|
|
39
|
+
options: {}, # content can be as you wish, can be used to semantically provide some options of this license
|
|
40
40
|
}
|
|
41
41
|
)
|
|
42
42
|
|
|
@@ -59,10 +59,10 @@ Code0::License.encryption_key = public_key
|
|
|
59
59
|
# load the license
|
|
60
60
|
license = Code0::License.load(File.read('license.txt'))
|
|
61
61
|
|
|
62
|
-
# exit if license is valid or outside of the valid time
|
|
62
|
+
# exit if license is not valid or outside of the valid time
|
|
63
63
|
exit unless license.valid?
|
|
64
64
|
exit unless license.in_active_time?
|
|
65
65
|
|
|
66
66
|
# for example, exit if users exceed licensed amount
|
|
67
|
-
exit if User.count > license.restrictions[
|
|
67
|
+
exit if license.restricted?(:user_count) && User.count > license.restrictions[:user_count]
|
|
68
68
|
```
|
data/lib/code0/license.rb
CHANGED
|
@@ -28,7 +28,7 @@ module Code0
|
|
|
28
28
|
|
|
29
29
|
decrypted_license = encryptor.decrypt(data)
|
|
30
30
|
|
|
31
|
-
new(JSON.parse(decrypted_license))
|
|
31
|
+
new(JSON.parse(decrypted_license, symbolize_names: true))
|
|
32
32
|
rescue JSON::ParserError
|
|
33
33
|
raise ValidationError, "License data is invalid JSON"
|
|
34
34
|
end
|
|
@@ -60,19 +60,23 @@ module Code0
|
|
|
60
60
|
def valid?
|
|
61
61
|
return false if !licensee || !licensee.is_a?(Hash) || licensee.empty?
|
|
62
62
|
return false if !start_date || !start_date.is_a?(Date)
|
|
63
|
-
return false if (!end_date || !end_date.is_a?(Date)) && !options[
|
|
63
|
+
return false if (!end_date || !end_date.is_a?(Date)) && !options[:allow_missing_end_date]
|
|
64
64
|
|
|
65
65
|
true
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def in_active_time?
|
|
69
69
|
return false if start_date > Date.today
|
|
70
|
-
return true if !end_date && options[
|
|
71
|
-
return false if !end_date && !options[
|
|
70
|
+
return true if !end_date && options[:allow_missing_end_date]
|
|
71
|
+
return false if !end_date && !options[:allow_missing_end_date]
|
|
72
72
|
|
|
73
73
|
end_date >= Date.today
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
def restricted?(attribute)
|
|
77
|
+
restrictions.key?(attribute)
|
|
78
|
+
end
|
|
79
|
+
|
|
76
80
|
def data
|
|
77
81
|
ATTRIBUTES.to_h { |attr| [attr, send(attr)] }
|
|
78
82
|
end
|
|
@@ -82,15 +86,15 @@ module Code0
|
|
|
82
86
|
attr_writer(*ATTRIBUTES)
|
|
83
87
|
|
|
84
88
|
def assign_attributes(data)
|
|
85
|
-
%
|
|
89
|
+
%i[start_date end_date].each do |property|
|
|
86
90
|
value = data[property]
|
|
87
91
|
value = parse_date(data[property]) unless data[property].is_a?(Date)
|
|
88
92
|
send("#{property}=", value)
|
|
89
93
|
end
|
|
90
94
|
|
|
91
|
-
send("licensee=", data[
|
|
92
|
-
send("restrictions=", data[
|
|
93
|
-
send("options=", data[
|
|
95
|
+
send("licensee=", data[:licensee])
|
|
96
|
+
send("restrictions=", data[:restrictions] || {})
|
|
97
|
+
send("options=", data[:options] || {})
|
|
94
98
|
end
|
|
95
99
|
|
|
96
100
|
def parse_date(str)
|
data/sig/code0/license.rbs
CHANGED
|
@@ -18,11 +18,13 @@ module Code0
|
|
|
18
18
|
|
|
19
19
|
def in_active_time?: -> bool
|
|
20
20
|
|
|
21
|
+
def restricted?: (Symbol) -> bool
|
|
22
|
+
|
|
21
23
|
def valid?: -> bool
|
|
22
24
|
|
|
23
25
|
private
|
|
24
26
|
|
|
25
|
-
def assign_attributes: (Hash[
|
|
27
|
+
def assign_attributes: (Hash[Symbol, any]) -> void
|
|
26
28
|
|
|
27
29
|
def parse_date: (String) -> Date?
|
|
28
30
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: code0-license
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Niklas van Schrick
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: base64
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.3.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.3.0
|
|
13
26
|
- !ruby/object:Gem::Dependency
|
|
14
27
|
name: rake
|
|
15
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,7 +93,6 @@ dependencies:
|
|
|
80
93
|
- - "~>"
|
|
81
94
|
- !ruby/object:Gem::Version
|
|
82
95
|
version: '2.29'
|
|
83
|
-
description:
|
|
84
96
|
email:
|
|
85
97
|
- mc.taucher2003@gmail.com
|
|
86
98
|
executables: []
|
|
@@ -111,7 +123,6 @@ metadata:
|
|
|
111
123
|
source_code_uri: https://github.com/code0-tech/code0-license
|
|
112
124
|
changelog_uri: https://github.com/code0-tech/code0-license/releases
|
|
113
125
|
rubygems_mfa_required: 'true'
|
|
114
|
-
post_install_message:
|
|
115
126
|
rdoc_options: []
|
|
116
127
|
require_paths:
|
|
117
128
|
- lib
|
|
@@ -126,8 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
126
137
|
- !ruby/object:Gem::Version
|
|
127
138
|
version: '0'
|
|
128
139
|
requirements: []
|
|
129
|
-
rubygems_version: 3.
|
|
130
|
-
signing_key:
|
|
140
|
+
rubygems_version: 3.6.9
|
|
131
141
|
specification_version: 4
|
|
132
142
|
summary: code0-license is used to validate software licenses
|
|
133
143
|
test_files: []
|