Skip to content

Commit 146f7fd

Browse files
committed
Initial commit
0 parents  commit 146f7fd

26 files changed

Lines changed: 919 additions & 0 deletions

.github/workflows/main.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Lint & Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
name: Ruby ${{ matrix.ruby }}
14+
strategy:
15+
matrix:
16+
ruby:
17+
- '3.2.2'
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Set up Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ matrix.ruby }}
25+
- name: Install gems
26+
run: bundle install
27+
- name: Run the default task
28+
run: bundle exec rake

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Push Gem
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
push:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: write
14+
id-token: write
15+
16+
steps:
17+
# Set up
18+
- uses: actions/checkout@v4
19+
- name: Set up Ruby
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: '3.2.2'
23+
24+
# Release
25+
- uses: rubygems/release-gem@v1

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
.idea/
10+
11+
license_key.key
12+
license_key.pub
13+
14+
# rspec failure tracking
15+
.rspec_status

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

.rubocop.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require:
2+
- rubocop-rake
3+
- rubocop-rspec
4+
5+
AllCops:
6+
TargetRubyVersion: 3.0.0
7+
NewCops: enable
8+
9+
Gemspec/DevelopmentDependencies:
10+
EnforcedStyle: gemspec
11+
12+
Metrics/AbcSize:
13+
Enabled: false
14+
15+
Metrics/MethodLength:
16+
Enabled: false
17+
18+
Metrics/CyclomaticComplexity:
19+
Enabled: false
20+
21+
Metrics/PerceivedComplexity:
22+
Enabled: false
23+
24+
Style/StringLiterals:
25+
Enabled: true
26+
EnforcedStyle: double_quotes
27+
28+
Style/StringLiteralsInInterpolation:
29+
Enabled: true
30+
EnforcedStyle: double_quotes
31+
32+
Layout/LineLength:
33+
Max: 120
34+
35+
RSpec/ExampleLength:
36+
Enabled: false

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 3.2.2

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in code0-license.gemspec
6+
gemspec

Gemfile.lock

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
PATH
2+
remote: .
3+
specs:
4+
code0-license (0.1.0.pre.release.testing)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
ast (2.4.2)
10+
diff-lcs (1.5.1)
11+
json (2.7.2)
12+
language_server-protocol (3.17.0.3)
13+
parallel (1.24.0)
14+
parser (3.3.1.0)
15+
ast (~> 2.4.1)
16+
racc
17+
racc (1.7.3)
18+
rainbow (3.1.1)
19+
rake (13.2.1)
20+
regexp_parser (2.9.0)
21+
rexml (3.2.6)
22+
rspec (3.13.0)
23+
rspec-core (~> 3.13.0)
24+
rspec-expectations (~> 3.13.0)
25+
rspec-mocks (~> 3.13.0)
26+
rspec-core (3.13.0)
27+
rspec-support (~> 3.13.0)
28+
rspec-expectations (3.13.0)
29+
diff-lcs (>= 1.2.0, < 2.0)
30+
rspec-support (~> 3.13.0)
31+
rspec-mocks (3.13.0)
32+
diff-lcs (>= 1.2.0, < 2.0)
33+
rspec-support (~> 3.13.0)
34+
rspec-support (3.13.1)
35+
rubocop (1.63.4)
36+
json (~> 2.3)
37+
language_server-protocol (>= 3.17.0)
38+
parallel (~> 1.10)
39+
parser (>= 3.3.0.2)
40+
rainbow (>= 2.2.2, < 4.0)
41+
regexp_parser (>= 1.8, < 3.0)
42+
rexml (>= 3.2.5, < 4.0)
43+
rubocop-ast (>= 1.31.1, < 2.0)
44+
ruby-progressbar (~> 1.7)
45+
unicode-display_width (>= 2.4.0, < 3.0)
46+
rubocop-ast (1.31.3)
47+
parser (>= 3.3.1.0)
48+
rubocop-capybara (2.20.0)
49+
rubocop (~> 1.41)
50+
rubocop-factory_bot (2.25.1)
51+
rubocop (~> 1.41)
52+
rubocop-rake (0.6.0)
53+
rubocop (~> 1.0)
54+
rubocop-rspec (2.29.1)
55+
rubocop (~> 1.40)
56+
rubocop-capybara (~> 2.17)
57+
rubocop-factory_bot (~> 2.22)
58+
rubocop-rspec_rails (~> 2.28)
59+
rubocop-rspec_rails (2.28.3)
60+
rubocop (~> 1.40)
61+
ruby-progressbar (1.13.0)
62+
unicode-display_width (2.5.0)
63+
64+
PLATFORMS
65+
x86_64-linux
66+
67+
DEPENDENCIES
68+
code0-license!
69+
rake (~> 13.0)
70+
rspec (~> 3.0)
71+
rubocop (~> 1.21)
72+
rubocop-rake (~> 0.6)
73+
rubocop-rspec (~> 2.29)
74+
75+
BUNDLED WITH
76+
2.4.12

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Niklas van Schrick
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Code0::License
2+
3+
`Code0::License` can create and validate software licenses.
4+
5+
## Installation
6+
7+
Install the gem and add to the application's Gemfile by executing:
8+
9+
$ bundle add code0-license
10+
11+
If bundler is not being used to manage dependencies, install the gem by executing:
12+
13+
$ gem install code0-license
14+
15+
## Usage
16+
17+
To start using the gem, you need to have a public and private RSA key.
18+
If you don't have a key pair, you can generate one by running `bin/create_key`
19+
20+
To generate a license, use the private key as encryption key:
21+
22+
```ruby
23+
require "code0/license"
24+
25+
# read private key from file
26+
private_key_file = File.read('license_key.key')
27+
private_key = OpenSSL::PKey::RSA.new(private_key_file)
28+
29+
# set private key as encryption key
30+
Code0::License.encryption_key = private_key
31+
32+
# create a license
33+
license = Code0::License.new(
34+
{
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+
}
41+
)
42+
43+
# export the license
44+
File.write('license.txt', Code0::License.export(license, 'CODE0'))
45+
```
46+
47+
To verify the license in your application, use the public key
48+
49+
```ruby
50+
require "code0/license"
51+
52+
# read public key from file
53+
public_key_file = File.read('license_key.pub')
54+
public_key = OpenSSL::PKey::RSA.new(public_key_file)
55+
56+
# set public key as encryption key
57+
Code0::License.encryption_key = public_key
58+
59+
# load the license
60+
license = Code0::License.load(File.read('license.txt'))
61+
62+
# exit if license is valid or outside of the valid time
63+
exit unless license.valid?
64+
exit unless license.in_active_time?
65+
66+
# for example, exit if users exceed licensed amount
67+
exit if User.count > license.restrictions['user_count']
68+
```

0 commit comments

Comments
 (0)