rack-webfinger 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: 6b9a43430d1f41be38e2b5e38fdcba83610562bd44e7f2a456a02be9e3a85e18
4
+ data.tar.gz: 7f00c46856f655d5b89bad2e13c22761cc28dc22201b96ce88a15875f770690b
5
+ SHA512:
6
+ metadata.gz: 8c763cf4294ea00e20e6d4239474adb36f50ea8f94e4e431b83ea6bfd8b5b54df07335b7243f8a6ef9e3e78d95cb4c2da885b43e097f9851a0b9bd7eb70d47a2
7
+ data.tar.gz: 35388dd7682829e76db423a71e3a8d3247ef6f3667f90aad2fec7ffe4aa0d5c3418e961654ff2ecdec9f104e986e7cf45b7521b39424dad8da70495f698809c1
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Vidar Hokstad
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,33 @@
1
+ # Rack::Webfinger
2
+
3
+ A very basic first pass at a Rack middleware to serve up Webfinger
4
+ requests. There isn't much to serving up Webfinger requests, so this
5
+ middleware won't do much.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add rack-webfinger
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install rack-webfinger
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vidarh/rack-webfinger.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ class Webfinger
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+ require 'json'
5
+ require_relative "webfinger/version"
6
+
7
+ module Rack
8
+ class Webfinger
9
+ def initialize(data_provider)
10
+ @data_provider = data_provider
11
+ end
12
+
13
+ def not_found = [404, { 'Content-Type' => 'text/plain' }, ['Resource not found']]
14
+
15
+ def call(env)
16
+ request = Rack::Request.new(env)
17
+
18
+ return not_found if request.path != '/.well-known/webfinger'
19
+
20
+ resource = request.params['resource']
21
+
22
+ if !resource
23
+ return [400, { 'Content-Type' => 'text/plain' }, ['Missing resource parameter']]
24
+ end
25
+
26
+ # We need this because Rack's handling of the query string by default overwrites
27
+ # subsequent 'rel' parameters.
28
+
29
+ query_params = Rack::Utils.parse_query(env['QUERY_STRING'])
30
+ rel_params = Array(query_params['rel'])
31
+
32
+ data = @data_provider.call(resource, rel_params)
33
+
34
+ return not_found if !data
35
+
36
+ response_data = {
37
+ subject: resource,
38
+ aliases: data[:aliases],
39
+ links: data[:links]
40
+ }
41
+ filtered_data = filter_by_rel(response_data, rel_params)
42
+
43
+ [200,
44
+ { 'Content-Type' => 'application/jrd+json' },
45
+ [JSON.generate(filtered_data)]
46
+ ]
47
+ end
48
+
49
+ private
50
+
51
+ def filter_by_rel(data, rel_params)
52
+ return data if rel_params.empty?
53
+
54
+ data.merge(links: data[:links].select { |link| rel_params.include?(link[:rel]) })
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ module Rack
2
+ module Webfinger
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-webfinger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vidar Hokstad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-test
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - vidar@hokstad.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - lib/rack/webfinger.rb
39
+ - lib/rack/webfinger/version.rb
40
+ - sig/rack/webfinger.rbs
41
+ homepage: https://github.com/vidarh/rack-webfinger
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://github.com/vidarh/rack-webfinger
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.4.10
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Serve Webfinger responses easily from Rack
65
+ test_files: []