Class: Yast::CWMTsigKeysClass

Inherits:
Module
  • Object
show all
Defined in:
library/cwm/src/modules/CWMTsigKeys.rb

Instance Method Summary collapse

Instance Method Details

#AddTSIGKeyFile(filename) ⇒ Object

Add new file with TSIG key

Parameters:

  • filename (String)

    string filename of the file with the TSIG key



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 118

def AddTSIGKeyFile(filename)
  @deleted_tsig_keys = Builtins.filter(@deleted_tsig_keys) do |f|
    f != filename
  end
  @new_tsig_keys = Builtins.add(@new_tsig_keys, filename)
  keys = AnalyzeTSIGKeyFile(filename)
  Builtins.foreach(keys) do |k|
    @tsig_keys = Builtins.add(
      @tsig_keys,
      "key" => k, "filename" => filename
    )
  end

  nil
end

#AnalyzeTSIGKeyFile(filename) ⇒ Object

Analyze file that may contain TSIG keys

Parameters:

  • filename (String)

    string filename of the file that may contain TSIG keys

Returns:

  • a list of all TSIG key IDs in the file



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 168

def AnalyzeTSIGKeyFile(filename)
  filename = NormalizeFilename(filename)
  contents = Convert.to_string(SCR.Read(path(".target.string"), filename))
  if contents.nil?
    Builtins.y2warning("Unable to read file with TSIG keys: %1", filename)
    return []
  end
  ret = []
  parts = Builtins.splitstring(contents, "{}")
  Builtins.foreach(parts) do |p|
    if Builtins.regexpmatch(p, ".*key[[:space:]]+[^[:space:]}{;]+\\.* $")
      ret = Builtins.add(
        ret,
        Builtins.regexpsub(
          p,
          ".*key[[:space:]]+([^[:space:]}{;]+)\\.* $",
          "\\1"
        )
      )
    end
  end
  Builtins.y2milestone("File: %1, Keys: %2", filename, ret)
  deep_copy(ret)
end

#CreateWidget(settings) ⇒ Object

Get the widget description map


"get_keys_info" : map<string,any>() -- function for getting information
         about TSIG keys. Return map should contain:
          - "removed_files" : list<string> -- files that have been removed
          - "new_files" : list<string> -- files that have been added
          - "tsig_keys" : list<map<string,string>> -- list of all TSIG keys
          - "key_files" : list<string> -- list of all files that may contain
                      TSIG keys
          Either "tsig_keys" or "key_files" are mandatory
"set_keys_info" : void (map<string,any>) -- function for storing information
         about keys. Map has keys:
          - "removed_files" : list<string> -- files that have been removed
          - "new_files" : list<string> -- files that have been added
          - "tsig_keys" : list<map<string,string>> -- list of all TSIG keys
          - "key_files" : list<string> -- list of all files that contain
                      TSIG keys

Additional settings:
- "list_used_keys" : list<string>() -- function for getting the list of
         used TSIG keys. The list is used to prevent used TSIG keys from
         being deleted. If not present, all keys may get deleted.
- "help" : string -- help to the whole widget. If not specified, generic help
         is used (button labels are patched correctly)

Parameters:

  • settings (Hash{String => Object})

    a map of all parameters needed to create the widget properly

Returns:

  • a map the widget description map



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 554

