diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-08 10:32:13 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-08 10:32:13 +0300 |
| commit | 2bc4585db96da4000fbf727beadfc25af64bcd4a (patch) | |
| tree | 2df64b440728e198a6752323f61447aea57f73b2 /internal/config | |
| parent | cb38f62ea7fe65732180805a1555bf969e9394ee (diff) | |
initial restructure for oauth2
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/args.go | 13 | ||||
| -rw-r--r-- | internal/config/secrets.go | 24 |
2 files changed, 31 insertions, 6 deletions
diff --git a/internal/config/args.go b/internal/config/args.go index b380dcd..601a2d1 100644 --- a/internal/config/args.go +++ b/internal/config/args.go @@ -10,12 +10,13 @@ import ( var validPlatforms = []string{"mastodon", "linkedin"} type Args struct { - GosDir string - DryRun bool - Platforms []string - Target int - Lookback time.Duration - Secrets Secrets + GosDir string + DryRun bool + Platforms []string + Target int + Lookback time.Duration + SecretsConfigPath string + Secrets Secrets } func (a Args) Validate() error { 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) +} |
