cogito 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1007e6e554e00e04747405c8ee6add85d5dd0627
4
+ data.tar.gz: cc6ae872ca66b6b9436de4599319c86a0773f3d9
5
+ SHA512:
6
+ metadata.gz: 319f5492ee692f7cd90aa4dc09353d76629f40f530a12ea648f4ad247dbc3193bea7cd6895a7fc3a409e59aae24fb5039b741cd619d831144bb1f2d952d677fe
7
+ data.tar.gz: 5caf12fbf6b8949d73c7c16bdfdd9de33821eeceafdd6ca4c0a9f3e4e58f6c62be95e3bb0e0f2cc0fbe483f1740b7a95219987569e2fd4331e00d89b96318530
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /lib/cogito/cogito.bundle
@@ -0,0 +1,29 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ TargetRubyVersion: 2.3
5
+
6
+ # Increase to github width
7
+ Metrics/LineLength:
8
+ Max: 117
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/EmptyLinesAroundClassBody:
14
+ Enabled: false
15
+
16
+ Style/EmptyLinesAroundModuleBody:
17
+ Enabled: false
18
+
19
+ Style/FrozenStringLiteralComment:
20
+ Enabled: false
21
+
22
+ # Prefer [] to () default
23
+ Style/PercentLiteralDelimiters:
24
+ PreferredDelimiters:
25
+ '%w': '[]'
26
+ '%i': '[]'
27
+
28
+ Style/PerlBackrefs:
29
+ Enabled: false
@@ -0,0 +1,15 @@
1
+ sudo: required
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ cache: bundler
6
+ branches:
7
+ only:
8
+ - master
9
+ before_install:
10
+ - FILE=$(mktemp)
11
+ - wget 'https://s3.amazonaws.com/public.localytics/artifacts/cogito/libcogito_0.0.1-1_amd64.deb' -qO $FILE
12
+ - sudo dpkg -i $FILE && rm $FILE
13
+ script:
14
+ - bundle exec rake
15
+ - bundle exec rubocop
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Localytics
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.
@@ -0,0 +1,59 @@
1
+ # cogito-rb
2
+
3
+ [![Build Status](https://travis-ci.org/localytics/cogito-rb.svg?branch=master)](https://travis-ci.org/localytics/cogito-rb)
4
+ [![Coverage Status](https://coveralls.io/repos/github/localytics/cogito-rb/badge.svg?branch=master)](https://coveralls.io/github/localytics/cogito-rb?branch=master)
5
+
6
+ A small ruby library that links against [libcogito](https://github.com/localytics/libcogito).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'cogito'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install cogito
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ irb(main):001:0> puts Cogito.to_json('ALLOW a ON b;')
28
+ [
29
+ {
30
+ "Effect": "Allow",
31
+ "Action": [
32
+ "a"
33
+ ],
34
+ "Resource": [
35
+ "b"
36
+ ]
37
+ }
38
+ ]
39
+
40
+ irb(main):002:0> puts Cogito.to_iam(['Effect' => 'Allow', 'Action' => 'a', 'Resource' => 'b'].to_json)
41
+ ALLOW
42
+ a
43
+ ON
44
+ b;
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bundle/install` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/localytics/cogito-rb.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/extensiontask'
3
+ require 'rake/testtask'
4
+
5
+ Rake::ExtensionTask.new('cogito') do |ext|
6
+ ext.lib_dir = File.join('lib', 'cogito')
7
+ end
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'test'
11
+ t.libs << 'lib'
12
+ t.test_files = FileList['test/**/*_test.rb']
13
+ end
14
+
15
+ Rake::Task[:test].prerequisites << :compile
16
+
17
+ task default: :test
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cogito'
5
+
6
+ require 'irb'
7
+ IRB.start
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cogito/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cogito'
8
+ spec.version = Cogito::VERSION
9
+ spec.authors = ['Localytics']
10
+ spec.email = ['oss@localytics.com']
11
+
12
+ spec.summary = 'A ruby library that wraps libcogito'
13
+ spec.homepage = 'https://github.com/localytics/cogito-rb'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.extensions = ['ext/cogito/extconf.rb']
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.12'
23
+ spec.add_development_dependency 'coveralls', '~> 0.8'
24
+ spec.add_development_dependency 'minitest', '~> 5.9'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rake-compiler', '~> 0.9'
27
+ spec.add_development_dependency 'rubocop', '~> 0.39'
28
+ spec.add_development_dependency 'simplecov', '~> 0.11'
29
+ end
@@ -0,0 +1,52 @@
1
+ #include "cogito.h"
2
+
3
+ extern int cg_to_json(cg_buf_t *buffer, char *input);
4
+ extern int cg_to_iam(cg_buf_t *buffer, char *input);
5
+
6
+ extern cg_buf_t* cg_buf_build(void);
7
+ extern void cg_buf_free(cg_buf_t *buffer);
8
+
9
+ static VALUE CogitoError;
10
+
11
+ static VALUE to_json(VALUE self, VALUE str)
12
+ {
13
+ if (TYPE(str) == T_NIL) return Qnil;
14
+
15
+ cg_buf_t *buffer = cg_buf_build();
16
+ char *input = rb_string_value_cstr(&str);
17
+
18
+ if (cg_to_json(buffer, input) != 0) {
19
+ rb_raise(CogitoError, "JSON conversion failed");
20
+ }
21
+
22
+ VALUE response = rb_str_new2(buffer->content);
23
+ cg_buf_free(buffer);
24
+ return response;
25
+ }
26
+
27
+ static VALUE to_iam(VALUE self, VALUE str)
28
+ {
29
+ if (TYPE(str) == T_NIL) return Qnil;
30
+
31
+ cg_buf_t *buffer = cg_buf_build();
32
+ char *input = rb_string_value_cstr(&str);
33
+
34
+ if (cg_to_iam(buffer, input) != 0) {
35
+ rb_raise(CogitoError, "IAM conversion failed");
36
+ }
37
+
38
+ VALUE response = rb_str_new2(buffer->content);
39
+ cg_buf_free(buffer);
40
+ return response;
41
+ }
42
+
43
+ void Init_cogito()
44
+ {
45
+ VALUE Cogito = rb_define_module("Cogito");
46
+ VALUE CogitoSingleton = rb_singleton_class(Cogito);
47
+
48
+ rb_define_private_method(CogitoSingleton, "convert_to_json", to_json, 1);
49
+ rb_define_singleton_method(Cogito, "to_iam", to_iam, 1);
50
+
51
+ CogitoError = rb_define_class_under(Cogito, "CogitoError", rb_eStandardError);
52
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef RUBY_COGITO
2
+ #define RUBY_COGITO
3
+
4
+ #include <ruby.h>
5
+ #include <cogito.h>
6
+
7
+ typedef struct cg_buf {
8
+ size_t length;
9
+ size_t capacity;
10
+ char *content;
11
+ } cg_buf_t;
12
+
13
+ void Init_cogito();
14
+
15
+ #endif
@@ -0,0 +1,52 @@
1
+ require 'mkmf'
2
+
3
+ HEADER_DIRS = [
4
+ # First search /opt/local for macports
5
+ '/opt/local/include',
6
+
7
+ # Then search /usr/local for people that installed from source
8
+ '/usr/local/include',
9
+
10
+ # Check the ruby install locations
11
+ RbConfig::CONFIG['includedir'],
12
+
13
+ # Finally fall back to /usr
14
+ '/usr/include'
15
+ ].freeze
16
+
17
+ LIB_DIRS = [
18
+ # First search /opt/local for macports
19
+ '/opt/local/lib',
20
+
21
+ # Then search /usr/local for people that installed from source
22
+ '/usr/local/lib',
23
+
24
+ # Check the ruby install locations
25
+ RbConfig::CONFIG['libdir'],
26
+
27
+ # Finally fall back to /usr
28
+ '/usr/lib'
29
+ ].freeze
30
+
31
+ failure_message = "\n" << '=' * 85 << "\n"
32
+ failure_message << "libcogito is missing from your system. Please install by running the following steps:\n\n"
33
+ failure_message <<
34
+ if `uname`.chomp == 'Darwin'
35
+ <<-MSG
36
+ $ brew tap localytics/formulae
37
+ $ brew install cogito
38
+ MSG
39
+ else
40
+ <<-MSG
41
+ $ FILE=$(mktemp)
42
+ $ wget 'https://s3.amazonaws.com/public.localytics/artifacts/libcogito_0.0.1-1_amd64.deb' -qO $FILE
43
+ $ sudo dpkg -i $FILE && rm $FILE
44
+ MSG
45
+ end
46
+ failure_message << '=' * 85 << "\n\n"
47
+
48
+ dir_config('cogito', HEADER_DIRS, LIB_DIRS)
49
+ abort failure_message unless find_header('cogito.h', *HEADER_DIRS)
50
+ abort failure_message unless find_library('cogito', 'cg_to_json', *LIB_DIRS)
51
+
52
+ create_makefile('cogito/cogito')
@@ -0,0 +1,20 @@
1
+ require 'cogito/cogito'
2
+ require 'cogito/version'
3
+
4
+ module Cogito
5
+ class << self
6
+ def to_json(str, subs = {})
7
+ convert_to_json(substitute(str, subs))
8
+ end
9
+
10
+ private
11
+
12
+ def substitute(str, subs)
13
+ substituted = str.dup
14
+ subs.each do |key, value|
15
+ substituted.gsub!("${#{key}}", value)
16
+ end
17
+ substituted
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Cogito
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cogito
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Localytics
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-compiler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.39'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.39'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ description:
112
+ email:
113
+ - oss@localytics.com
114
+ executables: []
115
+ extensions:
116
+ - ext/cogito/extconf.rb
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - cogito.gemspec
128
+ - ext/cogito/cogito.c
129
+ - ext/cogito/cogito.h
130
+ - ext/cogito/extconf.rb
131
+ - lib/cogito.rb
132
+ - lib/cogito/version.rb
133
+ homepage: https://github.com/localytics/cogito-rb
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.8
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: A ruby library that wraps libcogito
157
+ test_files: []