import type { IComponentController, IComponentOptions } from 'angular'; import { module } from 'angular'; import { SETTINGS } from '../config/settings'; import type { IPagerDutyService } from './pagerDuty.read.service'; import { PagerDutyReader } from './pagerDuty.read.service'; import { SchedulerFactory } from '../scheduler/SchedulerFactory'; export class PagerDutySelectFieldController implements IComponentController { public component: any; public pagerDutyServices: IPagerDutyService[]; public servicesLoaded: boolean; private scheduler: any; public helpContents = `

Make sure your service exists in Pager Duty and includes the "Generic API" integration.

Setting up a new integration
  1. Find your service in Pager Duty
  2. Click "New Integration"
  3. Select "Use our API directly"
  4. Make sure to select "Events API v1" (Spinnaker is not compatible with v2)

Note: it can take up to five minutes for the service to appear in Spinnaker

`; public required = (SETTINGS.pagerDuty && SETTINGS.pagerDuty.required) || false; public label = `PagerDuty${this.required ? ' *' : ''}`; public $onInit() { this.scheduler = SchedulerFactory.createScheduler(10000); this.scheduler.subscribe(() => this.loadPagerDutyServices()); this.loadPagerDutyServices(); } public $onDestroy(): void { this.scheduler.unsubscribe(); } private loadPagerDutyServices(): void { PagerDutyReader.listServices().subscribe((pagerDutyServices: IPagerDutyService[]) => { this.pagerDutyServices = pagerDutyServices.filter((service) => service.integration_key); this.servicesLoaded = true; }); } } const pagerDutySelectField: IComponentOptions = { bindings: { component: '=', }, controller: PagerDutySelectFieldController, template: `
{{$ctrl.label}}
{{$select.selected.name}} {{pagerDuty.name}}
`, }; export const PAGER_DUTY_SELECT_FIELD_COMPONENT = 'spinnaker.core.pagerDuty.pagerDutySelectField.component'; module(PAGER_DUTY_SELECT_FIELD_COMPONENT, []).component('pagerDutySelectField', pagerDutySelectField);