def CreateWidget(settings)
  settings = deep_copy(settings)
  # tsig keys management dialog help 1/4
  help = _(
    "<p><big><b>TSIG Key Management</b></big><br>\nUse this dialog to manage the TSIG keys.</p>\n"
  ) +
    # tsig keys management dialog help 2/4
    _(
      "<p><big><b>Adding an Existing TSIG Key</b></big><br>\n" \
      "To add an already created TSIG key, select a <b>Filename</b> of the file\n" \
      "containing the key and click <b>Add</b>.</p>\n"
    ) +
    # tsig keys management dialog help 3/4
    _(
      "<p><big><b>Creating a New TSIG Key</b></big><br>\n" \
      "To create a new TSIG key, set the <b>Filename</b> of the file in which to\n" \
      "create the key and the <b>Key ID</b> to identify the key then click\n" \
      "<b>Generate</b>.</p>\n"
    ) +
    # tsig keys management dialog help 4/4
    _(
      "<p><big><b>Removing a TSIG Key</b></big><br>\n" \
      "To remove a configured TSIG key, select it and click <b>Delete</b>.\n" \
      "All keys in the same file are deleted.\n" \
      "If a TSIG key is in use in the configuration\n" \
      "of the server, it cannot be deleted. The server must stop using it\n" \
      "in the configuration first.</p>\n"
    )

  add_existing = VSquash(
    # Frame label - adding a created server key
    Frame(
      _("Add an Existing TSIG Key"),
      HBox(
        HWeight(
          9,
          HBox(
            HWeight(
              7,
              HBox(
                InputField(
                  Id("_cwm_existing_key_file"),
                  Opt(:hstretch),
                  # text entry
                  Label.FileName
                )
              )
            ),
            HWeight(
              2,
              HBox(
                VBox(
                  Label(" "),
                  PushButton(
                    Id("_cwm_browse_existing_key_file"),
                    Label.BrowseButton
                  )
                )
              )
            )
          )
        ),
        HWeight(
          2,
          Bottom(
            VSquash(
              PushButton(
                Id("_cwm_add_key"),
                Opt(:hstretch),
                Label.AddButton
              )
            )
          )
        )
      )
    )
  )

  create_new = VSquash(
    # Frame label - creating a new server key
    Frame(
      _("Create a New TSIG Key"),
      HBox(
        HWeight(
          9,
          HBox(
            HWeight(
              7,
              HBox(
                # text entry
                InputField(
                  Id("_cwm_new_key_id"),
                  Opt(:hstretch),
                  _("&Key ID")
                ),
                # text entry
                InputField(
                  Id("_cwm_new_key_file"),
                  Opt(:hstretch),
                  Label.FileName
                )
              )
            ),
            HWeight(
              2,
              HBox(
                VBox(
                  Label(" "),
                  PushButton(
                    Id("_cwm_browse_new_key_file"),
                    Label.BrowseButton
                  )
                )
              )
            )
          )
        ),
        HWeight(
          2,
          Bottom(
            # push button
            VSquash(
              PushButton(
                Id("_cwm_generate_key"),
                Opt(:hstretch),
                _("&Generate")
              )
            )
          )
        )
      )
    )
  )

  current_keys = VBox(
    VSpacing(0.5),
    # Table header - in fact label
    Left(Label(_("Current TSIG Keys"))),
    HBox(
      HWeight(
        9,
        Table(
          Id("_cwm_key_listing_table"),
          Header(
            # Table header item - DNS key listing
            _("Key ID"),
            # Table header item - DNS key listing
            _("Filename")
          ),
          []
        )
      ),
      HWeight(
        2,
        VBox(
          VSquash(
            PushButton(
              Id("_cwm_delete_key"),
              Opt(:hstretch),
              Label.DeleteButton
            )
          ),
          VStretch()
        )
      )
    )
  )

  contents = VBox(add_existing, create_new, current_keys)

  ret = Convert.convert(
    Builtins.union(
      {
        "widget"        => :custom,
        "custom_widget" => contents,
        "help"          => help,
        "init"          => fun_ref(method(:InitWrapper), "void (string)"),
        "store"         => fun_ref(
          method(:StoreWrapper),
          "void (string, map)"
        ),
        "handle"        => fun_ref(
          method(:HandleWrapper),
          "symbol (string, map)"
        )
      },
      settings
    ),
    from: "map",
    to:   "map <string, any>"
  )

  deep_copy(ret)
end

#DdnsKeysWidgetRedrawObject

Redraw the table of DDNS keys



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 60

def DdnsKeysWidgetRedraw
  items = Builtins.maplist(@tsig_keys) do |k|
    Item(
      Id(Ops.get(k, "key", "")),
      Ops.get(k, "key", ""),
      Ops.get(k, "filename", "")
    )
  end
  UI.ChangeWidget(
    Id("_cwm_delete_key"),
    :Enabled,
    Ops.greater_than(Builtins.size(items), 0)
  )
  UI.ChangeWidget(Id("_cwm_key_listing_table"), :Items, items)
  UI.SetFocus(Id("_cwm_key_listing_table"))

  nil
end

#DeleteTSIGKeyFromDisk(main) ⇒ Object

Remove all 3 files holding the TSIG key data

Parameters:

  • main (String)

    string filename of the main file



195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 195

def DeleteTSIGKeyFromDisk(main)
  keys = AnalyzeTSIGKeyFile(main)
  Builtins.y2milestone("Removing file %1, found keys: %2", main, keys)
  Builtins.foreach(keys) do |k|
    SCR.Execute(
      path(".target.bash"),
      Builtins.sformat("/usr/bin/rm -rf /etc/named.d/K%1\\.* ", Builtins.tolower(k).shellescape)
    )
  end
  SCR.Execute(path(".target.remove"), main)

  nil
end

#Files2KeyMaps(filenames) ⇒ Object

Transformate the list of files to the list of TSIG key description maps

Parameters:

  • filenames (Array<String>)

    a list of file names of the TSIG keys

Returns:

  • a list of TSIG key describing maps



212
213
214
215
216
217
218
219
220
221
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 212

def Files2KeyMaps(filenames)
  filenames = deep_copy(filenames)
  tmpret = Builtins.maplist(filenames) do |f|
    keys = AnalyzeTSIGKeyFile(f)
    Builtins.maplist(keys) { |k| { "filename" => f, "key" => k } }
  end
  ret = Builtins.flatten(tmpret)
  Builtins.y2milestone("Files: %1, Keys: %2", filenames, ret)
  deep_copy(ret)
end

#Files2Keys(filenames) ⇒ Object

Get all TSIG keys that present in the files

Parameters:

  • filename

    a list of file names

Returns:

  • a list of all TSIG key IDs



226
227
228
229
230
231
232
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 226

def Files2Keys(filenames)
  filenames = deep_copy(filenames)
  keys = Files2KeyMaps(filenames)
  ret = Builtins.maplist(keys) { |k| Ops.get(k, "key", "") }
  Builtins.y2milestone("Files: %1, Keys: %2", filenames, ret)
  deep_copy(ret)
end

#Handle(widget, _key, event) ⇒ Symbol

Handle function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 272

def Handle(widget, _key, event)
  widget = deep_copy(widget)
  event = deep_copy(event)
  ret = Ops.get(event, "ID")
  existing_filename = Convert.to_string(
    UI.QueryWidget(Id("_cwm_existing_key_file"), :Value)
  )
  new_filename = Convert.to_string(
    UI.QueryWidget(Id("_cwm_new_key_file"), :Value)
  )
  case ret
  when "_cwm_delete_key"
    key2 = Convert.to_string(
      UI.QueryWidget(Id("_cwm_key_listing_table"), :CurrentItem)
    )
    delete_filename = Key2File(key2)
    if Ops.get(widget, "list_used_keys") &&
        Ops.is(Ops.get(widget, "list_used_keys"), "list <string> ()")
      lister = Convert.convert(
        Ops.get(widget, "list_used_keys"),
        from: "any",
        to:   "list <string> ()"
      )
      used_keys = lister.call
      keys_to_delete = AnalyzeTSIGKeyFile(delete_filename)
      keys_to_delete = Builtins.filter(keys_to_delete) do |k|
        Builtins.contains(used_keys, k)
      end
      if Ops.greater_than(Builtins.size(keys_to_delete), 0)
        # popup message
        message = _(
          "The selected TSIG key cannot be deleted,\n" \
          "because it is in use.\n" \
          "Stop using it in the configuration first."
        )
        # popup title
        Popup.AnyMessage(_("Cannot delete TSIG key."), message)
        return nil
      end
    end
    RemoveTSIGKeyFile(delete_filename)
  when "_cwm_browse_existing_key_file"
    existing_filename = UI.AskForExistingFile(
      existing_filename,
      "",
      # popup headline
      _("Select File with the Authentication Key")
    )
    if !existing_filename.nil?
      UI.ChangeWidget(
        Id("_cwm_existing_key_file"),
        :Value,
        existing_filename
      )
    end
    return nil
  when "_cwm_browse_new_key_file"
    new_filename = UI.AskForSaveFileName(
      new_filename,
      "",
      # popup headline
      _("Select File for the Authentication Key")
    )
    UI.ChangeWidget(Id("_cwm_new_key_file"), :Value, new_filename) if !new_filename.nil?
    return nil
  when "_cwm_generate_key"
    if !UI.WidgetExists(Id("_cwm_new_key_file"))
      Builtins.y2error("No such UI widget: %1", "_cwm_new_key_file")
      return nil
    end

    key2 = Convert.to_string(UI.QueryWidget(Id("_cwm_new_key_id"), :Value))
    stat = Convert.to_map(SCR.Read(path(".target.stat"), new_filename))

    if Builtins.size(stat) != 0
      if Ops.get_boolean(stat, "isdir", false)
        UI.SetFocus(Id("_cwm_new_key_file"))
        Report.Error(
          # error report
          _("Specified filename is an existing directory.")
        )
        return nil
      end
      # yes-no popup
      return nil unless Popup.YesNo(_("Specified file exists. Rewrite it?"))

      DeleteTSIGKeyFromDisk(new_filename)
      RemoveTSIGKeyFile(new_filename)
    end
    if key2.nil? || key2 == ""
      UI.SetFocus(Id("_cwm_new_key_id"))
      # error report
      Popup.Error(_("The TSIG key ID was not specified."))
      return nil
    end
    # specified key exists
    if Key2File(key2) != ""
      # yes-no popup
      if Popup.YesNo(
        _("The key with the specified ID exists and is used.\nRemove it?")
      )
        remove_file = Key2File(key2)
        DeleteTSIGKeyFromDisk(remove_file)
        RemoveTSIGKeyFile(remove_file)
      else
        return nil
      end
    end
    # specified key is present on the disk, but not used
    if 0 ==
        SCR.Execute(
          path(".target.bash"),
          Builtins.sformat(
            "/usr/bin/ls /etc/named.d/K%1\\.*",
            Builtins.tolower(key2).shellescape
          )
        ) && Popup.YesNo(
        _(
          "A key with the specified ID was found\non your disk. Remove it?"
        )
      )
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat(
          "/usr/bin/rm -rf `/usr/bin/ls /etc/named.d/K%1\\.*`",
          Builtins.tolower(key2).shellescape
        )
      )
      files = Convert.convert(
        SCR.Read(path(".target.dir"), "/etc/named.d"),
        from: "any",
        to:   "list <string>"
      )
      Builtins.foreach(files) do |f|
        DeleteTSIGKeyFromDisk(f) if Builtins.contains(AnalyzeTSIGKeyFile(f), key2)
      end
    end

    # yes-no popup
    return nil if !Popup.YesNo(_("The key will be created now. Continue?"))

    SCR.Execute(
      path(".target.bash"),
      "/usr/bin/mkdir -p /etc/named.d"
    )
    gen_command = Builtins.sformat(
      "/usr/bin/genDDNSkey --force  -f '%1' -n '%2' -d /etc/named.d",
      String.Quote(new_filename),
      String.Quote(key2)
    )
    Builtins.y2milestone("Running %1", gen_command)
    gen_ret = Convert.to_integer(
      SCR.Execute(path(".target.bash"), gen_command)
    )
    if gen_ret != 0
      # error report
      Report.Error(_("Creating the TSIG key failed."))
      return nil
    end
    ret = "_cwm_add_key"
    existing_filename = new_filename
  end
  if ret == "_cwm_add_key"
    stat = Convert.to_map(SCR.Read(path(".target.stat"), new_filename))
    if Builtins.size(stat) == 0
      # message popup
      Popup.Message(_("The specified file does not exist."))
      return nil
    end
    keys = AnalyzeTSIGKeyFile(existing_filename)
    if Builtins.size(keys) == 0
      # message popup
      Popup.Message(_("The specified file does not contain any TSIG key."))
      return nil
    end
    coliding_files = Builtins.maplist(keys) { |k| Key2File(k) }
    coliding_files = Builtins.filter(Builtins.toset(coliding_files)) do |f|
      f != ""
    end
    if Ops.greater_than(Builtins.size(coliding_files), 0)
      # yes-no popup
      if Popup.YesNo(
        _(
          "The specified file contains a TSIG key with the same\n" \
          "identifier as some of already present keys.\n" \
          "Old keys will be removed. Continue?"
        )
      )
        Builtins.foreach(coliding_files) { |f| RemoveTSIGKeyFile(f) }
      else
        return nil
      end
    end
    AddTSIGKeyFile(existing_filename)
  end
  DdnsKeysWidgetRedraw()
  nil
