key.pp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # == Define: apt::key
  2. define apt::key (
  3. $id = $title,
  4. $ensure = present,
  5. $content = undef,
  6. $source = undef,
  7. $server = $::apt::keyserver,
  8. $options = undef,
  9. $key = undef,
  10. $key_content = undef,
  11. $key_source = undef,
  12. $key_server = undef,
  13. $key_options = undef,
  14. ) {
  15. if $key != undef {
  16. warning('$key is deprecated and will be removed in the next major release. Please use $id instead.')
  17. $_id = $key
  18. } else {
  19. $_id = $id
  20. }
  21. if $key_content != undef {
  22. warning('$key_content is deprecated and will be removed in the next major release. Please use $content instead.')
  23. $_content = $key_content
  24. } else {
  25. $_content = $content
  26. }
  27. if $key_source != undef {
  28. warning('$key_source is deprecated and will be removed in the next major release. Please use $source instead.')
  29. $_source = $key_source
  30. } else {
  31. $_source = $source
  32. }
  33. if $key_server != undef {
  34. warning('$key_server is deprecated and will be removed in the next major release. Please use $server instead.')
  35. $_server = $key_server
  36. } else {
  37. $_server = $server
  38. }
  39. if $key_options != undef {
  40. warning('$key_options is deprecated and will be removed in the next major release. Please use $options instead.')
  41. $_options = $key_options
  42. } else {
  43. $_options = $options
  44. }
  45. validate_re($_id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
  46. validate_re($ensure, ['\A(absent|present)\Z',])
  47. if $_content {
  48. validate_string($_content)
  49. }
  50. if $_source {
  51. validate_re($_source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
  52. }
  53. if $_server {
  54. validate_re($_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
  55. }
  56. if $_options {
  57. validate_string($_options)
  58. }
  59. case $ensure {
  60. present: {
  61. if defined(Anchor["apt_key ${_id} absent"]){
  62. fail("key with id ${_id} already ensured as absent")
  63. }
  64. if !defined(Anchor["apt_key ${_id} present"]) {
  65. apt_key { $title:
  66. ensure => $ensure,
  67. id => $_id,
  68. source => $_source,
  69. content => $_content,
  70. server => $_server,
  71. options => $_options,
  72. } ->
  73. anchor { "apt_key ${_id} present": }
  74. }
  75. }
  76. absent: {
  77. if defined(Anchor["apt_key ${_id} present"]){
  78. fail("key with id ${_id} already ensured as present")
  79. }
  80. if !defined(Anchor["apt_key ${_id} absent"]){
  81. apt_key { $title:
  82. ensure => $ensure,
  83. id => $_id,
  84. source => $_source,
  85. content => $_content,
  86. server => $_server,
  87. options => $_options,
  88. } ->
  89. anchor { "apt_key ${_id} absent": }
  90. }
  91. }
  92. default: {
  93. fail "Invalid 'ensure' value '${ensure}' for apt::key"
  94. }
  95. }
  96. }