Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jaredhendrickson13/pfsense-api in…
Browse files Browse the repository at this point in the history
…to next_minor
  • Loading branch information
jaredhendrickson13 committed Sep 24, 2024
2 parents 4ea2fa6 + d4bc0b3 commit f74c89a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require_once 'RESTAPI/autoloader.inc';

use RESTAPI\Core\Cache;
use RESTAPI\Core\Command;
use RESTAPI\Models\RESTAPIVersion;

/**
* Defines a Cache that can be used to update the available pfSense-pkg-RESTAPI releases cache. This Cache
Expand All @@ -21,9 +22,18 @@ class RESTAPIVersionReleasesCache extends Cache {
* Retrieves available release information from external repos and updates the releases cache files.
*/
public function get_data_to_cache(): array {
# TODO: Change this to use PHP curl instead of a shell command
$fetch_releases_cmd = 'curl -s ' . self::RELEASES_URL . " -m $this->timeout";
$releases_json = new Command($fetch_releases_cmd);
return json_decode($releases_json->output, true);
# Retrieve the current API version for the User-Agent header
$api_version = RESTAPIVersion::get_api_version();

# Retrieve the available releases from the GitHub API
$releases_json = \RESTAPI\Core\Tools\http_request(
url: self::RELEASES_URL,
method: 'GET',
headers: ["User-Agent: pfSense-pkg-RESTAPI/$api_version"],
);
$releases = json_decode($releases_json, true);

# Return the fetched releases if in a valid format, otherwise retain the existing cache
return is_array($releases) ? $releases : $this->read();
}
}
13 changes: 7 additions & 6 deletions tools/make_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def generate_makefile(self):

# Set Jijna2 environment and variables
j2_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(searchpath=str(template_dir))
autoescape=jinja2.select_autoescape([]),
loader=jinja2.FileSystemLoader(searchpath=str(template_dir)),
)
j2_env.filters["dirname"] = self.dirname
plist_template = j2_env.get_template("pkg-plist.j2")
Expand Down Expand Up @@ -97,13 +98,13 @@ def generate_makefile(self):

def run_ssh_cmd(self, cmd):
"""Formats the SSH command to use when building on remote hosts."""
ssh_cmd = f"ssh {self.args.username}@{self.args.host} '{cmd}'"
return subprocess.call(ssh_cmd, shell=True)
ssh_cmd = ["ssh", f"{self.args.username}@{self.args.host}", cmd]
return subprocess.call(ssh_cmd, shell=False)

def run_scp_cmd(self, src, dst, recurse=False):
def run_scp_cmd(self, src, dst):
"""Formats the SCP command to use when copying over the built package."""
scp_cmd = f"scp {'-r' if recurse else ''} {src} {dst}"
return subprocess.call(scp_cmd, shell=True)
scp_cmd = ["scp", src, dst]
return subprocess.call(scp_cmd, shell=False)

def build_package(self, pkg_dir):
"""Builds the package when the local system is FreeBSD."""
Expand Down

0 comments on commit f74c89a

Please sign in to comment.