end

#HandleWrapper(key, event) ⇒ Symbol

Handle function of the widget

Parameters:

  • map

    widget a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map event to be handled

Returns:

  • (Symbol)

    for wizard sequencer or nil



512
513
514
515
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 512

def HandleWrapper(key, event)
  event = deep_copy(event)
  Handle(CWM.GetProcessedWidget, key, event)
end

#Init(widget, _key) ⇒ Object

Init function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 239

def Init(widget, _key)
  widget = deep_copy(widget)
  get_keys_info = Convert.convert(
    Ops.get(widget, "get_keys_info"),
    from: "any",
    to:   "map <string, any> ()"
  )
  info = get_keys_info.call
  @tsig_keys = Ops.get_list(info, "tsig_keys", [])
  @deleted_tsig_keys = Ops.get_list(info, "removed_files", [])
  @new_tsig_keys = Ops.get_list(info, "new_files", [])
  if !Builtins.haskey(info, "tsig_keys")
    files = Ops.get_list(info, "key_files", [])
    @tsig_keys = Files2KeyMaps(files)
  end
  initial_path = "/etc/named.d/"
  UI.ChangeWidget(Id("_cwm_existing_key_file"), :Value, initial_path)
  UI.ChangeWidget(Id("_cwm_new_key_file"), :Value, initial_path)
  UI.ChangeWidget(
    Id("_cwm_new_key_id"),
    :ValidChars,
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
  )
  DdnsKeysWidgetRedraw()

  nil
