Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple pkg repositories #1

Open
Freaky opened this issue Jan 11, 2020 · 24 comments
Open

Support multiple pkg repositories #1

Freaky opened this issue Jan 11, 2020 · 24 comments
Assignees

Comments

@Freaky
Copy link

Freaky commented Jan 11, 2020

pkg supports an arbitrary number of active package repositories, but SameDrucker seems to assume There Can Be Only One馃尒.

@dlangille
Copy link
Owner

dlangille commented Jan 11, 2020

What problems does this create?

I think you refer to this line:

https://github.com/dlangille/SamDrucker/blob/master/clients/samdrucker.sh#L53

Also, I think repo is getting the wrong values in that field.

Examples from my database. pkg should not be there at the start of each line.

samdrucker=# select distinct(repo) from host;
                                    repo                                     
-----------------------------------------------------------------------------
 pkg http://fedex.int.example.org/packages/120amd64-default-mysql56/
 pkg https://fedex.example.org/packages/121amd64-default-master-list/
 pkg http://fedex.example.org/packages/121amd64-default-master-list/
 pkg https://fedex.example.org/packages/121i386-default-master-list-i386/
 pkg http://fedex.int.example.org/packages/120amd64-default-pg96/
 pkg http://fedex.example.org/packages/120amd64-default-pg12/
 http://pkg.freebsd.org/FreeBSD:12:amd64/latest/
 pkg http://fedex.int.example.org/packages/120amd64-default-pg95/
 pkg http://fedex.int.example.org/packages/120amd64-default-mysql80/
 pkg http://fedex.int.example.org/packages/120amd64-default-unifi/
 pkg http://fedex.int.example.org/packages/120amd64-default-pg94/
 pkg http://fedex.int.example.org/packages/120amd64-default-pg11/
 pkg http://fedex.int.example.org/packages/120amd64-default-master-list/
 pkg http://fedex.int.example.org/packages/121amd64-default-master-list/
 pkg http://fedex.int.example.org/packages/120amd64-default-pg10/
 pkg http://fedex.int.example.org/packages/121amd64-default-pg12-121/
 pkg http://fedex.int.example.org/packages/120amd64-default-mysql57/
 pkg http://fedex.example.org/packages/120amd64-default-master-list/
(18 rows)

samdrucker=# 

@Freaky
Copy link
Author

Freaky commented Jan 11, 2020

I think it mostly works by accident - jo happens to silently ignore arguments without = but that contain :, so feeding it bare URLs does nothing.

This looks to be an implementation detail, it's not documented behaviour from what I can see.

@dlangille
Copy link
Owner

In the past, I used multiple repos, but stopped. That has contributed to this.

@dlangille dlangille self-assigned this Jan 11, 2020
@dlangille
Copy link
Owner

@jpmens see above where jo is mentioned.

@jpmens
Copy link
Contributor

jpmens commented Jan 11, 2020 via email

@dlangille
Copy link
Owner

You are everywhere.

@jpmens
Copy link
Contributor

jpmens commented Jan 11, 2020

Actually I thought you were referring to the README. Now I see @Freaky might have uncovered a small issue and/or something which isn鈥檛 documented, so if you think it鈥檚 a bug I鈥檇 appreciate a bug report and more so a fix. :)

@dlangille
Copy link
Owner

Also, I think repo is getting the wrong values in that field.

Examples from my database. pkg should not be there at the start of each line.

samdrucker=# select distinct(repo) from host;
                                    repo                                     
-----------------------------------------------------------------------------
 pkg http://fedex.int.example.org/packages/120amd64-default-mysql56/
...

samdrucker=# 

I think I see why. That value is actually:

[dan@pg02:~] $ repo=`/usr/sbin/pkg -vv | grep  url | cut -f2 -d \"`
[dan@pg02:~] $ echo $repo
pkg+http://fedex.int.unixathome.org/packages/121amd64-default-pg12-121/
[dan@pg02:~] $ 

It makes me think of url encoding issues.

@Freaky
Copy link
Author

Freaky commented Jan 11, 2020

@jpmens This is my first time using jo, and I only skimmed the docs, but this does look unintentional considering other invalid argument forms produce a warning diagnostic on stderr:

-% jo foo:bar
{}
-% jo foobar
Argument `foobar' is neither k=v nor k@v
{}

@Freaky
Copy link
Author

Freaky commented Jan 11, 2020

@dlangille Maybe you want --data-urlencode instead of just -d?

@dlangille
Copy link
Owner

dlangille commented Jan 11, 2020

@Freaky I was just trying that, but:

$ $CURL -d --data-urlencode "$SAMDRUCKER_ARG=$payload" -H "Content-Type: application/x-www-form-urlencoded" -X POST $SAMDRUCKER_URL
curl: (3) nested brace in URL position 204:
packages={
   "name": "pg02.int.example.org",
   "os": "FreeBSD",
   "version": "12.1-RELEASE-p1",
   "repo": "pkg+http://fedex.int.example.org/packages/121amd64-default-pg12-121/",
   "packages": [
      "SamDruckerClientShell-0.0.1",
      "anvil-0.0.17_2",
      "apr-1.7.0.1.6.1",
      "bash-5.0.11",
      "bind-tools-9.14.9",
      "ca_root_nss-3.49",
      "curl-7.68.0",
      "cyrus-sasl-2.1.27",
      "db5-5.3.28_7",
      "expat-2.2.8",
      "gdbm-1.18.1_1"
$

@dlangille
Copy link
Owner

If I manually urlencode payload before invoking curl, the database gets the correct results.

@dlangille
Copy link
Owner

I thought using -d (POST, content-type:application/x-www-form-urlencoded) would remove the need for urlencoding the data. I am seeing that was incorrect. Unless there is more curl can do here.

@Freaky
Copy link
Author

Freaky commented Jan 11, 2020

Don't mix -d with --data-urlencode:

-% curl -d "foo={bar+[foo]}" https://voi.aagh.net/post.php -X POST
array(1) {
  ["foo"]=>
  string(11) "{bar [foo]}"
}

-% curl -d --data-urlencode "foo={bar+[foo]}" https://voi.aagh.net/post.php -X POST
curl: (3) nested brace in URL position 10:
foo={bar+[foo]}
         ^
-% curl --data-urlencode "foo={bar+[foo]}" https://voi.aagh.net/post.php -X POST
array(1) {
  ["foo"]=>
  string(11) "{bar+[foo]}"
}

@dlangille
Copy link
Owner

This works:

$ $CURL --data-urlencode "$SAMDRUCKER_ARG=$payload" -X POST $SAMDRUCKER_URL

@dlangille
Copy link
Owner

I think you've found it.

@jpmens
Copy link
Contributor

jpmens commented Jan 12, 2020

I'm only half paying attention, but IMO URL encoding the data is not really needed, and passing all that data on the command ine might even blow some limit (MAX ARGS?) some time / some day.

If this were mine, I would run jo's output into a file and then curl up the raw data:

t=$(mkstemp /tmp/xxxxxx)
jo .... > $t
curl --data @${t} ...

The @ as first char in curl's --data or -d has it read the data from a file and uses that data uninterpreted.

@jpmens
Copy link
Contributor

jpmens commented Jan 12, 2020

@Freaky there are likely a number of undocumented / unintentional cases in jo. :)

@dlangille
Copy link
Owner

This works:

$ $CURL --data-urlencode "$SAMDRUCKER_ARG=$payload" -X POST $SAMDRUCKER_URL

This works in release 0.0.2

@dlangille
Copy link
Owner

I'm only half paying attention, but IMO URL encoding the data is not really needed, and passing all that data on the command ine might even blow some limit (MAX ARGS?) some time / some day.

If this were mine, I would run jo's output into a file and then curl up the raw data:

t=$(mkstemp /tmp/xxxxxx)
jo .... > $t
curl --data @${t} ...

The @ as first char in curl's --data or -d has it read the data from a file and uses that data uninterpreted.

This works:

payload=$(mktemp /tmp/SamDrucker.payload.XXXXXX)
$JO -p name=$hostname os=$uname version=$version repo=$repo $pkg_args > $payload
$CURL --data-urlencode ${SAMDRUCKER_ARG}@${payload} -H "Content-Type: application/x-www-form-urlencoded" -X POST $SAMDRUCKER_URL

More importantly, so does this:

$CURL --data-urlencode ${SAMDRUCKER_ARG}@${payload} ${SAMDRUCKER_URL}

@jpmens
Copy link
Contributor

jpmens commented Jan 12, 2020

I'm sure you have a reason for --data-urlencode even if I don't see it, but I haven't looked at the server part of all this.

FWIW, I typically use --data and save on encoding/decoding, but if you're using a form on the backend then this is fine.

@jpmens
Copy link
Contributor

jpmens commented Jan 12, 2020

Ah, I see it here:

json_decode($_REQUEST['packages']);

yes, fine. Just FYI, if you prefer to avoid the encoding you can pick up the raw POST (sent with curl --data) with

$data = file_get_contents('php://input');
json_decode(...);

@dlangille
Copy link
Owner

I encoded because we're sending data in a URL. I thought urlencoding was the thing to do when sending data in a URL.

At present, we are just sending one parameter over, packages. I was leaving room for sending more items.

@dlangille
Copy link
Owner

Sorry, this got dropped. Not sure what is next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants