-
Notifications
You must be signed in to change notification settings - Fork 10
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
Implement new 'discover' command #109
Open
AbGuthrie
wants to merge
2
commits into
master
Choose a base branch
from
discover
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/AbGuthrie/goquery/api" | ||
"github.com/AbGuthrie/goquery/utils" | ||
|
||
prompt "github.com/c-bata/go-prompt" | ||
) | ||
|
||
func discover(cmdline string) error { | ||
args := strings.Split(cmdline, " ") // Separate command and arguments | ||
if len(args) != 1 { | ||
return fmt.Errorf("This command takes no parameters") | ||
} | ||
|
||
// Query for list of available hosts | ||
enrolledHosts, err := api.ListHosts() | ||
if err != nil { | ||
return fmt.Errorf("Error querying available hosts: %s", err) | ||
} | ||
|
||
utils.PrettyPrintQueryResults(enrolledHosts) | ||
|
||
return nil | ||
} | ||
|
||
func discoverHelp() string { | ||
return "Prints all hosts registered with api server" | ||
} | ||
|
||
func discoverSuggest(cmdline string) []prompt.Suggest { | ||
return []prompt.Suggest{} | ||
} |
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
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
"math/rand" | ||
"net/http" | ||
"net/url" | ||
"sort" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -290,6 +291,26 @@ func checkHost(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "%s", renderedHost) | ||
} | ||
|
||
func listHosts(w http.ResponseWriter, r *http.Request) { | ||
fmt.Printf("List hosts call") | ||
hosts := []Host{} | ||
|
||
for _, enrolledHost := range enrolledHosts { | ||
hosts = append(hosts, enrolledHost) | ||
} | ||
|
||
sort.SliceStable(hosts, func(i, j int) bool { | ||
return hosts[i].ComputerName > hosts[j].ComputerName | ||
}) | ||
|
||
hostsJSON, err := json.Marshal(hosts) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
fmt.Fprintf(w, "%s", hostsJSON) | ||
} | ||
|
||
func scheduleQuery(w http.ResponseWriter, r *http.Request) { | ||
uuid := r.FormValue("uuid") | ||
sentQuery, err := json.Marshal(r.FormValue("query")) | ||
|
@@ -416,16 +437,19 @@ func main() { | |
} | ||
fmt.Printf("Registered ourselves with the IDP Service\n") | ||
|
||
ch := http.HandlerFunc(checkHost) | ||
sq := http.HandlerFunc(scheduleQuery) | ||
fr := http.HandlerFunc(fetchResults) | ||
_checkHost := http.HandlerFunc(checkHost) | ||
_listHosts := http.HandlerFunc(listHosts) | ||
_scheduleQuery := http.HandlerFunc(scheduleQuery) | ||
_fetchResults := http.HandlerFunc(fetchResults) | ||
|
||
http.Handle("/checkHost", samlSP.RequireAccount(ch)) | ||
http.Handle("/scheduleQuery", samlSP.RequireAccount(sq)) | ||
http.Handle("/fetchResults", samlSP.RequireAccount(fr)) | ||
http.Handle("/checkHost", samlSP.RequireAccount(_checkHost)) | ||
http.Handle("/listHosts", _listHosts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be protected by SAML |
||
http.Handle("/scheduleQuery", samlSP.RequireAccount(_scheduleQuery)) | ||
http.Handle("/fetchResults", samlSP.RequireAccount(_fetchResults)) | ||
http.Handle("/saml/", samlSP) | ||
} else { | ||
http.HandleFunc("/checkHost", checkHost) | ||
http.HandleFunc("/listHosts", listHosts) | ||
http.HandleFunc("/scheduleQuery", scheduleQuery) | ||
http.HandleFunc("/fetchResults", fetchResults) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this is
utils.Rows
and not[]hosts.Host
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Zachary, it is because this branch is out of date with master, which recently had the big rewrite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed the point of your question. No there is no reason, this was implemented as if this function expected the standard query response rows structure from the server. Since it is a specific goquery endpoint then yes, you are right, the shape of returned JSON from the server (or whatever is implementing this) should be of type
[]hosts.Host
Thanks for the catch, will update