fripa 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c4b9a552724de9440ae408046a6e38c16f8d384726525ad589ba864dce04ae14
4
+ data.tar.gz: 4330ef7308fd8302b2c513b6f899ebdde194baea527b6d9c93eb633e1bf9e12b
5
+ SHA512:
6
+ metadata.gz: 27f407fe7b2e73c25c3800b2caddfe6e2c249895aeaec1a1a2fb7bf8435207d5084b051b024bff153addc0908391b3971e49a233398e9ca253ac4159e9497c1a
7
+ data.tar.gz: e45bda9e4d673f372421f8ed90173d83f153ae7d7a074d741750f3dd00b6057b09079e82d314f5987695331b983d80456625ff04fe7b00fb7f535b31a8bf60b3
data/.simplecov ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.start do
4
+ add_filter "/test/"
5
+ enable_coverage :branch
6
+ primary_coverage :branch
7
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-10-07
4
+
5
+ Initial release of Fripa - A Ruby client for the FreeIPA JSON-RPC API.
6
+
7
+ ### Added
8
+ - FreeIPA client with automatic authentication
9
+ - User resource management (find, show, add, modify, delete, password change)
10
+ - Group resource management (find, show, add, modify, delete)
11
+ - Group membership operations (add/remove members and member managers)
12
+ - Global configuration system with multiple configuration styles
13
+ - Comprehensive error handling with custom exception classes
14
+ - Parameter validation for resource methods
15
+ - Full test suite with VCR cassettes
16
+ - Complete API documentation and usage examples
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,96 @@
1
+ # Contributing to Fripa
2
+
3
+ Thank you for your interest in contributing to Fripa! This document provides guidelines and instructions for contributing.
4
+
5
+ ## How to Contribute
6
+
7
+ ### Reporting Bugs
8
+
9
+ If you find a bug, please open an issue on GitHub with:
10
+ - A clear, descriptive title
11
+ - Steps to reproduce the issue
12
+ - Expected behavior vs. actual behavior
13
+ - Your Ruby version and FreeIPA version
14
+ - Any relevant code samples or error messages
15
+
16
+ ### Suggesting Features
17
+
18
+ Feature suggestions are welcome! Please open an issue with:
19
+ - A clear description of the feature
20
+ - Use cases explaining why this feature would be useful
21
+ - Any implementation ideas you might have
22
+
23
+ ### Pull Requests
24
+
25
+ 1. **Fork the repository** and create your branch from `main`
26
+ 2. **Make your changes** following our coding standards
27
+ 3. **Add tests** for any new functionality
28
+ 4. **Ensure all tests pass** by running `bin/test`
29
+ 5. **Run the linter** with `bundle exec rubocop`
30
+ 6. **Update documentation** if you're changing functionality
31
+ 7. **Submit your pull request** with a clear description of changes
32
+
33
+ ## Development Setup
34
+
35
+ 1. Clone the repository:
36
+ ```bash
37
+ git clone https://github.com/brunocostanzo/fripa.git
38
+ cd fripa
39
+ ```
40
+
41
+ 2. Install dependencies:
42
+ ```bash
43
+ bin/setup
44
+ ```
45
+
46
+ 3. Run tests:
47
+ ```bash
48
+ bin/test
49
+ ```
50
+
51
+ 4. Run linter:
52
+ ```bash
53
+ bundle exec rubocop
54
+ ```
55
+
56
+ ## Coding Standards
57
+
58
+ - Follow the [Ruby Style Guide](https://rubystyle.guide/)
59
+ - Use RuboCop to check your code style
60
+ - Write clear, self-documenting code
61
+ - Add comments for complex logic
62
+ - Keep methods small and focused
63
+ - Maintain test coverage above 95%
64
+
65
+ ## Testing Guidelines
66
+
67
+ - Write tests for all new features
68
+ - Update tests when modifying existing features
69
+ - Use VCR cassettes for API interactions
70
+ - Ensure both line and branch coverage remain high
71
+ - Test both success and error cases
72
+
73
+ ## Commit Messages
74
+
75
+ Write clear, descriptive commit messages:
76
+ - Use present tense ("Add feature" not "Added feature")
77
+ - Capitalize the first letter
78
+ - Keep the first line under 72 characters
79
+ - Add detailed description if needed
80
+
81
+ Example:
82
+ ```
83
+ Add support for host management
84
+
85
+ - Implement host resource with CRUD operations
86
+ - Add tests with VCR cassettes
87
+ - Update README with usage examples
88
+ ```
89
+
90
+ ## Questions?
91
+
92
+ If you have questions about contributing, feel free to open an issue labeled "question".
93
+
94
+ ## Code of Conduct
95
+
96
+ By participating in this project, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md).
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Bruno Costanzo
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.
data/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # Fripa
2
+
3
+ A Ruby client for the FreeIPA JSON-RPC API.
4
+
5
+ Docs: [FreeIPA JSON-RPC API](https://freeipa.readthedocs.io/en/latest/api/json-rpc.html)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fripa'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ gem install fripa
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ Configure your FreeIPA server settings globally. These settings are shared across all client instances:
30
+
31
+ ### With a block
32
+
33
+ ```ruby
34
+ Fripa.configure do |config|
35
+ config.host = 'ipa.example.com'
36
+ config.verify_ssl = true # default: true
37
+ end
38
+ ```
39
+
40
+ ### With a hash
41
+
42
+ ```ruby
43
+ Fripa.config = {
44
+ host: 'ipa.example.com',
45
+ verify_ssl: true
46
+ }
47
+ ```
48
+
49
+ ### With a Configuration instance
50
+
51
+ ```ruby
52
+ config = Fripa::Configuration.new(
53
+ host: 'ipa.example.com',
54
+ verify_ssl: true
55
+ )
56
+ Fripa.config = config
57
+ ```
58
+
59
+ ### Direct attribute assignment
60
+
61
+ ```ruby
62
+ Fripa.config.host = 'ipa.example.com'
63
+ Fripa.config.verify_ssl = false
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ ### Creating a Client
69
+
70
+ Create a client instance with user credentials. The client authenticates immediately upon creation:
71
+
72
+ ```ruby
73
+ client = Fripa::Client.new(
74
+ username: 'your-username',
75
+ password: 'your-password'
76
+ )
77
+ # Client is now authenticated and ready to use
78
+ ```
79
+
80
+ If authentication fails, a `Fripa::AuthenticationError` will be raised immediately:
81
+
82
+ ```ruby
83
+ begin
84
+ client = Fripa::Client.new(username: 'admin', password: 'wrong-password')
85
+ rescue Fripa::AuthenticationError => e
86
+ puts "Authentication failed: #{e.message}"
87
+ end
88
+ ```
89
+
90
+ ### Making API Calls
91
+
92
+ #### Using Resource Methods (Recommended)
93
+
94
+ The gem provides convenient resource methods with parameter validation:
95
+
96
+ ##### Users
97
+
98
+ ```ruby
99
+ client = Fripa::Client.new(username: 'admin', password: 'secret')
100
+
101
+ # Find users
102
+ users = client.users.find # All users
103
+ user = client.users.find("admin") # Find specific user
104
+
105
+ # Show user details
106
+ details = client.users.show("admin")
107
+
108
+ # Add a user (validates required fields)
109
+ client.users.add("newuser",
110
+ givenname: "New",
111
+ sn: "User",
112
+ cn: "New User",
113
+ userpassword: "TempPassword123"
114
+ )
115
+
116
+ # Modify a user
117
+ client.users.mod("newuser", mail: "newuser@example.com")
118
+
119
+ # Change user password
120
+ client.users.passwd("newuser", "NewPassword123", "TempPassword123")
121
+
122
+ # Delete a user
123
+ client.users.delete("newuser")
124
+ ```
125
+
126
+ ##### Groups
127
+
128
+ ```ruby
129
+ client = Fripa::Client.new(username: 'admin', password: 'secret')
130
+
131
+ # Find groups
132
+ groups = client.groups.find # All groups
133
+ group = client.groups.find("admins") # Find specific group
134
+
135
+ # Show group details
136
+ details = client.groups.show("admins")
137
+
138
+ # Add a group
139
+ client.groups.add("developers", description: "Development Team")
140
+
141
+ # Modify a group
142
+ client.groups.mod("developers", description: "Software Development Team")
143
+
144
+ # Add members to a group
145
+ client.groups.add_member("developers", user: ["alice", "bob"])
146
+
147
+ # Remove members from a group
148
+ client.groups.remove_member("developers", user: ["alice"])
149
+
150
+ # Add member managers (users who can manage group membership)
151
+ client.groups.add_member_manager("developers", user: ["manager"])
152
+
153
+ # Remove member managers
154
+ client.groups.remove_member_manager("developers", user: ["manager"])
155
+
156
+ # Delete a group
157
+ client.groups.delete("developers")
158
+ ```
159
+
160
+ #### Using Raw API Calls
161
+
162
+ For API methods without a resource wrapper, use the `call` method directly:
163
+
164
+ ```ruby
165
+ client = Fripa::Client.new(username: 'admin', password: 'secret')
166
+
167
+ # Any FreeIPA JSON-RPC method
168
+ result = client.call("user_find", ["admin"], { all: true })
169
+ puts result.dig("result", "count")
170
+ ```
171
+
172
+ The client will automatically authenticate if no session exists.
173
+
174
+ ## Development
175
+
176
+ After checking out the repo, run `bin/setup` to install dependencies.
177
+
178
+ ### Running Tests
179
+
180
+ To run the test suite with coverage:
181
+
182
+ ```bash
183
+ bin/test
184
+ ```
185
+
186
+ This will run all tests and generate a coverage report in `coverage/index.html`. The test suite includes:
187
+ - Line coverage tracking
188
+ - Branch coverage tracking
189
+ - VCR cassettes for testing against FreeIPA sandbox
190
+
191
+ ### Other Development Commands
192
+
193
+ - `bin/console` - Interactive prompt for experimentation
194
+ - `bundle exec rake install` - Install gem onto your local machine
195
+ - `bundle exec rubocop` - Run code style checks
196
+
197
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
198
+
199
+ ## Contributing
200
+
201
+ Bug reports and pull requests are welcome on GitHub at https://github.com/renuo/fripa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/renuo/fripa/blob/main/CODE_OF_CONDUCT.md).
202
+
203
+ For detailed contributing guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md).
204
+
205
+ ## License
206
+
207
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
208
+
209
+ ## Code of Conduct
210
+
211
+ Everyone interacting in the Fripa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/renuo/fripa/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create do |t|
7
+ t.warning = false
8
+ end
9
+
10
+ require "rubocop/rake_task"
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i[test rubocop]
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "uri"
5
+
6
+ module Fripa
7
+ class Authenticator
8
+ LOGIN_PATH = "/ipa/session/login_password"
9
+ CONTENT_TYPE = "application/x-www-form-urlencoded"
10
+
11
+ attr_reader :client
12
+
13
+ def initialize(client)
14
+ @client = client
15
+ end
16
+
17
+ def login!
18
+ validate_credentials!
19
+ response = perform_login
20
+
21
+ raise AuthenticationError, "Login failed: #{response.status}" unless response.success?
22
+
23
+ response.headers["set-cookie"]
24
+ end
25
+
26
+ private
27
+
28
+ def validate_credentials!
29
+ raise ArgumentError, "Username cannot be blank" if client.username.to_s.strip.empty?
30
+ raise ArgumentError, "Password cannot be blank" if client.password.to_s.strip.empty?
31
+ end
32
+
33
+ def perform_login
34
+ connection.post(LOGIN_PATH) do |request|
35
+ request.headers["Content-Type"] = CONTENT_TYPE
36
+ request.headers["Referer"] = "#{client.config.base_url}/ipa"
37
+ request.body = URI.encode_www_form(user: client.username, password: client.password)
38
+ end
39
+ end
40
+
41
+ def connection
42
+ @connection ||= Faraday.new(url: client.config.base_url.to_s) do |f|
43
+ f.request :url_encoded
44
+ f.adapter Faraday.default_adapter
45
+ f.ssl.verify = client.config.verify_ssl
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+
6
+ module Fripa
7
+ class Client
8
+ API_PATH = "/ipa/session/json"
9
+ API_VERSION = "2.251"
10
+
11
+ attr_reader :config, :username, :password
12
+ attr_accessor :session_cookie
13
+
14
+ def initialize(username:, password:, config: nil)
15
+ @config = config || Fripa.config
16
+ @username = username
17
+ @password = password
18
+ @session_cookie = authenticator.login!
19
+ end
20
+
21
+ def users
22
+ @users ||= Resources::User.new(self)
23
+ end
24
+
25
+ def groups
26
+ @groups ||= Resources::Group.new(self)
27
+ end
28
+
29
+ def authenticator
30
+ @authenticator ||= Authenticator.new(self)
31
+ end
32
+
33
+ def call(method, args = [], options = {})
34
+ response = perform_request(method, args, options)
35
+
36
+ raise ConnectionError, "API call failed: #{response.status}" unless response.success?
37
+
38
+ parse_response(response)
39
+ end
40
+
41
+ private
42
+
43
+ def perform_request(method, args, options)
44
+ connection.post(API_PATH) do |request|
45
+ request.headers["Content-Type"] = "application/json"
46
+ request.headers["Referer"] = "#{config.base_url}/ipa"
47
+ request.headers["Cookie"] = session_cookie
48
+ request.body = build_request_body(method, args, options).to_json
49
+ end
50
+ end
51
+
52
+ def build_request_body(method, args, options)
53
+ {
54
+ method: method,
55
+ params: [args, options.merge(version: API_VERSION)],
56
+ id: 0
57
+ }
58
+ end
59
+
60
+ def parse_response(response)
61
+ JSON.parse(response.body)
62
+ end
63
+
64
+ def connection
65
+ @connection ||= Faraday.new(url: config.base_url.to_s) do |f|
66
+ f.request :url_encoded
67
+ f.adapter Faraday.default_adapter
68
+ f.ssl.verify = config.verify_ssl
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ # Fripa configuration
6
+ module Fripa
7
+ # Configuration for Fripa
8
+ class Configuration
9
+ attr_accessor :host, :verify_ssl
10
+
11
+ def initialize(host: nil, verify_ssl: true)
12
+ @host = host
13
+ @verify_ssl = verify_ssl
14
+ end
15
+
16
+ def base_url
17
+ URI::HTTPS.build(host: host)
18
+ end
19
+
20
+ def login_url
21
+ URI::HTTPS.build(host: host, path: "/ipa/session/login_password")
22
+ end
23
+
24
+ def api_url
25
+ URI::HTTPS.build(host: host, path: "/ipa/session/json")
26
+ end
27
+ end
28
+
29
+ class << self
30
+ def config
31
+ @config ||= Configuration.new
32
+ end
33
+
34
+ def config=(value)
35
+ @config = case value
36
+ when Hash
37
+ Configuration.new(**value)
38
+ when Configuration
39
+ value
40
+ else
41
+ raise ArgumentError, "config must be a Hash or Configuration instance"
42
+ end
43
+ end
44
+
45
+ def configure
46
+ yield(config)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fripa
4
+ class Error < StandardError; end
5
+ class AuthenticationError < Error; end
6
+ class ConnectionError < Error; end
7
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fripa
4
+ module Resources
5
+ class Base
6
+ attr_reader :client
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ private
13
+
14
+ def call(method, args = [], options = {})
15
+ client.call(method, args, options)
16
+ end
17
+
18
+ def validate_identifier!(identifier, name = "identifier")
19
+ raise ArgumentError, "#{name} is required" if identifier.to_s.strip.empty?
20
+ end
21
+
22
+ def validate_attributes!(attributes)
23
+ raise ArgumentError, "attributes cannot be empty" if attributes.empty?
24
+ end
25
+
26
+ def validate_required_fields!(attributes, required_fields)
27
+ missing = required_fields.reject { |field| attributes.key?(field) }
28
+ return if missing.empty?
29
+
30
+ raise ArgumentError, "Missing required fields: #{missing.join(", ")}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fripa
4
+ module Resources
5
+ class Group < Base
6
+ def find(cn = nil, **options)
7
+ args = cn ? [cn] : []
8
+ call("group_find", args, options)
9
+ end
10
+
11
+ def show(cn)
12
+ validate_identifier!(cn, "cn")
13
+ call("group_show", [cn])
14
+ end
15
+
16
+ def add(cn, **attributes)
17
+ validate_identifier!(cn, "cn")
18
+ call("group_add", [cn], attributes)
19
+ end
20
+
21
+ def mod(cn, **attributes)
22
+ validate_identifier!(cn, "cn")
23
+ validate_attributes!(attributes)
24
+ call("group_mod", [cn], attributes)
25
+ end
26
+
27
+ def delete(cn)
28
+ validate_identifier!(cn, "cn")
29
+ call("group_del", [cn])
30
+ end
31
+
32
+ def add_member(cn, **members)
33
+ validate_identifier!(cn, "cn")
34
+ validate_attributes!(members)
35
+ call("group_add_member", [cn], members)
36
+ end
37
+
38
+ def remove_member(cn, **members)
39
+ validate_identifier!(cn, "cn")
40
+ validate_attributes!(members)
41
+ call("group_remove_member", [cn], members)
42
+ end
43
+
44
+ def add_member_manager(cn, **managers)
45
+ validate_identifier!(cn, "cn")
46
+ validate_attributes!(managers)
47
+ call("group_add_member_manager", [cn], managers)
48
+ end
49
+
50
+ def remove_member_manager(cn, **managers)
51
+ validate_identifier!(cn, "cn")
52
+ validate_attributes!(managers)
53
+ call("group_remove_member_manager", [cn], managers)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fripa
4
+ module Resources
5
+ class User < Base
6
+ REQUIRED_ADD_FIELDS = %i[givenname sn cn].freeze
7
+
8
+ def find(uid = nil, **options)
9
+ args = uid ? [uid] : []
10
+ call("user_find", args, options)
11
+ end
12
+
13
+ def show(uid)
14
+ validate_identifier!(uid, "uid")
15
+ call("user_show", [uid])
16
+ end
17
+
18
+ def add(uid, **attributes)
19
+ validate_identifier!(uid, "uid")
20
+ validate_required_fields!(attributes, REQUIRED_ADD_FIELDS)
21
+ call("user_add", [uid], attributes)
22
+ end
23
+
24
+ def mod(uid, **attributes)
25
+ validate_identifier!(uid, "uid")
26
+ validate_attributes!(attributes)
27
+ call("user_mod", [uid], attributes)
28
+ end
29
+
30
+ def delete(uid)
31
+ validate_identifier!(uid, "uid")
32
+ call("user_del", [uid])
33
+ end
34
+
35
+ def passwd(uid, new_password, current_password, **options)
36
+ validate_identifier!(uid, "uid")
37
+ validate_password!(new_password, "new_password")
38
+ validate_password!(current_password, "current_password")
39
+ call("passwd", [uid, new_password, current_password], options)
40
+ end
41
+
42
+ private
43
+
44
+ def validate_password!(password, name)
45
+ raise ArgumentError, "#{name} cannot be blank" if password.to_s.strip.empty?
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fripa
4
+ VERSION = "0.1.0"
5
+ end
data/lib/fripa.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "fripa/version"
4
+ require_relative "fripa/configuration"
5
+ require_relative "fripa/errors"
6
+ require_relative "fripa/authenticator"
7
+ require_relative "fripa/resources/base"
8
+ require_relative "fripa/resources/user"
9
+ require_relative "fripa/resources/group"
10
+ require_relative "fripa/client"
11
+
12
+ module Fripa
13
+ end
data/sig/fripa.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Fripa
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fripa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Costanzo
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: A Ruby client library for interacting with FreeIPA's JSON-RPC API
27
+ email:
28
+ - dev.bcostanzo@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".simplecov"
34
+ - CHANGELOG.md
35
+ - CODE_OF_CONDUCT.md
36
+ - CONTRIBUTING.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/fripa.rb
41
+ - lib/fripa/authenticator.rb
42
+ - lib/fripa/client.rb
43
+ - lib/fripa/configuration.rb
44
+ - lib/fripa/errors.rb
45
+ - lib/fripa/resources/base.rb
46
+ - lib/fripa/resources/group.rb
47
+ - lib/fripa/resources/user.rb
48
+ - lib/fripa/version.rb
49
+ - sig/fripa.rbs
50
+ homepage: https://github.com/renuo/fripa
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ homepage_uri: https://github.com/renuo/fripa
55
+ source_code_uri: https://github.com/renuo/fripa
56
+ changelog_uri: https://github.com/renuo/fripa/blob/main/CHANGELOG.md
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.2.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.6.9
72
+ specification_version: 4
73
+ summary: Ruby client for FreeIPA JSON-RPC API
74
+ test_files: []