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

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

06 Feb 2024 07:28PM UTC coverage: 45.675% (-0.2%) from 45.913%
7805057844

push

github

web-flow
Housekeeping (#162)

11 of 35 new or added lines in 14 files covered. (31.43%)

9 existing lines in 7 files now uncovered.

264 of 578 relevant lines covered (45.67%)

14.07 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

NEW
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
                // Not permitted in creates since Jan 2022 (but fine for updates)
82
                unset($hook['topicName']);
×
83

84
                $hook['active'] = true;
×
85

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

97
    protected function delete($queue_name)
98
    {
99
        try {
100
            $this->webhook_api->delete($queue_name);
×
101
        } catch (EventHub\Exception\EventHubError $e) {
×
102
            $this->line('');
×
103
            $this->error(vsprintf('Failed to delete %s: %s', [$queue_name, $e->getMessage()]));
×
104
            $this->line('');
×
105
        }
106
    } // end delete
107
} // 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

© 2026 Coveralls, Inc