Skip to content

Commit

Permalink
Workload entry expiry features
Browse files Browse the repository at this point in the history
Signed-off-by: Maia Iyer <maia.raj.iyer@gmail.com>
  • Loading branch information
maia-iyer authored and lumjjb committed Aug 24, 2021
1 parent a64c80a commit 58056c6
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ class AgentDashboardTable extends React.Component {
}

agentList() {
if ((typeof this.props.globalEntries.globalEntriesList === 'undefined') ||
(typeof this.props.globalAgents.globalAgentsList === 'undefined')) {
if ((typeof this.props.globalAgents.globalAgentsList === 'undefined')) {
return [];
}

let agentEntriesDict = this.SpiffeHelper.getAgentsEntries(this.props.globalAgents.globalAgentsList, this.props.globalEntries.globalEntriesList)
let agentEntriesDict = this.SpiffeHelper.getAgentsEntries(this.props.globalAgents.globalAgentsList, this.props.globalEntries.globalEntriesList) // TODO this.props.globalEntries.globalEntriesList may be undefined if there are no entries
return this.props.globalAgents.globalAgentsList.map(currentAgent => {
return this.getChildEntries(currentAgent, agentEntriesDict);
})
Expand Down
157 changes: 143 additions & 14 deletions tornjak-frontend/src/components/entry-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ class CreateEntry extends Component {
this.prepareSelectorsList = this.prepareSelectorsList.bind(this);
this.onChangeSelectorsRecommended = this.onChangeSelectorsRecommended.bind(this);
this.onChangeTtl = this.onChangeTtl.bind(this);
this.onChangeExpiresAt = this.onChangeExpiresAt.bind(this);
this.onChangeExpiryOption = this.onChangeExpiryOption.bind(this);
this.expiryTimeUpdate = this.expiryTimeUpdate.bind(this);
this.onChangeExpiresAtSeconds = this.onChangeExpiresAtSeconds.bind(this);
this.isValidDate = this.isValidDate.bind(this);
this.updateValidDateAndTime = this.updateValidDateAndTime.bind(this);
this.onChangeExpiresAtTime = this.onChangeExpiresAtTime.bind(this);
this.onChangeExpiresAtDate = this.onChangeExpiresAtDate.bind(this);
this.onChangeFederatesWith = this.onChangeFederatesWith.bind(this);
this.onChangeDownStream = this.onChangeDownStream.bind(this);
this.onChangeDnsNames = this.onChangeDnsNames.bind(this);
Expand All @@ -57,7 +63,13 @@ class CreateEntry extends Component {
adminFlag: false,

ttl: 0,
expiryOption: "None",
expiryOptionList: ["None", "Seconds Since Epoch", "Date/Time"],
expiryDate: "1/1/2021",
expiryTime: "00:00",
expiresAt: 0,
expiryUnsafe: false,
expiryInvalid: false,
dnsNames: [],
federatesWith: [],
downstream: false,
Expand Down Expand Up @@ -204,12 +216,65 @@ class CreateEntry extends Component {
});
}

onChangeExpiresAt(e) {
onChangeExpiryOption(e) {
this.setState({
expiresAt: Number(e.imaginaryTarget.value)
expiresAt: 0,
expiryOption: e.selectedItem,
expiryUnsafe: false,
expiryInvalid: false
});
}

isValidExpiryTime(seconds) {
const JSMaxSafeTime = 8640000000000 // JS cannot represent times safely larger than this
return seconds > 0 && seconds <= JSMaxSafeTime
}

expiryTimeUpdate(seconds) {
this.setState({
expiresAt: seconds,
expiryUnsafe: !this.isValidExpiryTime(seconds)
})
}

onChangeExpiresAtSeconds(e) {
var seconds = Number(e.imaginaryTarget.value)
this.expiryTimeUpdate(seconds)
}

// TODO some odd behavior with dates like February 33 exists
isValidDate(d) { // date is successfully translated in Javascript
return d instanceof Date && isFinite(d)
}

updateValidDateAndTime(d, t) {
var testDate = new Date(d + ", " + t)
this.setState({ // should always reflect what the user sees
expiryDate: d,
expiryTime: t
})
if (this.isValidDate(testDate)) {
this.setState({
expiryInvalid: false,
})
var seconds = Math.round(testDate / 1000)
this.expiryTimeUpdate(seconds)
console.log(d, t, this.state.expiryDate, this.state.expiryTime)
return
}
this.setState({
expiryInvalid: true,
})
}

onChangeExpiresAtDate(e) {
this.updateValidDateAndTime(e.target.value, this.state.expiryTime)
}

onChangeExpiresAtTime(e) {
this.updateValidDateAndTime(this.state.expiryDate, e.target.value)
}

onChangeDownStream = selected => {
var sid = selected;
this.setState({
Expand Down Expand Up @@ -408,6 +473,7 @@ class CreateEntry extends Component {
newTags.splice(currPos, 1);
newTags.splice(newPos, 0, tag);


// re-render
this.setState({ tags: newTags });
}
Expand Down Expand Up @@ -605,17 +671,80 @@ class CreateEntry extends Component {
/>
</div>
<div className="expiresAt-input">
<NumberInput
helperText="Entry expires at (seconds since Unix epoch)"
id="expiresAt-input"
invalidText="Number is not valid"
label="Expires At"
//max={100}
min={0}
step={1}
value={0}
onChange={this.onChangeExpiresAt}
/>
<div className="expiry-drop-down">
<Dropdown
//aria-required="true"
//ariaLabel="expiry-drop-down"
id="expiry-drop-down"
items={this.state.expiryOptionList}
label="None"
defaultValue="None"
titleText="Entry Expiry"
helperText="Choose Entry Expiry Format"
onChange={this.onChangeExpiryOption}
/>
</div>
{this.state.expiryOption !== "None" && <div className="expiryEntryFields">
{this.state.expiryOption === "Seconds Since Epoch" &&
<div className="expiryOption-field">
<div className="expiryOption-entry">
<NumberInput
aria-required="true"
helperText="(seconds since Unix epoch)"
id="expiresAt-input"
invalidText="Number is not valid"
label="Enter expiry time [*required]"
min={1}
step={1}
onChange={this.onChangeExpiresAtSeconds}
/>
</div>
</div>
}
{this.state.expiryOption === "Date/Time" &&
<div className="expiryOption-field">
<div className="expiryOption-entry">
<TextInput
labelText="Enter expiry date [*required]"
helperText="mm/dd/yyyy or mm/dd/yyyyy"
placeholder="08/13/2345"
pattern={["^\\d{2}/\\d{2}/\\d{4,5}$"]}
onChange={this.onChangeExpiresAtDate}
required
/>
</div>
<div className="expiryOption-entry">
<TextInput
labelText="Enter local time [*required]"
helperText="00:00:00 - 23:59:59"
placeholder="hh:mm:ss"
pattern={["^([0-1]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$"]}
onChange={this.onChangeExpiresAtTime}
invalidText="NotGoodTime"
required
/>
</div>
</div>
}
</div>


}
{(this.state.expiryUnsafe || this.state.expiryInvalid) &&
<div role="alert">
<p className="failed-message">Warning: expiry time either in invalid format, is negative, or is too large. Submitting this time may result in undefined behavior.</p>
{this.state.expiryOption === "Seconds Since Epoch" && this.state.expiryUnsafe &&
<p className="failed-message">Seconds must be positive and less than 8640000000000</p>
}
{this.state.expiryOption === "Date/Time" && this.state.expiryUnsafe &&
<p className="failed-message">Date must be past January 1, 1970 @ 12:00AM GMT</p>
}
{this.state.expiryOption === "Date/Time" && this.state.expiryInvalid &&
<p className="failed-message">Date or time format is invalid</p>
}
</div>
}

</div>
<div className="federates-with-input-field">
<TextInput
Expand Down
4 changes: 4 additions & 0 deletions tornjak-frontend/src/components/spiffe-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class SpiffeHelper extends Component {
// n:1, this would reduce the total cost. This may be useful when
// performance is impacted.
getAgentsEntries (agents, entries) {
if (typeof entries === 'undefined') {
console.log("spiffe-helper.js: getAgentEntries: this should not happen, entries undefined`")
//return {};
}
let nodeEntries = entries.filter(e => e.parent_id.path === "/spire/server");
var lambdas = [];
var agentEntriesDict = {};
Expand Down
Loading

0 comments on commit 58056c6

Please sign in to comment.