bonita 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +50 -0
  9. data/Rakefile +6 -0
  10. data/VERSION +1 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/bonita.gemspec +41 -0
  14. data/lib/bonita.rb +52 -0
  15. data/lib/bonita/client.rb +105 -0
  16. data/lib/bonita/error.rb +25 -0
  17. data/lib/bonita/error_handler.rb +20 -0
  18. data/lib/bonita/mappings/bpm/process_mapping.rb +31 -0
  19. data/lib/bonita/mappings/customuserinfo/definition_mapping.rb +23 -0
  20. data/lib/bonita/mappings/customuserinfo/user_mapping.rb +18 -0
  21. data/lib/bonita/mappings/customuserinfo/value_mapping.rb +16 -0
  22. data/lib/bonita/mappings/error_mapping.rb +18 -0
  23. data/lib/bonita/mappings/identity/group_mapping.rb +39 -0
  24. data/lib/bonita/mappings/identity/membership_mapping.rb +26 -0
  25. data/lib/bonita/mappings/identity/role_mapping.rb +30 -0
  26. data/lib/bonita/mappings/identity/user_mapping.rb +53 -0
  27. data/lib/bonita/middleware/csrf.rb +19 -0
  28. data/lib/bonita/models/base_model.rb +29 -0
  29. data/lib/bonita/models/bpm/process.rb +19 -0
  30. data/lib/bonita/models/customuserinfo/definition.rb +10 -0
  31. data/lib/bonita/models/customuserinfo/user.rb +10 -0
  32. data/lib/bonita/models/customuserinfo/value.rb +8 -0
  33. data/lib/bonita/models/identity/group.rb +18 -0
  34. data/lib/bonita/models/identity/membership.rb +12 -0
  35. data/lib/bonita/models/identity/role.rb +15 -0
  36. data/lib/bonita/models/identity/user.rb +23 -0
  37. data/lib/bonita/resources/bpm/process_resource.rb +38 -0
  38. data/lib/bonita/resources/customuserinfo/definition_resource.rb +31 -0
  39. data/lib/bonita/resources/customuserinfo/user_resource.rb +18 -0
  40. data/lib/bonita/resources/customuserinfo/value_resource.rb +18 -0
  41. data/lib/bonita/resources/identity/group_resource.rb +43 -0
  42. data/lib/bonita/resources/identity/membership_resource.rb +31 -0
  43. data/lib/bonita/resources/identity/role_resource.rb +44 -0
  44. data/lib/bonita/resources/identity/user_resource.rb +58 -0
  45. data/lib/bonita/utils.rb +93 -0
  46. data/lib/bonita/version.rb +6 -0
  47. metadata +194 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 572ccd6cb3b9400725507a810146bee1cd19c530
