-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan Vlasic
committed
Jul 29, 2021
1 parent
5127ec0
commit ff98f78
Showing
15 changed files
with
189 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package data | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/atoz-technology/mantil-backend/internal/mantil" | ||
"github.com/atoz-technology/mantil-backend/internal/stream" | ||
) | ||
|
||
type Data struct { | ||
} | ||
|
||
type DataRequest struct { | ||
ProjectName string | ||
Token string | ||
} | ||
|
||
type DataResponse struct { | ||
Project *mantil.Project | ||
} | ||
|
||
func (f *Data) Invoke(ctx context.Context, req *DataRequest) (*DataResponse, error) { | ||
return f.Project(ctx, req) | ||
} | ||
|
||
func (f *Data) Project(ctx context.Context, req *DataRequest) (*DataResponse, error) { | ||
if req.ProjectName == "" || req.Token == "" { | ||
return nil, fmt.Errorf("bad request") | ||
} | ||
|
||
var p *mantil.Project | ||
err := stream.LambdaLogStream(ctx, func() error { | ||
var err error | ||
p, err = mantil.LoadProject(req.ProjectName) | ||
if err != nil { | ||
log.Printf("%v", err) | ||
return err | ||
} | ||
|
||
if p.Token != req.Token { | ||
log.Printf("access denied - %s", p.Token) | ||
return fmt.Errorf("access denied") | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Printf("%v", err) | ||
return nil, err | ||
} | ||
|
||
return &DataResponse{ | ||
Project: p, | ||
}, nil | ||
} | ||
|
||
func New() *Data { | ||
return &Data{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"Bucket":"mantil-project-try-mantil-backend","GithubOrg":"atoz-technology"} | ||
{"Bucket": "mantil-project-try-mantil-backend", "Name":"mantil-backend","GithubOrg":"atoz-technology"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/atoz-technology/mantil-backend/api/data" | ||
"github.com/atoz-technology/mantil.go" | ||
) | ||
|
||
func main() { | ||
var api = data.New() | ||
mantil.LambdaHandler(api) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
package security | ||
|
||
const FederationTokenPolicyTemplate = ` | ||
{ | ||
const CredentialsTemplate = `{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:GetObject", | ||
"s3:PutObject" | ||
], | ||
"s3:PutObject" | ||
], | ||
"Effect": "Allow", | ||
"Resource": "arn:aws:s3:::{{.Bucket}}/*" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ecr:BatchCheckLayerAvailability", | ||
"ecr:CompleteLayerUpload", | ||
"ecr:InitiateLayerUpload", | ||
"ecr:PutImage", | ||
"ecr:UploadLayerPart" | ||
], | ||
"Effect": "Allow", | ||
"Resource": "arn:aws:ecr:{{.Region}}:{{.AccountID}}:repository/mantil-project-{{.OrganizationName}}-{{.Name}}" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
{ | ||
"Action": "ecr:GetAuthorizationToken", | ||
"Effect": "Allow", | ||
"Resource": "*" | ||
} | ||
} | ||
] | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters