Skip to content

Commit

Permalink
Merge pull request #13 from yueyongyue/dev
Browse files Browse the repository at this point in the history
增加:创建产品线的时候进行gitlab api 及salt api的测试
  • Loading branch information
yueyongyue authored Mar 9, 2019
2 parents 3729434 + caf8cac commit 01b2359
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from resources.minions import MinionsKeys, MinionsStatus, MinionsGrains, MinionsGrainsList
from resources.job import Job, JobList, JobManager
from resources.event import Event, EventList
from system.product import ProductList, Product
from system.product import ProductList, Product, ProductCheck
from system.role import RoleList, Role
from system.user import UserList, User, Register, ResetPassword, ResetPasswordByOwner, ChangeUserInfo
from system.login import Login
Expand Down Expand Up @@ -41,6 +41,7 @@
# product
api.add_resource(ProductList, "/saltshaker/api/v1.0/product")
api.add_resource(Product, "/saltshaker/api/v1.0/product/<string:product_id>")
api.add_resource(ProductCheck, "/saltshaker/api/v1.0/product/check/<string:name>")

# role
api.add_resource(RoleList, "/saltshaker/api/v1.0/role")
Expand Down
44 changes: 44 additions & 0 deletions system/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from system.user import update_user_privilege, update_user_product
from common.const import role_dict
from fileserver.rsync_fs import rsync_config
from common.saltstack_api import SaltAPI
import gitlab

logger = loggers()

Expand Down Expand Up @@ -179,4 +181,46 @@ def post(self):
return {"status": False, "message": result}, 500


class ProductCheck(Resource):
@access_required(role_dict["common_user"])
def post(self, name):
args = parser.parse_args()
if name == "salt_api":
if args["salt_master_url"] is "":
return {"status": False, "message": "Salt API address is empty"}, 200
salt_api = SaltAPI(
url=args["salt_master_url"],
user=args["salt_master_user"],
passwd=args["salt_master_password"]
)
if isinstance(salt_api, dict):
return {"status": False, "message": salt_api}, 200
else:
result = salt_api.shell_remote_execution(args["salt_master_id"], "echo true")
if result:
try:
if result['status'] is False:
return {"status": False, "message": result['message']}, 200
except KeyError:
return {"data": "", "status": True, "message": ""}, 200
else:
return {"data": "", "status": False,
"message": "Execute echo command on Master ID is not returned"}, 200
else:
if args["gitlab_url"] is "":
return {"status": False, "message": "GitLab API address is empty"}, 200
if args["api_version"] is "":
return {"status": False, "message": "GitLab API version is empty"}, 200
if args["state_project"] is "":
return {"status": False, "message": "GitLab State is empty"}, 200
try:
gl = gitlab.Gitlab(url=args["gitlab_url"],
private_token=args["private_token"],
timeout=120,
api_version=args["api_version"],
)

gl.projects.get(args["state_project"])
return {"data": "", "status": True, "message": ""}, 200
except Exception as e:
return {"data": "", "status": False, "message": str(e)}, 200

0 comments on commit 01b2359

Please sign in to comment.