From a0dca82bf37dfff10181d43571e435158dfeea49 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 22 Oct 2020 20:26:03 +0000 Subject: [PATCH] Add `oc ignition convert3` The transition to Ignition Spec 3 with 4.6 creates a discontinuity. Some users want to update their bootimages, e.g. for a cluster originally provisioned as 4.4 but upgraded in place to 4.6, it should be possible to directly use RHCOS 4.6 bootimages for new workers. In some cases in fact, this could be required for things like adding a node with newer hardware. The main stumbling block here is the pointer ignition config which is generated by `openshift-install`. Since the idea is `openshift-install` should in theory be disposable after a cluster is provisioned, let's add this to `oc` which admins will need anyways. Vendor and use https://github.com/coreos/ign-converter the same as the MCO uses. xref openshift/enhancements#492 (comment) xref https://bugzilla.redhat.com/show_bug.cgi?id=1884750 --- contrib/completions/bash/oc | 128 ++ contrib/completions/zsh/oc | 128 ++ go.mod | 2 + go.sum | 26 + pkg/cli/cli.go | 2 + pkg/cli/ignition/convert3.go | 116 ++ pkg/cli/ignition/ignition.go | 28 + vendor/github.com/ajeddeloh/go-json/README | 10 + vendor/github.com/ajeddeloh/go-json/decode.go | 1226 +++++++++++++++++ vendor/github.com/ajeddeloh/go-json/encode.go | 1194 ++++++++++++++++ vendor/github.com/ajeddeloh/go-json/fold.go | 143 ++ vendor/github.com/ajeddeloh/go-json/indent.go | 137 ++ .../github.com/ajeddeloh/go-json/scanner.go | 630 +++++++++ vendor/github.com/ajeddeloh/go-json/stream.go | 480 +++++++ vendor/github.com/ajeddeloh/go-json/tags.go | 44 + .../coreos/go-systemd/unit/deserialize.go | 278 ++++ .../coreos/go-systemd/unit/escape.go | 116 ++ .../coreos/go-systemd/unit/option.go | 59 + .../coreos/go-systemd/unit/serialize.go | 75 + .../github.com/coreos/go-systemd/v22/LICENSE | 191 +++ .../github.com/coreos/go-systemd/v22/NOTICE | 5 + .../coreos/go-systemd/v22/unit/deserialize.go | 350 +++++ .../coreos/go-systemd/v22/unit/escape.go | 116 ++ .../coreos/go-systemd/v22/unit/option.go | 59 + .../coreos/go-systemd/v22/unit/section.go | 44 + .../coreos/go-systemd/v22/unit/serialize.go | 98 ++ .../github.com/coreos/ign-converter/LICENSE | 202 +++ .../translate/v24tov31/v24tov31.go | 552 ++++++++ .../coreos/ign-converter/util/util.go | 134 ++ vendor/github.com/coreos/ignition/LICENSE | 202 +++ vendor/github.com/coreos/ignition/NOTICE | 5 + .../ignition/config/shared/errors/errors.go | 109 ++ .../config/shared/validations/unit.go | 54 + .../coreos/ignition/config/util/helpers.go | 34 + .../ignition/config/util/parsingErrors.go | 74 + .../coreos/ignition/config/v1/cloudinit.go | 53 + .../coreos/ignition/config/v1/config.go | 59 + .../coreos/ignition/config/v1/types/config.go | 35 + .../coreos/ignition/config/v1/types/disk.go | 123 ++ .../coreos/ignition/config/v1/types/file.go | 39 + .../ignition/config/v1/types/filesystem.go | 45 + .../coreos/ignition/config/v1/types/group.go | 22 + .../ignition/config/v1/types/networkd.go | 19 + .../ignition/config/v1/types/partition.go | 60 + .../coreos/ignition/config/v1/types/passwd.go | 20 + .../coreos/ignition/config/v1/types/path.go | 31 + .../coreos/ignition/config/v1/types/raid.go | 44 + .../ignition/config/v1/types/storage.go | 21 + .../ignition/config/v1/types/systemd.go | 19 + .../coreos/ignition/config/v1/types/unit.go | 73 + .../coreos/ignition/config/v1/types/user.go | 35 + .../coreos/ignition/config/v2_0/append.go | 76 + .../coreos/ignition/config/v2_0/cloudinit.go | 53 + .../coreos/ignition/config/v2_0/config.go | 70 + .../coreos/ignition/config/v2_0/translate.go | 173 +++ .../ignition/config/v2_0/types/compression.go | 31 + .../ignition/config/v2_0/types/config.go | 87 ++ .../coreos/ignition/config/v2_0/types/disk.go | 126 ++ .../coreos/ignition/config/v2_0/types/file.go | 61 + .../ignition/config/v2_0/types/filesystem.go | 60 + .../ignition/config/v2_0/types/group.go | 22 + .../coreos/ignition/config/v2_0/types/hash.go | 72 + .../ignition/config/v2_0/types/ignition.go | 64 + .../ignition/config/v2_0/types/networkd.go | 19 + .../ignition/config/v2_0/types/partition.go | 64 + .../ignition/config/v2_0/types/passwd.go | 20 + .../coreos/ignition/config/v2_0/types/path.go | 35 + .../coreos/ignition/config/v2_0/types/raid.go | 44 + .../ignition/config/v2_0/types/storage.go | 22 + .../ignition/config/v2_0/types/systemd.go | 19 + .../coreos/ignition/config/v2_0/types/unit.go | 115 ++ .../coreos/ignition/config/v2_0/types/url.go | 69 + .../coreos/ignition/config/v2_0/types/user.go | 35 + .../config/v2_0/types/verification.go | 19 + .../coreos/ignition/config/v2_1/append.go | 76 + .../coreos/ignition/config/v2_1/cloudinit.go | 53 + .../coreos/ignition/config/v2_1/config.go | 68 + .../coreos/ignition/config/v2_1/translate.go | 236 ++++ .../ignition/config/v2_1/types/config.go | 91 ++ .../ignition/config/v2_1/types/directory.go | 30 + .../coreos/ignition/config/v2_1/types/disk.go | 128 ++ .../coreos/ignition/config/v2_1/types/file.go | 56 + .../ignition/config/v2_1/types/filesystem.go | 144 ++ .../ignition/config/v2_1/types/ignition.go | 52 + .../coreos/ignition/config/v2_1/types/mode.go | 26 + .../coreos/ignition/config/v2_1/types/node.go | 73 + .../ignition/config/v2_1/types/partition.go | 77 ++ .../ignition/config/v2_1/types/passwd.go | 67 + .../coreos/ignition/config/v2_1/types/path.go | 28 + .../coreos/ignition/config/v2_1/types/raid.go | 57 + .../ignition/config/v2_1/types/schema.go | 221 +++ .../coreos/ignition/config/v2_1/types/unit.go | 109 ++ .../coreos/ignition/config/v2_1/types/url.go | 52 + .../config/v2_1/types/verification.go | 77 ++ .../coreos/ignition/config/v2_2/append.go | 76 + .../coreos/ignition/config/v2_2/cloudinit.go | 53 + .../coreos/ignition/config/v2_2/config.go | 71 + .../coreos/ignition/config/v2_2/translate.go | 354 +++++ .../coreos/ignition/config/v2_2/types/ca.go | 27 + .../ignition/config/v2_2/types/config.go | 91 ++ .../ignition/config/v2_2/types/directory.go | 37 + .../coreos/ignition/config/v2_2/types/disk.go | 128 ++ .../coreos/ignition/config/v2_2/types/file.go | 69 + .../ignition/config/v2_2/types/filesystem.go | 144 ++ .../ignition/config/v2_2/types/ignition.go | 52 + .../coreos/ignition/config/v2_2/types/mode.go | 26 + .../coreos/ignition/config/v2_2/types/node.go | 73 + .../ignition/config/v2_2/types/partition.go | 77 ++ .../ignition/config/v2_2/types/passwd.go | 67 + .../coreos/ignition/config/v2_2/types/path.go | 28 + .../coreos/ignition/config/v2_2/types/raid.go | 57 + .../ignition/config/v2_2/types/schema.go | 246 ++++ .../coreos/ignition/config/v2_2/types/unit.go | 131 ++ .../coreos/ignition/config/v2_2/types/url.go | 53 + .../config/v2_2/types/verification.go | 77 ++ .../coreos/ignition/config/v2_3/append.go | 76 + .../coreos/ignition/config/v2_3/cloudinit.go | 53 + .../coreos/ignition/config/v2_3/config.go | 70 + .../coreos/ignition/config/v2_3/translate.go | 380 +++++ .../coreos/ignition/config/v2_3/types/ca.go | 27 + .../ignition/config/v2_3/types/config.go | 91 ++ .../ignition/config/v2_3/types/directory.go | 37 + .../coreos/ignition/config/v2_3/types/disk.go | 164 +++ .../coreos/ignition/config/v2_3/types/file.go | 71 + .../ignition/config/v2_3/types/filesystem.go | 146 ++ .../ignition/config/v2_3/types/ignition.go | 52 + .../coreos/ignition/config/v2_3/types/mode.go | 26 + .../coreos/ignition/config/v2_3/types/node.go | 73 + .../ignition/config/v2_3/types/partition.go | 112 ++ .../ignition/config/v2_3/types/passwd.go | 67 + .../coreos/ignition/config/v2_3/types/path.go | 28 + .../coreos/ignition/config/v2_3/types/raid.go | 57 + .../ignition/config/v2_3/types/schema.go | 250 ++++ .../coreos/ignition/config/v2_3/types/unit.go | 131 ++ .../coreos/ignition/config/v2_3/types/url.go | 53 + .../config/v2_3/types/verification.go | 77 ++ .../coreos/ignition/config/v2_4/append.go | 76 + .../coreos/ignition/config/v2_4/cloudinit.go | 53 + .../coreos/ignition/config/v2_4/config.go | 70 + .../coreos/ignition/config/v2_4/translate.go | 398 ++++++ .../coreos/ignition/config/v2_4/types/ca.go | 58 + .../ignition/config/v2_4/types/config.go | 91 ++ .../ignition/config/v2_4/types/directory.go | 37 + .../coreos/ignition/config/v2_4/types/disk.go | 164 +++ .../coreos/ignition/config/v2_4/types/file.go | 100 ++ .../ignition/config/v2_4/types/filesystem.go | 146 ++ .../ignition/config/v2_4/types/headers.go | 47 + .../ignition/config/v2_4/types/ignition.go | 82 ++ .../coreos/ignition/config/v2_4/types/mode.go | 26 + .../coreos/ignition/config/v2_4/types/node.go | 73 + .../ignition/config/v2_4/types/partition.go | 112 ++ .../ignition/config/v2_4/types/passwd.go | 67 + .../coreos/ignition/config/v2_4/types/path.go | 28 + .../coreos/ignition/config/v2_4/types/raid.go | 57 + .../ignition/config/v2_4/types/schema.go | 269 ++++ .../coreos/ignition/config/v2_4/types/unit.go | 131 ++ .../coreos/ignition/config/v2_4/types/url.go | 53 + .../config/v2_4/types/verification.go | 77 ++ .../config/v2_5_experimental/types/ca.go | 58 + .../config/v2_5_experimental/types/config.go | 92 ++ .../v2_5_experimental/types/directory.go | 37 + .../config/v2_5_experimental/types/disk.go | 164 +++ .../config/v2_5_experimental/types/file.go | 100 ++ .../v2_5_experimental/types/filesystem.go | 146 ++ .../config/v2_5_experimental/types/headers.go | 47 + .../v2_5_experimental/types/ignition.go | 82 ++ .../config/v2_5_experimental/types/mode.go | 26 + .../config/v2_5_experimental/types/node.go | 73 + .../v2_5_experimental/types/partition.go | 112 ++ .../config/v2_5_experimental/types/passwd.go | 67 + .../config/v2_5_experimental/types/path.go | 28 + .../config/v2_5_experimental/types/raid.go | 57 + .../config/v2_5_experimental/types/schema.go | 269 ++++ .../config/v2_5_experimental/types/unit.go | 131 ++ .../config/v2_5_experimental/types/url.go | 53 + .../v2_5_experimental/types/verification.go | 77 ++ .../ignition/config/validate/astjson/node.go | 73 + .../config/validate/astnode/astnode.go | 45 + .../ignition/config/validate/report/report.go | 158 +++ .../ignition/config/validate/validate.go | 242 ++++ vendor/github.com/coreos/ignition/v2/LICENSE | 202 +++ vendor/github.com/coreos/ignition/v2/NOTICE | 5 + .../v2/config/shared/errors/errors.go | 100 ++ .../v2/config/shared/validations/unit.go | 49 + .../coreos/ignition/v2/config/util/helpers.go | 35 + .../ignition/v2/config/util/interfaces.go | 39 + .../ignition/v2/config/util/parsingErrors.go | 50 + .../ignition/v2/config/util/reflection.go | 55 + .../ignition/v2/config/v3_1/types/config.go | 26 + .../ignition/v2/config/v3_1/types/device.go | 25 + .../v2/config/v3_1/types/directory.go | 31 + .../ignition/v2/config/v3_1/types/disk.go | 134 ++ .../ignition/v2/config/v3_1/types/file.go | 45 + .../v2/config/v3_1/types/filesystem.go | 104 ++ .../ignition/v2/config/v3_1/types/headers.go | 65 + .../ignition/v2/config/v3_1/types/ignition.go | 49 + .../ignition/v2/config/v3_1/types/mode.go | 26 + .../ignition/v2/config/v3_1/types/node.go | 58 + .../v2/config/v3_1/types/partition.go | 88 ++ .../ignition/v2/config/v3_1/types/passwd.go | 23 + .../ignition/v2/config/v3_1/types/path.go | 42 + .../ignition/v2/config/v3_1/types/proxy.go | 49 + .../ignition/v2/config/v3_1/types/raid.go | 55 + .../ignition/v2/config/v3_1/types/resource.go | 91 ++ .../ignition/v2/config/v3_1/types/schema.go | 211 +++ .../ignition/v2/config/v3_1/types/storage.go | 70 + .../ignition/v2/config/v3_1/types/tls.go | 27 + .../ignition/v2/config/v3_1/types/unit.go | 82 ++ .../ignition/v2/config/v3_1/types/url.go | 57 + .../v2/config/v3_1/types/verification.go | 71 + .../ignition/v2/config/validate/validate.go | 118 ++ vendor/github.com/coreos/vcontext/LICENSE | 202 +++ .../github.com/coreos/vcontext/json/json.go | 64 + .../github.com/coreos/vcontext/path/path.go | 78 ++ .../coreos/vcontext/report/report.go | 153 ++ .../github.com/coreos/vcontext/tree/tree.go | 216 +++ .../coreos/vcontext/validate/validate.go | 149 ++ .../vincent-petithory/dataurl/LICENSE | 20 + .../vincent-petithory/dataurl/README.md | 81 ++ .../vincent-petithory/dataurl/dataurl.go | 280 ++++ .../vincent-petithory/dataurl/doc.go | 28 + .../vincent-petithory/dataurl/lex.go | 521 +++++++ .../vincent-petithory/dataurl/rfc2396.go | 130 ++ .../vincent-petithory/dataurl/wercker.yml | 1 + vendor/go4.org/AUTHORS | 8 + vendor/go4.org/LICENSE | 202 +++ vendor/go4.org/errorutil/highlight.go | 58 + vendor/modules.txt | 47 + 228 files changed, 23476 insertions(+) create mode 100644 pkg/cli/ignition/convert3.go create mode 100644 pkg/cli/ignition/ignition.go create mode 100644 vendor/github.com/ajeddeloh/go-json/README create mode 100644 vendor/github.com/ajeddeloh/go-json/decode.go create mode 100644 vendor/github.com/ajeddeloh/go-json/encode.go create mode 100644 vendor/github.com/ajeddeloh/go-json/fold.go create mode 100644 vendor/github.com/ajeddeloh/go-json/indent.go create mode 100644 vendor/github.com/ajeddeloh/go-json/scanner.go create mode 100644 vendor/github.com/ajeddeloh/go-json/stream.go create mode 100644 vendor/github.com/ajeddeloh/go-json/tags.go create mode 100644 vendor/github.com/coreos/go-systemd/unit/deserialize.go create mode 100644 vendor/github.com/coreos/go-systemd/unit/escape.go create mode 100644 vendor/github.com/coreos/go-systemd/unit/option.go create mode 100644 vendor/github.com/coreos/go-systemd/unit/serialize.go create mode 100644 vendor/github.com/coreos/go-systemd/v22/LICENSE create mode 100644 vendor/github.com/coreos/go-systemd/v22/NOTICE create mode 100644 vendor/github.com/coreos/go-systemd/v22/unit/deserialize.go create mode 100644 vendor/github.com/coreos/go-systemd/v22/unit/escape.go create mode 100644 vendor/github.com/coreos/go-systemd/v22/unit/option.go create mode 100644 vendor/github.com/coreos/go-systemd/v22/unit/section.go create mode 100644 vendor/github.com/coreos/go-systemd/v22/unit/serialize.go create mode 100644 vendor/github.com/coreos/ign-converter/LICENSE create mode 100644 vendor/github.com/coreos/ign-converter/translate/v24tov31/v24tov31.go create mode 100644 vendor/github.com/coreos/ign-converter/util/util.go create mode 100644 vendor/github.com/coreos/ignition/LICENSE create mode 100644 vendor/github.com/coreos/ignition/NOTICE create mode 100644 vendor/github.com/coreos/ignition/config/shared/errors/errors.go create mode 100644 vendor/github.com/coreos/ignition/config/shared/validations/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/util/helpers.go create mode 100644 vendor/github.com/coreos/ignition/config/util/parsingErrors.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/cloudinit.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/group.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/networkd.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/storage.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/systemd.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v1/types/user.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/append.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/cloudinit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/translate.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/compression.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/group.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/hash.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/ignition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/networkd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/storage.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/systemd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/url.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/user.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_0/types/verification.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/append.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/cloudinit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/translate.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/directory.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/ignition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/mode.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/node.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/schema.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/url.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_1/types/verification.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/append.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/cloudinit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/translate.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/ca.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/directory.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/ignition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/mode.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/node.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/schema.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/url.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_2/types/verification.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/append.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/cloudinit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/translate.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/ca.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/directory.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/ignition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/mode.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/node.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/schema.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/url.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_3/types/verification.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/append.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/cloudinit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/translate.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/ca.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/directory.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/headers.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/ignition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/mode.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/node.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/schema.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/url.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_4/types/verification.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/ca.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/config.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/directory.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/file.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/headers.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/ignition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/mode.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/node.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/path.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/schema.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/url.go create mode 100644 vendor/github.com/coreos/ignition/config/v2_5_experimental/types/verification.go create mode 100644 vendor/github.com/coreos/ignition/config/validate/astjson/node.go create mode 100644 vendor/github.com/coreos/ignition/config/validate/astnode/astnode.go create mode 100644 vendor/github.com/coreos/ignition/config/validate/report/report.go create mode 100644 vendor/github.com/coreos/ignition/config/validate/validate.go create mode 100644 vendor/github.com/coreos/ignition/v2/LICENSE create mode 100644 vendor/github.com/coreos/ignition/v2/NOTICE create mode 100644 vendor/github.com/coreos/ignition/v2/config/shared/errors/errors.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/shared/validations/unit.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/util/helpers.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/util/interfaces.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/util/parsingErrors.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/util/reflection.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/config.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/device.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/directory.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/disk.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/file.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/filesystem.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/headers.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/ignition.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/mode.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/node.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/partition.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/passwd.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/path.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/proxy.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/raid.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/resource.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/schema.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/storage.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/tls.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/unit.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/url.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/v3_1/types/verification.go create mode 100644 vendor/github.com/coreos/ignition/v2/config/validate/validate.go create mode 100644 vendor/github.com/coreos/vcontext/LICENSE create mode 100644 vendor/github.com/coreos/vcontext/json/json.go create mode 100644 vendor/github.com/coreos/vcontext/path/path.go create mode 100644 vendor/github.com/coreos/vcontext/report/report.go create mode 100644 vendor/github.com/coreos/vcontext/tree/tree.go create mode 100644 vendor/github.com/coreos/vcontext/validate/validate.go create mode 100644 vendor/github.com/vincent-petithory/dataurl/LICENSE create mode 100644 vendor/github.com/vincent-petithory/dataurl/README.md create mode 100644 vendor/github.com/vincent-petithory/dataurl/dataurl.go create mode 100644 vendor/github.com/vincent-petithory/dataurl/doc.go create mode 100644 vendor/github.com/vincent-petithory/dataurl/lex.go create mode 100644 vendor/github.com/vincent-petithory/dataurl/rfc2396.go create mode 100644 vendor/github.com/vincent-petithory/dataurl/wercker.yml create mode 100644 vendor/go4.org/AUTHORS create mode 100644 vendor/go4.org/LICENSE create mode 100644 vendor/go4.org/errorutil/highlight.go diff --git a/contrib/completions/bash/oc b/contrib/completions/bash/oc index a25ada03b3..d9d8978ddc 100644 --- a/contrib/completions/bash/oc +++ b/contrib/completions/bash/oc @@ -13373,6 +13373,133 @@ _oc_idle() noun_aliases=() } +_oc_ignition_convert3() +{ + last_command="oc_ignition_convert3" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--in=") + two_word_flags+=("--in") + flags_with_completion+=("--in") + flags_completion+=("_filedir") + local_nonpersistent_flags+=("--in=") + flags+=("--out=") + two_word_flags+=("--out") + flags_with_completion+=("--out") + flags_completion+=("_filedir") + local_nonpersistent_flags+=("--out=") + flags+=("--as=") + two_word_flags+=("--as") + flags+=("--as-group=") + two_word_flags+=("--as-group") + flags+=("--cache-dir=") + two_word_flags+=("--cache-dir") + flags+=("--certificate-authority=") + two_word_flags+=("--certificate-authority") + flags+=("--client-certificate=") + two_word_flags+=("--client-certificate") + flags+=("--client-key=") + two_word_flags+=("--client-key") + flags+=("--cluster=") + two_word_flags+=("--cluster") + flags+=("--context=") + two_word_flags+=("--context") + flags+=("--insecure-skip-tls-verify") + flags+=("--kubeconfig=") + two_word_flags+=("--kubeconfig") + flags+=("--match-server-version") + flags+=("--namespace=") + two_word_flags+=("--namespace") + flags_with_completion+=("--namespace") + flags_completion+=("__oc_get_namespaces") + two_word_flags+=("-n") + flags_with_completion+=("-n") + flags_completion+=("__oc_get_namespaces") + flags+=("--request-timeout=") + two_word_flags+=("--request-timeout") + flags+=("--server=") + two_word_flags+=("--server") + two_word_flags+=("-s") + flags+=("--tls-server-name=") + two_word_flags+=("--tls-server-name") + flags+=("--token=") + two_word_flags+=("--token") + flags+=("--user=") + two_word_flags+=("--user") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + +_oc_ignition() +{ + last_command="oc_ignition" + + command_aliases=() + + commands=() + commands+=("convert3") + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--as=") + two_word_flags+=("--as") + flags+=("--as-group=") + two_word_flags+=("--as-group") + flags+=("--cache-dir=") + two_word_flags+=("--cache-dir") + flags+=("--certificate-authority=") + two_word_flags+=("--certificate-authority") + flags+=("--client-certificate=") + two_word_flags+=("--client-certificate") + flags+=("--client-key=") + two_word_flags+=("--client-key") + flags+=("--cluster=") + two_word_flags+=("--cluster") + flags+=("--context=") + two_word_flags+=("--context") + flags+=("--insecure-skip-tls-verify") + flags+=("--kubeconfig=") + two_word_flags+=("--kubeconfig") + flags+=("--match-server-version") + flags+=("--namespace=") + two_word_flags+=("--namespace") + flags_with_completion+=("--namespace") + flags_completion+=("__oc_get_namespaces") + two_word_flags+=("-n") + flags_with_completion+=("-n") + flags_completion+=("__oc_get_namespaces") + flags+=("--request-timeout=") + two_word_flags+=("--request-timeout") + flags+=("--server=") + two_word_flags+=("--server") + two_word_flags+=("-s") + flags+=("--tls-server-name=") + two_word_flags+=("--tls-server-name") + flags+=("--token=") + two_word_flags+=("--token") + flags+=("--user=") + two_word_flags+=("--user") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + _oc_image_append() { last_command="oc_image_append" @@ -20655,6 +20782,7 @@ _oc_root_command() commands+=("extract") commands+=("get") commands+=("idle") + commands+=("ignition") commands+=("image") commands+=("import-image") commands+=("kustomize") diff --git a/contrib/completions/zsh/oc b/contrib/completions/zsh/oc index fc99cb14cd..2a20cfe6d6 100644 --- a/contrib/completions/zsh/oc +++ b/contrib/completions/zsh/oc @@ -13473,6 +13473,133 @@ _oc_idle() noun_aliases=() } +_oc_ignition_convert3() +{ + last_command="oc_ignition_convert3" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--in=") + two_word_flags+=("--in") + flags_with_completion+=("--in") + flags_completion+=("_filedir") + local_nonpersistent_flags+=("--in=") + flags+=("--out=") + two_word_flags+=("--out") + flags_with_completion+=("--out") + flags_completion+=("_filedir") + local_nonpersistent_flags+=("--out=") + flags+=("--as=") + two_word_flags+=("--as") + flags+=("--as-group=") + two_word_flags+=("--as-group") + flags+=("--cache-dir=") + two_word_flags+=("--cache-dir") + flags+=("--certificate-authority=") + two_word_flags+=("--certificate-authority") + flags+=("--client-certificate=") + two_word_flags+=("--client-certificate") + flags+=("--client-key=") + two_word_flags+=("--client-key") + flags+=("--cluster=") + two_word_flags+=("--cluster") + flags+=("--context=") + two_word_flags+=("--context") + flags+=("--insecure-skip-tls-verify") + flags+=("--kubeconfig=") + two_word_flags+=("--kubeconfig") + flags+=("--match-server-version") + flags+=("--namespace=") + two_word_flags+=("--namespace") + flags_with_completion+=("--namespace") + flags_completion+=("__oc_get_namespaces") + two_word_flags+=("-n") + flags_with_completion+=("-n") + flags_completion+=("__oc_get_namespaces") + flags+=("--request-timeout=") + two_word_flags+=("--request-timeout") + flags+=("--server=") + two_word_flags+=("--server") + two_word_flags+=("-s") + flags+=("--tls-server-name=") + two_word_flags+=("--tls-server-name") + flags+=("--token=") + two_word_flags+=("--token") + flags+=("--user=") + two_word_flags+=("--user") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + +_oc_ignition() +{ + last_command="oc_ignition" + + command_aliases=() + + commands=() + commands+=("convert3") + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--as=") + two_word_flags+=("--as") + flags+=("--as-group=") + two_word_flags+=("--as-group") + flags+=("--cache-dir=") + two_word_flags+=("--cache-dir") + flags+=("--certificate-authority=") + two_word_flags+=("--certificate-authority") + flags+=("--client-certificate=") + two_word_flags+=("--client-certificate") + flags+=("--client-key=") + two_word_flags+=("--client-key") + flags+=("--cluster=") + two_word_flags+=("--cluster") + flags+=("--context=") + two_word_flags+=("--context") + flags+=("--insecure-skip-tls-verify") + flags+=("--kubeconfig=") + two_word_flags+=("--kubeconfig") + flags+=("--match-server-version") + flags+=("--namespace=") + two_word_flags+=("--namespace") + flags_with_completion+=("--namespace") + flags_completion+=("__oc_get_namespaces") + two_word_flags+=("-n") + flags_with_completion+=("-n") + flags_completion+=("__oc_get_namespaces") + flags+=("--request-timeout=") + two_word_flags+=("--request-timeout") + flags+=("--server=") + two_word_flags+=("--server") + two_word_flags+=("-s") + flags+=("--tls-server-name=") + two_word_flags+=("--tls-server-name") + flags+=("--token=") + two_word_flags+=("--token") + flags+=("--user=") + two_word_flags+=("--user") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + _oc_image_append() { last_command="oc_image_append" @@ -20755,6 +20882,7 @@ _oc_root_command() commands+=("extract") commands+=("get") commands+=("idle") + commands+=("ignition") commands+=("image") commands+=("import-image") commands+=("kustomize") diff --git a/go.mod b/go.mod index 2302d29e9d..8da9f439e1 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,8 @@ require ( github.com/bugsnag/panicwrap v1.2.0 // indirect github.com/containers/image v0.0.0-00010101000000-000000000000 github.com/containers/storage v0.0.0-20190726081758-912de200380a // indirect + github.com/coreos/ign-converter v0.0.0-20200918193805-44d462f1c700 + github.com/coreos/ignition v0.35.0 github.com/davecgh/go-spew v1.1.1 github.com/docker/distribution v2.7.1+incompatible github.com/docker/docker v1.4.2-0.20200309214505-aa6a9891b09c diff --git a/go.sum b/go.sum index a1023022fa..9cb63efce1 100644 --- a/go.sum +++ b/go.sum @@ -78,6 +78,8 @@ github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:H github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= +github.com/ajeddeloh/go-json v0.0.0-20170920214419-6a2fe990e083 h1:uwcvnXW76Y0rHM+qs7y8iHknWUWXYFNlD6FEVhc47TU= +github.com/ajeddeloh/go-json v0.0.0-20170920214419-6a2fe990e083/go.mod h1:otnto4/Icqn88WCcM4bhIJNSgsh9VLBuspyyCfvof9c= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -99,6 +101,7 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7/go.mod h1:LWMyo4iOLWXHGdBki7NIht1kHru/0wM179h+d3g8ATM= github.com/aws/aws-sdk-go v1.6.10/go.mod h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k= github.com/aws/aws-sdk-go v1.17.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aws/aws-sdk-go v1.19.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.28.2 h1:j5IXG9CdyLfcVfICqo1PXVv+rua+QQHbkXuvuU/JF+8= github.com/aws/aws-sdk-go v1.28.2/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= @@ -145,6 +148,7 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/cilium/ebpf v0.0.0-20200507155900-a9f01edf17e3/go.mod h1:XT+cAw5wfvsodedcijoh1l9cf7v1x9FlFB/3VmF/O8s= github.com/cilium/ebpf v0.0.0-20200601085316-9f1617e5c574/go.mod h1:XT+cAw5wfvsodedcijoh1l9cf7v1x9FlFB/3VmF/O8s= github.com/cilium/ebpf v0.0.0-20200702112145-1c8d4c9ef775/go.mod h1:7cR51M8ViRLIdUjrmSXlK9pkrsDlLHbO8jiB8X8JnOc= +github.com/clarketm/json v1.14.1/go.mod h1:ynr2LRfb0fQU34l07csRNBTcivjySLLiY1YzQqKVfdo= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1wt9Z3DP8O6W3rvwCt0REIlshg1InHImaLW0t3ObY0= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= @@ -193,13 +197,23 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7 h1:u9SHYsPQNyt5tgDm3YN7+9dYrpK96E5wFilTFWIDZOM= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= +github.com/coreos/go-systemd/v22 v22.1.0 h1:kq/SbG2BCKLkDKkjQf5OWwKWUKj1lgs3lFI4PxnR5lg= github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= +github.com/coreos/ign-converter v0.0.0-20200918193805-44d462f1c700 h1:Un1+sTzUeZGSr0gFIpHMUEZnwfBJeswD1ZJS05W8m/Y= +github.com/coreos/ign-converter v0.0.0-20200918193805-44d462f1c700/go.mod h1:LNu0WTt8iVH/WJH15R/SjZw7AdyY2qAyf9ILZTCBvho= +github.com/coreos/ignition v0.35.0 h1:UFodoYq1mOPrbEjtxIsZbThcDyQwAI1owczRDqWmKkQ= +github.com/coreos/ignition v0.35.0/go.mod h1:WJQapxzEn9DE0ryxsGvm8QnBajm/XsS/PkrDqSpz+bA= +github.com/coreos/ignition/v2 v2.3.0 h1:TK+STbzVe6KZp4tQ2IaNSRMiWX4/diNngep1F7tP7Zk= +github.com/coreos/ignition/v2 v2.3.0/go.mod h1:85dmM/CERMZXNrJsXqtNLIxR/dn8G9qlL1CmEjCugp0= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/coreos/vcontext v0.0.0-20190529201340-22b159166068 h1:y2aHj7QqyAJ6YBBONTAr17YxHHiogDkYnTsJvFNhxwY= +github.com/coreos/vcontext v0.0.0-20190529201340-22b159166068/go.mod h1:E+6hug9bFSe0KZ2ZAzr8M9F5JlArJjv5D1JS7KSkPKE= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -540,6 +554,7 @@ github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= @@ -742,6 +757,7 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc= github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pin/tftp v2.1.0+incompatible/go.mod h1:xVpZOMCXTy+A5QMjEVN0Glwa1sUvaJhFXbr/aAxuxGY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -819,6 +835,7 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -875,6 +892,8 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= github.com/vbatts/tar-split v0.11.1/go.mod h1:LEuURwDEiWjRjwu46yU3KVGuUdVv/dcnpcEPSzR8z6g= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= +github.com/vincent-petithory/dataurl v0.0.0-20160330182126-9a301d65acbb h1:lyL3z7vYwTWXf4/bI+A01+cCSnfhKIBhy+SQ46Z/ml8= +github.com/vincent-petithory/dataurl v0.0.0-20160330182126-9a301d65acbb/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U= github.com/vishvananda/netlink v1.0.0 h1:bqNY2lgheFIu1meHUFSH3d7vG93AFyqg3oGbJCOJgSM= github.com/vishvananda/netlink v1.0.0/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk= github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0= @@ -884,6 +903,8 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17 github.com/vishvananda/netns v0.0.0-20200520041808-52d707b772fe h1:mjAZxE1nh8yvuwhGHpdDqdhtNu2dgbpk93TwoXuk5so= github.com/vishvananda/netns v0.0.0-20200520041808-52d707b772fe/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vmware/govmomi v0.20.3/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU= +github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk= +github.com/vmware/vmw-ovflib v0.0.0-20170608004843-1f217b9dc714/go.mod h1:jiPk45kn7klhByRvUq5i2vo1RtHKBHj+iWGFpxbXuuI= github.com/xanzy/go-gitlab v0.15.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs= github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= @@ -935,6 +956,8 @@ go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go4.org v0.0.0-20200104003542-c7e774b10ea0 h1:M6XsnQeLwG+rHQ+/rrGh3puBI3WZEy9TBWmf2H+enQA= +go4.org v0.0.0-20200104003542-c7e774b10ea0/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -997,6 +1020,7 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190228165749-92fc7df08ae7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190328230028-74de082e2cca/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -1073,6 +1097,7 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7 h1:HmbHVPwrPEKPGLAcHSrMe6+hqSUlvZU0rab6x5EXfGU= golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1245,6 +1270,7 @@ gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20190502103701-55513cacd4ae/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v0.0.0-20190624233834-05ebafbffc79 h1:C+K4iPg1rIvmCf4JjelkbWv2jeWevEwp05Lz8XfTYgE= gotest.tools v0.0.0-20190624233834-05ebafbffc79/go.mod h1:R//lfYlUuTOTfblYI3lGoAAAebUdzjvbmQsuB7Ykd90= diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 5c90c0382e..06c1f24a4a 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -28,6 +28,7 @@ import ( "github.com/openshift/oc/pkg/cli/expose" "github.com/openshift/oc/pkg/cli/extract" "github.com/openshift/oc/pkg/cli/idle" + "github.com/openshift/oc/pkg/cli/ignition" "github.com/openshift/oc/pkg/cli/image" "github.com/openshift/oc/pkg/cli/importimage" "github.com/openshift/oc/pkg/cli/kubectlwrappers" @@ -224,6 +225,7 @@ func NewOcCommand(in io.Reader, out, errout io.Writer) *cobra.Command { image.NewCmdImage(f, ioStreams), registry.NewCmd(f, ioStreams), idle.NewCmdIdle(f, ioStreams), + ignition.NewCmdIgnition(ioStreams), kubectlwrappers.NewCmdApiVersions(f, ioStreams), kubectlwrappers.NewCmdApiResources(f, ioStreams), kubectlwrappers.NewCmdClusterInfo(f, ioStreams), diff --git a/pkg/cli/ignition/convert3.go b/pkg/cli/ignition/convert3.go new file mode 100644 index 0000000000..2e21518e71 --- /dev/null +++ b/pkg/cli/ignition/convert3.go @@ -0,0 +1,116 @@ +package ignition + +import ( + "encoding/json" + "fmt" + "io" + "io/ioutil" + "os" + + "github.com/coreos/ign-converter/translate/v24tov31" + ignv2 "github.com/coreos/ignition/config/v2_4" + "github.com/pkg/errors" + "github.com/spf13/cobra" + + "k8s.io/cli-runtime/pkg/genericclioptions" + kcmdutil "k8s.io/kubectl/pkg/cmd/util" + "k8s.io/kubectl/pkg/util/templates" +) + +const convert3CommandName = "convert3" + +type convert3Options struct { + // source file + source string + // destination file + destination string + + sourceReader io.Reader + destWriter io.Writer +} + +var convert3Example = templates.Examples(` + # Convert an Ignition Spec 2 pointer configuration to Spec 3 + oc ignition convert3 < worker.ign > worker.ign3 +`) + +// NewCommandConvert3 creates the command +func NewCommandConvert3(streams genericclioptions.IOStreams) *cobra.Command { + o := convert3Options{ + sourceReader: streams.In, + destWriter: streams.Out, + } + cmd := &cobra.Command{ + Use: convert3CommandName, + Short: "Convert Ignition Spec 2 to Spec 3", + Example: convert3Example, + Args: cobra.ExactArgs(0), + Run: func(cmd *cobra.Command, args []string) { + kcmdutil.CheckErr(o.validate(args)) + kcmdutil.CheckErr(o.run()) + }, + } + + cmd.Flags().StringVar(&o.source, "in", o.source, "File containing input Ignition to convert. Read from stdin if omitted.") + cmd.Flags().StringVar(&o.destination, "out", o.destination, "Path to file for converted Ignition. Written to stdout if omitted.") + // autocompletion hints + cmd.MarkFlagFilename("in") + cmd.MarkFlagFilename("out") + + return cmd +} + +func (o *convert3Options) validate(args []string) error { + if len(o.source) == 0 && o.sourceReader == nil { + return errors.New("an input file, or reader is required") + } + + if len(o.destination) == 0 && o.destWriter == nil { + return errors.New("an output file or writer is required") + } + return nil +} + +func (o *convert3Options) run() error { + var data []byte + switch { + case len(o.source) > 0: + d, err := ioutil.ReadFile(o.source) + if err != nil { + return err + } + data = d + case o.sourceReader != nil: + d, err := ioutil.ReadAll(o.sourceReader) + if err != nil { + return err + } + data = d + } + + cfg, rpt, err := ignv2.Parse(data) + fmt.Fprintf(os.Stderr, "%s", rpt.String()) + if err != nil || rpt.IsFatal() { + return errors.Errorf("Error parsing spec v2 config: %v\n%v", err, rpt) + } + + newCfg, err := v24tov31.Translate(cfg, nil) + if err != nil { + return errors.Wrap(err, "translation failed") + } + dataOut, err := json.Marshal(newCfg) + if err != nil { + return errors.Wrap(err, "failed to marshal JSON") + } + + // Write data + if len(o.destination) > 0 { + return ioutil.WriteFile(o.destination, dataOut, 0644) + } else if o.destWriter != nil { + _, err := o.destWriter.Write(dataOut) + if err != nil { + return err + } + } + return nil +} diff --git a/pkg/cli/ignition/ignition.go b/pkg/cli/ignition/ignition.go new file mode 100644 index 0000000000..9e666fe356 --- /dev/null +++ b/pkg/cli/ignition/ignition.go @@ -0,0 +1,28 @@ +package ignition + +import ( + "github.com/spf13/cobra" + + "k8s.io/cli-runtime/pkg/genericclioptions" + cmdutil "k8s.io/kubectl/pkg/cmd/util" +) + +// NewCmdIgnition generates the command +func NewCmdIgnition(streams genericclioptions.IOStreams) *cobra.Command { + // Parent command to which all subcommands are added. + cmds := &cobra.Command{ + Use: "ignition", + Long: "Manage Ignition configuration", + Short: "", + Run: cmdutil.DefaultSubCommandRun(streams.ErrOut), + } + + subCommands := []*cobra.Command{ + NewCommandConvert3(streams), + } + for _, cmd := range subCommands { + cmds.AddCommand(cmd) + } + + return cmds +} diff --git a/vendor/github.com/ajeddeloh/go-json/README b/vendor/github.com/ajeddeloh/go-json/README new file mode 100644 index 0000000000..0f53d34501 --- /dev/null +++ b/vendor/github.com/ajeddeloh/go-json/README @@ -0,0 +1,10 @@ +This is a fork of go's encoding/json library. It adds the a third target for unmarshalling, json.Node. +Unmarshalling to a Node behaves similarilarly to unmarshalling to an interface{}, except it also records +the offsets for the start and end of the value that was unmarshalled and, if the value was part of a json +object, it also records the offsets of the start and end of the object's key. The Value field of the Node +will be unmarshalled to the same types as if it were an interface{}, except in the case of arrays and +objects. In those case it will be unmarshalled to a []Node or map[string]Node instead []interface{} or +map[string]interface{} for arrays and objects, respectively. + +There are two branchs, go15 and go16. go15 contains the modified go1.5 library and go16 contains the +modified go1.6 library. diff --git a/vendor/github.com/ajeddeloh/go-json/decode.go b/vendor/github.com/ajeddeloh/go-json/decode.go new file mode 100644 index 0000000000..1dc2fdf0d4 --- /dev/null +++ b/vendor/github.com/ajeddeloh/go-json/decode.go @@ -0,0 +1,1226 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Represents JSON data structure using native Go types: booleans, floats, +// strings, arrays, and maps. + +package json + +import ( + "bytes" + "encoding" + "encoding/base64" + "errors" + "fmt" + "reflect" + "runtime" + "strconv" + "unicode" + "unicode/utf16" + "unicode/utf8" +) + +// Unmarshal parses the JSON-encoded data and stores the result +// in the value pointed to by v. +// +// Unmarshal uses the inverse of the encodings that +// Marshal uses, allocating maps, slices, and pointers as necessary, +// with the following additional rules: +// +// To unmarshal JSON into a pointer, Unmarshal first handles the case of +// the JSON being the JSON literal null. In that case, Unmarshal sets +// the pointer to nil. Otherwise, Unmarshal unmarshals the JSON into +// the value pointed at by the pointer. If the pointer is nil, Unmarshal +// allocates a new value for it to point to. +// +// To unmarshal JSON into a struct, Unmarshal matches incoming object +// keys to the keys used by Marshal (either the struct field name or its tag), +// preferring an exact match but also accepting a case-insensitive match. +// +// To unmarshal JSON into an interface value, +// Unmarshal stores one of these in the interface value: +// +// bool, for JSON booleans +// float64, for JSON numbers +// string, for JSON strings +// []interface{}, for JSON arrays +// map[string]interface{}, for JSON objects +// nil for JSON null +// +// To unmarshal a JSON array into a slice, Unmarshal resets the slice to nil +// and then appends each element to the slice. +// +// To unmarshal a JSON object into a map, Unmarshal replaces the map +// with an empty map and then adds key-value pairs from the object to +// the map. +// +// If a JSON value is not appropriate for a given target type, +// or if a JSON number overflows the target type, Unmarshal +// skips that field and completes the unmarshalling as best it can. +// If no more serious errors are encountered, Unmarshal returns +// an UnmarshalTypeError describing the earliest such error. +// +// The JSON null value unmarshals into an interface, map, pointer, or slice +// by setting that Go value to nil. Because null is often used in JSON to mean +// ``not present,'' unmarshaling a JSON null into any other Go type has no effect +// on the value and produces no error. +// +// When unmarshaling quoted strings, invalid UTF-8 or +// invalid UTF-16 surrogate pairs are not treated as an error. +// Instead, they are replaced by the Unicode replacement +// character U+FFFD. +// +func Unmarshal(data []byte, v interface{}) error { + // Check for well-formedness. + // Avoids filling out half a data structure + // before discovering a JSON syntax error. + var d decodeState + err := checkValid(data, &d.scan) + if err != nil { + return err + } + + d.init(data) + return d.unmarshal(v) +} + +// Unmarshaler is the interface implemented by objects +// that can unmarshal a JSON description of themselves. +// The input can be assumed to be a valid encoding of +// a JSON value. UnmarshalJSON must copy the JSON data +// if it wishes to retain the data after returning. +type Unmarshaler interface { + UnmarshalJSON([]byte) error +} + +// An UnmarshalTypeError describes a JSON value that was +// not appropriate for a value of a specific Go type. +type UnmarshalTypeError struct { + Value string // description of JSON value - "bool", "array", "number -5" + Type reflect.Type // type of Go value it could not be assigned to + Offset int64 // error occurred after reading Offset bytes +} + +func (e *UnmarshalTypeError) Error() string { + return "json: cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String() +} + +// An UnmarshalFieldError describes a JSON object key that +// led to an unexported (and therefore unwritable) struct field. +// (No longer used; kept for compatibility.) +type UnmarshalFieldError struct { + Key string + Type reflect.Type + Field reflect.StructField +} + +func (e *UnmarshalFieldError) Error() string { + return "json: cannot unmarshal object key " + strconv.Quote(e.Key) + " into unexported field " + e.Field.Name + " of type " + e.Type.String() +} + +// An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. +// (The argument to Unmarshal must be a non-nil pointer.) +type InvalidUnmarshalError struct { + Type reflect.Type +} + +type Node struct { + Start int + End int + KeyStart int // Only value if a member of a struct + KeyEnd int + Value interface{} +} + +func (e *InvalidUnmarshalError) Error() string { + if e.Type == nil { + return "json: Unmarshal(nil)" + } + + if e.Type.Kind() != reflect.Ptr { + return "json: Unmarshal(non-pointer " + e.Type.String() + ")" + } + return "json: Unmarshal(nil " + e.Type.String() + ")" +} + +func (d *decodeState) unmarshal(v interface{}) (err error) { + defer func() { + if r := recover(); r != nil { + if _, ok := r.(runtime.Error); ok { + panic(r) + } + err = r.(error) + } + }() + + rv := reflect.ValueOf(v) + if rv.Kind() != reflect.Ptr || rv.IsNil() { + return &InvalidUnmarshalError{reflect.TypeOf(v)} + } + + d.scan.reset() + // We decode rv not rv.Elem because the Unmarshaler interface + // test must be applied at the top level of the value. + d.value(rv) + return d.savedError +} + +// A Number represents a JSON number literal. +type Number string + +// String returns the literal text of the number. +func (n Number) String() string { return string(n) } + +// Float64 returns the number as a float64. +func (n Number) Float64() (float64, error) { + return strconv.ParseFloat(string(n), 64) +} + +// Int64 returns the number as an int64. +func (n Number) Int64() (int64, error) { + return strconv.ParseInt(string(n), 10, 64) +} + +// decodeState represents the state while decoding a JSON value. +type decodeState struct { + data []byte + off int // read offset in data + scan scanner + nextscan scanner // for calls to nextValue + savedError error + useNumber bool +} + +// errPhase is used for errors that should not happen unless +// there is a bug in the JSON decoder or something is editing +// the data slice while the decoder executes. +var errPhase = errors.New("JSON decoder out of sync - data changing underfoot?") + +func (d *decodeState) init(data []byte) *decodeState { + d.data = data + d.off = 0 + d.savedError = nil + return d +} + +// error aborts the decoding by panicking with err. +func (d *decodeState) error(err error) { + panic(err) +} + +// saveError saves the first err it is called with, +// for reporting at the end of the unmarshal. +func (d *decodeState) saveError(err error) { + if d.savedError == nil { + d.savedError = err + } +} + +// next cuts off and returns the next full JSON value in d.data[d.off:]. +// The next value is known to be an object or array, not a literal. +func (d *decodeState) next() []byte { + c := d.data[d.off] + item, rest, err := nextValue(d.data[d.off:], &d.nextscan) + if err != nil { + d.error(err) + } + d.off = len(d.data) - len(rest) + + // Our scanner has seen the opening brace/bracket + // and thinks we're still in the middle of the object. + // invent a closing brace/bracket to get it out. + if c == '{' { + d.scan.step(&d.scan, '}') + } else { + d.scan.step(&d.scan, ']') + } + + return item +} + +// scanWhile processes bytes in d.data[d.off:] until it +// receives a scan code not equal to op. +// It updates d.off and returns the new scan code. +func (d *decodeState) scanWhile(op int) int { + var newOp int + for { + if d.off >= len(d.data) { + newOp = d.scan.eof() + d.off = len(d.data) + 1 // mark processed EOF with len+1 + } else { + c := int(d.data[d.off]) + d.off++ + newOp = d.scan.step(&d.scan, c) + } + if newOp != op { + break + } + } + return newOp +} + +// value decodes a JSON value from d.data[d.off:] into the value. +// it updates d.off to point past the decoded value. +func (d *decodeState) value(v reflect.Value) { + if !v.IsValid() { + _, rest, err := nextValue(d.data[d.off:], &d.nextscan) + if err != nil { + d.error(err) + } + d.off = len(d.data) - len(rest) + + // d.scan thinks we're still at the beginning of the item. + // Feed in an empty string - the shortest, simplest value - + // so that it knows we got to the end of the value. + if d.scan.redo { + // rewind. + d.scan.redo = false + d.scan.step = stateBeginValue + } + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '"') + + n := len(d.scan.parseState) + if n > 0 && d.scan.parseState[n-1] == parseObjectKey { + // d.scan thinks we just read an object key; finish the object + d.scan.step(&d.scan, ':') + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '}') + } + + return + } + + switch op := d.scanWhile(scanSkipSpace); op { + default: + d.error(errPhase) + + case scanBeginArray: + d.array(v) + + case scanBeginObject: + d.object(v) + + case scanBeginLiteral: + d.literal(v) + } +} + +type unquotedValue struct{} + +// valueQuoted is like value but decodes a +// quoted string literal or literal null into an interface value. +// If it finds anything other than a quoted string literal or null, +// valueQuoted returns unquotedValue{}. +func (d *decodeState) valueQuoted() interface{} { + switch op := d.scanWhile(scanSkipSpace); op { + default: + d.error(errPhase) + + case scanBeginArray: + d.array(reflect.Value{}) + + case scanBeginObject: + d.object(reflect.Value{}) + + case scanBeginLiteral: + switch v := d.literalInterface().(type) { + case nil, string: + return v + } + } + return unquotedValue{} +} + +// indirect walks down v allocating pointers as needed, +// until it gets to a non-pointer. +// if it encounters an Unmarshaler, indirect stops and returns that. +// if decodingNull is true, indirect stops at the last pointer so it can be set to nil. +func (d *decodeState) indirect(v reflect.Value, decodingNull bool) (Unmarshaler, encoding.TextUnmarshaler, reflect.Value) { + // If v is a named type and is addressable, + // start with its address, so that if the type has pointer methods, + // we find them. + if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() { + v = v.Addr() + } + for { + // Load value from interface, but only if the result will be + // usefully addressable. + if v.Kind() == reflect.Interface && !v.IsNil() { + e := v.Elem() + if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) { + v = e + continue + } + } + + if v.Kind() != reflect.Ptr { + break + } + + if v.Elem().Kind() != reflect.Ptr && decodingNull && v.CanSet() { + break + } + if v.IsNil() { + v.Set(reflect.New(v.Type().Elem())) + } + if v.Type().NumMethod() > 0 { + if u, ok := v.Interface().(Unmarshaler); ok { + return u, nil, reflect.Value{} + } + if u, ok := v.Interface().(encoding.TextUnmarshaler); ok { + return nil, u, reflect.Value{} + } + } + v = v.Elem() + } + return nil, nil, v +} + +// array consumes an array from d.data[d.off-1:], decoding into the value v. +// the first byte of the array ('[') has been read already. +func (d *decodeState) array(v reflect.Value) { + // Check for unmarshaler. + u, ut, pv := d.indirect(v, false) + if u != nil { + d.off-- + err := u.UnmarshalJSON(d.next()) + if err != nil { + d.error(err) + } + return + } + if ut != nil { + d.saveError(&UnmarshalTypeError{"array", v.Type(), int64(d.off)}) + d.off-- + d.next() + return + } + + v = pv + + // Check type of target. + switch v.Kind() { + case reflect.Interface: + if v.NumMethod() == 0 { + // Decoding into nil interface? Switch to non-reflect code. + v.Set(reflect.ValueOf(d.arrayInterface())) + return + } + // Otherwise it's invalid. + fallthrough + default: + if v.Type() == reflect.TypeOf(Node{}) { + // Decoding to Node? Switch to that code + v.Set(reflect.ValueOf(d.arrayNode())) + return + } + d.saveError(&UnmarshalTypeError{"array", v.Type(), int64(d.off)}) + d.off-- + d.next() + return + case reflect.Array: + case reflect.Slice: + break + } + + i := 0 + for { + // Look ahead for ] - can only happen on first iteration. + op := d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + + // Back up so d.value can have the byte we just read. + d.off-- + d.scan.undo(op) + + // Get element of array, growing if necessary. + if v.Kind() == reflect.Slice { + // Grow slice if necessary + if i >= v.Cap() { + newcap := v.Cap() + v.Cap()/2 + if newcap < 4 { + newcap = 4 + } + newv := reflect.MakeSlice(v.Type(), v.Len(), newcap) + reflect.Copy(newv, v) + v.Set(newv) + } + if i >= v.Len() { + v.SetLen(i + 1) + } + } + + if i < v.Len() { + // Decode into element. + d.value(v.Index(i)) + } else { + // Ran out of fixed array: skip. + d.value(reflect.Value{}) + } + i++ + + // Next token must be , or ]. + op = d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + if op != scanArrayValue { + d.error(errPhase) + } + } + + if i < v.Len() { + if v.Kind() == reflect.Array { + // Array. Zero the rest. + z := reflect.Zero(v.Type().Elem()) + for ; i < v.Len(); i++ { + v.Index(i).Set(z) + } + } else { + v.SetLen(i) + } + } + if i == 0 && v.Kind() == reflect.Slice { + v.Set(reflect.MakeSlice(v.Type(), 0, 0)) + } +} + +var nullLiteral = []byte("null") + +// object consumes an object from d.data[d.off-1:], decoding into the value v. +// the first byte ('{') of the object has been read already. +func (d *decodeState) object(v reflect.Value) { + // Check for unmarshaler. + u, ut, pv := d.indirect(v, false) + if u != nil { + d.off-- + err := u.UnmarshalJSON(d.next()) + if err != nil { + d.error(err) + } + return + } + if ut != nil { + d.saveError(&UnmarshalTypeError{"object", v.Type(), int64(d.off)}) + d.off-- + d.next() // skip over { } in input + return + } + v = pv + + // Decoding into nil interface? Switch to non-reflect code. + if v.Kind() == reflect.Interface && v.NumMethod() == 0 { + v.Set(reflect.ValueOf(d.objectInterface())) + return + } else if v.Type() == reflect.TypeOf(Node{}) { + // Decoding to Node? Switch to that code + v.Set(reflect.ValueOf(d.objectNode())) + return + } + + // Check type of target: struct or map[string]T + switch v.Kind() { + case reflect.Map: + // map must have string kind + t := v.Type() + if t.Key().Kind() != reflect.String { + d.saveError(&UnmarshalTypeError{"object", v.Type(), int64(d.off)}) + d.off-- + d.next() // skip over { } in input + return + } + if v.IsNil() { + v.Set(reflect.MakeMap(t)) + } + case reflect.Struct: + + default: + d.saveError(&UnmarshalTypeError{"object", v.Type(), int64(d.off)}) + d.off-- + d.next() // skip over { } in input + return + } + + var mapElem reflect.Value + + for { + // Read opening " of string key or closing }. + op := d.scanWhile(scanSkipSpace) + if op == scanEndObject { + // closing } - can only happen on first iteration. + break + } + if op != scanBeginLiteral { + d.error(errPhase) + } + + // Read key. + start := d.off - 1 + op = d.scanWhile(scanContinue) + item := d.data[start : d.off-1] + key, ok := unquoteBytes(item) + if !ok { + d.error(errPhase) + } + + // Figure out field corresponding to key. + var subv reflect.Value + destring := false // whether the value is wrapped in a string to be decoded first + + if v.Kind() == reflect.Map { + elemType := v.Type().Elem() + if !mapElem.IsValid() { + mapElem = reflect.New(elemType).Elem() + } else { + mapElem.Set(reflect.Zero(elemType)) + } + subv = mapElem + } else { + var f *field + fields := cachedTypeFields(v.Type()) + for i := range fields { + ff := &fields[i] + if bytes.Equal(ff.nameBytes, key) { + f = ff + break + } + if f == nil && ff.equalFold(ff.nameBytes, key) { + f = ff + } + } + if f != nil { + subv = v + destring = f.quoted + for _, i := range f.index { + if subv.Kind() == reflect.Ptr { + if subv.IsNil() { + subv.Set(reflect.New(subv.Type().Elem())) + } + subv = subv.Elem() + } + subv = subv.Field(i) + } + } + } + + // Read : before value. + if op == scanSkipSpace { + op = d.scanWhile(scanSkipSpace) + } + if op != scanObjectKey { + d.error(errPhase) + } + + // Read value. + if destring { + switch qv := d.valueQuoted().(type) { + case nil: + d.literalStore(nullLiteral, subv, false) + case string: + d.literalStore([]byte(qv), subv, true) + default: + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal unquoted value into %v", subv.Type())) + } + } else { + d.value(subv) + } + + // Write value back to map; + // if using struct, subv points into struct already. + if v.Kind() == reflect.Map { + kv := reflect.ValueOf(key).Convert(v.Type().Key()) + v.SetMapIndex(kv, subv) + } + + // Next token must be , or }. + op = d.scanWhile(scanSkipSpace) + if op == scanEndObject { + break + } + if op != scanObjectValue { + d.error(errPhase) + } + } +} + +// literal consumes a literal from d.data[d.off-1:], decoding into the value v. +// The first byte of the literal has been read already +// (that's how the caller knows it's a literal). +func (d *decodeState) literal(v reflect.Value) { + // All bytes inside literal return scanContinue op code. + start := d.off - 1 + op := d.scanWhile(scanContinue) + + // Scan read one byte too far; back up. + d.off-- + d.scan.undo(op) + + d.literalStore(d.data[start:d.off], v, false) +} + +// convertNumber converts the number literal s to a float64 or a Number +// depending on the setting of d.useNumber. +func (d *decodeState) convertNumber(s string) (interface{}, error) { + if d.useNumber { + return Number(s), nil + } + f, err := strconv.ParseFloat(s, 64) + if err != nil { + return nil, &UnmarshalTypeError{"number " + s, reflect.TypeOf(0.0), int64(d.off)} + } + return f, nil +} + +var numberType = reflect.TypeOf(Number("")) + +// literalStore decodes a literal stored in item into v. +// +// fromQuoted indicates whether this literal came from unwrapping a +// string from the ",string" struct tag option. this is used only to +// produce more helpful error messages. +func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool) { + // Check for unmarshaler. + if len(item) == 0 { + //Empty string given + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + return + } + wantptr := item[0] == 'n' // null + u, ut, pv := d.indirect(v, wantptr) + if u != nil { + err := u.UnmarshalJSON(item) + if err != nil { + d.error(err) + } + return + } + if ut != nil { + if item[0] != '"' { + if fromQuoted { + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + } + return + } + s, ok := unquoteBytes(item) + if !ok { + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } + } + err := ut.UnmarshalText(s) + if err != nil { + d.error(err) + } + return + } + + v = pv + + switch c := item[0]; c { + case 'n': // null + switch v.Kind() { + case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice: + v.Set(reflect.Zero(v.Type())) + // otherwise, ignore null for primitives/string + } + case 't', 'f': // true, false + value := c == 't' + switch v.Kind() { + default: + if fromQuoted { + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.saveError(&UnmarshalTypeError{"bool", v.Type(), int64(d.off)}) + } + case reflect.Bool: + v.SetBool(value) + case reflect.Interface: + if v.NumMethod() == 0 { + v.Set(reflect.ValueOf(value)) + } else { + d.saveError(&UnmarshalTypeError{"bool", v.Type(), int64(d.off)}) + } + } + + case '"': // string + s, ok := unquoteBytes(item) + if !ok { + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } + } + switch v.Kind() { + default: + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + case reflect.Slice: + if v.Type().Elem().Kind() != reflect.Uint8 { + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + break + } + b := make([]byte, base64.StdEncoding.DecodedLen(len(s))) + n, err := base64.StdEncoding.Decode(b, s) + if err != nil { + d.saveError(err) + break + } + v.Set(reflect.ValueOf(b[0:n])) + case reflect.String: + v.SetString(string(s)) + case reflect.Interface: + if v.NumMethod() == 0 { + v.Set(reflect.ValueOf(string(s))) + } else { + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + } + } + + default: // number + if c != '-' && (c < '0' || c > '9') { + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } + } + s := string(item) + switch v.Kind() { + default: + if v.Kind() == reflect.String && v.Type() == numberType { + v.SetString(s) + break + } + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(&UnmarshalTypeError{"number", v.Type(), int64(d.off)}) + } + case reflect.Interface: + n, err := d.convertNumber(s) + if err != nil { + d.saveError(err) + break + } + if v.NumMethod() != 0 { + d.saveError(&UnmarshalTypeError{"number", v.Type(), int64(d.off)}) + break + } + v.Set(reflect.ValueOf(n)) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + n, err := strconv.ParseInt(s, 10, 64) + if err != nil || v.OverflowInt(n) { + d.saveError(&UnmarshalTypeError{"number " + s, v.Type(), int64(d.off)}) + break + } + v.SetInt(n) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + n, err := strconv.ParseUint(s, 10, 64) + if err != nil || v.OverflowUint(n) { + d.saveError(&UnmarshalTypeError{"number " + s, v.Type(), int64(d.off)}) + break + } + v.SetUint(n) + + case reflect.Float32, reflect.Float64: + n, err := strconv.ParseFloat(s, v.Type().Bits()) + if err != nil || v.OverflowFloat(n) { + d.saveError(&UnmarshalTypeError{"number " + s, v.Type(), int64(d.off)}) + break + } + v.SetFloat(n) + } + } +} + +// The xxxInterface routines build up a value to be stored +// in an empty interface. They are not strictly necessary, +// but they avoid the weight of reflection in this common case. + +// valueInterface is like value but returns interface{} +func (d *decodeState) valueInterface() interface{} { + switch d.scanWhile(scanSkipSpace) { + default: + d.error(errPhase) + panic("unreachable") + case scanBeginArray: + return d.arrayInterface() + case scanBeginObject: + return d.objectInterface() + case scanBeginLiteral: + return d.literalInterface() + } +} + +// valueNode is like valueInterface but returns a wrapped version that +// contains metadata about where it decoded from +func (d *decodeState) valueNode() Node { + switch d.scanWhile(scanSkipSpace) { + default: + d.error(errPhase) + panic("unreachable") + case scanBeginArray: + return d.arrayNode() + case scanBeginObject: + return d.objectNode() + case scanBeginLiteral: + return d.literalNode() + } +} + +// arrayInterface is like array but returns []interface{}. +func (d *decodeState) arrayInterface() []interface{} { + var v = make([]interface{}, 0) + for { + // Look ahead for ] - can only happen on first iteration. + op := d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + + // Back up so d.value can have the byte we just read. + d.off-- + d.scan.undo(op) + + v = append(v, d.valueInterface()) + + // Next token must be , or ]. + op = d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + if op != scanArrayValue { + d.error(errPhase) + } + } + return v +} + +// arrayNode is like arrayInterface but returns Node. +func (d *decodeState) arrayNode() Node { + var v = make([]Node, 0) + node := Node{ + Start: d.off, + Value: v, + } + for { + // Look ahead for ] - can only happen on first iteration. + op := d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + + // Back up so d.value can have the byte we just read. + d.off-- + d.scan.undo(op) + + v = append(v, d.valueNode()) + + // Next token must be , or ]. + op = d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + if op != scanArrayValue { + d.error(errPhase) + } + } + node.Value = v + node.End = d.off - 1 + return node +} + +// objectInterface is like object but returns map[string]interface{}. +func (d *decodeState) objectInterface() map[string]interface{} { + m := make(map[string]interface{}) + for { + // Read opening " of string key or closing }. + op := d.scanWhile(scanSkipSpace) + if op == scanEndObject { + // closing } - can only happen on first iteration. + break + } + if op != scanBeginLiteral { + d.error(errPhase) + } + + // Read string key. + start := d.off - 1 + op = d.scanWhile(scanContinue) + item := d.data[start : d.off-1] + key, ok := unquote(item) + if !ok { + d.error(errPhase) + } + + // Read : before value. + if op == scanSkipSpace { + op = d.scanWhile(scanSkipSpace) + } + if op != scanObjectKey { + d.error(errPhase) + } + + // Read value. + m[key] = d.valueInterface() + + // Next token must be , or }. + op = d.scanWhile(scanSkipSpace) + if op == scanEndObject { + break + } + if op != scanObjectValue { + d.error(errPhase) + } + } + return m +} + +// objectNode is like object but returns Node. +func (d *decodeState) objectNode() Node { + m := make(map[string]Node) + node := Node{ + Start: d.off, + } + for { + // Read opening " of string key or closing }. + op := d.scanWhile(scanSkipSpace) + if op == scanEndObject { + // closing } - can only happen on first iteration. + break + } + if op != scanBeginLiteral { + d.error(errPhase) + } + + // Read string key. + start := d.off - 1 + op = d.scanWhile(scanContinue) + item := d.data[start : d.off-1] + keyEnd := d.off - 1 + key, ok := unquote(item) + if !ok { + d.error(errPhase) + } + + // Read : before value. + if op == scanSkipSpace { + op = d.scanWhile(scanSkipSpace) + } + if op != scanObjectKey { + d.error(errPhase) + } + + // Read value. + val := d.valueNode() + val.KeyStart = start + val.KeyEnd = keyEnd + m[key] = val + + // Next token must be , or }. + op = d.scanWhile(scanSkipSpace) + if op == scanEndObject { + break + } + if op != scanObjectValue { + d.error(errPhase) + } + } + node.Value = m + node.End = d.off - 1 + return node +} + +// literalInterface is like literal but returns an interface value. +func (d *decodeState) literalInterface() interface{} { + // All bytes inside literal return scanContinue op code. + start := d.off - 1 + op := d.scanWhile(scanContinue) + + // Scan read one byte too far; back up. + d.off-- + d.scan.undo(op) + item := d.data[start:d.off] + + switch c := item[0]; c { + case 'n': // null + return nil + + case 't', 'f': // true, false + return c == 't' + + case '"': // string + s, ok := unquote(item) + if !ok { + d.error(errPhase) + } + return s + + default: // number + if c != '-' && (c < '0' || c > '9') { + d.error(errPhase) + } + n, err := d.convertNumber(string(item)) + if err != nil { + d.saveError(err) + } + return n + } +} + +func (d *decodeState) literalNode() Node { + start := d.off - 1 + // Can just use the interface version since this has no children + node := Node{ + Start: start, + Value: d.literalInterface(), + } + node.End = d.off - 1 + return node +} + +// getu4 decodes \uXXXX from the beginning of s, returning the hex value, +// or it returns -1. +func getu4(s []byte) rune { + if len(s) < 6 || s[0] != '\\' || s[1] != 'u' { + return -1 + } + r, err := strconv.ParseUint(string(s[2:6]), 16, 64) + if err != nil { + return -1 + } + return rune(r) +} + +// unquote converts a quoted JSON string literal s into an actual string t. +// The rules are different than for Go, so cannot use strconv.Unquote. +func unquote(s []byte) (t string, ok bool) { + s, ok = unquoteBytes(s) + t = string(s) + return +} + +func unquoteBytes(s []byte) (t []byte, ok bool) { + if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' { + return + } + s = s[1 : len(s)-1] + + // Check for unusual characters. If there are none, + // then no unquoting is needed, so return a slice of the + // original bytes. + r := 0 + for r < len(s) { + c := s[r] + if c == '\\' || c == '"' || c < ' ' { + break + } + if c < utf8.RuneSelf { + r++ + continue + } + rr, size := utf8.DecodeRune(s[r:]) + if rr == utf8.RuneError && size == 1 { + break + } + r += size + } + if r == len(s) { + return s, true + } + + b := make([]byte, len(s)+2*utf8.UTFMax) + w := copy(b, s[0:r]) + for r < len(s) { + // Out of room? Can only happen if s is full of + // malformed UTF-8 and we're replacing each + // byte with RuneError. + if w >= len(b)-2*utf8.UTFMax { + nb := make([]byte, (len(b)+utf8.UTFMax)*2) + copy(nb, b[0:w]) + b = nb + } + switch c := s[r]; { + case c == '\\': + r++ + if r >= len(s) { + return + } + switch s[r] { + default: + return + case '"', '\\', '/', '\'': + b[w] = s[r] + r++ + w++ + case 'b': + b[w] = '\b' + r++ + w++ + case 'f': + b[w] = '\f' + r++ + w++ + case 'n': + b[w] = '\n' + r++ + w++ + case 'r': + b[w] = '\r' + r++ + w++ + case 't': + b[w] = '\t' + r++ + w++ + case 'u': + r-- + rr := getu4(s[r:]) + if rr < 0 { + return + } + r += 6 + if utf16.IsSurrogate(rr) { + rr1 := getu4(s[r:]) + if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar { + // A valid pair; consume. + r += 6 + w += utf8.EncodeRune(b[w:], dec) + break + } + // Invalid surrogate; fall back to replacement rune. + rr = unicode.ReplacementChar + } + w += utf8.EncodeRune(b[w:], rr) + } + + // Quote, control characters are invalid. + case c == '"', c < ' ': + return + + // ASCII + case c < utf8.RuneSelf: + b[w] = c + r++ + w++ + + // Coerce to well-formed UTF-8. + default: + rr, size := utf8.DecodeRune(s[r:]) + r += size + w += utf8.EncodeRune(b[w:], rr) + } + } + return b[0:w], true +} diff --git a/vendor/github.com/ajeddeloh/go-json/encode.go b/vendor/github.com/ajeddeloh/go-json/encode.go new file mode 100644 index 0000000000..90782deb70 --- /dev/null +++ b/vendor/github.com/ajeddeloh/go-json/encode.go @@ -0,0 +1,1194 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package json implements encoding and decoding of JSON objects as defined in +// RFC 4627. The mapping between JSON objects and Go values is described +// in the documentation for the Marshal and Unmarshal functions. +// +// See "JSON and Go" for an introduction to this package: +// https://golang.org/doc/articles/json_and_go.html +package json + +import ( + "bytes" + "encoding" + "encoding/base64" + "math" + "reflect" + "runtime" + "sort" + "strconv" + "strings" + "sync" + "unicode" + "unicode/utf8" +) + +// Marshal returns the JSON encoding of v. +// +// Marshal traverses the value v recursively. +// If an encountered value implements the Marshaler interface +// and is not a nil pointer, Marshal calls its MarshalJSON method +// to produce JSON. The nil pointer exception is not strictly necessary +// but mimics a similar, necessary exception in the behavior of +// UnmarshalJSON. +// +// Otherwise, Marshal uses the following type-dependent default encodings: +// +// Boolean values encode as JSON booleans. +// +// Floating point, integer, and Number values encode as JSON numbers. +// +// String values encode as JSON strings coerced to valid UTF-8, +// replacing invalid bytes with the Unicode replacement rune. +// The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e" +// to keep some browsers from misinterpreting JSON output as HTML. +// Ampersand "&" is also escaped to "\u0026" for the same reason. +// +// Array and slice values encode as JSON arrays, except that +// []byte encodes as a base64-encoded string, and a nil slice +// encodes as the null JSON object. +// +// Struct values encode as JSON objects. Each exported struct field +// becomes a member of the object unless +// - the field's tag is "-", or +// - the field is empty and its tag specifies the "omitempty" option. +// The empty values are false, 0, any +// nil pointer or interface value, and any array, slice, map, or string of +// length zero. The object's default key string is the struct field name +// but can be specified in the struct field's tag value. The "json" key in +// the struct field's tag value is the key name, followed by an optional comma +// and options. Examples: +// +// // Field is ignored by this package. +// Field int `json:"-"` +// +// // Field appears in JSON as key "myName". +// Field int `json:"myName"` +// +// // Field appears in JSON as key "myName" and +// // the field is omitted from the object if its value is empty, +// // as defined above. +// Field int `json:"myName,omitempty"` +// +// // Field appears in JSON as key "Field" (the default), but +// // the field is skipped if empty. +// // Note the leading comma. +// Field int `json:",omitempty"` +// +// The "string" option signals that a field is stored as JSON inside a +// JSON-encoded string. It applies only to fields of string, floating point, +// integer, or boolean types. This extra level of encoding is sometimes used +// when communicating with JavaScript programs: +// +// Int64String int64 `json:",string"` +// +// The key name will be used if it's a non-empty string consisting of +// only Unicode letters, digits, dollar signs, percent signs, hyphens, +// underscores and slashes. +// +// Anonymous struct fields are usually marshaled as if their inner exported fields +// were fields in the outer struct, subject to the usual Go visibility rules amended +// as described in the next paragraph. +// An anonymous struct field with a name given in its JSON tag is treated as +// having that name, rather than being anonymous. +// An anonymous struct field of interface type is treated the same as having +// that type as its name, rather than being anonymous. +// +// The Go visibility rules for struct fields are amended for JSON when +// deciding which field to marshal or unmarshal. If there are +// multiple fields at the same level, and that level is the least +// nested (and would therefore be the nesting level selected by the +// usual Go rules), the following extra rules apply: +// +// 1) Of those fields, if any are JSON-tagged, only tagged fields are considered, +// even if there are multiple untagged fields that would otherwise conflict. +// 2) If there is exactly one field (tagged or not according to the first rule), that is selected. +// 3) Otherwise there are multiple fields, and all are ignored; no error occurs. +// +// Handling of anonymous struct fields is new in Go 1.1. +// Prior to Go 1.1, anonymous struct fields were ignored. To force ignoring of +// an anonymous struct field in both current and earlier versions, give the field +// a JSON tag of "-". +// +// Map values encode as JSON objects. +// The map's key type must be string; the map keys are used as JSON object +// keys, subject to the UTF-8 coercion described for string values above. +// +// Pointer values encode as the value pointed to. +// A nil pointer encodes as the null JSON object. +// +// Interface values encode as the value contained in the interface. +// A nil interface value encodes as the null JSON object. +// +// Channel, complex, and function values cannot be encoded in JSON. +// Attempting to encode such a value causes Marshal to return +// an UnsupportedTypeError. +// +// JSON cannot represent cyclic data structures and Marshal does not +// handle them. Passing cyclic structures to Marshal will result in +// an infinite recursion. +// +func Marshal(v interface{}) ([]byte, error) { + e := &encodeState{} + err := e.marshal(v) + if err != nil { + return nil, err + } + return e.Bytes(), nil +} + +// MarshalIndent is like Marshal but applies Indent to format the output. +func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { + b, err := Marshal(v) + if err != nil { + return nil, err + } + var buf bytes.Buffer + err = Indent(&buf, b, prefix, indent) + if err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029 +// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029 +// so that the JSON will be safe to embed inside HTML