You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-core/core/variables/certificate.py

72 lines
2.3 KiB

#-*- coding: utf-8 -*-
# Copyright 2010-2012 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0 #
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# mode - read only or writeable variable
# value - default variable value
# select - list of posible values for variable
# hide - flag, if it is True, then the variable is not printable
# printval - print value of variable
from calculate.lib.datavars import Variable,ReadonlyVariable,VariableError
import os, glob, sys
from os import path
import OpenSSL
from calculate.lib.cl_lang import setLocalTranslate
from calculate.lib.utils.files import readLinesFile
#from calculate.api.cert_cmd import find_id_cert
setLocalTranslate('cl_core',sys.modules[__name__])
class VariableClAllCertId(Variable):
def get(self):
data_path = self.Get('cl_core_data')
result = []
cert_dir = data_path + '/client_certs/'
for filename in glob.glob(cert_dir+"*"):
if filename.endswith('.crt'):
temp = filename.split('.')[0].split('/')
id = temp[len(temp)-1]
try:
result.append(id)
except:
pass
return result
class VariableClCertId(Variable):
"""
Certificate Identification
"""
type = "choice"
opt = ["-c"]
metavalue = "CERT_ID"
def init(self):
self.help = _("Certificate Identification")
self.label = _("Certificate Identification")
def choice(self):
return self.Get('cl_all_cert_id')+['all']
def get(self):
return self.choice()[0]
def check(self, cert_id):
if cert_id != 'all':
try:
int(cert_id)
except ValueError:
raise VariableError(_("Certificate id must be int"))