{"action":"created","comment":{"url":"https://api.github.com/repos/yast/yast-bootloader/pulls/comments/32319594","id":32319594,"diff_hunk":"@@ -1,63 +1,146 @@\n require \"yast\"\n \n-# class is responsible for detection, encryption and writing of grub2 password protection\n-class GRUB2Pwd\n-  YAST_BASH_PATH = Yast::Path.new(\".target.bash_output\")\n-  PWD_ENCRYPTION_FILE = \"/etc/grub.d/42_password\"\n+Yast.import \"Stage\"\n \n-  def used?\n-    Yast.import \"FileUtils\"\n+module Bootloader\n+  # class is responsible for detection, encryption and writing of grub2 password protection\n+  class GRUB2Pwd\n+    # @!attribute used\n+    #   @return [bool] specifies if password protection enabled\n+    #\n+    # @!attribute unrestricted\n+    #   @return [bool] specifies if unrestricted password protection should be used\n+    attr_accessor :used, :unrestricted\n+    alias_method :used?, :used\n+    alias_method :unrestricted?, :unrestricted\n \n-    Yast::FileUtils.Exists PWD_ENCRYPTION_FILE\n-  end\n+    # Reads or proposes configuration depending on stage\n+    def initialize\n+      # TODO: offline upgrade should somehow read it when we need grub2 -> grub2 modifications\n+      if Yast::Stage.initial\n+        propose\n+      else\n+        read\n+      end\n+    end\n \n-  def enable(password)\n-    enc_passwd = encrypt(password)\n-\n-    file_content = \"#! /bin/sh\\n\" \\\n-      \"exec tail -n +3 $0\\n\" \\\n-      \"# File created by YaST and next password change in YaST will overwrite it\\n\" \\\n-      \"set superusers=\\\"root\\\"\\n\" \\\n-      \"password_pbkdf2 root #{enc_passwd}\\n\" \\\n-      \"export superusers\"\n-\n-    Yast::SCR.Write(\n-      Yast::Path.new(\".target.string\"),\n-      [PWD_ENCRYPTION_FILE, 0700],\n-      file_content\n-    )\n-  end\n+    # writes configuration to disk\n+    def write\n+      if used?\n+        enable\n+      else\n+        disable\n+      end\n+    end\n \n-  def disable\n-    return unless used?\n+    # Sets password in encrypted form\n+    # @param [String] value plain text password\n+    def password=(value)\n+      @encrypted_password = encrypt(value)\n+    end\n \n-    Yast::SCR.Execute(YAST_BASH_PATH, \"rm '#{PWD_ENCRYPTION_FILE}'\")\n-  end\n+    # Gets if password is specified\n+    # Rationale for this method is that in some cases it is possible\n+    # to disable password configuration, but still keep old configuration in\n+    # object, so after enabling it again it use old configuration\n+    def password?\n+      !@encrypted_password.nil?\n+    end\n+\n+  private\n+\n+    YAST_BASH_PATH = Yast::Path.new(\".target.bash_output\")\n+    PWD_ENCRYPTION_FILE = \"/etc/grub.d/42_password\"\n+\n+    def propose\n+      @used = false\n+      @unrestricted = false # TODO: ensure it in FATE","path":"src/lib/bootloader/grub2pwd.rb","position":85,"original_position":85,"commit_id":"6fd453c021c2e8461bd769f123c91f13bb0305da","original_commit_id":"6fd453c021c2e8461bd769f123c91f13bb0305da","user":{"login":"jreidinger","id":478871,"avatar_url":"https://avatars.githubusercontent.com/u/478871?v=3","gravatar_id":"","url":"https://api.github.com/users/jreidinger","html_url":"https://github.com/jreidinger","followers_url":"https://api.github.com/users/jreidinger/followers","following_url":"https://api.github.com/users/jreidinger/following{/other_user}","gists_url":"https://api.github.com/users/jreidinger/gists{/gist_id}","starred_url":"https://api.github.com/users/jreidinger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreidinger/subscriptions","organizations_url":"https://api.github.com/users/jreidinger/orgs","repos_url":"https://api.github.com/users/jreidinger/repos","events_url":"https://api.github.com/users/jreidinger/events{/privacy}","received_events_url":"https://api.github.com/users/jreidinger/received_events","type":"User","site_admin":false},"body":"fate is already in needinfo state so I need to wait","created_at":"2015-06-12T14:19:53Z","updated_at":"2015-06-12T14:19:53Z","html_url":"https://github.com/yast/yast-bootloader/pull/243#discussion_r32319594","pull_request_url":"https://api.github.com/repos/yast/yast-bootloader/pulls/243","_links":{"self":{"href":"https://api.github.com/repos/yast/yast-bootloader/pulls/comments/32319594"},"html":{"href":"https://github.com/yast/yast-bootloader/pull/243#discussion_r32319594"},"pull_request":{"href":"https://api.github.com/repos/yast/yast-bootloader/pulls/243"}}},"pull_request":{"url":"https://api.github.com/repos/yast/yast-bootloader/pulls/243","id":37467167,"html_url":"https://github.com/yast/yast-bootloader/pull/243","diff_url":"https://github.com/yast/yast-bootloader/pull/243.diff","patch_url":"https://github.com/yast/yast-bootloader/pull/243.patch","issue_url":"https://api.github.com/repos/yast/yast-bootloader/issues/243","number":243,"state":"open","locked":false,"title":"Unrestricted boot","user":{"login":"jreidinger","id":478871,"avatar_url":"https://avatars.githubusercontent.com/u/478871?v=3","gravatar_id":"","url":"https://api.github.com/users/jreidinger","html_url":"https://github.com/jreidinger","followers_url":"https://api.github.com/users/jreidinger/followers","following_url":"https://api.github.com/users/jreidinger/following{/other_user}","gists_url":"https://api.github.com/users/jreidinger/gists{/gist_id}","starred_url":"https://api.github.com/users/jreidinger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreidinger/subscriptions","organizations_url":"https://api.github.com/users/jreidinger/orgs","repos_url":"https://api.github.com/users/jreidinger/repos","events_url":"https://api.github.com/users/jreidinger/events{/privacy}","received_events_url":"https://api.github.com/users/jreidinger/received_events","type":"User","site_admin":false},"body":"Do not merge yet as grub2 is not yet ready. changelog update will be added later to avoid conflicts.","created_at":"2015-06-11T14:10:02Z","updated_at":"2015-06-12T14:19:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"83c926ef9f3b4c85057620f1edfe4a88732d2a21","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yast/yast-bootloader/pulls/243/commits","review_comments_url":"https://api.github.com/repos/yast/yast-bootloader/pulls/243/comments","review_comment_url":"https://api.github.com/repos/yast/yast-bootloader/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yast/yast-bootloader/issues/243/comments","statuses_url":"https://api.github.com/repos/yast/yast-bootloader/statuses/6fd453c021c2e8461bd769f123c91f13bb0305da","head":{"label":"yast:unrestricted_boot","ref":"unrestricted_boot","sha":"6fd453c021c2e8461bd769f123c91f13bb0305da","user":{"login":"yast","id":909990,"avatar_url":"https://avatars.githubusercontent.com/u/909990?v=3","gravatar_id":"","url":"https://api.github.com/users/yast","html_url":"https://github.com/yast","followers_url":"https://api.github.com/users/yast/followers","following_url":"https://api.github.com/users/yast/following{/other_user}","gists_url":"https://api.github.com/users/yast/gists{/gist_id}","starred_url":"https://api.github.com/users/yast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yast/subscriptions","organizations_url":"https://api.github.com/users/yast/orgs","repos_url":"https://api.github.com/users/yast/repos","events_url":"https://api.github.com/users/yast/events{/privacy}","received_events_url":"https://api.github.com/users/yast/received_events","type":"Organization","site_admin":false},"repo":{"id":4368075,"name":"yast-bootloader","full_name":"yast/yast-bootloader","owner":{"login":"yast","id":909990,"avatar_url":"https://avatars.githubusercontent.com/u/909990?v=3","gravatar_id":"","url":"https://api.github.com/users/yast","html_url":"https://github.com/yast","followers_url":"https://api.github.com/users/yast/followers","following_url":"https://api.github.com/users/yast/following{/other_user}","gists_url":"https://api.github.com/users/yast/gists{/gist_id}","starred_url":"https://api.github.com/users/yast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yast/subscriptions","organizations_url":"https://api.github.com/users/yast/orgs","repos_url":"https://api.github.com/users/yast/repos","events_url":"https://api.github.com/users/yast/events{/privacy}","received_events_url":"https://api.github.com/users/yast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yast/yast-bootloader","description":"YaST module bootloader","fork":false,"url":"https://api.github.com/repos/yast/yast-bootloader","forks_url":"https://api.github.com/repos/yast/yast-bootloader/forks","keys_url":"https://api.github.com/repos/yast/yast-bootloader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yast/yast-bootloader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yast/yast-bootloader/teams","hooks_url":"https://api.github.com/repos/yast/yast-bootloader/hooks","issue_events_url":"https://api.github.com/repos/yast/yast-bootloader/issues/events{/number}","events_url":"https://api.github.com/repos/yast/yast-bootloader/events","assignees_url":"https://api.github.com/repos/yast/yast-bootloader/assignees{/user}","branches_url":"https://api.github.com/repos/yast/yast-bootloader/branches{/branch}","tags_url":"https://api.github.com/repos/yast/yast-bootloader/tags","blobs_url":"https://api.github.com/repos/yast/yast-bootloader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yast/yast-bootloader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yast/yast-bootloader/git/refs{/sha}","trees_url":"https://api.github.com/repos/yast/yast-bootloader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yast/yast-bootloader/statuses/{sha}","languages_url":"https://api.github.com/repos/yast/yast-bootloader/languages","stargazers_url":"https://api.github.com/repos/yast/yast-bootloader/stargazers","contributors_url":"https://api.github.com/repos/yast/yast-bootloader/contributors","subscribers_url":"https://api.github.com/repos/yast/yast-bootloader/subscribers","subscription_url":"https://api.github.com/repos/yast/yast-bootloader/subscription","commits_url":"https://api.github.com/repos/yast/yast-bootloader/commits{/sha}","git_commits_url":"https://api.github.com/repos/yast/yast-bootloader/git/commits{/sha}","comments_url":"https://api.github.com/repos/yast/yast-bootloader/comments{/number}","issue_comment_url":"https://api.github.com/repos/yast/yast-bootloader/issues/comments{/number}","contents_url":"https://api.github.com/repos/yast/yast-bootloader/contents/{+path}","compare_url":"https://api.github.com/repos/yast/yast-bootloader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yast/yast-bootloader/merges","archive_url":"https://api.github.com/repos/yast/yast-bootloader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yast/yast-bootloader/downloads","issues_url":"https://api.github.com/repos/yast/yast-bootloader/issues{/number}","pulls_url":"https://api.github.com/repos/yast/yast-bootloader/pulls{/number}","milestones_url":"https://api.github.com/repos/yast/yast-bootloader/milestones{/number}","notifications_url":"https://api.github.com/repos/yast/yast-bootloader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yast/yast-bootloader/labels{/name}","releases_url":"https://api.github.com/repos/yast/yast-bootloader/releases{/id}","created_at":"2012-05-18T10:22:41Z","updated_at":"2015-04-21T10:00:09Z","pushed_at":"2015-06-12T10:53:56Z","git_url":"git://github.com/yast/yast-bootloader.git","ssh_url":"git@github.com:yast/yast-bootloader.git","clone_url":"https://github.com/yast/yast-bootloader.git","svn_url":"https://github.com/yast/yast-bootloader","homepage":"http://en.opensuse.org/Portal:YaST","size":28900,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":2,"forks":9,"open_issues":2,"watchers":3,"default_branch":"master"}},"base":{"label":"yast:master","ref":"master","sha":"0f6a80c6df2cb978647c4ecf385753a2d37e636c","user":{"login":"yast","id":909990,"avatar_url":"https://avatars.githubusercontent.com/u/909990?v=3","gravatar_id":"","url":"https://api.github.com/users/yast","html_url":"https://github.com/yast","followers_url":"https://api.github.com/users/yast/followers","following_url":"https://api.github.com/users/yast/following{/other_user}","gists_url":"https://api.github.com/users/yast/gists{/gist_id}","starred_url":"https://api.github.com/users/yast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yast/subscriptions","organizations_url":"https://api.github.com/users/yast/orgs","repos_url":"https://api.github.com/users/yast/repos","events_url":"https://api.github.com/users/yast/events{/privacy}","received_events_url":"https://api.github.com/users/yast/received_events","type":"Organization","site_admin":false},"repo":{"id":4368075,"name":"yast-bootloader","full_name":"yast/yast-bootloader","owner":{"login":"yast","id":909990,"avatar_url":"https://avatars.githubusercontent.com/u/909990?v=3","gravatar_id":"","url":"https://api.github.com/users/yast","html_url":"https://github.com/yast","followers_url":"https://api.github.com/users/yast/followers","following_url":"https://api.github.com/users/yast/following{/other_user}","gists_url":"https://api.github.com/users/yast/gists{/gist_id}","starred_url":"https://api.github.com/users/yast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yast/subscriptions","organizations_url":"https://api.github.com/users/yast/orgs","repos_url":"https://api.github.com/users/yast/repos","events_url":"https://api.github.com/users/yast/events{/privacy}","received_events_url":"https://api.github.com/users/yast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yast/yast-bootloader","description":"YaST module bootloader","fork":false,"url":"https://api.github.com/repos/yast/yast-bootloader","forks_url":"https://api.github.com/repos/yast/yast-bootloader/forks","keys_url":"https://api.github.com/repos/yast/yast-bootloader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yast/yast-bootloader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yast/yast-bootloader/teams","hooks_url":"https://api.github.com/repos/yast/yast-bootloader/hooks","issue_events_url":"https://api.github.com/repos/yast/yast-bootloader/issues/events{/number}","events_url":"https://api.github.com/repos/yast/yast-bootloader/events","assignees_url":"https://api.github.com/repos/yast/yast-bootloader/assignees{/user}","branches_url":"https://api.github.com/repos/yast/yast-bootloader/branches{/branch}","tags_url":"https://api.github.com/repos/yast/yast-bootloader/tags","blobs_url":"https://api.github.com/repos/yast/yast-bootloader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yast/yast-bootloader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yast/yast-bootloader/git/refs{/sha}","trees_url":"https://api.github.com/repos/yast/yast-bootloader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yast/yast-bootloader/statuses/{sha}","languages_url":"https://api.github.com/repos/yast/yast-bootloader/languages","stargazers_url":"https://api.github.com/repos/yast/yast-bootloader/stargazers","contributors_url":"https://api.github.com/repos/yast/yast-bootloader/contributors","subscribers_url":"https://api.github.com/repos/yast/yast-bootloader/subscribers","subscription_url":"https://api.github.com/repos/yast/yast-bootloader/subscription","commits_url":"https://api.github.com/repos/yast/yast-bootloader/commits{/sha}","git_commits_url":"https://api.github.com/repos/yast/yast-bootloader/git/commits{/sha}","comments_url":"https://api.github.com/repos/yast/yast-bootloader/comments{/number}","issue_comment_url":"https://api.github.com/repos/yast/yast-bootloader/issues/comments{/number}","contents_url":"https://api.github.com/repos/yast/yast-bootloader/contents/{+path}","compare_url":"https://api.github.com/repos/yast/yast-bootloader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yast/yast-bootloader/merges","archive_url":"https://api.github.com/repos/yast/yast-bootloader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yast/yast-bootloader/downloads","issues_url":"https://api.github.com/repos/yast/yast-bootloader/issues{/number}","pulls_url":"https://api.github.com/repos/yast/yast-bootloader/pulls{/number}","milestones_url":"https://api.github.com/repos/yast/yast-bootloader/milestones{/number}","notifications_url":"https://api.github.com/repos/yast/yast-bootloader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yast/yast-bootloader/labels{/name}","releases_url":"https://api.github.com/repos/yast/yast-bootloader/releases{/id}","created_at":"2012-05-18T10:22:41Z","updated_at":"2015-04-21T10:00:09Z","pushed_at":"2015-06-12T10:53:56Z","git_url":"git://github.com/yast/yast-bootloader.git","ssh_url":"git@github.com:yast/yast-bootloader.git","clone_url":"https://github.com/yast/yast-bootloader.git","svn_url":"https://github.com/yast/yast-bootloader","homepage":"http://en.opensuse.org/Portal:YaST","size":28900,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":2,"forks":9,"open_issues":2,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yast/yast-bootloader/pulls/243"},"html":{"href":"https://github.com/yast/yast-bootloader/pull/243"},"issue":{"href":"https://api.github.com/repos/yast/yast-bootloader/issues/243"},"comments":{"href":"https://api.github.com/repos/yast/yast-bootloader/issues/243/comments"},"review_comments":{"href":"https://api.github.com/repos/yast/yast-bootloader/pulls/243/comments"},"review_comment":{"href":"https://api.github.com/repos/yast/yast-bootloader/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yast/yast-bootloader/pulls/243/commits"},"statuses":{"href":"https://api.github.com/repos/yast/yast-bootloader/statuses/6fd453c021c2e8461bd769f123c91f13bb0305da"}}}}