end

#InitWrapper(key) ⇒ Object

Store function of the widget Init function of the widget

Parameters:

  • map

    widget a widget description map

  • key (String)

    strnig the widget key

  • event

    map that caused widget data storing/**

  • key (String)

    strnig the widget key



501
502
503
504
505
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 501

def InitWrapper(key)
  Init(CWM.GetProcessedWidget, key)

  nil
end

#Key2File(key) ⇒ String

Get the file that contains the specified key

Parameters:

  • key (String)

    string key ID

Returns:

  • (String)

    file containing the key



82
83
84
85
86
87
88
89
90
91
92
93
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 82

def Key2File(key)
  filename = ""
  Builtins.find(@tsig_keys) do |k|
    if Ops.get(k, "key") == key
      filename = Ops.get(k, "filename", "")
      next true
    end
    false
  end
  Builtins.y2milestone("Key: %1, File: %2", key, filename)
  filename
end

#mainObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 34

def main
  Yast.import "UI"
  textdomain "base"

  Yast.import "CWM"
  Yast.import "Label"
  Yast.import "Report"
  Yast.import "Popup"
  Yast.import "String"

  # private variables

  # Currently configured TSIG keys
  # Each entry is a map with keys "filename" and "key"
  @tsig_keys = []

  # Filenames of the files that contained deleted TSIG keys
  @deleted_tsig_keys = []

  # Filenames of the new added TSIG keys
  @new_tsig_keys = []
end

#NormalizeFilename(filename) ⇒ Object

Remove leading and trailibg blanks and quotes from file name

Parameters:

  • filename (String)

    string file name

Returns:

  • file name without leading/trailing quotes and blanks



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 139

def NormalizeFilename(filename)
  while filename != "" &&
      (Builtins.substring(filename, 0, 1) == " " ||
        Builtins.substring(filename, 0, 1) == "\"")
    filename = Builtins.substring(filename, 1)
  end
  while filename != "" &&
      (Builtins.substring(
        filename,
        Ops.subtract(Builtins.size(filename), 1),
        1
      ) == " " ||
        Builtins.substring(
          filename,
          Ops.subtract(Builtins.size(filename), 1),
          1
        ) == "\"")
    filename = Builtins.substring(
      filename,
      0,
      Ops.subtract(Builtins.size(filename), 1)
    )
  end
  filename
end

#RemoveTSIGKey(key) ⇒ Object

Remove file containing specified TSIG key

Parameters:

  • key (String)

    string key ID



109
110
111
112
113
114
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 109

def RemoveTSIGKey(key)
  filename = Key2File(key)
  RemoveTSIGKeyFile(filename)

  nil
end

#RemoveTSIGKeyFile(filename) ⇒ Object

Remove file with all TSIG keys it contains

Parameters:

  • filename (String)

    string filename of the file with the TSIG keys



97
98
99
100
101
102
103
104
105
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 97

def RemoveTSIGKeyFile(filename)
  @new_tsig_keys = Builtins.filter(@new_tsig_keys) { |f| f != filename }
  @deleted_tsig_keys = Builtins.add(@deleted_tsig_keys, filename)
  @tsig_keys = Builtins.filter(@tsig_keys) do |k|
    Ops.get(k, "filename", "") != filename
  end

  nil
end

#Store(widget, _key, _event) ⇒ Object

Store function of the widget

Parameters:

  • widget (Hash{String => Object})

    a widget description map

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 475

def Store(widget, _key, _event)
  widget = deep_copy(widget)
  set_info = Convert.convert(
    Ops.get(widget, "set_keys_info"),
    from: "any",
    to:   "void (map <string, any>)"
  )
  info = {
    "removed_files" => @deleted_tsig_keys,
    "new_files"     => @new_tsig_keys,
    "tsig_keys"     => @tsig_keys,
    "key_files"     => Builtins.toset(Builtins.maplist(@tsig_keys) do |k|
      Ops.get(k, "filename", "")
    end)
  }
  set_info.call(info)

  nil
end

#StoreWrapper(key, event) ⇒ Object

Store function of the widget

Parameters:

  • key (String)

    strnig the widget key

  • event (Hash)

    map that caused widget data storing



520
521
522
523
524
525
# File 'library/cwm/src/modules/CWMTsigKeys.rb', line 520

def StoreWrapper(key, event)
  event = deep_copy(event)
  Store(CWM.GetProcessedWidget, key, event)

  nil
end