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

yast / yast-users / 16077555618

04 Jul 2025 04:09PM UTC coverage: 70.346% (+10.0%) from 60.368%
16077555618

push

github

web-flow
Merge pull request #402 from yast/disable-auto-client-tests

Disable auto client unit tests

3212 of 4566 relevant lines covered (70.35%)

40.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/src/modules/SSHAuthorizedKeys.rb
1
# Copyright (c) 2016 SUSE LLC.
2
#  All Rights Reserved.
3
#
4
#  This program is free software; you can redistribute it and/or
5
#  modify it under the terms of version 2 or 3 of the GNU General
6
#  Public License as published by the Free Software Foundation.
7
#
8
#  This program is distributed in the hope that it will be useful,
9
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
11
#  GNU General Public License for more details.
12
#
13
#  You should have received a copy of the GNU General Public License
14
#  along with this program; if not, contact SUSE LLC.
15
#
16
#  To contact SUSE about this file by physical or electronic mail,
17
#  you may find current contact information at www.suse.com
18

19
require "yast"
1✔
20
require "users/ssh_authorized_keyring"
1✔
21

22
Yast.import "Message"
1✔
23

24
module Yast
1✔
25
  # This module add support to handle SSH authorized keys.
26
  #
27
  # It's inteded to be a thin layer on top of SSHAuthorizedKeyring to be used by
28
  # yast2-users module (which is mainly written in Perl).
29
  class SSHAuthorizedKeysClass < Module
1✔
30
    include Logger
1✔
31

32
    def main
1✔
33
      textdomain "users"
1✔
34
    end
35

36
    # Read keys from a given home directory
37
    #
38
    # @see Y2Y2Users::SSHAuthorizedKeyring#read_keys
39
    def read_keys(home)
1✔
40
      keyring = Y2Users::SSHAuthorizedKeyring.new(home)
×
41
      keyring.read_keys
×
42
    end
43

44
    # Write keys to a given home directory
45
    #
46
    # @see Y2Y2Users::SSHAuthorizedKeyring#write_keys
47
    def write_keys(home, keys)
1✔
48
      keyring = Y2Users::SSHAuthorizedKeyring.new(home)
4✔
49
      keyring.add_keys(keys)
4✔
50
      keyring.write_keys
4✔
51
    rescue Y2Users::SSHAuthorizedKeyring::HomeDoesNotExist => e
52
      log.warn(e.message)
1✔
53
      Report.Warning(
1✔
54
        # TRANSLATORS: '%s' is a directory path
55
        format(_("Home directory '%s' does not exist\n" \
56
                 "so authorized keys will not be written."), e.path)
57
      )
58
    rescue Y2Users::SSHAuthorizedKeyring::NotRegularSSHDirectory => e
59
      log.warn(e.message)
1✔
60
      Report.Warning(
1✔
61
        # TRANSLATORS: '%s' is a directory path
62
        format(_("'%s' exists but it is not a directory. It might be\n" \
63
                 "a security issue so authorized keys will not\n" \
64
                 "be written."), e.path)
65
      )
66
    rescue Y2Users::SSHAuthorizedKeyring::NotRegularAuthorizedKeysFile => e
67
      log.warn(e.message)
1✔
68
      Report.Warning(
1✔
69
        # TRANSLATORS: '%s' is a directory path
70
        format(_("'%s' exists but it is not a file. It might be\n" \
71
                 "a security issue so authorized keys will not\n" \
72
                 "be written."), e.path)
73
      )
74
    rescue Y2Users::SSHAuthorizedKeyring::CouldNotCreateSSHDirectory => e
75
      log.warn(e.message)
1✔
76
      Report.Warning(
1✔
77
        Message.UnableToCreateDirectory(e.path) + "\n" +
78
          _("Authorized keys will not be written.")
79
      )
80
    end
81

82
    publish function: :read_keys, type: "boolean (string)"
1✔
83
    publish function: :write_keys, type: "boolean (string, list <string>)"
1✔
84
  end
85

86
  SSHAuthorizedKeys = SSHAuthorizedKeysClass.new
1✔
87
  SSHAuthorizedKeys.main
1✔
88
end
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

© 2025 Coveralls, Inc