• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NIT-Administrative-Systems / SysDev-laravel-soa / 13508657684

24 Feb 2025 09:57PM UTC coverage: 45.13% (-0.1%) from 45.277%
13508657684

Pull #184

github

web-flow
Merge 265b9b845 into a782f5d90
Pull Request #184: Laravel 12 Support

0 of 4 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

278 of 616 relevant lines covered (45.13%)

14.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Console/Commands/EventHub/WebhookConfiguration.php
1
<?php
2

3
namespace Northwestern\SysDev\SOA\Console\Commands\EventHub;
4

5
use Illuminate\Console\Command;
6
use Illuminate\Console\ConfirmableTrait;
7
use Northwestern\SysDev\SOA\EventHub;
8
use Northwestern\SysDev\SOA\Routing\EventHubWebhookRegistration;
9

10
class WebhookConfiguration extends Command
11
{
12
    use ConfirmableTrait;
13

14
    protected $signature = 'eventhub:webhook:configure {--force}';
15

16
    protected $description = 'Configure webhook routes in EventHub';
17

18
    protected $webhook_api;
19

20
    protected $hook_registry;
21

22
    public function __construct(EventHub\Webhook $webhook_api, EventHubWebhookRegistration $hook_registry)
23
    {
24
        parent::__construct();
×
25

26
        $this->webhook_api = $webhook_api;
×
27
        $this->hook_registry = $hook_registry;
×
28
    } // end __construct
29

30
    public function handle()
31
    {
32
        $force_delete = $this->option('force');
×
33

34
        $registered_hooks = collect($this->webhook_api->listAll()['webhooks']);
×
35
        $registered_hooks = $registered_hooks->map(function ($hook) {
×
36
            return $hook['topicName'];
×
37
        })->all();
×
38

39
        // We can remove stuff from this one as we touch them -- that we we know which still exist.
40
        $existing_hooks_updated = $registered_hooks;
×
41

42
        $desired_hooks = $this->hook_registry->getHooks();
×
43
        foreach ($desired_hooks as $hook) {
×
44
            $hook = $hook->toArray();
×
45

46
            // Remove from unmanaged list
47
            $existing_hooks_updated = array_diff($existing_hooks_updated, [$hook['topicName']]);
×
48

49
            $this->createOrUpdate($hook, $registered_hooks);
×
50
        }
51

52
        if (count($existing_hooks_updated) > 0) {
×
53
            $this->line('');
×
54
            $this->error('The following webhooks are configured in EventHub but do not have a corresponding entry in the routes file:');
×
55
            $this->line('');
×
56
            $this->error(implode(', ', $existing_hooks_updated));
×
57
            $this->line('');
×
58

59
            $delete_unmanaged = $force_delete ?: $this->confirm('Would you like to delete these unmanaged webhooks?');
×
60
            if ($delete_unmanaged === true) {
×
61
                foreach ($existing_hooks_updated as $hook_to_delete) {
×
62
                    $this->delete($hook_to_delete);
×
63
                }
64
            }
65
        }
66

67
        // Display status after the changes are made.
68
        $this->call('eventhub:webhook:status');
×
69

70
        return 0;
×
71
    } // end handle
72

73
    protected function createOrUpdate($hook, $registered_hooks)
74
    {
75
        $topicName = $hook['topicName'];
×
76

77
        try {
78
            // If the hook exists on EventHub already, we don't need to touch the 'active' status.
79
            // But, new ones will require it.
80
            if (in_array($hook['topicName'], $registered_hooks) === false) {
×
81
                $hook['active'] = true;
×
82

83
                // Not allowed in the POST/PUT body
84
                unset($hook['topicName']);
×
85

86
                $this->webhook_api->create($topicName, $hook);
×
87
            } else {
88
                // Not allowed in the POST/PUT body
89
                unset($hook['topicName']);
×
90

91
                $this->webhook_api->updateConfig($topicName, $hook);
×
92
            }
93
        } catch (EventHub\Exception\EventHubError $e) {
×
94
            $this->line('');
×
95
            $this->error(vsprintf('Failed to update %s: %s', [$topicName, $e->getMessage()]));
×
96
            $this->line('');
×
97
        }
98
    } // end createOrUpdate
99

100
    protected function delete($queue_name)
101
    {
102
        try {
103
            $this->webhook_api->delete($queue_name);
×
104
        } catch (EventHub\Exception\EventHubError $e) {
×
105
            $this->line('');
×
106
            $this->error(vsprintf('Failed to delete %s: %s', [$queue_name, $e->getMessage()]));
×
107
            $this->line('');
×
108
        }
109
    } // end delete
110
} // end WebhookConfiguration
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc