| 62 | } |
| 63 | |
| 64 | func StoreAccessToken(tenant, value string) error { |
| 65 | // First, clear any existing chunks to prevent concatenation issues. |
| 66 | for i := 0; i < secretAccessTokenMaxChunks; i++ { |
| 67 | if err := keyring.Delete(fmt.Sprintf("%s %d", secretAccessToken, i), tenant); err != nil { |
| 68 | if !errors.Is(err, keyring.ErrNotFound) { |
| 69 | return fmt.Errorf("failed to delete access token chunk from keyring: %s", err) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // Now store the new token in chunks. |
| 75 | chunks := chunk(value, secretAccessTokenChunkSizeInBytes) |
| 76 | |
| 77 | for i := 0; i < len(chunks); i++ { |
| 78 | err := keyring.Set(fmt.Sprintf("%s %d", secretAccessToken, i), tenant, chunks[i]) |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return nil |
| 85 | } |
| 86 | |
| 87 | func GetAccessToken(tenant string) (string, error) { |
| 88 | var accessToken string |