huginn_delegated_google_calendar_agent 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aba61cc07f486b337c9c592b66c5b57ea2a7c54243c5cf0901fc1659d7eb0d70
4
+ data.tar.gz: 860afa0400302fa684b71bdb1541de2596d80bfcb5e07e0ccc16830fdcff54fb
5
+ SHA512:
6
+ metadata.gz: 06cafd360e62e19183933c5dba6f463d1193e11e3761b745df4cfd2620abdd600d2a15e851870165963bea02d1285269ea8d4cec6fcf7e1febf8c71cf02181ae
7
+ data.tar.gz: 86433059c7cf2ed8c832f1a288c21820f9b33b0353988a72b26999f2725b274474e04b7284daad243e0473eadccabcae6b870b91167d4dd24ddbcb7cdf7f072a
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2025 Christian Augustine
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ require 'googleauth'
2
+ require 'google/apis/calendar_v3'
3
+
4
+ class DelegatedGoogleCalendar
5
+ def initialize(config, logger)
6
+ @config = config
7
+ @logger = logger
8
+
9
+ if @config['google']['key'].present?
10
+ ENV['GOOGLE_PRIVATE_KEY'] = @config['google']['key']
11
+ ENV['GOOGLE_CLIENT_EMAIL'] = @config['google']['service_account_email']
12
+ ENV['GOOGLE_ACCOUNT_TYPE'] = 'service_account'
13
+ elsif @config['google']['key_file'].present?
14
+ ENV['GOOGLE_APPLICATION_CREDENTIALS'] = @config['google']['key_file']
15
+ end
16
+
17
+ @calendar = Google::Apis::CalendarV3::CalendarService.new
18
+ scopes = [Google::Apis::CalendarV3::AUTH_CALENDAR]
19
+ @authorization = Google::Auth.get_application_default(scopes)
20
+
21
+ delegated_email = @config.dig('google', 'delegated_email')
22
+ if delegated_email && !delegated_email.empty? && @authorization.respond_to?(:sub=)
23
+ @authorization.sub = delegated_email
24
+ @logger.info("DelegatedGoogleCalendar: impersonating #{delegated_email}")
25
+ else
26
+ @logger.info("DelegatedGoogleCalendar: using service account identity")
27
+ end
28
+ end
29
+
30
+ def self.open(*args, &block)
31
+ instance = new(*args)
32
+ block.call(instance)
33
+ ensure
34
+ instance&.cleanup!
35
+ end
36
+
37
+ def auth_as
38
+ @authorization.fetch_access_token!
39
+ @calendar.authorization = @authorization
40
+ end
41
+
42
+ def publish_as(who, details)
43
+ auth_as
44
+ event = Google::Apis::CalendarV3::Event.new(**details.deep_symbolize_keys)
45
+ ret = @calendar.insert_event(who, event, send_notifications: true)
46
+ ret.to_h
47
+ end
48
+
49
+ def cleanup!
50
+ ENV.delete('GOOGLE_PRIVATE_KEY')
51
+ ENV.delete('GOOGLE_CLIENT_EMAIL')
52
+ ENV.delete('GOOGLE_ACCOUNT_TYPE')
53
+ ENV.delete('GOOGLE_APPLICATION_CREDENTIALS')
54
+ end
55
+ end
@@ -0,0 +1,46 @@
1
+ module Agents
2
+ class DelegatedGoogleCalendarAgent < Agent
3
+ cannot_be_scheduled!
4
+ no_bulk_receive!
5
+
6
+ def default_options
7
+ {
8
+ 'expected_update_period_in_days' => "10",
9
+ 'calendar_id' => 'you@example.com',
10
+ 'google' => {
11
+ 'key_file' => '/path/to/private.key',
12
+ 'key' => '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n',
13
+ 'service_account_email' => '',
14
+ 'delegated_email' => '' # 👈 NEW
15
+ }
16
+ }
17
+ end
18
+
19
+ def validate_options
20
+ errors.add(:base, "expected_update_period_in_days is required") unless options['expected_update_period_in_days'].present?
21
+ end
22
+
23
+ def receive(incoming_events)
24
+ require 'delegated_google_calendar'
25
+
26
+ incoming_events.each do |event|
27
+ DelegatedGoogleCalendar.open(interpolate_options(options, event), Rails.logger) do |calendar|
28
+ cal_message = event.payload["message"]
29
+ # same dateTime → date_time fixups as before...
30
+
31
+ calendar_event = calendar.publish_as(
32
+ interpolated(event)['calendar_id'],
33
+ cal_message
34
+ )
35
+
36
+ create_event payload: {
37
+ 'success' => true,
38
+ 'published_calendar_event' => calendar_event,
39
+ 'agent_id' => event.agent_id,
40
+ 'event_id' => event.id
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ require 'huginn_agent'
2
+
3
+ HuginnAgent.load "huginn_delegated_google_calendar_agent/delegated_google_calendar"
4
+ HuginnAgent.register 'huginn_delegated_google_calendar_agent/delegated_google_calendar_agent'
5
+
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::DelegatedGoogleCalendarAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::DelegatedGoogleCalendarAgent.new.default_options
7
+ @checker = Agents::DelegatedGoogleCalendarAgent.new(:name => "DelegatedGoogleCalendarAgent", :options => @valid_options)
8
+ @checker.user = users(:bob)
9
+ @checker.save!
10
+ end
11
+
12
+ pending "add specs here"
13
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huginn_delegated_google_calendar_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Christian Augustine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-12-02 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: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: huginn_agent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A Google Calendar Agent which supports delegation
56
+ email:
57
+ - me@christianaugustine.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - lib/huginn_delegated_google_calendar_agent.rb
64
+ - lib/huginn_delegated_google_calendar_agent/delegated_google_calendar.rb
65
+ - lib/huginn_delegated_google_calendar_agent/delegated_google_calendar_agent.rb
66
+ - spec/delegated_google_calendar_agent_spec.rb
67
+ homepage: https://github.com/christianaugustine/huginn_delegated_google_calendar_agent
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.4.19
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Huginn Delegated Google Calendar Agent
90
+ test_files:
91
+ - spec/delegated_google_calendar_agent_spec.rb