1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-04 22:17:59 +08:00
Dušan Borovčanin 412593ae94
NOISSUE - Update dependencies (#1838)
* Update dependencies

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Update dependencies

Fix Timescale Reader bug.

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Revert influxdb-reader changes

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Update dependencies to latest supported versions

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

---------

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
2023-07-06 20:44:12 +02:00

70 lines
1.9 KiB
Go

// Copyright (C) MongoDB, Inc. 2023-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package credproviders
import (
"os"
"go.mongodb.org/mongo-driver/internal/aws/credentials"
)
// envProviderName provides a name of Env provider
const envProviderName = "EnvProvider"
// EnvVar is an environment variable
type EnvVar string
// Get retrieves the environment variable
func (ev EnvVar) Get() string {
return os.Getenv(string(ev))
}
// A EnvProvider retrieves credentials from the environment variables of the
// running process. Environment credentials never expire.
type EnvProvider struct {
AwsAccessKeyIDEnv EnvVar
AwsSecretAccessKeyEnv EnvVar
AwsSessionTokenEnv EnvVar
retrieved bool
}
// NewEnvProvider returns a pointer to an ECS credential provider.
func NewEnvProvider() *EnvProvider {
return &EnvProvider{
// AwsAccessKeyIDEnv is the environment variable for AWS_ACCESS_KEY_ID
AwsAccessKeyIDEnv: EnvVar("AWS_ACCESS_KEY_ID"),
// AwsSecretAccessKeyEnv is the environment variable for AWS_SECRET_ACCESS_KEY
AwsSecretAccessKeyEnv: EnvVar("AWS_SECRET_ACCESS_KEY"),
// AwsSessionTokenEnv is the environment variable for AWS_SESSION_TOKEN
AwsSessionTokenEnv: EnvVar("AWS_SESSION_TOKEN"),
}
}
// Retrieve retrieves the keys from the environment.
func (e *EnvProvider) Retrieve() (credentials.Value, error) {
e.retrieved = false
v := credentials.Value{
AccessKeyID: e.AwsAccessKeyIDEnv.Get(),
SecretAccessKey: e.AwsSecretAccessKeyEnv.Get(),
SessionToken: e.AwsSessionTokenEnv.Get(),
ProviderName: envProviderName,
}
err := verify(v)
if err == nil {
e.retrieved = true
}
return v, err
}
// IsExpired returns true if the credentials have not been retrieved.
func (e *EnvProvider) IsExpired() bool {
return !e.retrieved
}