4
+ data.tar.gz: 31548ca22dd29800d89733b3adc6e9bff3d1a2ff
5
+ SHA512:
6
+ metadata.gz: d44eddbc53c53afd5e42da0af36c7acd5f64e8893fa683476ae969163b23e7309291aa8767917941c8fb83cf0be55f94851894597c2a425dfebd8315033d2fb2
7
+ data.tar.gz: 073a5a847a94e5009b699b6ee2e1e23195de93ad03770584ef8564305d9fa5cefb0b2a93612d420edb10dbf79d43c01c47e956b9c9f639055f52b7cff6e2dab7
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
11
+ .rubocop-*
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at pierre.deville@effilab.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bonita.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Pierre Deville
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,50 @@
1
+ # BonitaBPM Ruby API Client
2
+
3
+ Unofficial API client for [Bonita API](https://effilab.atlassian.net/wiki/display/IT/Product+Launch+-+Overview)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bonita'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bonita
20
+
21
+ ## Usage
22
+
23
+ Bonita API requires you to login to the portal URL, then logout when you're done.
24
+
25
+ There is two way to handle this authentication logic.
26
+
27
+ ### With a block
28
+
29
+ ```ruby
30
+ Bonita::Client.start(username: "YOUR_USERNAME", password: "YOUR_PASSWORD", url: "YOUR_BONITA_SERVER_URL") do |client|
31
+ # Perform your request while authenticated using the client object
32
+ end # Logout seamlessly when closing the block_given
33
+ ```
34
+
35
+ ### With an instance
36
+ ```ruby
37
+ client = Bonita::Client.new(username: "YOUR_USERNAME", password: "YOUR_PASSWORD", url: "YOUR_BONITA_SERVER_URL")
38
+ client.login
39
+ # perform request
40
+ client.logout
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Pierre Deville/bonita. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bonita"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bonita/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bonita"
8
+ spec.version = Bonita::VERSION
9
+ spec.authors = ["Pierre Deville"]
10
+ spec.email = ["pierre.deville@effilab.com"]
11
+
12
+ spec.summary = "Unofficial REST API client for Bonita BPM"
13
+ spec.description = "Unofficial REST API client for Bonita BPM"
14
+ spec.homepage = "http://example.com"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency 'activesupport', '> 3.0', '< 5.1'
34
+ spec.add_dependency 'resource_kit', '~> 0.1.6'
35
+ spec.add_dependency 'kartograph', '~> 0.2.4'
36
+ spec.add_dependency 'faraday-cookie_jar', '~> 0.0.6'
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.14"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # 3rd party dependencies
4
+ require 'resource_kit'
5
+ require 'kartograph'
6
+ require 'faraday'
7
+ require 'faraday-cookie_jar'
8
+
9
+ # Utils
10
+ require 'bonita/utils'
11
+
12
+ # Error Handling
13
+ require 'bonita/mappings/error_mapping'
14
+ require 'bonita/error'
15
+ require 'bonita/error_handler'
16
+
17
+ # Models
18
+ require 'bonita/models/base_model'
19
+ require 'bonita/models/bpm/process'
20
+ require 'bonita/models/customuserinfo/definition'
21
+ require 'bonita/models/customuserinfo/value'
22
+ require 'bonita/models/customuserinfo/user'
23
+ require 'bonita/models/identity/user'
24
+ require 'bonita/models/identity/group'
25
+ require 'bonita/models/identity/role'
26
+ require 'bonita/models/identity/membership'
27
+
28
+ # JSON Maps
29
+ require 'bonita/mappings/bpm/process_mapping'
30
+ require 'bonita/mappings/customuserinfo/definition_mapping'
31
+ require 'bonita/mappings/customuserinfo/value_mapping'
32
+ require 'bonita/mappings/customuserinfo/user_mapping'
33
+ require 'bonita/mappings/identity/user_mapping'
34
+ require 'bonita/mappings/identity/group_mapping'
35
+ require 'bonita/mappings/identity/role_mapping'
36
+ require 'bonita/mappings/identity/membership_mapping'
37
+
38
+ # Resources
39
+ require 'bonita/resources/bpm/process_resource'
40
+ require 'bonita/resources/customuserinfo/definition_resource'
41
+ require 'bonita/resources/customuserinfo/value_resource'
42
+ require 'bonita/resources/customuserinfo/user_resource'
43
+ require 'bonita/resources/identity/user_resource'
44
+ require 'bonita/resources/identity/group_resource'
45
+ require 'bonita/resources/identity/role_resource'
46
+ require 'bonita/resources/identity/membership_resource'
47
+
48
+ require 'bonita/middleware/csrf'
49
+ require 'bonita/client'
50
+
51
+ module Bonita
52
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ class Client
4
+ attr_reader :username, :password, :url, :redirect_url, :tenant
5
+
6
+ class << self
7
+ def resources
8
+ {
9
+ customuserinfo: {
10
+ definitions: Customuserinfo::DefinitionResource,
11
+ users: Customuserinfo::UserResource,
12
+ values: Customuserinfo::ValueResource,
13
+ },
14
+ bpm: {
15
+ processes: Bpm::ProcessResource,
16
+ },
17
+ identity: {
18
+ groups: Identity::GroupResource,
19
+ memberships: Identity::MembershipResource,
20
+ roles: Identity::RoleResource,
21
+ users: Identity::UserResource,
22
+ },
23
+ }
24
+ end
25
+
26
+ def start(options = {})
27
+ client = new(options)
28
+ client.login
29
+
30
+ yield(client)
31
+ ensure
32
+ client.logout
33
+ end
34
+ end
35
+
36
+ resources.each do |key, value|
37
+ if value.is_a? Hash
38
+ mod = Object.const_get("Bonita::#{key.capitalize}")
39
+ mod.module_eval do
40
+ value.each do |k, v|
41
+ define_singleton_method(k) { v.new(connection: connection) }
42
+ end
43
+ end
44
+
45
+ define_method(key) do
46
+ this = self
47
+ mod.define_singleton_method(:connection) { this.connection }
48
+ mod
49
+ end
50
+ else
51
+ define_method(key) { value.new(connection: connection) }
52
+ end
53
+ end
54
+
55
+ def initialize(options = {})
56
+ @url = options[:url]
57
+ @username = options[:username]
58
+ @password = options[:password]
59
+ @tenant = options[:tenant]
60
+ end
61
+
62
+ def login
63
+ response =
64
+ connection.post '/bonita/loginservice' do |req|
65
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
66
+ req.body = {
67
+ username: @username,
68
+ password: @password,
69
+ tenant: @tenant,
70
+ }
71
+ end
72
+
73
+ raise Bonita::AuthError, 'Unable to log in' if response.body.include?('Unable to log in')
74
+ true
75
+ end
76
+
77
+ def logout
78
+ connection.get '/bonita/logoutservice?redirect=false'
79
+ end
80
+
81
+ def connection
82
+ @faraday ||=
83
+ Faraday.new connection_options do |conn|
84
+ conn.use :cookie_jar
85
+ conn.use Bonita::Middleware::CSRF
86
+ conn.use Faraday::Request::UrlEncoded
87
+ conn.adapter Faraday.default_adapter
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def connection_options
94
+ {
95
+ url: @url,
96
+ request: {
97
+ params_encoder: Faraday::FlatParamsEncoder,
98
+ },
99
+ headers: {
100
+ content_type: 'application/json',
101
+ },
102
+ }
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ class Error < StandardError
4
+ attr_reader :java_exception, :error_message, :explanations, :status
5
+
6
+ def initialize(status, body)
7
+ if body['exception']
8
+ mapping = Bonita::ErrorMapping.extract_single(body, :read)
9
+ @java_exception = mapping.exception
10
+ @error_message = mapping.message
11
+ @explanations = mapping.explanations
12
+ @status = status
13
+ values = Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
14
+ else
15
+ values = body
16
+ end
17
+
18
+ super(values)
19
+ end
20
+ end
21
+
22
+ AuthError = Class.new(StandardError)
23
+ UnauthorizedError = Class.new(StandardError)
24
+ ForbiddenError = Class.new(StandardError)
25
+ end