Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

share helpers for gc #271

Merged
merged 2 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions extensions/lifecycle/tasks/LifecycleObjectTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const BackbeatTask = require('../../../lib/tasks/BackbeatTask');
const async = require('async');
const getVaultCredentials =
require('../../../lib/credentials/getVaultCredentials');
const attachReqUids =
require('../../replication/utils/attachReqUids');
const { attachReqUids } = require('../../../lib/clients/utils');


class LifecycleObjectTask extends BackbeatTask {
Expand Down
2 changes: 1 addition & 1 deletion extensions/lifecycle/tasks/LifecycleTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const async = require('async');
const { errors } = require('arsenal');

const attachReqUids = require('../../replication/utils/attachReqUids');
const { attachReqUids } = require('../../../lib/clients/utils');
const BackbeatTask = require('../../../lib/tasks/BackbeatTask');

const RETRYTIMEOUTS = 300;
Expand Down
2 changes: 1 addition & 1 deletion extensions/replication/tasks/MultipleBackendTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const jsutil = require('arsenal').jsutil;
const ObjectMDLocation = require('arsenal').models.ObjectMDLocation;

const ReplicateObject = require('./ReplicateObject');
const attachReqUids = require('../utils/attachReqUids');
const { attachReqUids } = require('../../../lib/clients/utils');

const MPU_CONC_LIMIT = 10;
const MPU_GCP_MAX_PARTS = 1024;
Expand Down
16 changes: 6 additions & 10 deletions extensions/replication/tasks/ReplicateObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ const ObjectMDLocation = require('arsenal').models.ObjectMDLocation;

const BackbeatClient = require('../../../lib/clients/BackbeatClient');

const attachReqUids = require('../utils/attachReqUids');
const { attachReqUids } = require('../../../lib/clients/utils');
const BackbeatTask = require('../../../lib/tasks/BackbeatTask');
const {
StaticFileAccountCredentials,
ProvisionedServiceAccountCredentials,
} = require('../../../lib/credentials/AccountCredentials');
const { getAccountCredentials } =
require('../../../lib/credentials/AccountCredentials');
const RoleCredentials =
require('../../../lib/credentials/RoleCredentials');

Expand Down Expand Up @@ -49,11 +47,9 @@ class ReplicateObject extends BackbeatTask {
}

_createCredentials(where, authConfig, roleArn, log) {
if (authConfig.type === 'account') {
return new StaticFileAccountCredentials(authConfig, log);
}
if (authConfig.type === 'service') {
return new ProvisionedServiceAccountCredentials(authConfig, log);
const accountCredentials = getAccountCredentials(authConfig, log);
if (accountCredentials) {
return accountCredentials;
}
let vaultclient;
if (where === 'source') {
Expand Down
16 changes: 6 additions & 10 deletions extensions/replication/tasks/UpdateReplicationStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const jsutil = require('arsenal').jsutil;

const ObjectQueueEntry = require('../../replication/utils/ObjectQueueEntry');
const BackbeatClient = require('../../../lib/clients/BackbeatClient');
const attachReqUids = require('../utils/attachReqUids');
const { attachReqUids } = require('../../../lib/clients/utils');
const BackbeatTask = require('../../../lib/tasks/BackbeatTask');
const {
StaticFileAccountCredentials,
ProvisionedServiceAccountCredentials,
} = require('../../../lib/credentials/AccountCredentials');
const { getAccountCredentials } =
require('../../../lib/credentials/AccountCredentials');
const RoleCredentials =
require('../../../lib/credentials/RoleCredentials');

Expand All @@ -34,11 +32,9 @@ class UpdateReplicationStatus extends BackbeatTask {
}

_createCredentials(authConfig, roleArn, log) {
if (authConfig.type === 'account') {
return new StaticFileAccountCredentials(authConfig, log);
}
if (authConfig.type === 'service') {
return new ProvisionedServiceAccountCredentials(authConfig, log);
const accountCredentials = getAccountCredentials(authConfig, log);
if (accountCredentials) {
return accountCredentials;
}
const vaultclient = this.vaultclientCache.getClient('source:s3');
return new RoleCredentials(vaultclient, 'replication', roleArn, log);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ function attachReqUids(s3req, log) {
});
}

module.exports = attachReqUids;
module.exports = {
attachReqUids,
};
23 changes: 23 additions & 0 deletions lib/credentials/AccountCredentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,30 @@ class ProvisionedServiceAccountCredentials extends AccountCredentials {
}
}

/**
* gather account credentials object and return it
*
* @param {object} authConfig - authentication config params
* @param {string} authConfig.type - type of authentication -
* supported are 'account' for static file accounts, and 'service' for
* externally provisioned accounts through Orbit
* @param {string} authConfig.account - account name
* @param {Logger} log - logger object
* @return {AWS.Credentials|null} credentials object, or null if
* authConfig.type is not 'account' or 'service'
*/
function getAccountCredentials(authConfig, log) {
if (authConfig.type === 'account') {
return new StaticFileAccountCredentials(authConfig, log);
}
if (authConfig.type === 'service') {
return new ProvisionedServiceAccountCredentials(authConfig, log);
}
return null;
}

module.exports = {
StaticFileAccountCredentials,
ProvisionedServiceAccountCredentials,
getAccountCredentials,
};