Example #1
0
func (p *AWSProvider) describeTaskDefinition(name string) (*ecs.TaskDefinition, error) {
	td, ok := cache.Get("describeTaskDefinition", name).(*ecs.TaskDefinition)
	if ok {
		return td, nil
	}

	res, err := p.ecs().DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
		TaskDefinition: aws.String(name),
	})
	if ae, ok := err.(awserr.Error); ok && ae.Code() == "ValidationError" {
		return nil, errorNotFound(fmt.Sprintf("%s not found", name))
	}
	if err != nil {
		return nil, err
	}

	td = res.TaskDefinition

	if !p.SkipCache {
		if err := cache.Set("describeTaskDefinition", name, td, 10*time.Second); err != nil {
			return nil, err
		}
	}

	return td, nil
}
Example #2
0
func hashExists(bucket, hash string) (bool, error) {
	if exists, ok := cache.Get("index.missingHash", hash).(bool); ok && exists {
		return true, nil
	}

	exists, err := s3Exists(bucket, fmt.Sprintf("index/%s", hash))

	if err != nil {
		return false, err
	}

	if exists {
		cache.Set("index.missingHash", hash, true, 30*24*time.Hour)
	}

	return exists, nil
}
Example #3
0
func (p *AWSProvider) describeStackEvents(input *cloudformation.DescribeStackEventsInput) (*cloudformation.DescribeStackEventsOutput, error) {
	res, ok := cache.Get("describeStackEvents", input.StackName).(*cloudformation.DescribeStackEventsOutput)

	if ok {
		return res, nil
	}

	res, err := p.cloudformation().DescribeStackEvents(input)
	if err != nil {
		return nil, err
	}

	err = cache.Set("describeStackEvents", input.StackName, res, 5*time.Second)
	if err != nil {
		return nil, err
	}

	return res, nil
}
Example #4
0
func ListResources(app string) (Resources, error) {
	if resources, ok := cache.Get("ListResources", app).(Resources); ok {
		return resources, nil
	}

	stackName := shortNameToStackName(app)

	res, err := CloudFormation().DescribeStackResources(&cloudformation.DescribeStackResourcesInput{
		StackName: aws.String(stackName),
	})

	if app != stackName && awsError(err) == "ValidationError" {
		res, err = CloudFormation().DescribeStackResources(&cloudformation.DescribeStackResourcesInput{
			StackName: aws.String(app),
		})
	}

	if err != nil {
		return nil, err
	}

	resources := make(Resources, len(res.StackResources))

	for _, r := range res.StackResources {
		resources[*r.LogicalResourceId] = Resource{
			Id:     cs(r.PhysicalResourceId, ""),
			Name:   cs(r.LogicalResourceId, ""),
			Reason: cs(r.ResourceStatusReason, ""),
			Status: cs(r.ResourceStatus, ""),
			Type:   cs(r.ResourceType, ""),
			Time:   ct(r.Timestamp),
		}
	}

	err = cache.Set("ListResources", app, resources, 15*time.Second)

	if err != nil {
		return nil, err
	}

	return resources, nil
}
Example #5
0
func (p *AWSProvider) describeStackResources(input *cloudformation.DescribeStackResourcesInput) (*cloudformation.DescribeStackResourcesOutput, error) {
	res, ok := cache.Get("describeStackResources", input.StackName).(*cloudformation.DescribeStackResourcesOutput)

	if ok {
		return res, nil
	}

	res, err := p.cloudformation().DescribeStackResources(input)
	if err != nil {
		return nil, err
	}

	if !p.SkipCache {
		if err := cache.Set("describeStackResources", input.StackName, res, 5*time.Second); err != nil {
			return nil, err
		}
	}

	return res, nil
}
Example #6
0
func (p *AWSProvider) listContainerInstances(input *ecs.ListContainerInstancesInput) (*ecs.ListContainerInstancesOutput, error) {
	res, ok := cache.Get("listContainerInstances", input).(*ecs.ListContainerInstancesOutput)

	if ok {
		return res, nil
	}

	res, err := p.ecs().ListContainerInstances(input)

	if err != nil {
		return nil, err
	}

	if !p.SkipCache {
		if err := cache.Set("listContainerInstances", input, res, 10*time.Second); err != nil {
			return nil, err
		}
	}

	return res, nil
}
Example #7
0
func (p *AWSProvider) describeServices(input *ecs.DescribeServicesInput) (*ecs.DescribeServicesOutput, error) {
	res, ok := cache.Get("describeServices", input.Services).(*ecs.DescribeServicesOutput)

	if ok {
		return res, nil
	}

	res, err := p.ecs().DescribeServices(input)

	if err != nil {
		return nil, err
	}

	if !p.SkipCache {
		if err := cache.Set("describeServices", input.Services, res, 5*time.Second); err != nil {
			return nil, err
		}
	}

	return res, nil
}