diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-04-18 22:45:04 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-04-18 22:45:04 +0200 |
commit | 24600c8787f949d0de2596a9c6b54a38474e461a (patch) | |
tree | d37910ea960b6da08b98d8ca8a65d7e157ecfa95 /garage.go | |
parent | e77b9ebd9c6bc1edca7233042b531a9204d8fa6d (diff) | |
download | guichet-24600c8787f949d0de2596a9c6b54a38474e461a.tar.gz guichet-24600c8787f949d0de2596a9c6b54a38474e461a.zip |
add dependency to garage
Diffstat (limited to 'garage.go')
-rw-r--r-- | garage.go | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -2,10 +2,40 @@ package main import ( "net/http" + "context" + "fmt" + garage "git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang" ) +func gadmin() (*garage.APIClient, context.Context) { + // Set Host and other parameters + configuration := garage.NewConfiguration() + configuration.Host = config.S3AdminEndpoint + + // We can now generate a client + client := garage.NewAPIClient(configuration) + + // Authentication is handled through the context pattern + ctx := context.WithValue(context.Background(), garage.ContextAccessToken, config.S3AdminToken) + return client, ctx +} + + +func createKey(name string) error { + client, ctx := gadmin() + + kr := garage.AddKeyRequest{Name: &name} + resp, _, err := client.KeyApi.AddKey(ctx).AddKeyRequest(kr).Execute() + if err != nil { + fmt.Printf("%+v\n", err) + return err + } + fmt.Printf("%+v\n", resp) + return nil +} func handleGarageKey(w http.ResponseWriter, r *http.Request) { + createKey("toto") tKey := getTemplate("garage_key.html") tKey.Execute(w, nil) } |