Esempio n. 1
0
func putPrivateRegistry(request *restful.Request, response *restful.Response) {
	server := request.PathParameter("server")

	privateRegistry := &registry.PrivateRegistry{}
	err := request.ReadEntity(&privateRegistry)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Read body failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["server"] = server
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(400, string(errorMessageByteSlice))
		return
	}

	if server != privateRegistry.Name {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Path parameter name is different from name in the body"
		jsonMap["path"] = server
		jsonMap["body"] = privateRegistry.Name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(400, string(errorMessageByteSlice))
		return
	}

	oldPrivateRegistry, _ := registry.GetStorage().LoadPrivateRegistry(server)
	if oldPrivateRegistry == nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "The private registry server configuration to update doesn't exist"
		jsonMap["name"] = server
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	err = registry.GetStorage().SavePrivateRegistry(privateRegistry)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save private registry server configuration failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["privateRegistry"] = privateRegistry
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Esempio n. 2
0
func deleteImageInPrivateRegistryRepository(request *restful.Request, response *restful.Response) {
	server := request.PathParameter("server")
	repository := request.PathParameter("repository")
	tag := request.PathParameter("tag")

	privateRegistry, err := registry.GetStorage().LoadPrivateRegistry(server)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get private registry server configuration failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["server"] = server
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	err = privateRegistry.DeleteImageInRepository(repository, tag)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Delete image in repository failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["server"] = server
		jsonMap["repository"] = repository
		jsonMap["tag"] = tag
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}
}
Esempio n. 3
0
func getAllImageTagInPrivateRegistryRepository(request *restful.Request, response *restful.Response) {
	server := request.PathParameter("server")
	repository := request.PathParameter("repository")

	privateRegistry, err := registry.GetStorage().LoadPrivateRegistry(server)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get private registry server configuration failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["server"] = server
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	tagSlice, err := privateRegistry.GetAllImageTag(repository)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get all tags failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["server"] = server
		jsonMap["repository"] = repository
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(tagSlice, "[]string")
}
Esempio n. 4
0
func getAllPrivateRegistry(request *restful.Request, response *restful.Response) {
	privateRegistrySlice, err := registry.GetStorage().LoadAllPrivateRegistry()
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Get all private registry server configuration failure"
		jsonMap["ErrorMessage"] = err.Error()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(404, string(errorMessageByteSlice))
		return
	}

	response.WriteJson(privateRegistrySlice, "[]PrivateRegistry")
}
Esempio n. 5
0
func postPrivateRegistry(request *restful.Request, response *restful.Response) {
	privateRegistry := &registry.PrivateRegistry{}
	err := request.ReadEntity(&privateRegistry)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Read body failure"
		jsonMap["ErrorMessage"] = err.Error()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(400, string(errorMessageByteSlice))
		return
	}

	oldPrivateRegistry, _ := registry.GetStorage().LoadPrivateRegistry(privateRegistry.Name)
	if oldPrivateRegistry != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "The private registry server configuration to create already exists"
		jsonMap["name"] = privateRegistry.Name
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(409, string(errorMessageByteSlice))
		return
	}

	err = registry.GetStorage().SavePrivateRegistry(privateRegistry)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Save private registry server configuration failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["privateRegistry"] = privateRegistry
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
Esempio n. 6
0
func deletePrivateRegistry(request *restful.Request, response *restful.Response) {
	server := request.PathParameter("server")

	err := registry.GetStorage().DeletePrivateRegistry(server)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Delete private registry server configuration failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["server"] = server
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}