summaryrefslogtreecommitdiff
path: root/internal/config/secrets.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/secrets.go')
-rw-r--r--internal/config/secrets.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/config/secrets.go b/internal/config/secrets.go
index e480e67..dc3f8e7 100644
--- a/internal/config/secrets.go
+++ b/internal/config/secrets.go
@@ -7,12 +7,17 @@ import (
"os"
)
+// The config file containing all the secrets and credentials.
type Secrets struct {
MastodonURL string
MastodonAccessToken string
LinkedInClientID string
LinkedInSecret string
LinkedInRedirectURL string
+ // Will be updated by gos automatically, after successful oauth2
+ LinkedInAccessToken string `json:"LinedInAccessToken,omitempty"`
+ // Will be updated by gos automatically, after successful oauth2
+ LinkedInPersonID string `json:"LinedInPersonID,omitempty"`
}
func NewSecrets(configPath string) (Secrets, error) {
@@ -34,3 +39,22 @@ func NewSecrets(configPath string) (Secrets, error) {
return sec, nil
}
+
+func (s Secrets) WriteToDisk(configPath string) error {
+ bytes, err := json.MarshalIndent(s, "", " ")
+ if err != nil {
+ return fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ tmpConfigPath := fmt.Sprintf("%s.tmp", configPath)
+ file, err := os.Create(tmpConfigPath)
+ if err != nil {
+ return fmt.Errorf("failed to create file: %w", err)
+ }
+ defer file.Close()
+
+ if _, err := file.Write(bytes); err != nil {
+ return fmt.Errorf("failed to write to file: %w", err)
+ }
+
+ return os.Rename(tmpConfigPath, configPath)
+}