Exemple #1
0
 def edit(self):
     if self.options.key is None:
         self.edit_config()
         return
     buff = self.decode_key(self.options.key)
     if buff is None:
         raise ex.Error("could not decode the secret key '%s'" %
                        self.options.key)
     if isinstance(buff, bytes):
         raise ex.Error("binary keys are not editable")
     no_newline = os.sep not in try_decode(buff)
     editor = find_editor()
     fpath = self.tempfilename()
     create_protected_file(fpath, buff)
     try:
         os.system(' '.join((editor, fpath)))
         edited = read_unicode_file(fpath)
         if no_newline and edited.count(
                 os.linesep) == 1 and edited.endswith(os.linesep):
             self.log.debug(
                 "striping trailing newline from edited key value")
             edited = edited.rstrip(os.linesep)
         if buff == edited:
             return
         self.add_key(self.options.key, edited)
     finally:
         os.unlink(fpath)
Exemple #2
0
    def test_get_env_comment(tmp_file, capture_stdout):
        """
        Get node env.comment
        """

        with capture_stdout(tmp_file):
            ret = commands.node.main(argv=["get", "--param", "env.comment"])

        assert ret == 0
        with open(tmp_file) as output_file:
            assert try_decode(output_file.read()) == UNICODE_STRING
Exemple #3
0
    def test_0082_get_default(self):
        """
        Get DEFAULT.comment
        """
        _stdout = sys.stdout

        try:
            out = StringIO()
            sys.stdout = out
            ret = commands.svc.main(
                argv=["-s", SVCNAME, "get", "--param", "comment"])
            output = out.getvalue().strip()
        finally:
            sys.stdout = _stdout
        assert ret == 0
        assert try_decode(output) == UNICODE_STRING
Exemple #4
0
    def __get_ref(self, idx):
        """
        Get ref
        """
        name, val, exp_val = REFS[idx]
        _stdout = sys.stdout

        try:
            out = StringIO()
            sys.stdout = out
            ret = Mgr()(argv=["-s", SVCNAME, "get", "--eval", "--kw", name])
            output = out.getvalue().strip()
        finally:
            sys.stdout = _stdout
        print(ret, output, exp_val)
        assert ret == 0
        assert try_decode(output) == exp_val
Exemple #5
0
 def action(self, nodename, thr=None, **kwargs):
     options = self.parse_options(kwargs)
     timeout = options.timeout if options.timeout and options.timeout < MAX_TIMEOUT else MAX_TIMEOUT
     if not which("gotty"):
         raise ex.HTTP(500, "The gotty executable is not installed")
     creds = "user:"******"private_key")
     cert_chain = os.path.join(Env.paths.certs, "certificate_chain")
     cmd = [
         "gotty",
         "--port",
         "0",
         "--random-url",
         "--tls",
         "--tls-crt",
         cert_chain,
         "--tls-key",
         private_key,
         "--timeout",
         str(timeout),
         "--once",
         "--ws-origin",
         ".*",
         "--permit-write",
         "om",
         options.path,
         "enter",
         "--rid",
         options.rid,
     ]
     env = dict(os.environ).update({
         "GOTTY_CREDENTIAL": creds,
     })
     proc = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             env=env)
     thr.parent.push_proc(proc)
     for line in iter(proc.stderr.readline, ""):
         line = try_decode(line)
         if "https://" not in line:
             continue
         url = line.split("https://::", 1)[-1].strip()
         url = "https://" + creds + "@" + Env.nodename + url
         return {"data": {"url": url}}
Exemple #6
0
    def test_set_get_unset_some_env_value(tmp_file, capture_stdout,
                                          get_set_arg):
        assert commands.node.main(
            argv=["set", "--param", "env.this_is_test", "--value", "true"
                  ]) == 0

        with capture_stdout(tmp_file):
            ret = commands.node.main(
                argv=["get", get_set_arg, "env.this_is_test"])
            assert ret == 0
        with open(tmp_file) as output_file:
            assert try_decode(output_file.read()).strip() == "true"

        ret = commands.node.main(
            argv=["unset", get_set_arg, "env.this_is_test"])
        assert ret == 0

        tmp_file_1 = tmp_file + '-1'
        with capture_stdout(tmp_file_1):
            ret = commands.node.main(
                argv=["get", get_set_arg, "env.this_is_test"])
            assert ret == 0
        with open(tmp_file_1) as output_file:
            assert output_file.read().strip() == "None"