-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/improve gcp experience (#20)
* Initial GCP native auth (no gcloud needed) * Add ability to force re-authentication; * Added debug command for development.
- Loading branch information
Showing
18 changed files
with
636 additions
and
36 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright © 2022 Aurelio Calegari, et al. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/aurc/loggo/internal/loggo" | ||
"github.com/aurc/loggo/internal/reader" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// streamCmd represents the stream command | ||
var debugCmd = &cobra.Command{ | ||
Use: "debug", | ||
Short: "Continuously stream l'oggo log", | ||
Long: `This command aims to assist troubleshoot loggos issue and would be rarely utilised by loggo's users': | ||
loggo debug`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
reader := reader.MakeReader(loggo.LatestLog, nil) | ||
app := loggo.NewLoggoApp(reader, "") | ||
app.Run() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(debugCmd) | ||
} |
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,69 @@ | ||
/* | ||
Copyright © 2022 Aurelio Calegari, et al. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package gcp | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path" | ||
) | ||
|
||
type Auth struct { | ||
ClientId string `json:"client_id"` | ||
ClientSecret string `json:"client_secret"` | ||
RefreshToken string `json:"refresh_token"` | ||
Type string `json:"type"` | ||
} | ||
|
||
func AuthDir() string { | ||
hd, _ := os.UserHomeDir() | ||
dir := path.Join(hd, ".loggo", "auth") | ||
return dir | ||
} | ||
|
||
func AuthFile() string { | ||
return path.Join(AuthDir(), "gcp.json") | ||
} | ||
|
||
func Delete() { | ||
_ = os.Remove(AuthFile()) | ||
} | ||
|
||
func (a *Auth) Save() error { | ||
if err := os.MkdirAll(AuthDir(), os.ModePerm); err != nil { | ||
return err | ||
} | ||
b, err := json.MarshalIndent(a, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
file, err := os.Create(AuthFile()) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
_, err = file.Write(b) | ||
return err | ||
} |
Oops, something went wrong.