예제 #1
0
파일: ec2.go 프로젝트: sh0tt/awstagger
func printTags(ctx context.Context, svc ec2.EC2, instanceIds []*string) {
	if ctx.Verbose {
		tagsOut := getTags(svc, instanceIds)
		lastID := ""

		for _, td := range tagsOut.Tags {
			if lastID != *td.ResourceId {
				ctx.PrintVerbose(fmt.Sprintf("    Resource ID %s", *td.ResourceId))
				lastID = *td.ResourceId
			}
			ctx.PrintVerbose(fmt.Sprintf("      %s=%s", *td.Key, *td.Value))
		}
	}
}
예제 #2
0
func printTags(ctx context.Context, svc elasticsearchservice.ElasticsearchService, resourceIds []*string) {
	if ctx.Verbose {
		for _, arn := range resourceIds {
			ctx.PrintVerbose(fmt.Sprintf("    Processing domain %s", *arn))
			resp, _ := svc.ListTags(&elasticsearchservice.ListTagsInput{
				ARN: arn,
			})

			// Well, this will throw an error if there are no tags instead of just returning an empty list...ugh
			// kingpin.FatalIfError(err, "Could not retrieve tags for elastic search domain %s", arn)

			for _, tag := range resp.TagList {
				ctx.PrintVerbose(fmt.Sprintf("      %s=%s", *tag.Key, *tag.Value))
			}
		}
	}
}
예제 #3
0
func Process(ctx context.Context, region string) {
	ctx.Print("  Processing elastic search resources...")
	svc := elasticsearchservice.New(ctx.AwsSession, &aws.Config{Region: aws.String(region)})

	processARNs := func(resourceIds []*string) {
		nextWindow := func(ids []*string) ([]*string, []*string) {
			w := int(math.Min(float64(len(ids)), float64(200)))
			return ids[0:w], ids[w:]
		}

		for thisRound, remaining := nextWindow(resourceIds); len(thisRound) > 0; thisRound, remaining = nextWindow(remaining) {
			updateTags(ctx, *svc, thisRound)
			deleteTags(ctx, *svc, thisRound)
			printTags(ctx, *svc, thisRound)
		}
	}

	processARNs(getArns(svc))
}
예제 #4
0
파일: ec2.go 프로젝트: sh0tt/awstagger
func Process(ctx context.Context, region string) {
	svc := ec2.New(ctx.AwsSession, &aws.Config{Region: aws.String(region)})

	switch {

	case ctx.TagFlags.Ec2Instances:
		ctx.Print("  Processing EC2 instances...")
		processInstances(svc, &ctx.BatchSize, applyTags(ctx, svc))
		fallthrough

	case ctx.TagFlags.Ec2Amis:
		ctx.Print("  Processing EC2 AMIs...")
		processAmis(svc, ctx.BatchSize, applyTags(ctx, svc))
		fallthrough

	case ctx.TagFlags.Ec2Volumes:
		ctx.Print("  Processing EC2 volumes...")
		processVolumes(svc, ctx.BatchSize, applyTags(ctx, svc))
		fallthrough

	case ctx.TagFlags.Ec2Snapshots:
		ctx.Print("  Processing EC2 snapshots...")
		processSnapshots(svc, ctx.BatchSize, applyTags(ctx, svc))
		fallthrough

	case ctx.TagFlags.Ec2Vpcs:
		ctx.Print("  Processing EC2 VPCs...")
		processVpcs(svc, ctx.BatchSize, applyTags(ctx, svc))
		fallthrough

	case ctx.TagFlags.Ec2SecurityGroups:
		ctx.Print("  Processing EC2 security groups...")
		processSecurityGroups(svc, ctx.BatchSize, applyTags(ctx, svc))
		fallthrough

	case ctx.TagFlags.Ec2NetInterfaces:
		ctx.Print("  Processing EC2 network interfaces...")
		processNetInterfaces(svc, ctx.BatchSize, applyTags(ctx, svc))
	}
}