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

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

21 Jan 2026 05:55PM UTC coverage: 38.99% (-6.1%) from 45.13%
21220108336

Pull #185

github

web-flow
Merge 7fa0e283e into 35f9e968a
Pull Request #185: EventHub command protection and restyling

0 of 189 new or added lines in 8 files covered. (0.0%)

6 existing lines in 5 files now uncovered.

278 of 713 relevant lines covered (38.99%)

12.51 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\Console\Commands\Concerns\ConfirmsEventHubChanges;
8
use Northwestern\SysDev\SOA\EventHub;
9
use Northwestern\SysDev\SOA\Routing\EventHubWebhookRegistration;
10

11
use function Laravel\Prompts\confirm;
12
use function Laravel\Prompts\spin;
13

14
class WebhookConfiguration extends Command
15
{
16
    use ConfirmableTrait, ConfirmsEventHubChanges;
17

18
    protected $signature = 'eventhub:webhook:configure {--force}';
19

20
    protected $description = 'Configure webhook routes in EventHub';
21

22
    public function __construct(
23
        protected EventHub\Webhook $webhook_api,
24
        protected EventHubWebhookRegistration $hook_registry
25
    ) {
NEW
26
        parent::__construct();
×
27
    }
28

29
    public function handle(): int
30
    {
NEW
31
        if (! $this->confirmWebhookConfiguration()) {
×
NEW
32
            $this->components->error('Command aborted.');
×
33

NEW
34
            return self::FAILURE;
×
35
        }
36

UNCOV
37
        $force_delete = $this->option('force');
×
38

NEW
39
        $registered_hooks = spin(
×
NEW
40
            fn () => collect($this->webhook_api->listAll()['webhooks']),
×
NEW
41
            'Fetching existing webhooks...'
×
NEW
42
        );
×
43

NEW
44
        $registered_hooks = $registered_hooks->map(fn ($hook) => $hook['topicName'])->all();
×
45

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

49
        $desired_hooks = $this->hook_registry->getHooks();
×
50
        foreach ($desired_hooks as $hook) {
×
51
            $hook = $hook->toArray();
×
52

53
            // Remove from unmanaged list
54
            $existing_hooks_updated = array_diff($existing_hooks_updated, [$hook['topicName']]);
×
55

56
            $this->createOrUpdate($hook, $registered_hooks);
×
57
        }
58

59
        if (count($existing_hooks_updated) > 0) {
×
NEW
60
            $this->newLine();
×
NEW
61
            $this->components->error('The following webhooks are configured in EventHub but do not have a corresponding entry in the routes file:');
×
NEW
62
            $this->newLine();
×
NEW
63
            $this->components->bulletList($existing_hooks_updated);
×
NEW
64
            $this->newLine();
×
65

NEW
66
            $delete_unmanaged = $force_delete ?: confirm(
×
NEW
67
                label: 'Would you like to delete these unmanaged webhooks?',
×
NEW
68
                default: false,
×
NEW
69
                hint: 'This will remove webhooks not defined in your routes file.'
×
NEW
70
            );
×
71

72
            if ($delete_unmanaged === true) {
×
73
                foreach ($existing_hooks_updated as $hook_to_delete) {
×
74
                    $this->delete($hook_to_delete);
×
75
                }
76
            }
77
        }
78

79
        // Display status after the changes are made.
80
        $this->call('eventhub:webhook:status');
×
81

NEW
82
        return self::SUCCESS;
×
83
    }
84

85
    protected function createOrUpdate($hook, $registered_hooks)
86
    {
87
        $topicName = $hook['topicName'];
×
88

89
        try {
90
            // If the hook exists on EventHub already, we don't need to touch the 'active' status.
91
            // But, new ones will require it.
92
            if (in_array($hook['topicName'], $registered_hooks) === false) {
×
93
                $hook['active'] = true;
×
94

95
                // Not allowed in the POST/PUT body
96
                unset($hook['topicName']);
×
97

NEW
98
                spin(
×
NEW
99
                    fn () => $this->webhook_api->create($topicName, $hook),
×
NEW
100
                    "Creating webhook for {$topicName}..."
×
NEW
101
                );
×
102

NEW
103
                $this->components->info("Created webhook for <bg=magenta;fg=white;options=bold> {$topicName} </>");
×
104
            } else {
105
                // Not allowed in the POST/PUT body
106
                unset($hook['topicName']);
×
107

NEW
108
                spin(
×
NEW
109
                    fn () => $this->webhook_api->updateConfig($topicName, $hook),
×
NEW
110
                    "Updating webhook for {$topicName}..."
×
NEW
111
                );
×
112

NEW
113
                $this->components->info("Updated webhook for <bg=magenta;fg=white;options=bold> {$topicName} </>");
×
114
            }
115
        } catch (EventHub\Exception\EventHubError $e) {
×
NEW
116
            $this->newLine();
×
NEW
117
            $this->components->error("Failed to update {$topicName}: {$e->getMessage()}");
×
NEW
118
            $this->newLine();
×
119
        }
120
    }
121

122
    protected function delete($queue_name)
123
    {
124
        try {
NEW
125
            spin(
×
NEW
126
                fn () => $this->webhook_api->delete($queue_name),
×
NEW
127
                "Deleting webhook for {$queue_name}..."
×
NEW
128
            );
×
129

NEW
130
            $this->components->info("Deleted webhook for <bg=magenta;fg=white;options=bold> {$queue_name} </>");
×
131
        } catch (EventHub\Exception\EventHubError $e) {
×
NEW
132
            $this->newLine();
×
NEW
133
            $this->components->error("Failed to delete {$queue_name}: {$e->getMessage()}");
×
NEW
134
            $this->newLine();
×
135
        }
136
    }
137
}
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