Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
53c7b339
Commit
53c7b339
authored
Sep 26, 2018
by
Aidan Rowe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
imguploader: Add support for ECS credential provider for S3
parent
af0f3f21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletions
+28
-1
pkg/components/imguploader/s3uploader.go
+28
-1
No files found.
pkg/components/imguploader/s3uploader.go
View file @
53c7b339
...
...
@@ -2,12 +2,15 @@ package imguploader
import
(
"context"
"fmt"
"os"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/aws/credentials/endpointcreds"
"github.com/aws/aws-sdk-go/aws/defaults"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
...
...
@@ -50,7 +53,7 @@ func (u *S3Uploader) Upload(ctx context.Context, imageDiskPath string) (string,
SecretAccessKey
:
u
.
secretKey
,
}},
&
credentials
.
EnvProvider
{},
&
ec2rolecreds
.
EC2RoleProvider
{
Client
:
ec2metadata
.
New
(
sess
),
ExpiryWindow
:
5
*
time
.
Minute
}
,
remoteCredProvider
(
sess
)
,
})
cfg
:=
&
aws
.
Config
{
Region
:
aws
.
String
(
u
.
region
),
...
...
@@ -85,3 +88,27 @@ func (u *S3Uploader) Upload(ctx context.Context, imageDiskPath string) (string,
}
return
image_url
,
nil
}
func
remoteCredProvider
(
sess
*
session
.
Session
)
credentials
.
Provider
{
ecsCredURI
:=
os
.
Getenv
(
"AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
)
if
len
(
ecsCredURI
)
>
0
{
return
ecsCredProvider
(
sess
,
ecsCredURI
)
}
return
ec2RoleProvider
(
sess
)
}
func
ecsCredProvider
(
sess
*
session
.
Session
,
uri
string
)
credentials
.
Provider
{
const
host
=
`169.254.170.2`
d
:=
defaults
.
Get
()
return
endpointcreds
.
NewProviderClient
(
*
d
.
Config
,
d
.
Handlers
,
fmt
.
Sprintf
(
"http://%s%s"
,
host
,
uri
),
func
(
p
*
endpointcreds
.
Provider
)
{
p
.
ExpiryWindow
=
5
*
time
.
Minute
})
}
func
ec2RoleProvider
(
sess
*
session
.
Session
)
credentials
.
Provider
{
return
&
ec2rolecreds
.
EC2RoleProvider
{
Client
:
ec2metadata
.
New
(
sess
),
ExpiryWindow
:
5
*
time
.
Minute
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment