YQ Tool: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 31: Line 31:
|}
|}


==Knowledge==
==Convert » JSON » YAML==
{|class='wikitable mw-collapsible mw-made-collapsible mw-collapsed'
!scope='col' colspan='2' style='width:1000px'|
'''Convert » JSON » YAML'''
|-
|valign='top' style='width:490px'|
<syntaxhighlight lang="json">
cat <<'JSN'| yq -P
{
"Version": "2012-10-17",
"Statement": [{
  "Action": [
      "admin:SetTier",
      "admin:ListTier" ],
  "Effect": "Allow",
  "Sid": "EnableRemoteTierManagement" },{
  "Action": [
      "s3:PutLifecycleConfiguration",
      "s3:GetLifecycleConfiguration" ],
  "Resource": [
      "arn:aws:s3:::*" ],
  "Effect": "Allow",
  "Sid": "EnableLifecycleManagementRules" }]}
JSN
</syntaxhighlight>
 
|valign='top' style='width:490px'|
<syntaxhighlight lang="yaml">
cat <<'YML'| yq -o=json
---
Version: "2012-10-17"
Statement:
  - Action:
      - admin:SetTier
      - admin:ListTier
    Effect: Allow
    Sid: EnableRemoteTierManagement
  - Action:
      - s3:PutLifecycleConfiguration
      - s3:GetLifecycleConfiguration
    Resource:
      - arn:aws:s3:::*
    Effect: Allow
    Sid: EnableLifecycleManagementRules
YML
</syntaxhighlight>
|}
 
==Playground==
{|class='wikitable mw-collapsible mw-made-collapsible mw-collapsed'
!scope='col' style='width:1000px'|
'''YQ » Playground'''
|-
|valign='top'|
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# append or replace ports
# append or replace ports
Line 46: Line 99:
yq eval '.services.registry.extra_hosts += ["host.docker.internal:host-gateway"]' -i docker-compose.yml
yq eval '.services.registry.extra_hosts += ["host.docker.internal:host-gateway"]' -i docker-compose.yml
</syntaxhighlight>
</syntaxhighlight>
|}


==References==
==References==

Revision as of 08:34, 1 July 2025

# ubuntu/debian
cat << EXE|sudo bash
PLATFORM=\$(uname -s)_\$(dpkg --print-architecture)
YQ_BINARY=\$(echo "yq_\${PLATFORM}"|tr '[:upper:]' '[:lower:]')
wget https://github.com/mikefarah/yq/releases/latest/download/\${YQ_BINARY} -O /usr/bin/yq
chmod +x /usr/bin/yq
EXE
windows:
1. Press ⊞ + R
2. Type in PowerShell
run as administrator user
3. Press Ctrl + Shift + Enter
4. Choose Yes and Press Enter
5. choco install yq
macos:



brew doctor
brew update
brew install yq

Convert » JSON » YAML

Convert » JSON » YAML

cat <<'JSN'| yq -P
{
"Version": "2012-10-17",
"Statement": [{
   "Action": [
      "admin:SetTier",
      "admin:ListTier" ],
   "Effect": "Allow",
   "Sid": "EnableRemoteTierManagement" },{
   "Action": [
      "s3:PutLifecycleConfiguration",
      "s3:GetLifecycleConfiguration" ],
   "Resource": [
      "arn:aws:s3:::*" ],
   "Effect": "Allow",
   "Sid": "EnableLifecycleManagementRules" }]}
JSN
cat <<'YML'| yq -o=json
---
Version: "2012-10-17"
Statement:
  - Action:
      - admin:SetTier
      - admin:ListTier
    Effect: Allow
    Sid: EnableRemoteTierManagement
  - Action:
      - s3:PutLifecycleConfiguration
      - s3:GetLifecycleConfiguration
    Resource:
      - arn:aws:s3:::*
    Effect: Allow
    Sid: EnableLifecycleManagementRules
YML

Playground

YQ » Playground

# append or replace ports
cat docker-compose.yml|yq -r '.services.proxy.ports'
yq eval '.services.proxy.ports += ["127.0.0.1:1980:8080"]' -i docker-compose.yml
yq eval '.services.proxy.ports  = ["127.0.0.1:1980:8080"]' -i docker-compose.yml

# read decoded docker password
yq -r '.auths."hub.chorke.org".auth' ~/.docker/config.json|base64 --decode && echo
yq -r '.auths."reg.chorke.org".auth' ~/.docker/config.json|base64 --decode && echo

# append extra_hosts for host.docker.internal
yq eval '.services.core.extra_hosts     += ["host.docker.internal:host-gateway"]' -i docker-compose.yml
yq eval '.services.registry.extra_hosts += ["host.docker.internal:host-gateway"]' -i docker-compose.yml

References