~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/authentication/src/main/java/com/eucalyptus/auth/policy/key/ImageNumberQuotaKey.java

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.auth.policy.key;
 
2
 
 
3
import net.sf.json.JSONException;
 
4
import com.eucalyptus.auth.AuthException;
 
5
import com.eucalyptus.auth.policy.PolicySpec;
 
6
import com.eucalyptus.auth.principal.AccountFullName;
 
7
import com.eucalyptus.auth.principal.UserFullName;
 
8
import com.eucalyptus.cloud.ImageMetadata;
 
9
import com.eucalyptus.component.id.Euare;
 
10
import com.eucalyptus.util.RestrictedTypes;
 
11
 
 
12
/**
 
13
 * GRZE:NOTE: this class is a {@link Euare} specific type and needs to move as well as not
 
14
 * referring to private implementation types. {@link ImageMetadata} should be considered a public
 
15
 * type while {@code ImageInfo} is implementation specific and will change as needed by the
 
16
 * implementation.
 
17
 */
 
18
@PolicyKey( Keys.EC2_QUOTA_IMAGE_NUMBER )
 
19
public class ImageNumberQuotaKey extends QuotaKey {
 
20
  
 
21
  private static final String KEY = Keys.EC2_QUOTA_IMAGE_NUMBER;
 
22
  
 
23
  @Override
 
24
  public void validateValueType( final String value ) throws JSONException {
 
25
    KeyUtils.validateIntegerValue( value, KEY );
 
26
  }
 
27
  
 
28
  @Override
 
29
  public boolean canApply( final String action, final String resourceType ) {
 
30
    if ( PolicySpec.qualifiedName( PolicySpec.VENDOR_EC2, PolicySpec.EC2_REGISTERIMAGE ).equals( action ) &&
 
31
         PolicySpec.qualifiedName( PolicySpec.VENDOR_EC2, PolicySpec.EC2_RESOURCE_IMAGE ).equals( resourceType ) ) {
 
32
      return true;
 
33
    }
 
34
    return false;
 
35
  }
 
36
  
 
37
  @Override
 
38
  public String value( final Scope scope, final String id, final String resource, final Long quantity ) throws AuthException {
 
39
    switch ( scope ) {
 
40
      case ACCOUNT:
 
41
        return Long.toString( RestrictedTypes.quantityMetricFunction( ImageMetadata.class ).apply( AccountFullName.getInstance( id ) ) + 1 );
 
42
      case GROUP:
 
43
        return NOT_SUPPORTED;
 
44
      case USER:
 
45
        return Long.toString( RestrictedTypes.quantityMetricFunction( ImageMetadata.class ).apply( UserFullName.getInstance( id ) ) + 1 );
 
46
    }
 
47
    throw new AuthException( "Invalid scope" );
 
48
  }
 
49
  
 
50
}