-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
query resource fields from remote system
- Loading branch information
1 parent
a78d341
commit ba99fef
Showing
8 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package client | ||
|
||
import ( | ||
"strings" | ||
|
||
consoleinspected "github.com/ddelnano/terraform-provider-mikrotik/client/console-inspected" | ||
) | ||
|
||
func (c Mikrotik) InspectConsoleCommand(command string) (consoleinspected.ConsoleItem, error) { | ||
client, err := c.getMikrotikClient() | ||
if err != nil { | ||
return consoleinspected.ConsoleItem{}, err | ||
} | ||
normalizedCommand := strings.ReplaceAll(command[1:], "/", ",") | ||
cmd := []string{"/console/inspect", "as-value", "=path=" + normalizedCommand, "=request=child"} | ||
reply, err := client.RunArgs(cmd) | ||
if err != nil { | ||
return consoleinspected.ConsoleItem{}, err | ||
} | ||
var items []consoleinspected.Item | ||
var result consoleinspected.ConsoleItem | ||
if err := Unmarshal(*reply, &items); err != nil { | ||
return consoleinspected.ConsoleItem{}, err | ||
} | ||
|
||
for _, v := range items { | ||
if v.Type == consoleinspected.TypeSelf { | ||
result.Self = v | ||
continue | ||
} | ||
switch v.NodeType { | ||
case consoleinspected.NodeTypeArg: | ||
result.Arguments = append(result.Arguments, v) | ||
case consoleinspected.NodeTypeCommand: | ||
result.Commands = append(result.Commands, v.Name) | ||
case consoleinspected.NodeTypeDir: | ||
result.Subcommands = append(result.Subcommands, v.Name) | ||
} | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters