microsoft-azure-storage/src/com/microsoft/azure/storage/CloudStorageAccount.java
private static CloudStorageAccount tryConfigureServiceAccount(final Map<String, String> settings)
            throws URISyntaxException, InvalidKeyException {

        ConnectionStringFilter endpointsOptional =
                optional(
                        BLOB_ENDPOINT_NAME, BLOB_SECONDARY_ENDPOINT_NAME,
                        QUEUE_ENDPOINT_NAME, QUEUE_SECONDARY_ENDPOINT_NAME,
                        TABLE_ENDPOINT_NAME, TABLE_SECONDARY_ENDPOINT_NAME,
                        FILE_ENDPOINT_NAME, FILE_SECONDARY_ENDPOINT_NAME
                );

        ConnectionStringFilter primaryEndpointRequired =
                atLeastOne(
                        BLOB_ENDPOINT_NAME,
                        QUEUE_ENDPOINT_NAME,
                        TABLE_ENDPOINT_NAME,
                        FILE_ENDPOINT_NAME
                );

        ConnectionStringFilter secondaryEndpointsOptional =
                optional(
                        BLOB_SECONDARY_ENDPOINT_NAME,
                        QUEUE_SECONDARY_ENDPOINT_NAME,
                        TABLE_SECONDARY_ENDPOINT_NAME,
                        FILE_SECONDARY_ENDPOINT_NAME
                );

        ConnectionStringFilter automaticEndpointsMatchSpec =
                matchesExactly(matchesAll(
                        matchesOne(
                                matchesAll(allRequired(ACCOUNT_KEY_NAME)), // Key + Name, Endpoints optional
                                allRequired(SHARED_ACCESS_SIGNATURE_NAME) // SAS + Name, Endpoints optional
                        ),
                        allRequired(ACCOUNT_NAME_NAME), // Name required to automatically create URIs
                        endpointsOptional,
                        optional(DEFAULT_ENDPOINTS_PROTOCOL_NAME, ENDPOINT_SUFFIX_NAME)
                ));

        ConnectionStringFilter explicitEndpointsMatchSpec =
                matchesExactly(matchesAll( // Any Credentials, Endpoints must be explicitly declared
                        validCredentials,
                        primaryEndpointRequired,
                        secondaryEndpointsOptional
                ));

        Boolean matchesAutomaticEndpointsSpec = matchesSpecification(settings, automaticEndpointsMatchSpec);
        Boolean matchesExplicitEndpointsSpec = matchesSpecification(settings, explicitEndpointsMatchSpec);

        if (matchesAutomaticEndpointsSpec || matchesExplicitEndpointsSpec) {
            if (matchesAutomaticEndpointsSpec && !settings.containsKey(DEFAULT_ENDPOINTS_PROTOCOL_NAME)) {
                settings.put(DEFAULT_ENDPOINTS_PROTOCOL_NAME, "https");
            }

            String blobEndpoint = settingOrDefault(settings, BLOB_ENDPOINT_NAME);
            String queueEndpoint = settingOrDefault(settings, QUEUE_ENDPOINT_NAME);
            String tableEndpoint = settingOrDefault(settings, TABLE_ENDPOINT_NAME);
            String fileEndpoint = settingOrDefault(settings, FILE_ENDPOINT_NAME);
            String blobSecondaryEndpoint = settingOrDefault(settings, BLOB_SECONDARY_ENDPOINT_NAME);
            String queueSecondaryEndpoint = settingOrDefault(settings, QUEUE_SECONDARY_ENDPOINT_NAME);
            String tableSecondaryEndpoint = settingOrDefault(settings, TABLE_SECONDARY_ENDPOINT_NAME);
            String fileSecondaryEndpoint = settingOrDefault(settings, FILE_SECONDARY_ENDPOINT_NAME);

            // if secondary is specified, primary must also be specified

            if (
                    isValidEndpointPair(blobEndpoint, blobSecondaryEndpoint)
                            && isValidEndpointPair(queueEndpoint, queueSecondaryEndpoint)
                            && isValidEndpointPair(tableEndpoint, tableSecondaryEndpoint)
                            && isValidEndpointPair(fileEndpoint, fileSecondaryEndpoint)
                    ) {
                CloudStorageAccount accountInformation =
                        new CloudStorageAccount(
                                StorageCredentials.tryParseCredentials(settings),
                                getStorageUri(settings, SR.BLOB, BLOB_ENDPOINT_NAME, BLOB_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec),
                                getStorageUri(settings, SR.QUEUE, QUEUE_ENDPOINT_NAME, QUEUE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec),
                                getStorageUri(settings, SR.TABLE, TABLE_ENDPOINT_NAME, TABLE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec),
                                getStorageUri(settings, SR.FILE, FILE_ENDPOINT_NAME, FILE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec)
                        );

                accountInformation.isBlobEndpointDefault = blobEndpoint == null;
                accountInformation.isFileEndpointDefault = fileEndpoint == null;
                accountInformation.isQueueEndpointDefault = queueEndpoint == null;
                accountInformation.isTableEndpointDefault = tableEndpoint == null;

                accountInformation.endpointSuffix = settingOrDefault(settings, ENDPOINT_SUFFIX_NAME);

                accountInformation.accountName = settingOrDefault(settings, ACCOUNT_NAME_NAME);

                return accountInformation;
            }
        }

        return null;
    }
private static CloudStorageAccount tryConfigureServiceAccount(final Map<String, String> settings)
            throws URISyntaxException, InvalidKeyException {

        ConnectionStringFilter endpointsOptional =
                optional(
                        BLOB_ENDPOINT_NAME, BLOB_SECONDARY_ENDPOINT_NAME,
                        QUEUE_ENDPOINT_NAME, QUEUE_SECONDARY_ENDPOINT_NAME,
                        TABLE_ENDPOINT_NAME, TABLE_SECONDARY_ENDPOINT_NAME,
                        FILE_ENDPOINT_NAME, FILE_SECONDARY_ENDPOINT_NAME
                );

        ConnectionStringFilter primaryEndpointRequired =
                atLeastOne(
                        BLOB_ENDPOINT_NAME,
                        QUEUE_ENDPOINT_NAME,
                        TABLE_ENDPOINT_NAME,
                        FILE_ENDPOINT_NAME
                );

        ConnectionStringFilter secondaryEndpointsOptional =
                optional(
                        BLOB_SECONDARY_ENDPOINT_NAME,
                        QUEUE_SECONDARY_ENDPOINT_NAME,
                        TABLE_SECONDARY_ENDPOINT_NAME,
                        FILE_SECONDARY_ENDPOINT_NAME
                );

        ConnectionStringFilter automaticEndpointsMatchSpec =
                matchesExactly(matchesAll(
                        matchesOne(
                                matchesAll(allRequired(ACCOUNT_KEY_NAME)), // Key + Name, Endpoints optional
                                allRequired(SHARED_ACCESS_SIGNATURE_NAME) // SAS + Name, Endpoints optional
                        ),
                        allRequired(ACCOUNT_NAME_NAME), // Name required to automatically create URIs
                        endpointsOptional,
                        optional(DEFAULT_ENDPOINTS_PROTOCOL_NAME, ENDPOINT_SUFFIX_NAME)
                ));

        ConnectionStringFilter explicitEndpointsMatchSpec =
                matchesExactly(matchesAll( // Any Credentials, Endpoints must be explicitly declared
                        validCredentials,
                        primaryEndpointRequired,
                        secondaryEndpointsOptional
                ));

        Boolean matchesAutomaticEndpointsSpec = matchesSpecification(settings, automaticEndpointsMatchSpec);
        Boolean matchesExplicitEndpointsSpec = matchesSpecification(settings, explicitEndpointsMatchSpec);

        if (matchesAutomaticEndpointsSpec || matchesExplicitEndpointsSpec) {
            if (matchesAutomaticEndpointsSpec && !settings.containsKey(DEFAULT_ENDPOINTS_PROTOCOL_NAME)) {
                settings.put(DEFAULT_ENDPOINTS_PROTOCOL_NAME, "https");
            }

            String blobEndpoint = settingOrDefault(settings, BLOB_ENDPOINT_NAME);
            String queueEndpoint = settingOrDefault(settings, QUEUE_ENDPOINT_NAME);
            String tableEndpoint = settingOrDefault(settings, TABLE_ENDPOINT_NAME);
            String fileEndpoint = settingOrDefault(settings, FILE_ENDPOINT_NAME);
            String blobSecondaryEndpoint = settingOrDefault(settings, BLOB_SECONDARY_ENDPOINT_NAME);
            String queueSecondaryEndpoint = settingOrDefault(settings, QUEUE_SECONDARY_ENDPOINT_NAME);
            String tableSecondaryEndpoint = settingOrDefault(settings, TABLE_SECONDARY_ENDPOINT_NAME);
            String fileSecondaryEndpoint = settingOrDefault(settings, FILE_SECONDARY_ENDPOINT_NAME);

            // if secondary is specified, primary must also be specified

            if (
                    isValidEndpointPair(blobEndpoint, blobSecondaryEndpoint)
                            && isValidEndpointPair(queueEndpoint, queueSecondaryEndpoint)
                            && isValidEndpointPair(tableEndpoint, tableSecondaryEndpoint)
                            && isValidEndpointPair(fileEndpoint, fileSecondaryEndpoint)
                    ) {
                CloudStorageAccount accountInformation =
                        new CloudStorageAccount(
                                StorageCredentials.tryParseCredentials(settings),
                                getStorageUri(settings, SR.BLOB, BLOB_ENDPOINT_NAME, BLOB_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec),
                                getStorageUri(settings, SR.QUEUE, QUEUE_ENDPOINT_NAME, QUEUE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec),
                                getStorageUri(settings, SR.TABLE, TABLE_ENDPOINT_NAME, TABLE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec),
                                getStorageUri(settings, SR.FILE, FILE_ENDPOINT_NAME, FILE_SECONDARY_ENDPOINT_NAME, matchesAutomaticEndpointsSpec)
                        );

                accountInformation.isBlobEndpointDefault = blobEndpoint == null;
                accountInformation.isFileEndpointDefault = fileEndpoint == null;
                accountInformation.isQueueEndpointDefault = queueEndpoint == null;
                accountInformation.isTableEndpointDefault = tableEndpoint == null;

                accountInformation.endpointSuffix = settingOrDefault(settings, ENDPOINT_SUFFIX_NAME);

                accountInformation.accountName = settingOrDefault(settings, ACCOUNT_NAME_NAME);

                return accountInformation;
            }
        }

        return null;
    }
private static CloudStorageAccount tryConfigureServiceAccount ( final Map < String , String > settings ) throws URISyntaxException , InvalidKeyException { ConnectionStringFilter endpointsOptional = optional ( BLOB_ENDPOINT_NAME , BLOB_SECONDARY_ENDPOINT_NAME , QUEUE_ENDPOINT_NAME , QUEUE_SECONDARY_ENDPOINT_NAME , TABLE_ENDPOINT_NAME , TABLE_SECONDARY_ENDPOINT_NAME , FILE_ENDPOINT_NAME , FILE_SECONDARY_ENDPOINT_NAME ) ; ConnectionStringFilter primaryEndpointRequired = atLeastOne ( BLOB_ENDPOINT_NAME , QUEUE_ENDPOINT_NAME , TABLE_ENDPOINT_NAME , FILE_ENDPOINT_NAME ) ; ConnectionStringFilter secondaryEndpointsOptional = optional ( BLOB_SECONDARY_ENDPOINT_NAME , QUEUE_SECONDARY_ENDPOINT_NAME , TABLE_SECONDARY_ENDPOINT_NAME , FILE_SECONDARY_ENDPOINT_NAME ) ; ConnectionStringFilter automaticEndpointsMatchSpec = matchesExactly ( matchesAll ( matchesOne ( matchesAll ( allRequired ( ACCOUNT_KEY_NAME ) ) , // Key + Name, Endpoints optional allRequired ( SHARED_ACCESS_SIGNATURE_NAME ) // SAS + Name, Endpoints optional ) , allRequired ( ACCOUNT_NAME_NAME ) , // Name required to automatically create URIs endpointsOptional , optional ( DEFAULT_ENDPOINTS_PROTOCOL_NAME , ENDPOINT_SUFFIX_NAME ) ) ) ; ConnectionStringFilter explicitEndpointsMatchSpec = matchesExactly ( matchesAll ( // Any Credentials, Endpoints must be explicitly declared validCredentials , primaryEndpointRequired , secondaryEndpointsOptional ) ) ; Boolean matchesAutomaticEndpointsSpec = matchesSpecification ( settings , automaticEndpointsMatchSpec ) ; Boolean matchesExplicitEndpointsSpec = matchesSpecification ( settings , explicitEndpointsMatchSpec ) ; if ( matchesAutomaticEndpointsSpec || matchesExplicitEndpointsSpec ) { if ( matchesAutomaticEndpointsSpec && ! settings . containsKey ( DEFAULT_ENDPOINTS_PROTOCOL_NAME ) ) { settings . put ( DEFAULT_ENDPOINTS_PROTOCOL_NAME , "https" ) ; } String blobEndpoint = settingOrDefault ( settings , BLOB_ENDPOINT_NAME ) ; String queueEndpoint = settingOrDefault ( settings , QUEUE_ENDPOINT_NAME ) ; String tableEndpoint = settingOrDefault ( settings , TABLE_ENDPOINT_NAME ) ; String fileEndpoint = settingOrDefault ( settings , FILE_ENDPOINT_NAME ) ; String blobSecondaryEndpoint = settingOrDefault ( settings , BLOB_SECONDARY_ENDPOINT_NAME ) ; String queueSecondaryEndpoint = settingOrDefault ( settings , QUEUE_SECONDARY_ENDPOINT_NAME ) ; String tableSecondaryEndpoint = settingOrDefault ( settings , TABLE_SECONDARY_ENDPOINT_NAME ) ; String fileSecondaryEndpoint = settingOrDefault ( settings , FILE_SECONDARY_ENDPOINT_NAME ) ; // if secondary is specified, primary must also be specified if ( isValidEndpointPair ( blobEndpoint , blobSecondaryEndpoint ) && isValidEndpointPair ( queueEndpoint , queueSecondaryEndpoint ) && isValidEndpointPair ( tableEndpoint , tableSecondaryEndpoint ) && isValidEndpointPair ( fileEndpoint , fileSecondaryEndpoint ) ) { CloudStorageAccount accountInformation = new CloudStorageAccount ( StorageCredentials . tryParseCredentials ( settings ) , getStorageUri ( settings , SR . BLOB , BLOB_ENDPOINT_NAME , BLOB_SECONDARY_ENDPOINT_NAME , matchesAutomaticEndpointsSpec ) , getStorageUri ( settings , SR . QUEUE , QUEUE_ENDPOINT_NAME , QUEUE_SECONDARY_ENDPOINT_NAME , matchesAutomaticEndpointsSpec ) , getStorageUri ( settings , SR . TABLE , TABLE_ENDPOINT_NAME , TABLE_SECONDARY_ENDPOINT_NAME , matchesAutomaticEndpointsSpec ) , getStorageUri ( settings , SR . FILE , FILE_ENDPOINT_NAME , FILE_SECONDARY_ENDPOINT_NAME , matchesAutomaticEndpointsSpec ) ) ; accountInformation . isBlobEndpointDefault = blobEndpoint == null ; accountInformation . isFileEndpointDefault = fileEndpoint == null ; accountInformation . isQueueEndpointDefault = queueEndpoint == null ; accountInformation . isTableEndpointDefault = tableEndpoint == null ; accountInformation . endpointSuffix = settingOrDefault ( settings , ENDPOINT_SUFFIX_NAME ) ; accountInformation . accountName = settingOrDefault ( settings , ACCOUNT_NAME_NAME ) ; return accountInformation ; } } return null ; }
Evaluates connection settings and configures a CloudStorageAccount accordingly.

@param settings
A <code>java.util.Map</code> of key/value pairs which represents
the connection settings.
@return A {@link CloudStorageAccount} represented by the settings.
@throws URISyntaxException
if the connectionString specifies an invalid URI.
@throws InvalidKeyException
if credentials in the connection settings contain an invalid key.
Evaluates connection settings and configures a CloudStorageAccount accordingly .