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

Glome server example #57

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

pedrobn23
Copy link

Example implementation of glome server

@pedrobn23 pedrobn23 force-pushed the pedrobn23/go-glome-server-example branch from 0be30f2 to 34c63e5 Compare September 25, 2020 16:09
@pedrobn23 pedrobn23 changed the title Pedrobn23/go glome server example Glome server example Sep 28, 2020
@pedrobn23 pedrobn23 force-pushed the pedrobn23/go-glome-server-example branch 9 times, most recently from f24bccd to 72755be Compare September 30, 2020 11:40
Copy link
Member

@pkern pkern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove compiled files from the change.

go/login/server/example-server/config/authorization.go Outdated Show resolved Hide resolved
go/login/server/example-server/config/authorization.go Outdated Show resolved Hide resolved
go/login/server/example-server/config/authorization.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/utils.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/utils.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/utils.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/utils.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/utils.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/run.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/run.go Outdated Show resolved Hide resolved
go/login/server/example-server/README.md Outdated Show resolved Hide resolved
go/login/server/example-server/README.md Outdated Show resolved Hide resolved
go/login/server/example-server/README.md Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/run.go Outdated Show resolved Hide resolved
go/login/server/example-server/cmd/run.go Outdated Show resolved Hide resolved
fmt.Println(`Please, provide key file, authorization script and address.
For more information read --help option.`)
os.Exit(0)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a mechanism for enforcing flag presence, https://github.com/spf13/cobra#required-flags. If you still need to do more complicated sanity checks (cross-deps between flags, for example), you can do that check in a PreRunE: https://github.com/spf13/cobra#prerun-and-postrun-hooks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use a PreRunE that returns an error with that message. That would automatically terminate the process with a non-zero exit code.

@pedrobn23 pedrobn23 force-pushed the pedrobn23/go-glome-server-example branch 3 times, most recently from cc1205b to a084525 Compare September 30, 2020 17:10
@burgerdev burgerdev force-pushed the pedrobn23/go-glome-server-example branch 3 times, most recently from 70af180 to 8abcfd0 Compare October 5, 2020 07:38
Implements an example of use of glome server framework. This example of use is a binary with cobra interface and support different configurations

Signed-off-by: pedrobn <pedrobn@google.com>
@burgerdev burgerdev force-pushed the pedrobn23/go-glome-server-example branch from 8abcfd0 to 8b27bc5 Compare October 5, 2020 08:19
fmt.Println(`Please, provide key file, authorization script and address.
For more information read --help option.`)
os.Exit(0)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use a PreRunE that returns an error with that message. That would automatically terminate the process with a non-zero exit code.

cmd := exec.Command(p)
cmd.Stdin = nil
cmd.Env = []string{
fmt.Sprintf("USER=%s", user),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The env vars used for configuration should avoid conflicts, a list of names that already have meaning can be found here: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html. IT might be a good idea to use a GLOME_AUTHZ_ prefix or similar.

if err == nil {
return true, nil
} else {
return false, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return the error message (authz binary stderr).

} else {
os.Exit(1)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover, is superseded by authorization.sh.

TOKEN=`curl -s 127.0.0.1:8000/v1/UYcvQ1u4uJ0OOtYqouURB07hleHDnvaogAFBi-ZW48N2/serial-number:1234567890=ABCDFGH%2F%23%3F/reboot/`
if [[ "$TOKEN" != "p8M_BUKj7zXBVM2JlQhNYFxs4J-DzxRAps83ZaNDquY=" ]]
then
kill $ID
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should report the HTTP code and the return body in case != 200. In the 200 case, it should output the returned token if it does not match.

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

Successfully merging this pull request may close these issues.

None yet

4 participants