Skip to content

Commit 19aa5cd

Browse files
committed
Modify ordered auth selection in azureBlobFactory and azureQueueStore
This is to make it consistent with the storageQueueManager.
1 parent 4b67c4a commit 19aa5cd

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

config/cdConfig.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const cd_azblob = {
77
connection: config.get('CRAWLER_AZBLOB_CONNECTION_STRING'),
88
container: config.get('CRAWLER_AZBLOB_CONTAINER_NAME'),
99
account: config.get('CRAWLER_AZBLOB_ACCOUNT_NAME'),
10-
spnAuth: config.get('CRAWLER_AZBLOB_SPN_AUTH')
10+
spnAuth: config.get('CRAWLER_AZBLOB_SPN_AUTH'),
11+
isSpnAuth: config.get('CRAWLER_AZBLOB_IS_SPN_AUTH') || false
1112
}
1213

1314
const githubToken = config.get('CRAWLER_GITHUB_TOKEN')
@@ -115,7 +116,8 @@ module.exports = {
115116
connectionString: cd_azblob.connection,
116117
account: cd_azblob.account,
117118
queueName: config.get('CRAWLER_HARVESTS_QUEUE_NAME') || 'harvests',
118-
spnAuth: config.get('CRAWLER_HARVESTS_QUEUE_SPN_AUTH')
119+
spnAuth: config.get('CRAWLER_HARVESTS_QUEUE_SPN_AUTH'),
120+
isSpnAuth: config.get('CRAWLER_HARVESTS_QUEUE_IS_SPN_AUTH') || false
119121
},
120122
'cd(azblob)': cd_azblob,
121123
'cd(file)': cd_file

ghcrawler/providers/queuing/storageQueueManager.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class StorageQueueManager {
2121

2222
const { account, spnAuth, isSpnAuth } = options
2323
if (isSpnAuth) {
24+
options.logger.info('using service principal credentials in storageQueueManager')
2425
const authParsed = JSON.parse(spnAuth)
2526
this.client = new QueueServiceClient(
2627
`https://${account}.queue.core.windows.net`,
@@ -31,10 +32,12 @@ class StorageQueueManager {
3132
}
3233

3334
if (connectionString) {
35+
options.logger.info('using connection string in storageQueueManager')
3436
this.client = QueueServiceClient.fromConnectionString(connectionString, pipelineOptions)
3537
return
3638
}
3739

40+
options.logger.info('using default credentials in storageQueueManager')
3841
this.client = new QueueServiceClient(
3942
`https://${account}.queue.core.windows.net`,
4043
new DefaultAzureCredential(),

ghcrawler/providers/storage/azureBlobFactory.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ const { DefaultAzureCredential, ClientSecretCredential } = require('@azure/ident
1313
* @param {string} options.container
1414
* @param {object} options.logger
1515
* @param {object} options.spnAuth
16+
* @param {object} options.isSpnAuth
1617
*/
1718
module.exports = options => {
1819
options.logger.info('creating azure storage store')
19-
const { account, connection, container, spnAuth } = options
20+
const { account, connection, container, spnAuth, isSpnAuth } = options
2021

2122
const pipelineOptions = {
2223
retryOptions: {
@@ -27,22 +28,28 @@ module.exports = options => {
2728
retryPolicyType: StorageRetryPolicyType.EXPONENTIAL
2829
}
2930
}
30-
3131
let blobServiceClient
32-
if (connection) {
33-
options.logger.info('using connection string')
34-
blobServiceClient = BlobServiceClient.fromConnectionString(connection, pipelineOptions)
32+
33+
if (isSpnAuth) {
34+
options.logger.info('using service principal credentials in azureBlobFactory')
35+
const authParsed = JSON.parse(spnAuth)
36+
blobServiceClient = new BlobServiceClient(
37+
`https://${account}.queue.core.windows.net`,
38+
new ClientSecretCredential(authParsed.tenantId, authParsed.clientId, authParsed.clientSecret),
39+
pipelineOptions
40+
)
3541
} else {
36-
let credential
37-
if (spnAuth) {
38-
const authParsed = JSON.parse(spnAuth)
39-
credential = new ClientSecretCredential(authParsed.tenantId, authParsed.clientId, authParsed.clientSecret)
40-
options.logger.info('using service principal credentials')
42+
if (connection) {
43+
options.logger.info('using connection string in azureBlobFactory')
44+
blobServiceClient = BlobServiceClient.fromConnectionString(connection, pipelineOptions)
4145
} else {
42-
credential = new DefaultAzureCredential()
43-
options.logger.info('using default credentials')
46+
options.logger.info('using default credentials in azureBlobFactory')
47+
blobServiceClient = new BlobServiceClient(
48+
`https://${account}.queue.core.windows.net`,
49+
new DefaultAzureCredential(),
50+
pipelineOptions
51+
)
4452
}
45-
blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net`, credential, pipelineOptions)
4653
}
4754

4855
const containerClient = blobServiceClient.getContainerClient(container)

providers/store/azureQueueStore.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AzureStorageQueue {
1010
this.queueName = options.queueName
1111
this.logger = options.logger
1212

13-
const { connectionString, account, spnAuth } = options
13+
const { connectionString, account, spnAuth, isSpnAuth } = options
1414

1515
const pipelineOptions = {
1616
retryOptions: {
@@ -21,18 +21,30 @@ class AzureStorageQueue {
2121
retryPolicyType: StorageRetryPolicyType.FIXED
2222
}
2323
}
24+
25+
if (isSpnAuth) {
26+
options.logger.info('using service principal credentials in azureQueueStore')
27+
const authParsed = JSON.parse(spnAuth)
28+
this.client = new QueueServiceClient(
29+
`https://${account}.queue.core.windows.net`,
30+
new ClientSecretCredential(authParsed.tenantId, authParsed.clientId, authParsed.clientSecret),
31+
pipelineOptions
32+
)
33+
return
34+
}
35+
2436
if (connectionString) {
37+
options.logger.info('using connection string in azureQueueStore')
2538
this.client = QueueServiceClient.fromConnectionString(connectionString, pipelineOptions)
26-
} else {
27-
let credential
28-
if (spnAuth) {
29-
const authParsed = JSON.parse(spnAuth)
30-
credential = new ClientSecretCredential(authParsed.tenantId, authParsed.clientId, authParsed.clientSecret)
31-
} else {
32-
credential = new DefaultAzureCredential()
33-
}
34-
this.client = new QueueServiceClient(`https://${account}.queue.core.windows.net`, credential, pipelineOptions)
39+
return
3540
}
41+
42+
options.logger.info('using default credentials in azureQueueStore')
43+
this.client = new QueueServiceClient(
44+
`https://${account}.queue.core.windows.net`,
45+
new DefaultAzureCredential(),
46+
pipelineOptions
47+
)
3648
}
3749

3850
async connect() {

0 commit comments

Comments
 (0)