Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Persistence to Sources-API after successful create #1

Merged
merged 7 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ all: build
build:
go build .

clean:
rm sources-superkey-worker

container:
docker build . -t sources-superkey-worker -f Containerfile

run: build
./sources-superkey-worker

fancyrun: build
./sources-superkey-worker | grep '^{' | jq -r .

runcontainer: container
docker run -ti --rm --net host -e KAFKA_BROKERS=localhost:9092 sources-superkey-worker

.PHONY: build container run runcontainer
.PHONY: build container run fancyrun runcontainer clean
8 changes: 4 additions & 4 deletions amazon/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (

// CreateRole - creates a role with name from a json payload
// returns: error
func (a *Client) CreateRole(name, payload string) error {
_, err := a.Iam.CreateRole(context.Background(), &iam.CreateRoleInput{
func (a *Client) CreateRole(name, payload string) (*string, error) {
iamRole, err := a.Iam.CreateRole(context.Background(), &iam.CreateRoleInput{
AssumeRolePolicyDocument: &payload,
RoleName: &name,
})

if err != nil {
return err
return nil, err
}

return nil
return iamRole.Role.Arn, nil
}

// DestroyRole - destroys a role with name
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module github.com/redhatinsights/sources-superkey-worker
go 1.15

require (
github.com/aws/aws-sdk-go v1.36.33
github.com/aws/aws-sdk-go-v2 v1.0.0
github.com/aws/aws-sdk-go-v2/config v1.0.0
github.com/aws/aws-sdk-go-v2/credentials v1.0.0
github.com/aws/aws-sdk-go-v2/service/iam v1.0.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.0.0
github.com/aws/aws-sdk-go v1.37.7
github.com/aws/aws-sdk-go-v2 v1.1.0
github.com/aws/aws-sdk-go-v2/config v1.1.0
github.com/aws/aws-sdk-go-v2/credentials v1.1.0
github.com/aws/aws-sdk-go-v2/service/iam v1.1.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.1.0
github.com/frankban/quicktest v1.11.3 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/snappy v0.0.2 // indirect
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe // indirect
github.com/klauspost/compress v1.11.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lindgrenj6/sources-api-client-go v0.0.0-20210127232859-d79703a7d11e
github.com/lindgrenj6/sources-api-client-go v0.0.0-20210208213119-f8c85ca5cb90
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
Expand Down
54 changes: 30 additions & 24 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,30 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aws/aws-sdk-go v1.36.33 h1:ASmYIgWuPW1p01Xxch3ygaptshrEe7Vt+CirmwIqMtI=
github.com/aws/aws-sdk-go v1.36.33/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go-v2 v1.0.0 h1:ncEVPoHArsG+HjoDe/3ex/TG1CbLwMQ4eaWj0UGdyTo=
github.com/aws/aws-sdk-go-v2 v1.0.0/go.mod h1:smfAbmpW+tcRVuNUjo3MOArSZmW72t62rkCzc2i0TWM=
github.com/aws/aws-sdk-go-v2/config v1.0.0 h1:x6vSFAwqAvhYPeSu60f0ZUlGHo3PKKmwDOTL8aMXtv4=
github.com/aws/aws-sdk-go-v2/config v1.0.0/go.mod h1:WysE/OpUgE37tjtmtJd8GXgT8s1euilE5XtUkRNUQ1w=
github.com/aws/aws-sdk-go-v2/credentials v1.0.0 h1:0M7netgZ8gCV4v7z1km+Fbl7j6KQYyZL7SS0/l5Jn/4=
github.com/aws/aws-sdk-go-v2/credentials v1.0.0/go.mod h1:/SvsiqBf509hG4Bddigr3NB12MIpfHhZapyBurJe8aY=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0 h1:lO7fH5n7Q1dKcDBpuTmwJylD1bOQiRig8LI6TD9yVQk=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.0/go.mod h1:wpMHDCXvOXZxGCRSidyepa8uJHY4vaBGfY2/+oKU/Bc=
github.com/aws/aws-sdk-go-v2/service/iam v1.0.0 h1:hbMu6cCgLxEYyhrba9RqkxewyfxrUWiNDc12Epmk338=
github.com/aws/aws-sdk-go-v2/service/iam v1.0.0/go.mod h1:2Q65VwdiZuvBXXmr45Velx3g5sEgqQomdwJKu2+413Q=
github.com/aws/aws-sdk-go v1.37.7 h1:vfald/ssuWaA2HgJ9DrieVVXVE9eD0Kly/9kl0hofbE=
github.com/aws/aws-sdk-go v1.37.7/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go-v2 v1.1.0 h1:sKP6QWxdN1oRYjl+k6S3bpgBI+XUx/0mqVOLIw4lR/Q=
github.com/aws/aws-sdk-go-v2 v1.1.0/go.mod h1:smfAbmpW+tcRVuNUjo3MOArSZmW72t62rkCzc2i0TWM=
github.com/aws/aws-sdk-go-v2/config v1.1.0 h1:f3QVGpAcKrWpYNhKB8hE/buMjcfei95buQ5xdr/xYcU=
github.com/aws/aws-sdk-go-v2/config v1.1.0/go.mod h1:zfTyI6wH8yiZEvb6hGVza+S5oIB2lts2M7TDB4zMoeo=
github.com/aws/aws-sdk-go-v2/credentials v1.1.0 h1:RV0yzjGSNnJhTBco+01lwvWlc2m8gqBfha3D9dQDk78=
github.com/aws/aws-sdk-go-v2/credentials v1.1.0/go.mod h1:cV0qgln5tz/76IxAV0EsJVmmR5ZzKSQwWixsIvzk6lY=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.1 h1:eoT5e1jJf8Vcacu+mkEe1cgsgEAkuabpjhgq03GiXKc=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.1/go.mod h1:b+8dhYiS3m1xpzTZWk5EuQml/vSmPhKlzM/bAm/fttY=
github.com/aws/aws-sdk-go-v2/service/iam v1.1.0 h1:iQ+xe9a2K70/6RbZPc/ANuy+cI8Q6Ya4xL4yIbcAuU4=
github.com/aws/aws-sdk-go-v2/service/iam v1.1.0/go.mod h1:e+on0FWvO5ommIlztsVMOy7tZR5uY7CVUvvLMRtR9b8=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.0 h1:jjZzz89+Uii7XKlgWXNHiLVtJfvCG8oVoMLpiWsjnt8=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.0/go.mod h1:cZbnzYflIuoRkuKp4BB4q/R4xklYIwpLYs26vS3/Sac=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0 h1:IAutMPSrynpvKOpHG6HyWHmh1xmxWAmYOK84NrQVqVQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.0/go.mod h1:3jExOmpbjgPnz2FJaMOfbSk1heTkZ66aD3yNtVhnjvI=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.0.0 h1:Cg1XFRo41piOIT8Qp9RPQxfwLac5ddwGQxTPM8lowGk=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.0.0/go.mod h1:ElU0+utGClu2dFpCf1NIFxFAG+xO4n5b5RBuIiVaCY0=
github.com/aws/aws-sdk-go-v2/service/s3 v1.0.0 h1:7petFdJE3VuXZnXNVDdynznREElHSzjYI4xjkGNWPX8=
github.com/aws/aws-sdk-go-v2/service/s3 v1.0.0/go.mod h1:IdVR1fGqVS8Zv/oraQXdBzbGmdpc3FBOHhCTI7tpsYE=
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0 h1:6XCgxNfE4L/Fnq+InhVNd16DKc6Ue1f3dJl3IwwJRUQ=
github.com/aws/aws-sdk-go-v2/service/sts v1.0.0/go.mod h1:5f+cELGATgill5Pu3/vK3Ebuigstc+qYEHW5MvGWZO4=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.1 h1:E7zGGgca12s7jA3VqirtaltXj5Wwe5eUIsUlNl1v+d8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.1/go.mod h1:PISaKWylTYAyruocNk4Lr9miOOJjOcVBd7twCPbydDk=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.0.1 h1:U78TX1VNmbtb7Mea2LdXQXNtLJ6wWZ0yDJgEYeRX0wg=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.0.1/go.mod h1:IQF5AljyiiUz/CnLbe1FeE3hZZ/Kr87gJ1+/yEYel3I=
github.com/aws/aws-sdk-go-v2/service/s3 v1.1.0 h1:d3PK2s3MB8ikznU/tChWoWQM2EVHo+4ZymURcl9WVE4=
github.com/aws/aws-sdk-go-v2/service/s3 v1.1.0/go.mod h1:FunhqiuImyH0bxYm3xESmYTwq4dcESZQeaSAO4GjnTc=
github.com/aws/aws-sdk-go-v2/service/sso v1.1.0 h1:oQ/FE7bk1MldOs6RBTr+D7uMv1RfQ8WxxBRuH4lYEEo=
github.com/aws/aws-sdk-go-v2/service/sso v1.1.0/go.mod h1:VnS0vieB4YxutHFP9ROJ3ciT3T/XJZjxxv9L39eo8OQ=
github.com/aws/aws-sdk-go-v2/service/sts v1.1.0 h1:X9oTTSm14wc0ef4dit7aIB02UIw1kVi/imV7zLhFDdM=
github.com/aws/aws-sdk-go-v2/service/sts v1.1.0/go.mod h1:A15vQm/MsXL3a410CxwKQ5IBoSvIg+cr10fEFzPgEYs=
github.com/aws/smithy-go v1.0.0 h1:hkhcRKG9rJ4Fn+RbfXY7Tz7b3ITLDyolBnLLBhwbg/c=
github.com/aws/smithy-go v1.0.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down Expand Up @@ -109,8 +111,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe h1:rcf1P0fm+1l0EjG16p06mYLj9gW9X36KgdHJ/88hS4g=
github.com/gopherjs/gopherjs v0.0.0-20210202160940-bed99a852dfe/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
Expand Down Expand Up @@ -148,6 +150,7 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.9.8 h1:VMAMUUOh+gaxKTMk+zqbjsSjsIcUcL/LF4o63i82QyA=
github.com/klauspost/compress v1.9.8/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
Expand All @@ -165,8 +168,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lindgrenj6/sources-api-client-go v0.0.0-20210127232859-d79703a7d11e h1:tlJvvTrqHZIV0PVz1I4Qv8zriBX/4uQbFL4B3nFhwSM=
github.com/lindgrenj6/sources-api-client-go v0.0.0-20210127232859-d79703a7d11e/go.mod h1:/YFovfrDZPDRqtBJuTbMGwL5VbP8umAzBFS6cqhfOw4=
github.com/lindgrenj6/sources-api-client-go v0.0.0-20210208213119-f8c85ca5cb90 h1:Rr5xPhTgx5AvQ4iL12zVQemeSWI9wC3D06VDN8AsEzU=
github.com/lindgrenj6/sources-api-client-go v0.0.0-20210208213119-f8c85ca5cb90/go.mod h1:/YFovfrDZPDRqtBJuTbMGwL5VbP8umAzBFS6cqhfOw4=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY=
Expand Down Expand Up @@ -260,6 +263,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down Expand Up @@ -361,6 +365,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -387,6 +392,7 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
l.Log.Info("SuperKey Worker started.")

// anonymous function, kinda like passing a block in ruby.
messaging.ConsumeWithFunction("testtopic", func(msg kafka.Message) {
messaging.ConsumeWithFunction("platform.sources.superkey-requests", func(msg kafka.Message) {
l.Log.Infof("Started processing message %s", string(msg.Value))
ProcessSuperkeyRequest(msg)
l.Log.Infof("Finished processing message %s", string(msg.Value))
Expand Down
23 changes: 16 additions & 7 deletions provider/amazon_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/redhatinsights/sources-superkey-worker/amazon"
l "github.com/redhatinsights/sources-superkey-worker/logger"
"github.com/redhatinsights/sources-superkey-worker/superkey"
)

// AmazonProvider struct for implementing the Amazon Provider interface
Expand All @@ -19,10 +20,10 @@ type AmazonProvider struct {
// ForgeApplication transforms a superkey request with the amazon provider into a list
// of resources required for the application, specified by the request.
// returns: the new forged application payload with info on what was processed, in case something went wrong.
func (a *AmazonProvider) ForgeApplication(request *SuperKeyRequest) (*ForgedApplication, error) {
f := &ForgedApplication{
Request: request,
func (a *AmazonProvider) ForgeApplication(request *superkey.CreateRequest) (*superkey.ForgedApplication, error) {
f := &superkey.ForgedApplication{
StepsCompleted: make(map[string]map[string]string),
Request: request,
Client: a,
GUID: generateGUID(),
}
Expand Down Expand Up @@ -61,13 +62,14 @@ func (a *AmazonProvider) ForgeApplication(request *SuperKeyRequest) (*ForgedAppl
payload := substiteInPayload(step.Payload, f, step.Substitutions)
l.Log.Infof("Creating Role %v", name)

err := a.Client.CreateRole(name, payload)
roleArn, err := a.Client.CreateRole(name, payload)
if err != nil {
l.Log.Error("Failed to create Role %v, rolling back superkey request %v", name, f.Request)
return f, err
}

f.MarkCompleted("role", map[string]string{"output": name})
// Store the Role ARN since that is what we need to return for the Authentication object.
f.MarkCompleted("role", map[string]string{"output": name, "arn": *roleArn})
l.Log.Infof("Successfully created role %v", name)

case "bind_role":
Expand All @@ -88,6 +90,13 @@ func (a *AmazonProvider) ForgeApplication(request *SuperKeyRequest) (*ForgedAppl
l.Log.Infof("%v not implemented yet!", step.Name)
}
}

// Set the username to the role ARN since that is what is needed for this provider.
username := f.StepsCompleted["role"]["arn"]
appType := path.Base(f.Request.ApplicationType)
// Create the payload struct
f.CreatePayload(&username, nil, &appType)

return f, nil
}

Expand All @@ -103,7 +112,7 @@ func getShortName(name string) string {
return fmt.Sprintf("redhat-%s", path.Base(name))
}

func substiteInPayload(payload string, f *ForgedApplication, substitutions map[string]string) string {
func substiteInPayload(payload string, f *superkey.ForgedApplication, substitutions map[string]string) string {
// these are some special case substitutions, where `get_account` implies we need to fetch
// the account from the payload, and s3 is just the output from the s3 step
for name, sub := range substitutions {
Expand All @@ -125,7 +134,7 @@ func substiteInPayload(payload string, f *ForgedApplication, substitutions map[s
//
// Basically the StepsCompleted field keeps track of what parts of the forge operation
// went smoothly, and we just go through them in reverse and handle them.
func (a *AmazonProvider) TearDown(f *ForgedApplication) []error {
func (a *AmazonProvider) TearDown(f *superkey.ForgedApplication) []error {
errors := make([]error, 0)

// -----------------
Expand Down
9 changes: 5 additions & 4 deletions provider/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

"github.com/redhatinsights/sources-superkey-worker/amazon"
"github.com/redhatinsights/sources-superkey-worker/sources"
"github.com/redhatinsights/sources-superkey-worker/superkey"
)

// Forge -
func Forge(request *SuperKeyRequest) (*ForgedApplication, error) {
func Forge(request *superkey.CreateRequest) (*superkey.ForgedApplication, error) {
client, err := getProvider(request)
if err != nil {
return nil, err
Expand All @@ -20,7 +21,7 @@ func Forge(request *SuperKeyRequest) (*ForgedApplication, error) {
return f, err
}

func getProvider(request *SuperKeyRequest) (SuperKeyProvider, error) {
func getProvider(request *superkey.CreateRequest) (superkey.Provider, error) {
auth, err := sources.GetInternalAuthentication(request.TenantID, request.AuthenticationID)
if err != nil {
return nil, err
Expand All @@ -44,7 +45,7 @@ func getProvider(request *SuperKeyRequest) (SuperKeyProvider, error) {
}
}

func getStepNames(steps []SuperKeyStep) []string {
func getStepNames(steps []superkey.Step) []string {
names := make([]string, 0)
for _, step := range steps {
names = append(names, step.Name)
Expand All @@ -55,7 +56,7 @@ func getStepNames(steps []SuperKeyStep) []string {

// TearDown - tears down application that was forged
// returns: array of errors if any were returned.
func TearDown(f *ForgedApplication) []error {
func TearDown(f *superkey.ForgedApplication) []error {
if f.Client != nil {
return f.Client.TearDown(f)
}
Expand Down
45 changes: 0 additions & 45 deletions provider/types.go

This file was deleted.

Loading