Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Ability to pass config values to action command #67

Closed
davidferlay opened this issue Aug 29, 2024 · 5 comments
Closed

Ability to pass config values to action command #67

davidferlay opened this issue Aug 29, 2024 · 5 comments

Comments

@davidferlay
Copy link
Contributor

Current

  • Config file .launchrctl/config.yaml is used to store default values for commands
  • For now these values can only be used in certain cases

Expected

  • Would be great to have ability retrieve value from config need to create small processor to handle it, like processor: keyring.GetKeyValue used for keyring
@iignatevich
Copy link
Collaborator

to test:

  1. add to %binary_name config.yaml some vars, like
actions:
  test:
    deep:
      string: str
      int: 100
      bool: true

update your action arg or opt to have new launchr value processor

      process:
        - processor: launchr.GetConfigValue
          options:
            path: actions.test.deep.string

@davidferlay
Copy link
Contributor Author

davidferlay commented Sep 3, 2024

Tried with these:

  • action.yaml:
working_directory: "{{ .current_working_dir }}"
action:
  title: SSH Config
  descriptions: >
    This action generates an SSH configuration file based on the platform nodes available in the Ansible cache file.
    The configuration output can be customized using various options such as the SSH user, port, host prefix,
    and identity file. This allows for streamlined SSH access to the specified hosts.

  options:
    - name: user
      description: The SSH user to be used for connecting to the nodes (default is root).
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.user
    - name: port
      description: The SSH port for connections (default is 22).
    - name: host-prefix
      description: A prefix filter to limit the hosts included in the config to those matching the specified prefix.
    - name: identity-file
      description: The path to the SSH identity file (default is `~/.ssh/id_rsa`).
  image: platform-actions-sshconfig:1.0.0
  build:
    context: ./
  command:
    - echo
    - "{{.user}}"

  • .plasmactl/config.yaml
sshconfig:
  port: 1337
  user: skilld

Renders as:

➜  ./plasmactl platform:sshconfig
skilld

➜  ./plasmactl platform:sshconfig --user uservaluefromoption
uservaluefromoption

@davidferlay
Copy link
Contributor Author

davidferlay commented Sep 3, 2024

Tested OK with int and string option types

However with bool, when option is not passed to command, default value from action.yaml seem to override the value from config for now:

  • action.yaml
working_directory: "{{ .current_working_dir }}"
action:
  title: SSH Config
  descriptions: >
    This action generates an SSH configuration file based on the platform nodes available in the Ansible cache file.
    The configuration output can be customized using various options such as the SSH user, port, host prefix,
    and identity file. This allows for streamlined SSH access to the specified hosts.

  options:
    - name: user
      description: The SSH user to be used for connecting to the nodes (default is root).
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.user
    - name: port
      description: The SSH port for connections (default is 22).
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.port
    - name: secondoption
      title: Second option
      description: Option to do something
      type: boolean
      default: false              <-------------------- that value overrides the one from config
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.booltest
    - name: host-prefix
      description: A prefix filter to limit the hosts included in the config to those matching the specified prefix.
    - name: identity-file
      description: The path to the SSH identity file (default is `~/.ssh/id_rsa`).
  image: platform-actions-sshconfig:1.0.0
  build:
    context: ./
  command:
    - echo
    - "{{.secondoption}}"
  • .plasmactl/config.yaml
sshconfig:
  port: 1337
  user: skilld
  booltest: true

Renders as :

./plasmactl platform:sshconfig                     
false

In the same time, when option is passed to command, computed value seem to always be true:

  • action.yaml
      title: Second option
      description: Option to do something
      type: boolean
      default: false
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.booltest
    - name: host-prefix
      description: A prefix filter to limit the hosts included in the config to those matching the specified prefix.
    - name: identity-file
      description: The path to the SSH identity file (default is `~/.ssh/id_rsa`).
  image: platform-actions-sshconfig:1.0.0
  build:
    context: ./
  command:
    - echo
    - "{{.secondoption}}"

  • .plasmactl/config.yaml
sshconfig:
  port: 1337
  user: skilld
  booltest: true

Renders as:

./plasmactl platform:sshconfig --secondoption true 
true

./plasmactl platform:sshconfig --secondoption false
true

@davidferlay
Copy link
Contributor Author

davidferlay commented Sep 4, 2024

Something not ok yet:

  • with default: false + config: true -> command with or without option passed to cli behave all as expected
  • when default: true + config: false -> both command with or whout option get value from default, not from config or not from cli option

I think logic should be : cli option > should override config > should override default

Meaning:

  • if cli option is set: both value from config and/or from default should be ignored
  • if config is set: value from default should be ignored
  • if default is set: value from default should be used
  • if no default is set: value from type default i guess

image

@davidferlay
Copy link
Contributor Author

davidferlay commented Sep 20, 2024

with

  • action.yaml
working_directory: "{{ .current_working_dir }}"
action:
  title: SSH Config
  descriptions: >
    This action generates an SSH configuration file based on the platform nodes available in the Ansible cache file.
    The configuration output can be customized using various options such as the SSH user, port, host prefix,
    and identity file. This allows for streamlined SSH access to the specified hosts.

  options:
    - name: user
      description: The SSH user to be used for connecting to the nodes (default is root).
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.user
    - name: port
      description: The SSH port for connections (default is 22).
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.port
    - name: secondoption
      title: Second option
      description: Option to do something
      type: boolean
      default: false
      process:
        - processor: launchr.GetConfigValue
          options:
            path: sshconfig.booltest
    - name: host-prefix
      description: A prefix filter to limit the hosts included in the config to those matching the specified prefix.
    - name: identity-file
      description: The path to the SSH identity file (default is `~/.ssh/id_rsa`).
  image: platform-actions-sshconfig:1.0.0
  build:
    context: ./
  command:
    - echo
    - "{{.secondoption}}"
  • .plasmactl/config.yaml
sshconfig:
  port: 1337
  user: skilld
  booltest: false

then

➜ ./plasmactl platform:sshconfig                     
false <----- expected
➜ ./plasmactl platform:sshconfig --secondoption=true 
true
➜ ./plasmactl platform:sshconfig --secondoption=false
false

working as expected

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

No branches or pull requests

2 participants