   (-> (cc/registry registry-id)
       (cmi/->registry)))
 
-(defn registry-by-name
-  [registry-name]
-  (cc/registry-by-name registry-name))
-
 (defn registry-exist?
   [registry]
-  (some? (registry-by-name (:name registry))))
+  (cc/registry-exist? registry))
 
 (defn registry-valid?
   [registry]

    (->> (cmo/->registry registry)
         (cc/create-registry))))

;;; Secret API

(defn secrets
  []
  (-> (dc/secrets)
      (dmi/->secrets)))

(defn secret
  [secret-id]
  (-> (dc/secret secret-id)
      (dmi/->secret)))

(defn delete-secret
  [secret-id]
  (dc/delete-secret secret-id))

(defn create-secret
  [secret]
  (-> (dmo/->secret secret)
      (dc/create-secret)
      (rename-keys {:ID :id})))

(defn update-secret
  [secret-id secret]
  (let [secret-version (:version secret)]
    (->> (dmo/->secret secret)
         (dc/update-secret secret-id secret-version))))

;;; Network API

(defn networks
  []
  (-> (dc/networks)
      (dmi/->networks)))

(defn network
  [network-id]
  (-> (dc/network network-id)
      (dmi/->network)))

(defn delete-network
  [network-id]
  (dc/delete-network network-id))

(defn create-network
  [network]
  (->> (dmo/->network network)
       (dc/create-network)))

;;; Volume API

(defn volumes
  []
  (-> (dc/volumes)
      (dmi/->volumes)))

(defn volume
  [volume-name]
  (-> (dc/volume volume-name)
      (dmi/->volume)))

(defn delete-volume
  [volume-name]
  (dc/delete-volume volume-name))

(defn create-volume
  [volume]
  (->> (dmo/->volume volume)
       (dc/create-volume)
       (dmi/->volume)))

;;; Node API

(defn nodes
  []
  (-> (dc/nodes)
      (dmi/->nodes)))

(defn node
  [node-id]
  (-> (dc/node node-id)
      (dmi/->node)))

;;; Dockerhub API

(defn dockerusers
  []
  (-> (cc/docker-users)
      (cmi/->dockerusers)))

(defn dockerusers-list
  []
  (->> (dockerusers)
       (map :username)
       (into [])))

(defn dockeruser-info
  [dockeruser]
  (dhc/info dockeruser))

(defn dockeruser-login
  [dockeruser]
  (dhc/login dockeruser))

(defn dockeruser-by-username
  [dockeruser-name]
  (cc/docker-user-by-name dockeruser-name))

(defn dockeruser-exist?
  [dockeruser]
  (some? (dockeruser-by-username (:username dockeruser))))

(defn dockeruser
  [dockeruser-id]
  (-> (cc/docker-user dockeruser-id)
      (cmi/->dockeruser)))

(defn create-dockeruser
  [dockeruser dockeruser-info]
  (if (not (dockeruser-exist? dockeruser))
    (->> (cmo/->docker-user dockeruser dockeruser-info)
         (cc/create-docker-user))))

(defn delete-dockeruser
  [dockeruser-id]
  (-> (dockeruser dockeruser-id)
      (cc/delete-docker-user)))

(defn dockeruser-repositories
  [dockeruser]
  (let [user-token (:token (dhc/login dockeruser))]
    (->> (dhc/namespaces user-token)
         :namespaces
         (map #(:results (dhc/repositories-by-namespace user-token %)))
         (flatten)
         (dhmi/->user-repositories)
         (filter #(:private %)))))

(defn dockerhub-repositories
  [repository-query repository-page]
  (-> (dhc/repositories repository-query repository-page)
      (dhmi/->repositories repository-query repository-page)))

(defn dockerhub-tags
  [repository-name dockeruser-name]
  (let [user (dockeruser-by-username dockeruser-name)
        token (:token (dac/token user repository-name))]
    (->> (drc/tags token repository-name)
         :tags)))

(defn dockerhub-repository-id
  [repository-name repository-tag dockeruser-name]
  (let [user (dockeruser-by-username dockeruser-name)
        token (:token (dac/token user repository-name))]
    (-> (drc/manifest token repository-name repository-tag)
        (get-in [:config :digest]))))

;;; Registry V2 API

(defn repositories
  [registry]
  (->> (rc/repositories registry)
       (rmi/->repositories)))

(defn tags
  [registry repository-name]
  (->> (rc/tags registry repository-name)
       :tags))

(defn repository-id
  [registry-name repository-name repository-tag]
  (-> (registry-by-name registry-name)
      (rc/manifest repository-name repository-tag)
      (get-in [:config :digest])))

;;; Image API


      :Id))

(defn service-image-latest-id
  [{:keys [type id] :as registry}
   {:keys [name tag] :as repository}]
  (get-in
    (if (= "dockerhub" type)
      (-> (cc/dockeruser id)
          (dac/token name)
          :token
          (drc/manifest name tag))
      (-> (cc/registry id)
          (rc/manifest name tag))) [:config :digest]))

;;; Task API

