this method allows setting the current_tenant by reading the subdomain and looking
 it up in the tenant-model passed to the method. The method will look for the subdomain
 in a column referenced by the second argument.
162254
def set_current_tenant_by_subdomain(tenant = :account, column = :subdomain )
      self.class_eval do
        cattr_accessor :tenant_class, :tenant_column
      end

      self.tenant_class = tenant.to_s.camelcase.constantize
      self.tenant_column = column.to_sym

      self.class_eval do

        before_action :find_tenant_by_subdomain
        helper_method :current_tenant if respond_to?(:helper_method)


        private
          def find_tenant_by_subdomain
            if request.subdomains.last
              ActsAsTenant.current_tenant = tenant_class.where(tenant_column => request.subdomains.last.downcase).first
            end
          end

          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
1136583
protected void bindSubClass(HibernatePersistentEntity sub, PersistentClass parent,
                                InFlightMetadataCollector mappings, String sessionFactoryBeanName) {
        evaluateMapping(sub, defaultMapping);
        Mapping m = getMapping(parent.getMappedClass());
        Subclass subClass;
        boolean tablePerSubclass = m != null && !m.getTablePerHierarchy() && !m.isTablePerConcreteClass();
        boolean tablePerConcreteClass = m != null && m.isTablePerConcreteClass();
        final String fullName = sub.getName();
        if (tablePerSubclass) {
            subClass = new JoinedSubclass( parent, this.metadataBuildingContext);
        }
        else if(tablePerConcreteClass) {
            subClass = new UnionSubclass(parent, this.metadataBuildingContext);
        }
        else {
            subClass = new SingleTableSubclass(parent, this.metadataBuildingContext);
            // set the descriminator value as the name of the class. This is the
            // value used by Hibernate to decide what the type of the class is
            // to perform polymorphic queries
            Mapping subMapping = getMapping(sub);
            DiscriminatorConfig discriminatorConfig = subMapping != null ? subMapping.getDiscriminator() : null;

            subClass.setDiscriminatorValue(discriminatorConfig != null && discriminatorConfig.getValue() != null ? discriminatorConfig.getValue() : fullName);

            if (subMapping != null) {
                configureDerivedProperties(sub, subMapping);
            }
        }
        Integer bs = m.getBatchSize();
        if (bs != null) {
            subClass.setBatchSize(bs);
        }

        if (m.getDynamicUpdate()) {
            subClass.setDynamicUpdate(true);
        }
        if (m.getDynamicInsert()) {
            subClass.setDynamicInsert(true);
        }
        
        subClass.setAbstract(sub.isAbstract());
        subClass.setEntityName(fullName);
        subClass.setJpaEntityName(unqualify(fullName));

        parent.addSubclass(subClass);
        mappings.addEntityBinding(subClass);

        if (tablePerSubclass) {
            bindJoinedSubClass(sub, (JoinedSubclass) subClass, mappings, m, sessionFactoryBeanName);
        }
        else if( tablePerConcreteClass) {
            bindUnionSubclass(sub, (UnionSubclass) subClass, mappings, sessionFactoryBeanName);
        }
        else {
            bindSubClass(sub, subClass, mappings, sessionFactoryBeanName);
        }

        addMultiTenantFilterIfNecessary(sub, subClass, mappings, sessionFactoryBeanName);

        final java.util.Collection<PersistentEntity> childEntities = sub.getMappingContext().getDirectChildEntities(sub);
        if (!childEntities.isEmpty()) {
            // bind the sub classes
            bindSubClasses(sub, subClass, mappings, sessionFactoryBeanName);
        }
    }
932547
def is_subdomain(domain, reference):
    
    index_of_reference = domain.find(reference)
    if index_of_reference > 0 and domain[index_of_reference:] == reference:
        return True
    return False
1198436
def _extract_subdomain(self, rowdata):
        
        name = str(rowdata['fully_qualified_subdomain'])
        domain = str(rowdata['domain'])
        n = str(rowdata['sequence'])
        encoded_pubkey = str(rowdata['owner'])
        zonefile_hash = str(rowdata['zonefile_hash'])
        sig = rowdata['signature']
        block_height = int(rowdata['block_height'])
        parent_zonefile_hash = str(rowdata['parent_zonefile_hash'])
        parent_zonefile_index = int(rowdata['parent_zonefile_index'])
        zonefile_offset = int(rowdata['zonefile_offset'])
        txid = str(rowdata['txid'])
        missing = [int(i) for i in rowdata['missing'].split(',')] if rowdata['missing'] is not None and len(rowdata['missing']) > 0 else []
        accepted = int(rowdata['accepted'])
        resolver = str(rowdata['resolver']) if rowdata['resolver'] is not None else None

        if accepted == 0:
            accepted = False
        else:
            accepted = True

        if sig == '' or sig is None:
            sig = None
        else:
            sig = str(sig)

        name = str(name)
        is_subdomain, _, _ = is_address_subdomain(name)
        if not is_subdomain:
            raise Exception("Subdomain DB lookup returned bad subdomain result {}".format(name))

        zonefile_str = get_atlas_zonefile_data(zonefile_hash, self.zonefiles_dir)
        if zonefile_str is None:
            log.error("No zone file for {}".format(name))
            raise SubdomainNotFound('{}: missing zone file {}'.format(name, zonefile_hash))

        return Subdomain(str(name), str(domain), str(encoded_pubkey), int(n), str(zonefile_str), sig, block_height, parent_zonefile_hash, parent_zonefile_index, zonefile_offset, txid, domain_zonefiles_missing=missing, accepted=accepted, resolver=resolver)
1296186
def get_out_srvc_node_ip_addr(cls, tenant_id):
        
        if tenant_id not in cls.serv_obj_dict:
            LOG.error("Fabric not prepared for tenant %s", tenant_id)
            return
        tenant_obj = cls.serv_obj_dict.get(tenant_id)
        out_subnet_dict = tenant_obj.get_out_ip_addr()
        next_hop = str(netaddr.IPAddress(out_subnet_dict.get('subnet')) + 2)
        return next_hop
726520
def call(env)
      # Create a method called domain which will return the current domain
      # name
      Rails.application.send :define_singleton_method, 'domain_name' do
        env['SERVER_NAME']
      end

      # Create `fetch_domain` method on `Rails.application`
      # only if it didn't already define.
      unless Rails.application.respond_to? :fetch_domain
        Rails.application.send :define_singleton_method, 'fetch_domain' do
          if defined? ActiveRecord
            Domain.find_by(nam: Rails.application.domain_name)
          elsif defined? Mongoid
            Site.where('domains.name' => Rails.application.domain_name).domains.first
          end
        end
      end

      Rails.application.send :define_singleton_method, 'site' do
        site = nil
        unless Rails.application.domain.nil?
          site = Rails.application.domain.site
        end
        site
      end

      Rails.application
      @app.call(env)
    end
138894
protected function initializeCurrentUsername()
    {
        if (isset($this->currentUsername)) {
            return;
        }

        $currentUser = $this->userDomainService->getCurrentUser();
        if (!$currentUser instanceof User) {
            return;
        }

        $this->currentUsername = $this->userDomainService->getUsername($currentUser);
    }
465698
def get_subdomains_owned_by_address(self, owner, cur=None):
        
        get_cmd = "SELECT fully_qualified_subdomain, MAX(sequence) FROM {} WHERE owner = ? AND accepted=1 GROUP BY fully_qualified_subdomain".format(self.subdomain_table)

        cursor = None
        if cur is None:
            cursor = self.conn.cursor()
        else:
            cursor = cur

        db_query_execute(cursor, get_cmd, (owner,))

        try:
            return [ x['fully_qualified_subdomain'] for x in cursor.fetchall() ]
        except Exception as e:
            if BLOCKSTACK_DEBUG:
                log.exception(e)

            return []
104278
@Override
    public final void afterPropertiesSet() throws Exception {
        if (this.getLocator() != null) {
            this.logger.warn(
                    "Static "
                            + this.getClass().getName()
                            + " reference has already been set and setInstance is being called");
        }
        this.setLocator(this);
    }
469674
private void setRegionOrEndPoint() {
        String regionName = getParamString("ddb_region");
        if (regionName != null) {
            Regions regionEnum = Regions.fromName(regionName);
            Utils.require(regionEnum != null, "Unknown 'ddb_region': " + regionName);
            m_logger.info("Using region: {}", regionName);
            m_ddbClient.setRegion(Region.getRegion(regionEnum));
        } else {
            String ddbEndpoint = getParamString("ddb_endpoint");
            Utils.require(ddbEndpoint != null,
                          "Either 'ddb_region' or 'ddb_endpoint' must be defined for tenant: " + m_tenant.getName());
            m_logger.info("Using endpoint: {}", ddbEndpoint);
            m_ddbClient.setEndpoint(ddbEndpoint);
        }
    }
99937
function (contractAddress) {
  this.contractAddress = contractAddress;

  if (this.contractAddress) {
    stPrimeContractObj.options.address = this.contractAddress;
  }

  //stPrimeContractObj.setProvider(web3Provider.currentProvider);

  this.currContract = stPrimeContractObj;
}
1170754
def alloc_retrieve_subnet_info(self, tenant_id, direc):
        
        serv_obj = self.get_service_obj(tenant_id)
        subnet_dict = self.retrieve_dcnm_subnet_info(tenant_id, direc)
        if subnet_dict:
            return subnet_dict
        ip_subnet_dict = self.get_next_ip(tenant_id, direc)
        subnet_dict = self.fill_dcnm_subnet_info(
            tenant_id, ip_subnet_dict.get('subnet'),
            ip_subnet_dict.get('start'), ip_subnet_dict.get('end'),
            ip_subnet_dict.get('gateway'), ip_subnet_dict.get('sec_gateway'),
            direc)
        serv_obj.store_dcnm_subnet_dict(subnet_dict, direc)
        return subnet_dict
324308
def is_subdomain(self, other):
        
        compared = other.value if hasattr(other, 'value') else other
        try:
            return self.value.is_subdomain(compared)
        except AttributeError:
            return False
281362
def get_in_net_id(cls, tenant_id):
        
        if 'in' not in cls.ip_db_obj:
            LOG.error("Fabric not prepared for tenant %s", tenant_id)
            return None
        db_obj = cls.ip_db_obj.get('in')
        in_subnet_dict = cls.get_in_ip_addr(tenant_id)
        sub = db_obj.get_subnet(in_subnet_dict.get('subnet'))
        return sub.network_id
1163240
public Request<Tenant> update(Tenant tenant) {
        Asserts.assertNotNull(tenant, "tenant");

        String url = baseUrl
                .newBuilder()
                .addPathSegments("api/v2/tenants/settings")
                .build()
                .toString();

        CustomRequest<Tenant> request = new CustomRequest<>(client, url, "PATCH", new TypeReference<Tenant>() {
        });
        request.addHeader("Authorization", "Bearer " + apiToken);
        request.setBody(tenant);
        return request;
    }
958363
def subdomain?(*jids)
      !jids.flatten.index do |jid|
        !component?(jid) && !pubsub?(jid)
      end
    end
619275
private Persona establishOwner(org.hawkular.accounts.api.model.Resource resource, Persona current) {
        while (resource != null && resource.getPersona() == null) {
            resource = resource.getParent();
        }

        if (resource != null && resource.getPersona().equals(current)) {
            current = null;
        }

        return current;
    }