Skip to content

Commit

Permalink
Use clang-tidy hints
Browse files Browse the repository at this point in the history
  • Loading branch information
perkss committed Jan 15, 2024
1 parent 2d6d044 commit 1436193
Show file tree
Hide file tree
Showing 42 changed files with 96 additions and 165 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
# Clangd
.cache
compile_commands.json

.idea/
10 changes: 4 additions & 6 deletions include/abstr_sync_docker_cmd_exec.hh
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef SRC_ABSTR_SYNC_DOCKER_CMD_EXEC_HPP
#define SRC_ABSTR_SYNC_DOCKER_CMD_EXEC_HPP

#include <concepts>
#include <iostream>
#include <memory>
#include <type_traits>

#include "docker_client_config.hh"
Expand All @@ -13,19 +11,19 @@
namespace dockercpp::command::exec {

template <class Type>
concept CheckType = std::is_base_of<DockerCmd, Type>::value;
concept CheckType = std::is_base_of_v<DockerCmd, Type>;

template <CheckType CMD_T, typename RES_T>
class DockerCmdSyncExec {
public:
virtual RES_T exec(std::shared_ptr<CMD_T> command) = 0;

virtual ~DockerCmdSyncExec(){};
virtual ~DockerCmdSyncExec() = default;
};

class AbstrDockerCmdExec {
public:
~AbstrDockerCmdExec() {}
~AbstrDockerCmdExec() = default;

protected:
std::unique_ptr<core::WebTarget> m_webTarget;
Expand All @@ -38,7 +36,7 @@ class AbstrSyncDockerCmdExec : public AbstrDockerCmdExec,
public:
virtual RES_T exec(std::shared_ptr<CMD_T> command) = 0;

~AbstrSyncDockerCmdExec(){};
~AbstrSyncDockerCmdExec() = default;

protected:
virtual RES_T execute(std::shared_ptr<CMD_T> command) = 0;
Expand Down
11 changes: 5 additions & 6 deletions include/create_container_cmd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class CreateContainerCmd
: public SynchDockerCmd<model::CreateContainerResponse>,
public std::enable_shared_from_this<CreateContainerCmd> {
public:
CreateContainerCmd& withName(std::string name);
CreateContainerCmd& withName(const std::string& name);

CreateContainerCmd& withHost(std::string name);
CreateContainerCmd& withHost(const std::string& name);

CreateContainerCmd& withCmd(std::string cmd);
CreateContainerCmd& withCmd(const std::string& cmd);

CreateContainerCmd& withCmd(const std::vector<std::string>& cmd);

CreateContainerRequest getRequest() { return request; }

~CreateContainerCmd() {}
~CreateContainerCmd() override = default;

protected:
CreateContainerRequest request;
Expand All @@ -41,11 +41,10 @@ namespace createcontainer {
class Exec : public exec::DockerCmdSyncExec<CreateContainerCmd,
model::CreateContainerResponse> {
public:
~Exec() {}
~Exec() override = default;
};
} // namespace createcontainer

// https://github.com/docker-java/docker-java/blob/main/docker-java-core/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java
class CreateContainerCmdImpl
: public CreateContainerCmd,
public AbstrDockerCmd<CreateContainerCmd,
Expand Down
1 change: 0 additions & 1 deletion include/create_container_response.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <nlohmann/json.hpp>

// https://github.com/docker-java/docker-java/blob/main/docker-java-api/src/main/java/com/github/dockerjava/api/command/CreateContainerResponse.java
namespace dockercpp::model {
struct CreateContainerResponse : public DockerObject {
public:
Expand Down
2 changes: 0 additions & 2 deletions include/docker_client.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef DOCKER_CLIENT_H
#define DOCKER_CLIENT_H

#include <memory>

#include "create_container_cmd.hh"
#include "info_cmd.hh"
#include "ping_cmd.hh"
Expand Down
23 changes: 9 additions & 14 deletions include/docker_client_config.hh
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef SRC_DOCKER_CLIENT_CONFIG_HPP
#define SRC_DOCKER_CLIENT_CONFIG_HPP

#include <memory>
#include <string>
#include <unordered_set>

namespace dockercpp::core {

Expand All @@ -24,18 +22,18 @@ class DefaultDockerClientConfig : DockerClientConfig {
friend class Builder;
static Builder make();

std::string getDockerHost() override;
std::string getDockerHost() override;
std::string getRegistryUsername() override;
std::string getRegistryPassword() override;
std::string getRegistryEmail() override;
std::string getRegistryUrl() override;

~DefaultDockerClientConfig() {}
~DefaultDockerClientConfig() override = default;

private:
DefaultDockerClientConfig() = default;

std::string m_dockerHost;
std::string m_dockerHost;
std::string m_registryUsername;
std::string m_registryPassword;
std::string m_registryEmail;
Expand All @@ -44,16 +42,13 @@ class DefaultDockerClientConfig : DockerClientConfig {

class Builder {
public:
Builder& withDockerHost(std::string dockerHost);
Builder& withRegistryUsername(std::string username);
Builder& withRegistryPassword(std::string password);
Builder& withRegistryEmail(std::string email);
Builder& withRegistryUrl(std::string url);
Builder& withDockerHost(const std::string& dockerHost);
Builder& withRegistryUsername(const std::string& username);
Builder& withRegistryPassword(const std::string& password);
Builder& withRegistryEmail(const std::string& email);
Builder& withRegistryUrl(const std::string& url);

operator DefaultDockerClientConfig&&() {
// TODO think about this return
return std::move(m_dockerconfig);
}
operator DefaultDockerClientConfig&&() { return std::move(m_dockerconfig); }

private:
DefaultDockerClientConfig m_dockerconfig;
Expand Down
3 changes: 0 additions & 3 deletions include/docker_exception.hh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef DOCKER_EXCEPTION_H
#define DOCKER_EXCEPTION_H

//https://github.com/docker-java/docker-java/blob/docker-java-0.8.1/src/main/java/com/kpelykh/docker/client/DockerClient.java

class DockerException {
public:

};

Expand Down
4 changes: 2 additions & 2 deletions include/inspect_container_cmd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace inspectcontainer {
class Exec : public exec::DockerCmdSyncExec<InspectContainerCmd,
model::InspectContainerResponse> {
public:
~Exec() {}
~Exec() override = default;
};
} // namespace inspectcontainer

Expand All @@ -38,7 +38,7 @@ class InspectContainerCmdImpl

std::string getContainerId() override;

~InspectContainerCmdImpl() {}
~InspectContainerCmdImpl() override = default;

private:
std::string m_containerId;
Expand Down
2 changes: 1 addition & 1 deletion include/inspect_image_cmd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InspectImageCmdImpl

std::string getImageId() override;

~InspectImageCmdImpl() {}
~InspectImageCmdImpl() override = default;

private:
std::string m_imageId;
Expand Down
2 changes: 1 addition & 1 deletion include/inspect_image_response.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace dockercpp::model {

struct InspectImageResponse : public DockerObject {
struct InspectImageResponse : DockerObject {
std::string id;
};

Expand Down
7 changes: 1 addition & 6 deletions include/ping_cmd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

#include <spdlog/spdlog.h>

#include <concepts>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>

#include "abstr_sync_docker_cmd_exec.hh"
#include "docker_cmd.hh"
#include "synch_docker_cmd.hh"

namespace dockercpp::command {
Expand All @@ -19,7 +14,7 @@ namespace dockercpp::command {
class PingCmd : public SynchDockerCmd<std::string>,
public std::enable_shared_from_this<PingCmd> {
public:
~PingCmd() {}
~PingCmd() override = default;
};

namespace ping {
Expand Down
1 change: 0 additions & 1 deletion include/ping_cmd_exec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "ping_cmd.hh"

#include <string>
#include <memory>

namespace dockercpp::command::exec {

Expand Down
25 changes: 6 additions & 19 deletions include/pull_image_cmd.hh
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
#ifndef PULL_IMAGE_MD_H
#define PULL_IMAGE_MD_H


#include <memory>
#include <string>
#include <type_traits>

#include "abstr_sync_docker_cmd_exec.hh"

#include "docker_cmd.hh"
#include "synch_docker_cmd.hh"

namespace dockercpp::command {

// TODO this is an async example that needs sorting out
// https://github.com/docker-java/docker-java/blob/main/docker-java-core/src/main/java/com/github/dockerjava/core/exec/PullImageCmdExec.java
// https://github.com/docker-java/docker-java/blob/main/docker-java/src/test/java/com/github/dockerjava/cmd/PullImageCmdIT.java#L67
class PullImageCmd : public SynchDockerCmd<std::string>,
public std::enable_shared_from_this<PullImageCmd> {
public:
explicit PullImageCmd(const std::string& image);

explicit PullImageCmd(const std::string& image);

PullImageCmd& withTag(std::string tag);
PullImageCmd& withTag(std::string tag);

std::string getRepository();

std::string getTag();

std::string getRegistry();

std::string getPlatform();
std::string getPlatform();

~PullImageCmd() {}

Expand All @@ -51,18 +43,13 @@ class Exec : public exec::DockerCmdSyncExec<PullImageCmd, std::string> {
class PullImageCmdImpl : public PullImageCmd,
public AbstrDockerCmd<PullImageCmd, std::string> {
public:
PullImageCmdImpl(std::unique_ptr<pull::Exec> exec, const std::string& image);
PullImageCmdImpl(std::unique_ptr<pull::Exec> exec, const std::string& image);

std::string exec() override;

void close() override;
~PullImageCmdImpl();
void close() override;
~PullImageCmdImpl();
};

}; // namespace dockercpp::command
// https://stackoverflow.com/questions/51575956/libcurl-c-how-do-i-post-form-data-for-this-specific-form
// TODO add function to create the form data style rather than the json body
// https://docs.docker.com/engine/api/v1.43/#tag/Image/operation/ImageCreate
// cu rl --unix-socket /var/run/docker.sock \
// -X POST "http://localhost/v1.43/images/create?fromImage=alpine"
#endif
22 changes: 8 additions & 14 deletions include/remove_container_cmd.hh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#ifndef INCLUDE_REMOVE_CONTAINER_CMD_HPP
#define INCLUDE_REMOVE_CONTAINER_CMD_HPP

#include <concepts>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>

#include "abstr_sync_docker_cmd_exec.hh"
#include "docker_cmd.hh"
#include "synch_docker_cmd.hh"

namespace dockercpp::command {
Expand All @@ -17,11 +13,9 @@ class RemoveContainerCmd
: public SynchDockerCmd<std::string>,
public std::enable_shared_from_this<RemoveContainerCmd> {
public:


virtual void withContainerId(std::string id) = 0;

virtual std::string getContainerId() = 0;
virtual std::string getContainerId() = 0;

~RemoveContainerCmd() {}

Expand All @@ -35,22 +29,22 @@ class Exec : public exec::DockerCmdSyncExec<RemoveContainerCmd, std::string> {
~Exec() {}
};

} // namespace remove
} // namespace removecontainer

class RemoveContainerCmdImpl
: public RemoveContainerCmd,
public AbstrDockerCmd<RemoveContainerCmd, std::string> {
public:
RemoveContainerCmdImpl(std::unique_ptr<removecontainer::Exec> exec,
std::string containerId);
RemoveContainerCmdImpl(std::unique_ptr<removecontainer::Exec> exec,
std::string containerId);

std::string exec() override;
std::string exec() override;

void close() override {}
void close() override {}

void withContainerId(std::string id) override;
void withContainerId(std::string id) override;

std::string getContainerId() override;
std::string getContainerId() override;

~RemoveContainerCmdImpl() {}
};
Expand Down
5 changes: 0 additions & 5 deletions include/remove_image_cmd.hh
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#ifndef INCLUDE_REMOVE_IMAGE_CMD_HPP
#define INCLUDE_REMOVE_IMAGE_CMD_HPP

#include <concepts>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>

#include "abstr_sync_docker_cmd_exec.hh"
#include "docker_cmd.hh"
#include "synch_docker_cmd.hh"

namespace dockercpp::command {

// Understand if the parent needs public or just use private
class RemoveImageCmd : public SynchDockerCmd<std::string>,
public std::enable_shared_from_this<RemoveImageCmd> {
public:
Expand Down
7 changes: 0 additions & 7 deletions include/synch_docker_cmd.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <spdlog/spdlog.h>

#include <memory>
#include <typeinfo>

#include "abstr_sync_docker_cmd_exec.hh"
#include "docker_cmd.hh"
Expand All @@ -30,12 +29,6 @@ class AbstrDockerCmd : SynchDockerCmd<RES_T> {
: m_execution(std::move(execution)){};

RES_T exec() override {
//

auto x = this;
spdlog::info("calling exec {}");

// TODO this is used and is sync
}

~AbstrDockerCmd() {}
Expand Down
Loading

0 comments on commit 1436193

Please sign in to comment.